Skip to content

Commit eac1a95

Browse files
committed
Minor improvements added.
1 parent 11d2a72 commit eac1a95

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

aima-gui/src/main/java/aima/gui/fx/demo/search/MapColoringApp.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import aima.gui.fx.framework.SimulationPaneBuilder;
77
import aima.gui.fx.framework.SimulationPaneCtrl;
88
import aima.gui.fx.views.BinaryCspViewCtrl;
9-
import aima.gui.fx.views.NQueensViewCtrl;
109
import javafx.application.Platform;
1110
import javafx.scene.layout.BorderPane;
1211
import javafx.scene.layout.Pane;

aima-gui/src/main/java/aima/gui/fx/demo/search/NQueensSearchApp.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package aima.gui.fx.demo.search;
22

3+
import aima.core.environment.nqueens.AttackingPairsHeuristic;
34
import aima.core.environment.nqueens.NQueensBoard;
45
import aima.core.environment.nqueens.NQueensBoard.Config;
56
import aima.core.search.framework.Metrics;
7+
import aima.core.search.framework.qsearch.GraphSearch;
68
import aima.core.search.framework.qsearch.TreeSearch;
9+
import aima.core.search.informed.AStarSearch;
710
import aima.core.search.uninformed.DepthFirstSearch;
811
import aima.gui.fx.framework.IntegrableApplication;
912
import aima.gui.fx.framework.Parameter;
@@ -15,11 +18,13 @@
1518
import javafx.scene.layout.Pane;
1619
import 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"))

aima-gui/src/main/java/aima/gui/fx/views/BinaryCspViewCtrl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ protected void visualize(Constraint constraint) {
127127
}
128128

129129
/**
130-
* Computes transforms (translations and scaling) and applies them to the
131-
* environment state view. Those transforms map location positions in the
132-
* map to screen positions in the viewer pane.
130+
* Computes transforms (translations and scaling) and applies them to the environment state view. Those transforms
131+
* map logical positions to screen positions in the viewer pane. The purpose is to show the graphical state
132+
* representation as large as possible.
133133
*
134134
* @return The scale value.
135135
*/
@@ -145,11 +145,11 @@ private double adjustTransform() {
145145
yMin = Math.min(yMin, point.getY());
146146
yMax = Math.max(yMax, point.getY());
147147
}
148-
double scale = Math.min((pane.getWidth() - 150) / (xMax - xMin + 60),
149-
(pane.getHeight() - 100) / (yMax - yMin + 60));
148+
double scale = Math.min(pane.getWidth() / (xMax - xMin + 300),
149+
pane.getHeight() / (yMax - yMin + 150));
150150

151-
pane.setTranslateX((scale * (pane.getWidth() - xMin - xMax) / 2.0 - 30));
152-
pane.setTranslateY((scale * (pane.getHeight() - yMin - yMax) / 2.0 - 30));
151+
pane.setTranslateX((scale * (pane.getWidth() - xMin - xMax) / 2.0));
152+
pane.setTranslateY((scale * (pane.getHeight() - yMin - yMax) / 2.0));
153153
pane.setScaleX(scale);
154154
pane.setScaleY(scale);
155155
return scale;

0 commit comments

Comments
 (0)