-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchableGraph.java
More file actions
76 lines (61 loc) · 1.66 KB
/
SearchableGraph.java
File metadata and controls
76 lines (61 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package test;
import java.util.HashMap;
import java.util.List;
public class SearchableGraph implements Searchable { // the graph we want to solve
Builder g;
State startstate;
HashMap<String, State> map; // hash of each vertex and is name
public SearchableGraph(Builder g, State startstate, HashMap<String, State> map) {
super();
this.g = g;
this.startstate = startstate;
this.map=map;
}
public SearchableGraph(Builder g, State startstate) {
super();
this.g = g;
this.startstate = startstate;
}
@Override
public State getInitialState() {
return startstate;
}
@Override
public List<Edge> getAllPossibleEdges(State s) { // possible edges of each vertex
return s.listOfChildren;
}
public List<State> getGraph(){
return g.getGraph();
}
public HashMap<String, State> getMap() {
return this.map;
}
public void printGraphWithEdges() {
for(State s : this.g.getGraph()) {
System.out.print("The Neighborã of:");
if(!s.listOfChildren.isEmpty()) {
for(Edge e: s.listOfChildren) {
System.out.print( e.getFather() +"-"+ "("+e.getWieght()+")"+"->"+e.getChild() +" ");
}
}else
{
System.out.print(s.name+ "--> none");
}
System.out.println();
}
}
public void printGraphWithVretxes() {
System.out.println("The graph is :");
for(State s: this.g.getGraph())
{
if(s.getNieboresList().isEmpty()) {
System.out.print(s.name + "-->none");
}else {
for(State child: s.getNieboresList() ) {
System.out.print(s.name + "-->" + child.name+" ");
}
}
System.out.println();
}
}
}