-
Notifications
You must be signed in to change notification settings - Fork 42
/
SearchNode.java
95 lines (87 loc) · 1.46 KB
/
SearchNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
*
* Class to represent a SearchNode. This will be a wrapper for a State, and
* track the cost to get to that state and the state's parent node.
*
* @author Michael Langston && Gabe Ferrer
*
*/
public class SearchNode
{
private State curState;
private SearchNode parent;
private double cost; // cost to get to this state
private double hCost; // heuristic cost
private double fCost; // f(n) cost
/**
* Constructor for the root SearchNode
*
* @param s
* the state passed in
*/
public SearchNode(State s)
{
curState = s;
parent = null;
cost = 0;
hCost = 0;
fCost = 0;
}
/**
* Constructor for all other SearchNodes
*
* @param prev
* the parent node
* @param s
* the state
* @param c
* the g(n) cost to get to this node
* @param h
* the h(n) cost to get to this node
*/
public SearchNode(SearchNode prev, State s, double c, double h)
{
parent = prev;
curState = s;
cost = c;
hCost = h;
fCost = cost + hCost;
}
/**
* @return the curState
*/
public State getCurState()
{
return curState;
}
/**
* @return the parent
*/
public SearchNode getParent()
{
return parent;
}
/**
* @return the cost
*/
public double getCost()
{
return cost;
}
/**
*
* @return the heuristic cost
*/
public double getHCost()
{
return hCost;
}
/**
*
* @return the f(n) cost for A*
*/
public double getFCost()
{
return fCost;
}
}