-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath-planning-fix.cpp
147 lines (115 loc) · 4.56 KB
/
path-planning-fix.cpp
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "ibex.h"
#include "vibes.h"
#include "tools.h"
#include <ctime>
using namespace std;
using namespace ibex;
int main(int argc, char** argv) {
clock_t start = clock();
double waypoints[2][2] = {{0,0},{40,50}};
double pos[2][2] ={{-1,1},{-1,1}};
IntervalVector boatInitPos(2, pos);
double Pos1[2][2] = {{30,34},{30,34}};
IntervalVector obstacle1Pos(2, Pos1);
double Pos2[2][2] = {{27,32},{47,51}};
IntervalVector obstacle2Pos(2, Pos2);
double Pos3[2][2] = {{13, 17},{54,58}};
IntervalVector obstacle3Pos(2, Pos3);
double Pos4[2][2] = {{60,63},{48,51}};
IntervalVector obstacle4Pos(2,Pos4);
vector<IntervalVector> obstaclesPos;
obstaclesPos.push_back(obstacle1Pos);
obstaclesPos.push_back(obstacle2Pos);
obstaclesPos.push_back(obstacle3Pos);
obstaclesPos.push_back(obstacle4Pos);
vibes::beginDrawing();
vibes::newFigure("feasible path with fixed obstacles");
vibes::setFigureProperties(vibesParams("x", 100, "y", 100, "width", 800, "height", 800));
Contractor contractor;
double _X[2][2] = {{-10, 80},{-10, 80}};
IntervalVector X(2, _X);
vector<IntervalVector> listBoxes;
pavingFix(X, contractor, obstaclesPos, &listBoxes);
vector<Node> listNodes;
listNodes.reserve(100);
for ( int i = 0; i < listBoxes.size(); i++){
Node newNode(listBoxes[i]);
if (boatInitPos.is_subset(newNode.getValue())){
newNode.setDist(0);
}
listNodes.push_back(newNode);
}
for (int i = 0; i < listNodes.size(); i++){
for (int j = 0; j < listNodes.size(); j++){
if (listNodes[i].getValue().intersects(listNodes[j].getValue()) and j != i){
listNodes[i].addNeighbor(&listNodes[j]);
}
}
}
/*
for (int i = 0; listNodes.size(); i++){
cout << listNodes[i].getValue() << endl;
}*/
vector<Node*> priorityQueue;
priorityQueue.reserve(100);
for (int i = 0; i < listNodes.size(); i++){
priorityQueue.push_back(&listNodes[i]);
}
Node* currentNode;
while (priorityQueue.size() != 0){
currentNode = extractMin(priorityQueue);
for (int i = 0; i < currentNode->getNeighbor().size(); i++){
release(currentNode, currentNode->getNeighbor()[i]);
}
}
Node* origin;
for (int i = 0; i < listNodes.size(); i++){
if (listNodes[i].getValue()[0].contains(waypoints[1][0]) && listNodes[i].getValue()[1].contains(waypoints[1][1])){
origin = &listNodes[i];
}
}
currentNode = origin;
bool endLoop = 0;
vector<double> pathx;
vector<double> pathy;
pathx.push_back(waypoints[1][0]);
pathy.push_back(waypoints[1][1]);
//vector<IntervalVector> boxesPath;
while (endLoop == 0){
//boxesPath.push_back(currentNode->getValue());
vibes::drawBoxes({{currentNode->getValue()[0].lb(), currentNode->getValue()[0].ub(), currentNode->getValue()[1].lb(), currentNode->getValue()[1].ub()}}, "black[yellow]");
if (currentNode->getPred() == NULL){
endLoop = 1;
}
else{
if (currentNode->getValue()[0].overlaps(currentNode->getPred()->getValue()[0])){
if (currentNode->getValue()[1].lb() == currentNode->getPred()->getValue()[1].ub()){
pathx.push_back((currentNode->getValue()[0] & currentNode->getPred()->getValue()[0]).mid());
pathy.push_back(currentNode->getValue()[1].lb());
}
else{
pathx.push_back((currentNode->getValue()[0] & currentNode->getPred()->getValue()[0]).mid());
pathy.push_back(currentNode->getValue()[1].ub());
}
}
else{
if (currentNode->getValue()[0].lb() == currentNode->getPred()->getValue()[0].ub()){
pathx.push_back(currentNode->getValue()[0].lb());
pathy.push_back((currentNode->getValue()[1] & currentNode->getPred()->getValue()[1]).mid());
}
else{
pathx.push_back(currentNode->getValue()[0].ub());
pathx.push_back((currentNode->getValue()[1] & currentNode->getPred()->getValue()[1]).mid());
}
}
}
currentNode = currentNode->getPred();
}
pathx.push_back(waypoints[0][0]);
pathy.push_back(waypoints[0][1]);
vibes::drawLine(pathx, pathy, "red");
clock_t end = clock();
cout << (float(end - start))/CLOCKS_PER_SEC << endl;
vibes::endDrawing();
return 0;
}