-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.h
More file actions
89 lines (81 loc) · 1.53 KB
/
Copy pathnode.h
File metadata and controls
89 lines (81 loc) · 1.53 KB
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
#ifndef _NODE_
#define _NODE_
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
class node
{
public:
node *parent = nullptr;
int visited{};
int obs{1};
// int push{};
pair<int, int> position;
pair<int, int> positionF;
float cost{9999999};
node(pair<int, int> positioni)
: position(positioni)
{
}
node(node *parenti, pair<int, int> positioni, float costi)
: parent(parenti), position(positioni), cost(costi)
{
}
float findCost(node parent,pair<int, int> positionF)
{
int tempCost{};
tempCost = parent.cost + (sqrt(static_cast<float>(pow((parent.position.first - position.first), 2) + pow((parent.position.second - position.second), 2))))+(sqrt(static_cast<float>(pow((positionF.first - position.first), 2) + pow((positionF.second - position.second), 2))));
if (tempCost < cost)
{
cost = tempCost;
}
return cost;
}
bool operator>(const node &rhs) const
{
if (this->cost > rhs.cost)
{
return true;
}
else
{
return false;
}
}
bool operator<(const node &rhs) const
{
if (this->cost < rhs.cost)
{
return true;
}
else
{
return false;
}
}
bool operator==(node &rhs) const
{
if (this->position == rhs.position)
{
return true;
}
else
{
return false;
}
}
bool operator!=(node &rhs) const
{
if (this->position != rhs.position)
{
return true;
}
else
{
return false;
}
}
};
#endif //_NODE_