-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.java
55 lines (50 loc) · 1.95 KB
/
Main.java
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
import java.util.Scanner;
public class Main {
public static int nMissionaries, nCanniabals, capacity;
public static boolean timerFlag=false,nodeFlag=false;
public static int TIME_LIMIT=30000,NODE_LIMIT=30000000;
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Missionaries Cannibals BoatCapacity");
nMissionaries = sc.nextInt();
nCanniabals = sc.nextInt();
capacity = sc.nextInt();
node startNode = new node(nMissionaries, nCanniabals, false, 1);
node endNode = new node(0, 0, true, 99999);
long sTime = System.nanoTime();
BFS bfs = new BFS();
node ans = bfs.solve(startNode, endNode);
long diff = System.nanoTime() - sTime;
if (ans != null) {
System.out.println("Level:" + ans.level + ",Time:" + diff + "ns,Explored:" + bfs.explored + ",Expanded:" + bfs.expanded);
ans.printNode();
} else {
if(timerFlag)
System.out.println("Timeout");
else if(nodeFlag)
System.out.println("Explored node limit exceded");
else
System.out.println("No solutions found");
}
System.out.println("\n");
//dfs
nodeFlag=false;
timerFlag=false;
sTime = System.nanoTime();
DFS dfs = new DFS();
ans = dfs.solve(startNode, endNode);
diff = System.nanoTime() - sTime;
if (ans != null) {
System.out.println("Level:" + ans.level + ",Time:" + diff + "ns,Explored:" + dfs.explored + ",Expanded:" + dfs.expanded);
ans.printNode();
} else {
if(timerFlag)
System.out.println("Timeout");
else if(nodeFlag)
System.out.println("Explored node limit exceded");
else
System.out.println("No solutions found");
}
System.out.println("\n");
}
}