-
Notifications
You must be signed in to change notification settings - Fork 1
/
Roadmap.h
165 lines (135 loc) · 4.9 KB
/
Roadmap.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
Copyright (c) 2014 Mika Rantanen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef __ROADMAP_H__
#define __ROADMAP_H__
#include <ext/pb_ds/priority_queue.hpp>
#include <unordered_map>
#include <vector>
#include <cfloat>
#include "Common.h"
#include "DisjointSets.h"
#include "Solver.h"
class Configuration;
/*****************************************************************************/
/* RoadmapNode */
/*****************************************************************************/
class RoadmapNode: public DisjointSetsNode
{
friend class Roadmap;
public:
struct RoadmapNodeCmpRL: public std::binary_function<
RoadmapNode*,
RoadmapNode*,
bool>
{
inline bool operator()(const RoadmapNode* left,
const RoadmapNode* right) const
{
return right->compareElement < left->compareElement;
}
};
struct RoadmapNodeCmpLR: public std::binary_function<
RoadmapNode*,
RoadmapNode*,
bool>
{
inline bool operator()(const RoadmapNode* left,
const RoadmapNode* right) const
{
return left->compareElement < right->compareElement;
}
};
private:
enum RoadmapNodeStatus
{
ROADMAPNODE_STATUS_ACTIVE = 0,
ROADMAPNODE_STATUS_REMOVED
};
struct Edge
{
double length;
};
typedef __gnu_pbds::priority_queue<
RoadmapNode*,
RoadmapNodeCmpRL, // Smallest element is the first
__gnu_pbds::pairing_heap_tag> PriorityQueue;
RoadmapNode(const RMID id, const Configuration* const config);
public:
int getDegree() const;
bool isIsolated() const;
bool isLeaf() const;
bool isActive() const;
bool isRemoved() const;
const RMID id;
const Configuration* configuration;
// Used by nearest neighbor search and Dijkstra's algorithm, for example
mutable double compareElement;
// Used by LSH algorithm
mutable bool flagLSH;
private:
std::unordered_map<RMID, Edge> m_edges;
RoadmapNodeStatus m_status;
// Used by Dijkstra's algorithm
RMID previousElement;
PriorityQueue::point_iterator queueIterator;
};
/*****************************************************************************/
/* Roadmap */
/*****************************************************************************/
class Roadmap
{
public:
Roadmap();
~Roadmap();
RMID addInitConfiguration(const Configuration* const config);
RMID addGoalConfiguration(const Configuration* const config);
RMID addConfiguration(const Configuration* const config);
void addEdge(const RMID node1, const RMID node2, const double length);
bool hasEdge(const RMID node1, const RMID node2) const;
bool isConnected() const;
bool isConnected(const RMID node1, const RMID node2) const;
bool removeNode(const RMID node);
int getCurrentNodeCount() const;
int getGeneratedNodeCount() const;
int getGeneratedEdgeCount() const;
int getActiveEdgeCount() const;
int getRemovedEdgeCount() const;
int getActiveNodeCount() const;
int getRemovedNodeCount() const;
const RoadmapNode* getNode(RMID id) const;
const std::vector<RMID> getEdges(RMID id) const;
bool getPath(RoadmapNodePath& path,
double& length,
RMID initNode = -1,
RMID goalNode = -1,
double maxLength = DBL_MAX) const;
int getComponentCount() const;
Solver* solver;
private:
RMID m_initNode;
RMID m_goalNode;
int m_activeEdgeCount;
int m_removedEdgeCount;
int m_generatedNodeCount;
int m_removedNodeCount;
std::vector<RoadmapNode*> m_nodes;
mutable DisjointSets m_sets;
int m_removedSets;
};
#endif