Skip to content

Commit c0f6546

Browse files
author
magicindian
committed
checking in changed heursitic code
1 parent 68676b4 commit c0f6546

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

src/aima/search/demos/MapDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static void mapWithRecursiveBestFirstSearch() {
128128
new AStarEvaluationFunction()),
129129
new String[] { SimplifiedRoadMapOfPartOfRomania.BUCHAREST });
130130
ma.setHeuristicFunction(new HeuristicFunction() {
131-
public int getHeuristicValue(Object state) {
131+
public double getHeuristicValue(Object state) {
132132
return SimplifiedRoadMapOfPartOfRomania
133133
.getStraightLineDistancesToBucharest().getDistance(
134134
(String) state,

src/aima/search/eightpuzzle/ManhattanHeuristicFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class ManhattanHeuristicFunction implements HeuristicFunction {
1616

17-
public int getHeuristicValue(Object state) {
17+
public double getHeuristicValue(Object state) {
1818
EightPuzzleBoard board = (EightPuzzleBoard) state;
1919
int retVal = 0;
2020
for (int i = 1; i < 9; i++) {

src/aima/search/eightpuzzle/MisplacedTilleHeuristicFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class MisplacedTilleHeuristicFunction implements HeuristicFunction {
1616

17-
public int getHeuristicValue(Object state) {
17+
public double getHeuristicValue(Object state) {
1818
EightPuzzleBoard board = (EightPuzzleBoard) state;
1919
return getNumberOfMisplacedTiles(board);
2020

src/aima/search/framework/DefaultHeuristicFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
public class DefaultHeuristicFunction implements HeuristicFunction {
1313

14-
public int getHeuristicValue(Object state) {
14+
public double getHeuristicValue(Object state) {
1515
throw new IllegalStateException(
1616
"Should not be depending on the DefaultHeuristicFunction.");
1717
// return 1;

src/aima/search/framework/HeuristicFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
*/
77
public interface HeuristicFunction {
88

9-
int getHeuristicValue(Object state);
9+
double getHeuristicValue(Object state);
1010

1111
}

src/aima/search/informed/HillClimbingSearch.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ public Object getLastSearchState() {
8686
}
8787

8888
private Node getHighestValuedNodeFrom(List children, Problem p) {
89-
int highestValue = Integer.MIN_VALUE;
89+
double highestValue = Double.MIN_VALUE;
9090
Node nodeWithHighestValue = null;
9191
for (int i = 0; i < children.size(); i++) {
9292
Node child = (Node) children.get(i);
93-
int value = getValue(p, child);
93+
double value = getValue(p, child);
9494
if (value > highestValue) {
9595
highestValue = value;
9696
nodeWithHighestValue = child;
@@ -99,12 +99,12 @@ private Node getHighestValuedNodeFrom(List children, Problem p) {
9999
return nodeWithHighestValue;
100100
}
101101

102-
private int getValue(Problem p, Node n) {
102+
private double getValue(Problem p, Node n) {
103103
return -1 * getHeuristic(p, n); // assumption greater heuristic value =>
104104
// HIGHER on hill; 0 == goal state;
105105
}
106106

107-
private int getHeuristic(Problem p, Node aNode) {
107+
private double getHeuristic(Problem p, Node aNode) {
108108
return p.getHeuristicFunction().getHeuristicValue(aNode.getState());
109109
}
110110
}

src/aima/search/informed/SimulatedAnnealingSearch.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public List<String> search(Problem p) throws Exception {
9898
// next <- a randomly selected successor of current
9999
next = Util.selectRandomlyFromList(children);
100100
// /\E <- VALUE[next] - VALUE[current]
101-
int deltaE = getValue(p, next) - getValue(p, current);
101+
double deltaE = getValue(p, next) - getValue(p, current);
102102

103103
if (shouldAccept(temperature, deltaE)) {
104104
current = next;
@@ -111,13 +111,13 @@ public List<String> search(Problem p) throws Exception {
111111

112112
// if /\E > 0 then current <- next
113113
// else current <- next only with probablity e^(/\E/T)
114-
private boolean shouldAccept(double temperature, int deltaE) {
114+
private boolean shouldAccept(double temperature, double deltaE) {
115115
return (deltaE > 0.0)
116116
|| (new Random().nextDouble() <= probabilityOfAcceptance(
117117
temperature, deltaE));
118118
}
119119

120-
public double probabilityOfAcceptance(double temperature, int deltaE) {
120+
public double probabilityOfAcceptance(double temperature, double deltaE) {
121121
return Math.exp(deltaE / temperature);
122122
}
123123

@@ -129,13 +129,13 @@ public Object getLastSearchState() {
129129
return lastState;
130130
}
131131

132-
private int getValue(Problem p, Node n) {
132+
private double getValue(Problem p, Node n) {
133133
return -1 * getHeuristic(p, n); // assumption greater heuristic value =>
134134
// HIGHER on hill; 0 == goal state;
135135
// SA deals with gardient DESCENT
136136
}
137137

138-
private int getHeuristic(Problem p, Node aNode) {
138+
private double getHeuristic(Problem p, Node aNode) {
139139
return p.getHeuristicFunction().getHeuristicValue(aNode.getState());
140140
}
141141
}

src/aima/search/nqueens/QueensToBePlacedHeuristic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
public class QueensToBePlacedHeuristic implements HeuristicFunction {
11-
public int getHeuristicValue(Object state) {
11+
public double getHeuristicValue(Object state) {
1212
NQueensBoard board = (NQueensBoard) state;
1313
return board.size - board.getNumberOfQueensOnBoard();
1414
}

0 commit comments

Comments
 (0)