Skip to content

Commit 6e99445

Browse files
committed
Minor Cleanup.
1 parent 563189e commit 6e99445

File tree

9 files changed

+29
-20
lines changed

9 files changed

+29
-20
lines changed

aima-core/src/main/java/aima/core/environment/map/MapAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class MapAgent extends ProblemSolvingAgent<DynamicPercept, String, MoveTo
3131
protected final List<String> goals = new ArrayList<>();
3232
protected int nextGoalPos = 0;
3333

34-
private SearchForActions<String, MoveToAction> search;
34+
private final SearchForActions<String, MoveToAction> search;
3535
private Function<String, ToDoubleFunction<Node<String, MoveToAction>>> hFnFactory;
3636
protected Notifier notifier;
3737

aima-core/src/main/java/aima/core/search/adversarial/MonteCarloTreeSearch.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
public class MonteCarloTreeSearch<S, A, P> implements AdversarialSearch<S, A> {
4444
private int iterations = 0;
45-
private Game<S, A, P> game;
46-
private GameTree<S, A> tree;
45+
private final Game<S, A, P> game;
46+
private final GameTree<S, A> tree;
4747

4848
public MonteCarloTreeSearch(Game<S, A, P> game, int iterations) {
4949
this.game = game;
@@ -73,7 +73,7 @@ public A makeDecision(S state) {
7373
return bestAction(tree.getRoot());
7474
}
7575

76-
private Node<S, A> select(GameTree gameTree) {
76+
private Node<S, A> select(GameTree<S, A> gameTree) {
7777
Node<S, A> node = gameTree.getRoot();
7878
while (!game.isTerminal(node.getState()) && isNodeFullyExpanded(node)) {
7979
node = gameTree.getChildWithMaxUCT(node);
@@ -82,23 +82,21 @@ private Node<S, A> select(GameTree gameTree) {
8282
}
8383

8484
private Node<S, A> expand(Node<S, A> leaf) {
85-
if (game.isTerminal(leaf.getState())) return leaf;
86-
else {
87-
Node<S, A> child = randomlySelectUnvisitedChild(leaf);
88-
return child;
89-
}
85+
if (game.isTerminal(leaf.getState()))
86+
return leaf;
87+
else
88+
return randomlySelectUnvisitedChild(leaf);
9089
}
9190

9291
private boolean simulate(Node<S, A> node) {
9392
while (!game.isTerminal(node.getState())) {
9493
Random rand = new Random();
9594
A a = game.getActions(node.getState()).get(rand.nextInt(game.getActions(node.getState()).size()));
9695
S result = game.getResult(node.getState(), a);
97-
NodeFactory nodeFactory = new NodeFactory();
96+
NodeFactory<S, A> nodeFactory = new NodeFactory<>();
9897
node = nodeFactory.createNode(result);
9998
}
100-
if (game.getUtility(node.getState(), game.getPlayer(tree.getRoot().getState())) > 0) return true;
101-
else return false;
99+
return game.getUtility(node.getState(), game.getPlayer(tree.getRoot().getState())) > 0;
102100
}
103101

104102
private void backpropagate(boolean result, Node<S, A> node) {
@@ -135,8 +133,7 @@ private Node<S, A> randomlySelectUnvisitedChild(Node<S, A> node) {
135133
if (!visitedChildren.contains(result)) unvisitedChildren.add(result);
136134
}
137135
Random rand = new Random();
138-
Node<S, A> newChild = tree.addChild(node, unvisitedChildren.get(rand.nextInt(unvisitedChildren.size())));
139-
return newChild;
136+
return tree.addChild(node, unvisitedChildren.get(rand.nextInt(unvisitedChildren.size())));
140137
}
141138

142139
@Override

aima-core/src/main/java/aima/core/util/datastructure/Pair.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package aima.core.util.datastructure;
22

3+
import java.util.Objects;
4+
35
/**
46
* @author Ravi Mohan
57
* @author Mike Stampone
@@ -44,22 +46,20 @@ public Y getSecond() {
4446

4547
@Override
4648
public boolean equals(Object o) {
47-
if (o instanceof Pair<?, ?>) {
49+
if (o != null && getClass() == o.getClass()) {
4850
Pair<?, ?> p = (Pair<?, ?>) o;
49-
return (a == null ? p.a == null : a.equals(p.a)) &&
50-
(b == null ? p.b == null : b.equals(p.b));
51+
return Objects.equals(a, p.a) && Objects.equals(b, p.b);
5152
}
5253
return false;
5354
}
5455

5556
@Override
5657
public int hashCode() {
57-
return (a == null ? 0 : a.hashCode()) + 31 * (b == null ? 0 : b.hashCode());
58+
return (a == null ? 0 : 7 * a.hashCode()) + 31 * (b == null ? 0 : b.hashCode());
5859
}
5960

6061
@Override
6162
public String toString() {
62-
return "< " + getFirst().toString() + " , " + getSecond().toString()
63-
+ " > ";
63+
return "< " + getFirst().toString() + " , " + getSecond().toString() + " > ";
6464
}
6565
}

aimax-osm/src/main/java/aimax/osm/gui/fx/applications/ExtendedRouteFindingAgentOsmApp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.function.Function;
2424
import java.util.function.ToDoubleFunction;
2525

26+
// VM options (Java>8): --module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml
27+
2628
/**
2729
* Integrable application which demonstrates how different kinds of search
2830
* algorithms perform in a route finding scenario based on a real OSM map. This

aimax-osm/src/main/java/aimax/osm/gui/fx/applications/InteractiveMapViewerOsmApp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import java.util.Locale;
1212

13+
// VM options (Java>8): --module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml
14+
1315
/**
1416
* Shows a map of the city of Ulm with pan and zoom functionality (mouse drag, mouse wheel, arrow keys,
1517
* plus and minus keys). Set markers with Mouse-Left and remove them with Mouse-Right. Symbols can be changed in size

aimax-osm/src/main/java/aimax/osm/gui/fx/applications/OnlineAgentOsmApp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.util.List;
3535
import java.util.function.ToDoubleFunction;
3636

37+
// VM options (Java>8): --module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml
38+
3739
/**
3840
* Integrable application which demonstrates how the Learning Real-Time A*
3941
* (LRTA*) search agent performs compared to the Online DFS agent in a route

aimax-osm/src/main/java/aimax/osm/gui/fx/applications/RouteFindingAgentOsmApp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.List;
3434
import java.util.function.ToDoubleFunction;
3535

36+
// VM options (Java>8): --module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml
37+
3638
/**
3739
* Simple OSM route finding agent application which can be used as base class
3840
* for more advanced OSM agent applications. For example, by overriding some of

aimax-osm/src/main/java/aimax/osm/gui/fx/applications/RoutePlannerOsmApp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.text.DecimalFormat;
1919
import java.util.List;
2020

21+
// VM options (Java>8): --module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml
22+
2123
/**
2224
* Extendable application for route planning based on a real map of the city of Ulm.
2325
*

aimax-osm/src/main/java/aimax/osm/gui/fx/applications/SimpleMapViewerOsmApp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import java.util.Locale;
1414

15+
// VM options (Java>8): --module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml
16+
1517
/**
1618
* Simple demo application which shows a stage with the
1719
* map of Ulm, provided that a file with name ulm.osm is found

0 commit comments

Comments
 (0)