| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// Copyright (c) 2014, LAAS-CNRS |
| 2 |
|
|
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) |
| 3 |
|
|
// |
| 4 |
|
|
|
| 5 |
|
|
// Redistribution and use in source and binary forms, with or without |
| 6 |
|
|
// modification, are permitted provided that the following conditions are |
| 7 |
|
|
// met: |
| 8 |
|
|
// |
| 9 |
|
|
// 1. Redistributions of source code must retain the above copyright |
| 10 |
|
|
// notice, this list of conditions and the following disclaimer. |
| 11 |
|
|
// |
| 12 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
|
|
// notice, this list of conditions and the following disclaimer in the |
| 14 |
|
|
// documentation and/or other materials provided with the distribution. |
| 15 |
|
|
// |
| 16 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 |
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 |
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 |
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 |
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 |
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 |
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 |
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 27 |
|
|
// DAMAGE. |
| 28 |
|
|
|
| 29 |
|
|
#ifndef HPP_MANIPULATION_GRAPH_STATISTICS_HH |
| 30 |
|
|
#define HPP_MANIPULATION_GRAPH_STATISTICS_HH |
| 31 |
|
|
|
| 32 |
|
|
#include <hpp/manipulation/roadmap-node.hh> |
| 33 |
|
|
#include <hpp/statistics/bin.hh> |
| 34 |
|
|
#include <hpp/util/debug.hh> |
| 35 |
|
|
|
| 36 |
|
|
#include "hpp/manipulation/config.hh" |
| 37 |
|
|
#include "hpp/manipulation/fwd.hh" |
| 38 |
|
|
#include "hpp/manipulation/graph/graph.hh" |
| 39 |
|
|
#include "hpp/manipulation/graph/state.hh" |
| 40 |
|
|
|
| 41 |
|
|
namespace hpp { |
| 42 |
|
|
namespace manipulation { |
| 43 |
|
|
namespace graph { |
| 44 |
|
|
/// This class is used to do statistics on the roadmap. |
| 45 |
|
|
/// It keeps a track of which leaves of a foliation have been visited. |
| 46 |
|
|
class HPP_MANIPULATION_DLLAPI LeafBin : public ::hpp::statistics::Bin { |
| 47 |
|
|
public: |
| 48 |
|
|
typedef ::hpp::statistics::Bin Parent; |
| 49 |
|
|
typedef std::list<RoadmapNodePtr_t> RoadmapNodes_t; |
| 50 |
|
|
|
| 51 |
|
|
LeafBin(const vector_t& v, value_type* threshold_); |
| 52 |
|
|
|
| 53 |
|
|
void push_back(const RoadmapNodePtr_t& n); |
| 54 |
|
|
|
| 55 |
|
|
bool operator<(const LeafBin& rhs) const; |
| 56 |
|
|
|
| 57 |
|
|
bool operator==(const LeafBin& rhs) const; |
| 58 |
|
|
|
| 59 |
|
|
const vector_t& value() const; |
| 60 |
|
|
|
| 61 |
|
|
std::ostream& print(std::ostream& os) const; |
| 62 |
|
|
|
| 63 |
|
|
unsigned int numberOfObsOutOfConnectedComponent( |
| 64 |
|
|
const core::ConnectedComponentPtr_t& cc) const; |
| 65 |
|
|
|
| 66 |
|
|
const RoadmapNodes_t& nodes() const; |
| 67 |
|
|
|
| 68 |
|
|
private: |
| 69 |
|
|
vector_t value_; |
| 70 |
|
|
|
| 71 |
|
|
RoadmapNodes_t nodes_; |
| 72 |
|
|
|
| 73 |
|
|
value_type* thr_; |
| 74 |
|
|
|
| 75 |
|
|
std::ostream& printValue(std::ostream& os) const; |
| 76 |
|
|
}; |
| 77 |
|
|
|
| 78 |
|
|
/// This class is used to do statistics on the roadmap. |
| 79 |
|
|
/// It keeps a track of which nodes of the constraint graph have been visited. |
| 80 |
|
|
class HPP_MANIPULATION_DLLLOCAL NodeBin : public ::hpp::statistics::Bin { |
| 81 |
|
|
public: |
| 82 |
|
|
typedef ::hpp::statistics::Bin Parent; |
| 83 |
|
|
NodeBin(const StatePtr_t& n); |
| 84 |
|
|
|
| 85 |
|
|
void push_back(const RoadmapNodePtr_t& n); |
| 86 |
|
|
|
| 87 |
|
|
bool operator<(const NodeBin& rhs) const; |
| 88 |
|
|
|
| 89 |
|
|
bool operator==(const NodeBin& rhs) const; |
| 90 |
|
|
|
| 91 |
|
|
const StatePtr_t& state() const; |
| 92 |
|
|
|
| 93 |
|
|
std::ostream& print(std::ostream& os) const; |
| 94 |
|
|
|
| 95 |
|
|
private: |
| 96 |
|
|
StatePtr_t state_; |
| 97 |
|
|
|
| 98 |
|
|
typedef std::list<RoadmapNodePtr_t> RoadmapNodes_t; |
| 99 |
|
|
RoadmapNodes_t roadmapNodes_; |
| 100 |
|
|
|
| 101 |
|
|
std::ostream& printValue(std::ostream& os) const; |
| 102 |
|
|
}; |
| 103 |
|
|
|
| 104 |
|
|
class HPP_MANIPULATION_DLLLOCAL Histogram { |
| 105 |
|
|
public: |
| 106 |
|
4 |
virtual ~Histogram() {}; |
| 107 |
|
|
|
| 108 |
|
|
virtual void add(const RoadmapNodePtr_t& node) = 0; |
| 109 |
|
|
|
| 110 |
|
|
virtual HistogramPtr_t clone() const = 0; |
| 111 |
|
|
|
| 112 |
|
|
virtual void clear() = 0; |
| 113 |
|
|
}; |
| 114 |
|
|
|
| 115 |
|
|
/// This class represents a foliation of a submanifold of the configuration |
| 116 |
|
|
/// space. |
| 117 |
|
|
/// Such a foliation is defined by the two following functions: |
| 118 |
|
|
/// \li a condition $f$ such that the submanifold is |
| 119 |
|
|
/// $\mathcal{M}= \left{q \in \mathbb{C} | f(q)=0 \right}$ |
| 120 |
|
|
/// \li a parametrizer $g$ such that the leaf of this foliation is a level |
| 121 |
|
|
/// set of $g$. |
| 122 |
|
|
class HPP_MANIPULATION_DLLAPI Foliation { |
| 123 |
|
|
public: |
| 124 |
|
|
/// Whether the configuration is the submanifold $\mathcal{M}$ |
| 125 |
|
|
bool contains(ConfigurationIn_t q) const; |
| 126 |
|
|
/// Whether the configuration is the submanifold $\mathcal{M}$ |
| 127 |
|
|
vector_t parameter(ConfigurationIn_t q) const; |
| 128 |
|
|
|
| 129 |
|
|
void condition(const ConstraintSetPtr_t c); |
| 130 |
|
|
ConstraintSetPtr_t condition() const; |
| 131 |
|
|
void parametrizer(const ConstraintSetPtr_t p); |
| 132 |
|
|
ConstraintSetPtr_t parametrizer() const; |
| 133 |
|
|
|
| 134 |
|
|
private: |
| 135 |
|
|
// condition_ contains the constraints defining the submanifold |
| 136 |
|
|
// containing all the leaf. |
| 137 |
|
|
// parametrizer_ contains the constraints providing a parametrization |
| 138 |
|
|
// of the foliation. |
| 139 |
|
|
ConstraintSetPtr_t condition_, parametrizer_; |
| 140 |
|
|
}; |
| 141 |
|
|
|
| 142 |
|
|
class HPP_MANIPULATION_DLLAPI LeafHistogram |
| 143 |
|
|
: public ::hpp::statistics::Statistics<LeafBin>, |
| 144 |
|
|
public Histogram { |
| 145 |
|
|
public: |
| 146 |
|
|
typedef ::hpp::statistics::Statistics<LeafBin> Parent; |
| 147 |
|
|
|
| 148 |
|
|
static LeafHistogramPtr_t create(const Foliation f); |
| 149 |
|
|
|
| 150 |
|
|
/// Insert an occurence of a value in the histogram |
| 151 |
|
|
void add(const RoadmapNodePtr_t& n); |
| 152 |
|
|
|
| 153 |
|
|
std::ostream& print(std::ostream& os) const; |
| 154 |
|
|
|
| 155 |
|
|
virtual HistogramPtr_t clone() const; |
| 156 |
|
|
|
| 157 |
|
|
statistics::DiscreteDistribution<RoadmapNodePtr_t> |
| 158 |
|
|
getDistribOutOfConnectedComponent( |
| 159 |
|
|
const core::ConnectedComponentPtr_t& cc) const; |
| 160 |
|
|
|
| 161 |
|
|
statistics::DiscreteDistribution<RoadmapNodePtr_t> getDistrib() const; |
| 162 |
|
|
|
| 163 |
|
✗ |
void clear() { Parent::clear(); } |
| 164 |
|
|
|
| 165 |
|
|
const Foliation& foliation() const { return f_; } |
| 166 |
|
|
|
| 167 |
|
|
protected: |
| 168 |
|
|
/// Constructor |
| 169 |
|
|
/// \param state defines the submanifold containing the foliation. |
| 170 |
|
|
/// \param constraint The constraint that create the foliation being |
| 171 |
|
|
/// studied. |
| 172 |
|
|
LeafHistogram(const Foliation f); |
| 173 |
|
|
|
| 174 |
|
|
private: |
| 175 |
|
|
Foliation f_; |
| 176 |
|
|
|
| 177 |
|
|
/// Threshold used for equality between offset values. |
| 178 |
|
|
value_type threshold_; |
| 179 |
|
|
}; |
| 180 |
|
|
|
| 181 |
|
|
class HPP_MANIPULATION_DLLLOCAL StateHistogram |
| 182 |
|
|
: public ::hpp::statistics::Statistics<NodeBin>, |
| 183 |
|
|
public Histogram { |
| 184 |
|
|
public: |
| 185 |
|
|
typedef ::hpp::statistics::Statistics<NodeBin> Parent; |
| 186 |
|
|
/// Constructor |
| 187 |
|
|
/// \param graph The constraint graph used to get the states from |
| 188 |
|
|
/// a configuration. |
| 189 |
|
|
StateHistogram(const graph::GraphPtr_t& graph); |
| 190 |
|
|
|
| 191 |
|
|
/// Insert an occurence of a value in the histogram |
| 192 |
|
|
void add(const RoadmapNodePtr_t& n); |
| 193 |
|
|
|
| 194 |
|
|
std::ostream& print(std::ostream& os) const; |
| 195 |
|
|
|
| 196 |
|
|
const graph::GraphPtr_t& constraintGraph() const; |
| 197 |
|
|
|
| 198 |
|
|
virtual HistogramPtr_t clone() const; |
| 199 |
|
|
|
| 200 |
|
✗ |
void clear() { Parent::clear(); } |
| 201 |
|
|
|
| 202 |
|
|
private: |
| 203 |
|
|
/// The constraint graph |
| 204 |
|
|
graph::GraphPtr_t graph_; |
| 205 |
|
|
}; |
| 206 |
|
|
typedef shared_ptr<StateHistogram> NodeHistogramPtr_t; |
| 207 |
|
|
} // namespace graph |
| 208 |
|
|
} // namespace manipulation |
| 209 |
|
|
} // namespace hpp |
| 210 |
|
|
|
| 211 |
|
|
#endif // HPP_MANIPULATION_GRAPH_STATISTICS_HH |
| 212 |
|
|
|