-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
67 lines (54 loc) · 2.18 KB
/
Main.java
File metadata and controls
67 lines (54 loc) · 2.18 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
import IA.ProbIA5.ProbIA5Board;
import IA.ProbIA5.ProbIA5GoalTest;
import IA.ProbIA5.ProbIA5HeuristicFunction;
import IA.ProbIA5.ProbIA5SuccesorFunction;
import aima.search.framework.GraphSearch;
import aima.search.framework.Problem;
import aima.search.framework.Search;
import aima.search.framework.SearchAgent;
import aima.search.informed.AStarSearch;
import aima.search.informed.IterativeDeepeningAStarSearch;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
public class Main {
public static void main(String[] args) throws Exception{
/**
* For a problem to be solvable:
* count(0,prob) % 2 == count(0,sol) %2
*/
int [] prob = new int []{1 ,0, 1, 1, 0};
int [] sol = new int[]{1, 1, 0, 1, 0};
ProbIA5Board board = new ProbIA5Board(prob, sol );
// Create the Problem object
Problem p = new Problem(board,
new ProbIA5SuccesorFunction(),
new ProbIA5GoalTest(),
new ProbIA5HeuristicFunction());
// Instantiate the search algorithm
// AStarSearch(new GraphSearch()) or IterativeDeepeningAStarSearch()
Search alg = new AStarSearch(new GraphSearch());
// Instantiate the SearchAgent object
SearchAgent agent = new SearchAgent(p, alg);
// We print the results of the search
System.out.println();
printActions(agent.getActions());
printInstrumentation(agent.getInstrumentation());
// You can access also to the goal state using the
// method getGoalState of class Search
}
private static void printInstrumentation(Properties properties) {
Iterator keys = properties.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
String property = properties.getProperty(key);
System.out.println(key + " : " + property);
}
}
private static void printActions(List actions) {
for (int i = 0; i < actions.size(); i++) {
String action = (String) actions.get(i);
System.out.println(action);
}
}
}