-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoardDFSExploration.java
62 lines (52 loc) · 1.82 KB
/
BoardDFSExploration.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
56
57
58
59
60
61
62
package algs.blog.improving.main;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.Stack;
import algs.blog.graph.freeCell.Deal;
import algs.blog.graph.freeCell.DealIterator;
import algs.blog.graph.freeCell.FreeCellNode;
import algs.blog.graph.search.AnalyzeState;
import algs.blog.graph.search.DFS;
import algs.blog.graph.search.Result;
import algs.model.searchtree.IMove;
/**
* Must expand StackSize to run this one (also Heap space)
*
* -Xss32768k -Xmx1024m
*
* @author George Heineman
*/
public class BoardDFSExploration {
/**
* args[0] contains the name of a file in which one finds the
* list of games (one per line) that were not solved using the
* Staged Deepening
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// comparator to use.
Comparator<short[]> comp = FreeCellNode.comparator();
PrintWriter pw = new PrintWriter ("DFS-exploration.txt");
// iterate over all deals in this file.
for (DealIterator di = Deal.iterator(new File ("artifacts", "32000.txt")); di.hasNext(); ) {
// prepare the initial board. Skip those boards we don't want.
// Take care that board has already been advanced by iterator.
FreeCellNode fc = di.next();
pw.println(fc);
pw.flush();
System.out.println("working on: " + (di.getNextDealNumber()-1));
AnalyzeState st = new AnalyzeState();
DFS<short[]> dfs = new DFS<short[]>(st);
Result res = dfs.fullSearch(fc, Deal.goal(), comp);
Stack<IMove> sol = res.solution();
System.out.println("Solution has " + sol.size() + " moves.");
System.out.println(" Total number of states: " + dfs.getCounter());
st.report();
}
pw.close();
}
}