11package aima .gui .fx .demo .search ;
22
3+ import aima .core .environment .nqueens .AttackingPairsHeuristic ;
34import aima .core .environment .nqueens .NQueensBoard ;
45import aima .core .environment .nqueens .NQueensBoard .Config ;
56import aima .core .search .framework .Metrics ;
7+ import aima .core .search .framework .qsearch .GraphSearch ;
68import aima .core .search .framework .qsearch .TreeSearch ;
9+ import aima .core .search .informed .AStarSearch ;
710import aima .core .search .uninformed .DepthFirstSearch ;
811import aima .gui .fx .framework .IntegrableApplication ;
912import aima .gui .fx .framework .Parameter ;
1518import javafx .scene .layout .Pane ;
1619import javafx .scene .layout .StackPane ;
1720
21+ import java .util .Arrays ;
22+
1823
1924/**
2025 * Integrable application which demonstrates how different search strategies
2126 * solve the N-Queens problem.
22- *
27+ *
2328 * @author Ruediger Lunde
2429 *
2530 */
@@ -69,10 +74,10 @@ public Pane createRootPane() {
6974
7075 return root ;
7176 }
72-
77+
7378 protected Parameter [] createParameters () {
74- Parameter p1 = new Parameter (PARAM_STRATEGY , "Depth-First Search" , "Hill Climbing" , "Simulated Annealing " ,
75- "Genetic Algorithm" );
79+ Parameter p1 = new Parameter (PARAM_STRATEGY , "Depth-First Search" , "A* search (attacking pair heuristic) " ,
80+ "Hill Climbing" , "Simulated Annealing" , "Genetic Algorithm" );
7681 Parameter p2 = new Parameter (PARAM_BOARD_SIZE , 8 , 16 , 32 , 64 );
7782 Parameter p3 = new Parameter (PARAM_INIT_CONFIG , "FirstRow" , "Random" );
7883 p3 .setDependency (PARAM_STRATEGY , "Hill Climbing" , "Simulated Annealing" , "Genetic Algorithm" );
@@ -85,7 +90,8 @@ public void initialize() {
8590 experiment .setBoardSize (simPaneCtrl .getParamAsInt (PARAM_BOARD_SIZE ));
8691 Object strategy = simPaneCtrl .getParamValue (PARAM_STRATEGY );
8792 Config config ;
88- if (strategy .equals ("Depth-First Search" ) || strategy .equals ("Genetic Algorithm" ))
93+ if (Arrays .asList ("Depth-First Search" , "A* search (attacking pair heuristic)" , "Genetic Algorithm" )
94+ .contains (strategy ))
8995 config = Config .EMPTY ;
9096 else if (simPaneCtrl .getParamValue (PARAM_INIT_CONFIG ).equals ("Random" ))
9197 config = Config .QUEEN_IN_EVERY_COL ;
@@ -105,6 +111,8 @@ public void simulate() {
105111 Object strategy = simPaneCtrl .getParamValue (PARAM_STRATEGY );
106112 if (strategy .equals ("Depth-First Search" ))
107113 experiment .startExperiment (new DepthFirstSearch (new TreeSearch ()));
114+ else if (strategy .equals ("A* search (attacking pair heuristic)" ))
115+ experiment .startExperiment (new AStarSearch (new GraphSearch (), new AttackingPairsHeuristic ()));
108116 else if (strategy .equals ("Hill Climbing" ))
109117 experiment .startHillClimbingExperiment ();
110118 else if (strategy .equals ("Simulated Annealing" ))
0 commit comments