Skip to content

Commit

Permalink
Minor improvements added.
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedigerLunde committed Oct 28, 2016
1 parent fb0de40 commit 55a41e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
@@ -1,6 +1,6 @@
package aima.gui.fx.demo; package aima.gui.fx.demo;


import aima.gui.fx.demo.search.MapColoringApp; import aima.gui.fx.demo.search.CspMapColoringApp;
import aima.gui.fx.demo.search.games.EightPuzzleApp; import aima.gui.fx.demo.search.games.EightPuzzleApp;
import aima.gui.fx.demo.search.games.TicTacToeApp; import aima.gui.fx.demo.search.games.TicTacToeApp;
import aima.gui.prog.agent.NondeterministicVacuumEnvironmentProg; import aima.gui.prog.agent.NondeterministicVacuumEnvironmentProg;
Expand Down Expand Up @@ -57,7 +57,7 @@ protected void defineContent(IntegratedAppPaneBuilder builder) {
builder.registerApp(VacuumAgentApp.class); builder.registerApp(VacuumAgentApp.class);
builder.registerApp(RouteFindingAgentApp.class); builder.registerApp(RouteFindingAgentApp.class);


builder.registerApp(MapColoringApp.class); builder.registerApp(CspMapColoringApp.class);
builder.registerApp(NQueensSearchApp.class); builder.registerApp(NQueensSearchApp.class);


builder.registerApp(EightPuzzleApp.class); builder.registerApp(EightPuzzleApp.class);
Expand Down
Expand Up @@ -5,7 +5,7 @@
import aima.gui.fx.framework.Parameter; import aima.gui.fx.framework.Parameter;
import aima.gui.fx.framework.SimulationPaneBuilder; import aima.gui.fx.framework.SimulationPaneBuilder;
import aima.gui.fx.framework.SimulationPaneCtrl; import aima.gui.fx.framework.SimulationPaneCtrl;
import aima.gui.fx.views.BinaryCspViewCtrl; import aima.gui.fx.views.CspViewCtrl;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
Expand All @@ -19,7 +19,7 @@
* *
* @author Ruediger Lunde * @author Ruediger Lunde
*/ */
public class MapColoringApp extends IntegrableApplication { public class CspMapColoringApp extends IntegrableApplication {


public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
Expand All @@ -28,19 +28,19 @@ public static void main(String[] args) {
public final static String PARAM_MAP = "map"; public final static String PARAM_MAP = "map";
public final static String PARAM_STRATEGY = "strategy"; public final static String PARAM_STRATEGY = "strategy";


private BinaryCspViewCtrl stateViewCtrl; private CspViewCtrl stateViewCtrl;
private SimulationPaneCtrl simPaneCtrl; private SimulationPaneCtrl simPaneCtrl;


private CSP csp; private CSP csp;
private SolutionStrategy strategy; private SolutionStrategy strategy;
private int stepCounter; private int stepCounter;


public MapColoringApp() { public CspMapColoringApp() {
} }


@Override @Override
public String getTitle() { public String getTitle() {
return "Map Coloring App"; return "CSP Map Coloring App";
} }


/** /**
Expand All @@ -52,7 +52,7 @@ public Pane createRootPane() {
BorderPane root = new BorderPane(); BorderPane root = new BorderPane();


StackPane stateView = new StackPane(); StackPane stateView = new StackPane();
stateViewCtrl = new BinaryCspViewCtrl(stateView); stateViewCtrl = new CspViewCtrl(stateView);


Parameter[] params = createParameters(); Parameter[] params = createParameters();


Expand Down Expand Up @@ -203,7 +203,9 @@ private void updateStateView(CSP csp, Assignment assignment) {
private void updateStateViewLater(CSP csp, Assignment assignment) { private void updateStateViewLater(CSP csp, Assignment assignment) {
stateViewCtrl.update(csp, assignment); stateViewCtrl.update(csp, assignment);
String txt1 = "Step " + stepCounter + ": "; String txt1 = "Step " + stepCounter + ": ";
String txt2 = assignment != null ? assignment.toString() : "Domain reduced"; String txt2 = "Domain reduced";
if (assignment != null)
txt2 = assignment.toString() + (assignment.isSolution(csp) ? " (Solution)" : "");
simPaneCtrl.setStatus(txt1 + txt2); simPaneCtrl.setStatus(txt1 + txt2);
} }
} }
Expand Up @@ -21,7 +21,7 @@
* *
* @author Ruediger Lunde * @author Ruediger Lunde
*/ */
public class BinaryCspViewCtrl { public class CspViewCtrl {
protected Pane pane; protected Pane pane;
protected CSP csp; protected CSP csp;
protected Assignment assignment; protected Assignment assignment;
Expand All @@ -35,7 +35,7 @@ public class BinaryCspViewCtrl {
*/ */
protected Hashtable<Object, Color> colorMapping = new Hashtable<Object, Color>(); protected Hashtable<Object, Color> colorMapping = new Hashtable<Object, Color>();


public BinaryCspViewCtrl(StackPane viewRoot) { public CspViewCtrl(StackPane viewRoot) {
pane = new Pane(); pane = new Pane();
viewRoot.getChildren().add(pane); viewRoot.getChildren().add(pane);
viewRoot.setStyle("-fx-background-color: white"); viewRoot.setStyle("-fx-background-color: white");
Expand Down Expand Up @@ -106,12 +106,12 @@ protected void visualize(Variable var) {
label += " = " + value; label += " = " + value;
fillColor = colorMapping.get(value); fillColor = colorMapping.get(value);
} }
Circle circle = new Circle(pos.getX(), pos.getY(), 30); Circle circle = new Circle(pos.getX(), pos.getY(), 20);
circle.setStroke(Color.BLACK); circle.setStroke(Color.BLACK);
circle.setFill(fillColor != null ? fillColor : Color.WHITE); circle.setFill(fillColor != null ? fillColor : Color.WHITE);
Text t1 = new Text(pos.getX(), pos.getY(), label); Text t1 = new Text(pos.getX() + 25, pos.getY(), label);
t1.setTextOrigin(VPos.CENTER); t1.setTextOrigin(VPos.CENTER);
Text t2 = new Text(pos.getX(), pos.getY() + 50, csp.getDomain(var).toString()); Text t2 = new Text(pos.getX(), pos.getY() + 40, csp.getDomain(var).toString());
pane.getChildren().addAll(circle, t1, t2); pane.getChildren().addAll(circle, t1, t2);
} }


Expand Down

0 comments on commit 55a41e4

Please sign in to comment.