Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2016 CNRS |
3 |
|
|
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) |
4 |
|
|
// |
5 |
|
|
|
6 |
|
|
// Redistribution and use in source and binary forms, with or without |
7 |
|
|
// modification, are permitted provided that the following conditions are |
8 |
|
|
// met: |
9 |
|
|
// |
10 |
|
|
// 1. Redistributions of source code must retain the above copyright |
11 |
|
|
// notice, this list of conditions and the following disclaimer. |
12 |
|
|
// |
13 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright |
14 |
|
|
// notice, this list of conditions and the following disclaimer in the |
15 |
|
|
// documentation and/or other materials provided with the distribution. |
16 |
|
|
// |
17 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 |
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
19 |
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
20 |
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
21 |
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 |
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 |
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 |
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
28 |
|
|
// DAMAGE. |
29 |
|
|
|
30 |
|
|
#ifndef HPP_MANIPULATION_LEAF_CONNECTED_COMP_HH |
31 |
|
|
#define HPP_MANIPULATION_LEAF_CONNECTED_COMP_HH |
32 |
|
|
|
33 |
|
|
#include <hpp/manipulation/config.hh> |
34 |
|
|
#include <hpp/manipulation/fwd.hh> |
35 |
|
|
#include <hpp/manipulation/graph/fwd.hh> |
36 |
|
|
#include <hpp/manipulation/roadmap-node.hh> |
37 |
|
|
|
38 |
|
|
namespace hpp { |
39 |
|
|
namespace manipulation { |
40 |
|
|
/// Set of configurations accessible to each others by a single transition, |
41 |
|
|
/// with the same right hand side. |
42 |
|
|
/// |
43 |
|
|
/// This assumes the roadmap is not directed. |
44 |
|
|
class HPP_MANIPULATION_DLLAPI LeafConnectedComp { |
45 |
|
|
public: |
46 |
|
|
typedef LeafConnectedComp* RawPtr_t; |
47 |
|
|
typedef std::set<RawPtr_t> LeafConnectedComps_t; |
48 |
|
|
/// return a shared pointer to new instance |
49 |
|
|
static LeafConnectedCompPtr_t create(const RoadmapPtr_t& roadmap); |
50 |
|
|
|
51 |
|
|
/// Merge two connected components |
52 |
|
|
/// \param other manipulation symbolic component to merge into this one. |
53 |
|
|
/// \note other will be empty after calling this method. |
54 |
|
|
virtual void merge(const LeafConnectedCompPtr_t& otherCC); |
55 |
|
|
|
56 |
|
|
/// Whether this connected component can reach cc |
57 |
|
|
/// \param cc a connected component |
58 |
|
|
bool canReach(const LeafConnectedCompPtr_t& cc); |
59 |
|
|
|
60 |
|
|
/// Whether this connected component can reach cc |
61 |
|
|
/// \param cc a connected component |
62 |
|
|
/// \retval cc2Tocc1 list of connected components between cc2 and cc1 |
63 |
|
|
/// that should be merged. |
64 |
|
|
bool canReach(const LeafConnectedCompPtr_t& cc, |
65 |
|
|
LeafConnectedComp::LeafConnectedComps_t& cc2Tocc1); |
66 |
|
|
|
67 |
|
|
/// Add roadmap node to connected component |
68 |
|
|
/// \param roadmap node to be added |
69 |
|
|
void addNode(const RoadmapNodePtr_t& node); |
70 |
|
|
|
71 |
|
|
virtual void setFirstNode(const RoadmapNodePtr_t& node); |
72 |
|
|
|
73 |
|
|
core::ConnectedComponentPtr_t connectedComponent() const { |
74 |
|
|
assert(!nodes_.empty()); |
75 |
|
|
return nodes_.front()->connectedComponent(); |
76 |
|
|
}; |
77 |
|
|
|
78 |
|
|
const RoadmapNodes_t& nodes() const { return nodes_; } |
79 |
|
|
|
80 |
|
✗ |
LeafConnectedCompPtr_t self() { return weak_.lock(); } |
81 |
|
|
|
82 |
|
|
const LeafConnectedComp::LeafConnectedComps_t& from() const { return from_; } |
83 |
|
|
|
84 |
|
|
const LeafConnectedComp::LeafConnectedComps_t& to() const { return to_; } |
85 |
|
|
|
86 |
|
|
protected: |
87 |
|
✗ |
LeafConnectedComp(const RoadmapPtr_t& r) : roadmap_(r) {} |
88 |
|
|
|
89 |
|
✗ |
void init(const LeafConnectedCompWkPtr_t& shPtr) { weak_ = shPtr; } |
90 |
|
|
|
91 |
|
|
graph::StatePtr_t state_; |
92 |
|
|
RoadmapNodes_t nodes_; |
93 |
|
|
|
94 |
|
|
/// For serialization only. |
95 |
|
✗ |
LeafConnectedComp() {} |
96 |
|
|
|
97 |
|
|
private: |
98 |
|
|
static void clean(LeafConnectedComps_t& set); |
99 |
|
|
// status variable to indicate whether or not CC has been visited |
100 |
|
|
mutable bool explored_; |
101 |
|
|
RoadmapWkPtr_t roadmap_; |
102 |
|
|
LeafConnectedComps_t to_, from_; |
103 |
|
|
LeafConnectedCompWkPtr_t weak_; |
104 |
|
|
friend class Roadmap; |
105 |
|
|
|
106 |
|
|
HPP_SERIALIZABLE(); |
107 |
|
|
}; // class LeafConnectedComp |
108 |
|
|
|
109 |
|
|
class HPP_MANIPULATION_DLLAPI WeighedLeafConnectedComp |
110 |
|
|
: public LeafConnectedComp { |
111 |
|
|
public: |
112 |
|
|
void merge(const LeafConnectedCompPtr_t& otherCC); |
113 |
|
|
|
114 |
|
|
void setFirstNode(const RoadmapNodePtr_t& node); |
115 |
|
|
|
116 |
|
|
static WeighedLeafConnectedCompPtr_t create(const RoadmapPtr_t& roadmap); |
117 |
|
|
|
118 |
|
|
std::size_t indexOf(const graph::EdgePtr_t e) const; |
119 |
|
|
|
120 |
|
|
void normalizeProba() { |
121 |
|
|
const value_type s = p_.sum(); |
122 |
|
|
p_ /= s; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
value_type weight_; |
126 |
|
|
/// Transition probabilities |
127 |
|
|
vector_t p_; |
128 |
|
|
std::vector<graph::EdgePtr_t> edges_; |
129 |
|
|
|
130 |
|
|
protected: |
131 |
|
✗ |
WeighedLeafConnectedComp(const RoadmapPtr_t& r) |
132 |
|
✗ |
: LeafConnectedComp(r), weight_(1) {} |
133 |
|
|
|
134 |
|
|
private: |
135 |
|
✗ |
WeighedLeafConnectedComp() {} |
136 |
|
|
HPP_SERIALIZABLE(); |
137 |
|
|
}; // class LeafConnectedComp |
138 |
|
|
} // namespace manipulation |
139 |
|
|
} // namespace hpp |
140 |
|
|
#endif // HPP_MANIPULATION_LEAF_CONNECTED_COMP_HH |
141 |
|
|
|