libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
node.hpp
1 #ifndef NODE_HPP
2 #define NODE_HPP
3 
4 #include <tr1/memory>
5 
6 #include "API/ConfigSpace/configuration.hpp"
7 
8 #ifndef _ROADMAP_H
9 struct node;
10 struct edge;
11 struct compco;
12 #endif
13 
14 #include "BGL_Graph.hpp"
15 
16 #ifndef EDGE_HPP
17 class Edge;
18 #endif
19 
20 #ifndef COMPCO_HPP
21 class ConnectedComponent;
22 #endif
23 
24 class Graph;
25 
26 class NodeData
27 {
28  public :
29  // Constructor & Destructor
30  NodeData();
31  virtual ~NodeData();
32 };
33 
39 class Node
40 {
41 public:
42 
43  //Constructor and destructor
44  Node();
51  Node(Graph* G, std::tr1::shared_ptr<Configuration> C, bool newCompco=true);
52 
58  Node(Graph* G, node* N);
59 
63  ~Node();
64 
69  void deleteNode();
70 
74  bool operator==(Node& N);
75 
76  //Accessors
81  node* getNodeStruct();
82 
87  Graph* getGraph();
88 
93  Robot* getRobot();
94 
99  confPtr_t getConfiguration();
100 
105  void activ(bool b);
106 
111  bool isActiv();
112 
116  unsigned int getId() const;
117 
121  void setId(unsigned int id);
122 
127  Node*& parent() { return m_parent; }
128 
133  bool& isLeaf() { return m_is_leaf; }
134 
139  double cost();
140 
144  double& sumCost(bool recompute=false);
145 
150  double getTemp();
151 
156  void setTemp(double t);
157 
162  double getDist();
163 
167  double distMultisol(Node *node) const;
168 
169  double metric(Node* node);
170 
176  double dist(Node* N) const;
177 
183  double dist(confPtr_t q) const;
184 
190  bool equal(Node* N) const;
191 
197  bool inSameComponent(Node* N) const;
198 
205  bool isLinkable(Node* node, double* dist) const;
206 
213  bool isLinkableMultisol(Node* node, double* dist) const;
214 
218  void checkStopByWeight();
219 
224  unsigned int getNumberOfNodesInCompco() const;
225 
231  return m_Compco;
232  }
233 
239 
243  void deleteCompco();
244 
249  bool maximumNumberNodes();
250 
256  bool connectNodeToCompco(Node* N, double step);
257 
262  void merge(Node* compco);
263 
269  bool equalCompco(Node* compco) const;
270 
275  Node* randomNodeFromComp() const;
276 
278  unsigned getNumberOfEdges() { return edges.size(); }
279 
281  std::list<Edge *> & getEdges() { return edges; }
282 
284  void addEdge(Edge * edge) { edges.push_back(edge); }
285 
287  void removeEdge(Edge * edge) { edges.remove(edge); }
288 
290  std::vector<Edge *> computeEdges();
291 
293  unsigned getNumberOfNeighbors() { return neighbors.size(); }
294 
296  std::list<Node *> & getNeighbors() { return neighbors; }
297 
299  void addNeighbor(Node * node) { neighbors.push_back(node); }
300 
302  void removeNeighbor(Node * node) { neighbors.remove(node); }
303 
305  std::vector<Node *> computeNeighbors();
306 
310  void setSelectCost(double Cost) { _SelectCost = Cost; }
311  double getSelectCost() { return _SelectCost; }
312  void setExpandFailed() { _nbExpan++; }
313  int getNbExpandFailed() { return _nbExpan; }
314  std::vector<Node*>& getSortedNodes() { return _SortedNodes; }
315  void setSortedNodes(std::vector<Node*>& nodes) { _SortedNodes = nodes; }
316 
320  void print() const;
321 
322  //--------------------------------------
323  // BGL
324  BGL_Vertex getDescriptor();
325  void setDescriptor(const BGL_Vertex& V);
326  void unSetDescriptor();
327  int useful;
328 
329  // Used for directed graphs
330  bool isForwardConnectedToGoal();
331  bool isBackwardConnectedToSource();
332  void forwardConnectToGoal();
333  void backwardConnectToSource();
334  void resetConnections();
335  bool isFlaged();
336  void flag();
337  void unflag();
338  void unflagForward();
339  void unflagBackward();
340  void addForwardNeighbor(Node *N);
341  void addBackwardNeighbor(Node *N);
342  std::vector<Node*> getBackwardNeighbors();
343  std::vector<Node*> getForwardNeighbors();
344  void updateForward();
345  void updateBackward();
346  unsigned int getSccId();
347  void setSccId(unsigned int i);
348 
349 private:
350 
351  // Old Node structure
352  node* m_Node;
353  NodeData* _specificNodeData;
354 
355  bool m_is_BGL_Descriptor_Valid;
356  BGL_Vertex m_BGL_Descriptor;
357 
358  Graph* m_Graph;
359  Robot* m_Robot;
360  ConnectedComponent* m_Compco;
361 
363  std::list<Edge *> edges;
364 
366  std::list<Node *> neighbors;
367 
368  // In tree graphs
369  Node* m_parent;
370  bool m_is_leaf;
371 
372  std::tr1::shared_ptr<Configuration> m_Configuration;
373  bool _activ;
374 
375  double _SelectCost;
376  int _nbExpan;
377  std::vector<Node*> _SortedNodes;
378 
379  // Used for debug
380  bool m_specificNode;
381 
382  // Used for directed graphs
383  bool _isForwardConnectedToGoal;
384  bool _isBackwardConnectedToSource;
385  bool _flaged;
386  std::vector<Node*> _ForwardNeighbors;
387  std::vector<Node*> _BackwardNeighbors;
388  // Id of the stongly connected component of the node
389  unsigned int _SccId;
390 
391 };
392 
393 #endif
void deleteNode()
Deletes the p3d node without deleting the configuration allready stored in a shared_ptr.
Definition: node.cpp:127
void print() const
Prints the node to the standard output.
Definition: node.cpp:494
~Node()
destructeur de la classe
Definition: node.cpp:144
void setId(unsigned int id)
Sets the Id.
Definition: node.cpp:181
Definition: compco.hpp:23
double getTemp()
obtient la temperature du Node
Definition: node.cpp:156
bool connectNodeToCompco(Node *N, double step)
connect un Node à la composante connexe
Definition: node.cpp:465
Classe représentant un Node d'un Graph.
Definition: node.hpp:39
void setTemp(double t)
modifie la temperature du Node
Definition: node.cpp:165
Node *& parent()
returns a reference to the node parent when in a tree like structure the pointer is editable ...
Definition: node.hpp:127
bool inSameComponent(Node *N) const
teste si deux Node sont dans la même composante connexe
Definition: node.cpp:460
double getDist()
obtient la distance au Node courant créé
bool isLinkable(Node *node, double *dist) const
Checks if two nodes can be linked.
Definition: node.cpp:351
void removeNeighbor(Node *node)
Remove the given node from the list of neighbors of this node.
Definition: node.hpp:302
ConnectedComponent * getConnectedComponent() const
obtient la structure de composante connexe à laquelle appartient le Node
Definition: node.hpp:230
bool equalCompco(Node *compco) const
teste si deux composante connexe sont égales
Definition: node.cpp:484
double distMultisol(Node *node) const
copy of p3d_APInode_dist_multisol
Definition: node.cpp:329
unsigned getNumberOfNeighbors()
Get the number of neighbors of this node.
Definition: node.hpp:293
std::list< Edge * > & getEdges()
Get the list of edges going out of this node.
Definition: node.hpp:281
void addNeighbor(Node *node)
Add the given node to the list of neighbors of this node.
Definition: node.hpp:299
Definition: graph.hpp:28
Classe représentant une Edge d'un Graph.
Definition: edge.hpp:24
Node * randomNodeFromComp() const
tire un Node aléatoirement dans la composante connexe
Definition: node.cpp:489
void checkStopByWeight()
vérifie si le poids max du Node a été atteint
Definition: node.cpp:429
bool isLinkableMultisol(Node *node, double *dist) const
Check if two node are connectable.
Definition: node.cpp:412
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
void removeEdge(Edge *edge)
Remove the given edge from the list of edges going out of this node.
Definition: node.hpp:287
bool maximumNumberNodes()
teste si la composante connexe a atteint le nombre max de Nodes
Definition: node.cpp:449
void merge(Node *compco)
merge deux composantes connexes
Definition: node.cpp:479
void addEdge(Edge *edge)
Add the given edge to the list of edges going out of this node.
Definition: node.hpp:284
double dist(Node *N) const
calcule la distance entre deux Node et stocke la valeur dans DistNew
Definition: node.cpp:314
std::vector< Node * > computeNeighbors()
Recompute the list of neighbors of this node.
Definition: node.cpp:187
void activ(bool b)
modifie la valeur de activ
Definition: node.cpp:251
Definition: node.hpp:26
bool isActiv()
obtient la valeur de activ
Definition: node.cpp:256
std::vector< Edge * > computeEdges()
Recompute the list of edges going out of this node.
Definition: node.cpp:205
double & sumCost(bool recompute=false)
Returns the Sum of cost along the path.
Definition: node.cpp:272
unsigned int getNumberOfNodesInCompco() const
Gets the number of nodes in the connected componnent.
confPtr_t getConfiguration()
obtient la Configuration stockée
Definition: node.cpp:246
Graph * getGraph()
obtient le Graph pour lequel le Node a été créé
Definition: node.cpp:236
void deleteCompco()
detruit la composante connexe
Definition: node.cpp:443
node * getNodeStruct()
obtient la structure p3d_node
Definition: node.cpp:231
void setConnectedComponent(ConnectedComponent *compco)
Sets the compco of the node.
Definition: node.cpp:454
double cost()
obtient le cout du Node
Definition: node.cpp:261
Robot * getRobot()
obtient le Robot pour lequel le Node a été créé
Definition: node.cpp:241
unsigned int getId() const
Returns the node id.
Definition: node.cpp:173
bool & isLeaf()
returns a reference to the if leaf data the pointer is editable
Definition: node.hpp:133
std::list< Node * > & getNeighbors()
Get the list of neighbors of this node.
Definition: node.hpp:296
bool equal(Node *N) const
teste si deux Node sont égaux
Definition: node.cpp:343
void setSelectCost(double Cost)
Method for EST.
Definition: node.hpp:310
bool operator==(Node &N)
Equal operator.
Definition: node.cpp:122
Node()
Constructor.
Definition: node.cpp:33
unsigned getNumberOfEdges()
Get the number of edges going out of this node.
Definition: node.hpp:278