graph builders & searchers implement in JAVA
-
Define new state("state name") (state=node).
-
Add to each state the neighbors it leads to, with the function "addToNieboresList(STATE)".
-
Define new graphbuilder() ( for example - | Builder buffergraph= new Graphbuilder();|).
-
Add all the state that you made to the graph builder with the function "addToGraph(State)" (support in flowing programming).
-
Define new SearchableGraph( graphbuilder,state(the state we want to start with)).
-
For more examples please read the file "MainTrainBfs" line 10-32 or "DfsMainTrain" lines 10-24.
Congratulations you have a regular graph !!
- printGraphWithVretxes()- print the regular graph.
- getInitialState()- get the start state.
- getGraph()- get list of states that in the graph.
- Define new searcher = Bfs(),for example |Searcher Bfs=new Bfs();|.
- Use function search(SearchableGraph)- the function get a searchable graph and print the distance of the shortest path from the start. state.
3.For more examples please read the file "MainTrainBfs" line 10-35 and "BFS EXAMPLE.PNG".
- Define new searcher = Dfs(),for example |Searcher Dfs=new Dfs();|.
- Use function search(SearchableGraph)- the function gets searchable graph and prints the start time , end time and the father of each state in the shortest path from the start state.
3.For more examples please read the file "DfsMainTrain" line 10-26 and "DFS EXAMPLE.PNG".
- Define new arraylist of edges for exmpale |List bufferlist=new ArrayList();|.
- Add to the list new edges from one state according to your graph, every new edge get the | weight (int) |, | father (string) | and | child(string)| for exmpale |bufferlist.add(new Edge(33, "S", "A"));|.
- Define new state("state name",list of edges that we made in 1,2 (bufferlist)) (state=node).
- Remove all the buffer list |bufferlist.removeAll(bufferlist);|.
- Do 2-4 it for each state in the graph.
- Define new graphbuilder() ( for exmpale - | Builder buffergraph= new Graphbuilder();|).
- Define new hashmap<String,State> for example | HashMap<String , State> buffermap=new HashMap<String, State>();|.
- Add all the states with thier names to the map with put function | buffermap.put("S",S); |.
- Add all the state that you made to the graph builder with the function "addToGraph(State)" (support in flowing programing). 10.Define new SearchableGraph( graphbuilder,state(the state we want to start with),buffermap (the map with all the states)).
- For more exmpales please read the file "MainTrainDijkstra" line 10-49 or "MainTrainBellmanFord" lines 10-37.
Congratulations you have a weighted graph !!
- printGraphWithEdges()- print the graph with weights.
- getInitialState()- get the start state.
- getGraph()- get list of states that in the graph.
- getMap()- get the states map.
- getAllPossibleEdges(State s) - get array list of all the weighted edges that go from this specific state.
-
Define new searcher =BellmanFord ,for example |Searcher Bellman=new BellmanFord(); |.
-
Use function search(SearchableGraph)- the function gets searchable weighted graph and prints the short distance from the start state to any state.
-
For more exmpales please read the file "MainTrainBellmanFord" line 10-40 and "BELLMAN EXAMPLE.PNG".
-
Define new searcher = Dijkstra ,for example |Searcher dijkstra = new Dijkstra();|.
-
Use function search(SearchableGraph)- the function gets searchable weighted graph and prints the short distance from the start state to any state.
-
For more examples please read the file "MainTrainDijkstra" line 10-52 and "DIJKSTRA EXMPALE.PNG".
- This project it's just for practice and fun.
- I am aware of the Code smells, these issues will be fixed as soon as possible (I'm working on it).
- I intend to improve the project and add more searchers.