-
Notifications
You must be signed in to change notification settings - Fork 4
/
Node.h
124 lines (106 loc) · 3.45 KB
/
Node.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef NODE_H_
#define NODE_H_
#include <iostream> // std::cout, std::endl
#include <float.h> // DBL_MAX
#include <limits.h> // ULONG_MAX
#include "Vertex.h"
#include "Edge.h"
using std::cout ;
using std::endl ;
typedef unsigned long int ULONG ;
enum nodeType {SOURCE, OTHER} ;
// Node class to maintain path information up to a vertex
// contains parent node, (mu, sigma) of cost-to-come
class Node
{
public:
Node(Vertex * vertex):
itsVertex(vertex), itsParent(0), itsMeanCost(0.0), itsSigCost(0.0), itsDepth(0),
itsHeuristic(0.0), itsMeanCTG(0.0), itsSigCTG(0.0) {}
Node(Vertex * vertex, nodeType n):
itsVertex(vertex), itsParent(0), itsHeuristic(0.0)
{
switch (n)
{
case SOURCE:
itsMeanCost = 0.0 ;
itsSigCost = 0.0 ;
itsDepth = 0.0 ;
itsMeanCTG = 0.0 ;
break ;
default:
itsMeanCost = DBL_MAX ;
itsSigCost = DBL_MAX ;
itsDepth = ULONG_MAX ;
itsMeanCTG = DBL_MAX ;
itsSigCTG = DBL_MAX ;
}
}
Node(Node * parent, Edge * edge):
itsParent(parent), itsHeuristic(0.0), itsMeanCTG(0.0), itsSigCTG(0.0)
{
itsVertex = edge->GetVertex2() ;
itsMeanCost = itsParent->GetMeanCost() + edge->GetMeanSearch() ;
itsSigCost = itsParent->GetSigCost() + edge->GetSigSearch() ;
itsDepth = itsParent->GetDepth() + 1 ;
}
~Node(){} ;
Node * GetParent() const {return itsParent ;}
void SetParent(Node * parent) {itsParent = parent ;}
double GetMeanCost() const {return itsMeanCost ;}
void SetMeanCost(double cost) {itsMeanCost = cost ;}
double GetSigCost() const {return itsSigCost ;}
void SetSigCost(double sig) {itsSigCost = sig ;}
Vertex * GetVertex() const {return itsVertex ;}
void SetVertex(Vertex * vertex) {itsVertex = vertex ;}
ULONG GetDepth() const {return itsDepth ;}
void SetDepth(ULONG depth) {itsDepth = depth ;}
double GetHeuristic() const {return itsHeuristic ;}
void SetHeuristic(double h) {itsHeuristic = h ;}
double GetMeanCTG() const {return itsMeanCTG ;}
void SetMeanCTG(double mCTG){itsMeanCTG = mCTG ;}
double GetSigCTG() const {return itsSigCTG ;}
void SetSigCTG(double vCTG){itsSigCTG = vCTG ;}
void DisplayPath() ;
Node * ReverseList(Node * itsChild) ;
void SetCTG(double totalMean, double totalSig) ;
private:
Vertex * itsVertex ;
Node * itsParent ;
double itsMeanCost ;
double itsSigCost ;
ULONG itsDepth ;
double itsHeuristic ;
double itsMeanCTG ;
double itsSigCTG ;
} ;
void Node::DisplayPath()
{
cout << "Vertex: (" << itsVertex->GetX() << "," << itsVertex->GetY() << ")\n" ;
cout << "Mean cost-to-come: " << itsMeanCost << ", " << "standard deviation: " << itsSigCost << endl ;
cout << "Mean cost-to-go: " << itsMeanCTG << ", " << "standard deviation: " << itsSigCTG << endl ;
if (itsParent)
itsParent->DisplayPath() ;
}
Node * Node::ReverseList(Node * itsChild) // Can cause memleak if returned node pointer is not deleted properly
{
Node * itsParentR = new Node(GetVertex()) ;
itsParentR->SetMeanCost(GetMeanCost()) ;
itsParentR->SetSigCost(GetSigCost()) ;
itsParentR->SetParent(itsChild) ;
if (GetParent())
{
Node * itsReverse = GetParent()->ReverseList(itsParentR) ;
return itsReverse ;
}
else
return itsParentR ;
}
void Node::SetCTG(double totalMean, double totalSig)
{
itsMeanCTG = totalMean - itsMeanCost ;
itsSigCTG = totalSig - itsSigCost ;
if (itsParent)
itsParent->SetCTG(totalMean, totalSig) ;
}
#endif // NODE_H_