Skip to content
Snippets Groups Projects
Commit 00612069 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add Graph::initialize and fix const-correctness of constructor of constraints

parent ce815995
No related branches found
No related tags found
No related merge requests found
...@@ -29,32 +29,6 @@ ...@@ -29,32 +29,6 @@
namespace hpp { namespace hpp {
namespace manipulation { namespace manipulation {
namespace graph { namespace graph {
/// \cond
/// Cache mechanism that enable const-correctness of member functions.
template <typename C>
class HPP_MANIPULATION_LOCAL Cache
{
public:
void set (const C& c)
{
c_ = c;
}
operator bool() const
{
return (bool)c_;
}
const C& get () const
{
return c_;
}
private:
C c_;
};
/// \endcond
/// \addtogroup constraint_graph /// \addtogroup constraint_graph
/// \{ /// \{
...@@ -141,13 +115,13 @@ namespace hpp { ...@@ -141,13 +115,13 @@ namespace hpp {
/// Get steering method associated to the edge. /// Get steering method associated to the edge.
const core::SteeringMethodPtr_t& steeringMethod () const const core::SteeringMethodPtr_t& steeringMethod () const
{ {
return steeringMethod_->get(); return steeringMethod_;
} }
/// Get path validation associated to the edge. /// Get path validation associated to the edge.
const core::PathValidationPtr_t& pathValidation () const const core::PathValidationPtr_t& pathValidation () const
{ {
return pathValidation_->get(); return pathValidation_;
} }
const RelativeMotion::matrix_type& relativeMotion () const const RelativeMotion::matrix_type& relativeMotion () const
...@@ -190,9 +164,11 @@ namespace hpp { ...@@ -190,9 +164,11 @@ namespace hpp {
/// \return The initialized constraint. /// \return The initialized constraint.
ConstraintSetPtr_t pathConstraint() const; ConstraintSetPtr_t pathConstraint() const;
virtual ConstraintSetPtr_t buildConfigConstraint() const; virtual ConstraintSetPtr_t buildConfigConstraint();
virtual ConstraintSetPtr_t buildPathConstraint();
virtual ConstraintSetPtr_t buildPathConstraint() const; virtual void initialize ();
/// Print the object in a stream. /// Print the object in a stream.
virtual std::ostream& print (std::ostream& os) const; virtual std::ostream& print (std::ostream& os) const;
...@@ -200,16 +176,12 @@ namespace hpp { ...@@ -200,16 +176,12 @@ namespace hpp {
bool isShort_; bool isShort_;
private: private:
typedef Cache < ConstraintSetPtr_t > Constraint_t;
typedef Cache < core::SteeringMethodPtr_t > SteeringMethod_t;
typedef Cache < core::PathValidationPtr_t > PathValidation_t;
/// See pathConstraint member function. /// See pathConstraint member function.
Constraint_t* pathConstraints_; ConstraintSetPtr_t pathConstraints_;
/// Constraint ensuring that a q_proj will be in to_ and in the /// Constraint ensuring that a q_proj will be in to_ and in the
/// same leaf of to_ as the configuration used for initialization. /// same leaf of to_ as the configuration used for initialization.
Constraint_t* configConstraints_; ConstraintSetPtr_t configConstraints_;
/// The two ends of the transition. /// The two ends of the transition.
StateWkPtr_t from_, to_; StateWkPtr_t from_, to_;
...@@ -218,11 +190,11 @@ namespace hpp { ...@@ -218,11 +190,11 @@ namespace hpp {
StateWkPtr_t state_; StateWkPtr_t state_;
/// Steering method used to create paths associated to the edge /// Steering method used to create paths associated to the edge
SteeringMethod_t* steeringMethod_; core::SteeringMethodPtr_t steeringMethod_;
/// Path validation associated to the edge /// Path validation associated to the edge
mutable RelativeMotion::matrix_type relMotion_; mutable RelativeMotion::matrix_type relMotion_;
PathValidation_t* pathValidation_; core::PathValidationPtr_t pathValidation_;
/// Weak pointer to itself. /// Weak pointer to itself.
EdgeWkPtr_t wkPtr_; EdgeWkPtr_t wkPtr_;
...@@ -334,7 +306,7 @@ namespace hpp { ...@@ -334,7 +306,7 @@ namespace hpp {
virtual bool applyConstraints (core::NodePtr_t n_offset, ConfigurationOut_t q) const; virtual bool applyConstraints (core::NodePtr_t n_offset, ConfigurationOut_t q) const;
virtual ConstraintSetPtr_t buildConfigConstraint() const; virtual ConstraintSetPtr_t buildConfigConstraint();
void buildHistogram (); void buildHistogram ();
...@@ -383,6 +355,8 @@ namespace hpp { ...@@ -383,6 +355,8 @@ namespace hpp {
/// Populate DrawingAttributes tooltip /// Populate DrawingAttributes tooltip
virtual void populateTooltip (dot::Tooltip& tp) const; virtual void populateTooltip (dot::Tooltip& tp) const;
virtual void initialize ();
private: private:
bool applyConstraintsWithOffset (ConfigurationIn_t qoffset, bool applyConstraintsWithOffset (ConfigurationIn_t qoffset,
ConfigurationIn_t qlevelset, ConfigurationOut_t q) const; ConfigurationIn_t qlevelset, ConfigurationOut_t q) const;
......
...@@ -121,6 +121,8 @@ namespace hpp { ...@@ -121,6 +121,8 @@ namespace hpp {
/// Populate DrawingAttributes tooltip /// Populate DrawingAttributes tooltip
virtual void populateTooltip (dot::Tooltip& tp) const; virtual void populateTooltip (dot::Tooltip& tp) const;
virtual void initialize () = 0;
private: private:
/// Name of the component. /// Name of the component.
std::string name_; std::string name_;
...@@ -128,6 +130,8 @@ namespace hpp { ...@@ -128,6 +130,8 @@ namespace hpp {
GraphComponentWkPtr_t wkPtr_; GraphComponentWkPtr_t wkPtr_;
/// ID of the component (index in components vector). /// ID of the component (index in components vector).
std::size_t id_; std::size_t id_;
friend class Graph;
}; };
std::ostream& operator<< (std::ostream& os, const GraphComponent& graphComp); std::ostream& operator<< (std::ostream& os, const GraphComponent& graphComp);
......
...@@ -214,6 +214,8 @@ namespace hpp { ...@@ -214,6 +214,8 @@ namespace hpp {
/// Print the component in DOT language. /// Print the component in DOT language.
virtual std::ostream& dotPrint (std::ostream& os, dot::DrawingAttributes da = dot::DrawingAttributes ()) const; virtual std::ostream& dotPrint (std::ostream& os, dot::DrawingAttributes da = dot::DrawingAttributes ()) const;
virtual void initialize ();
protected: protected:
/// Initialization of the object. /// Initialization of the object.
void init (const GraphWkPtr_t& weak, DevicePtr_t robot); void init (const GraphWkPtr_t& weak, DevicePtr_t robot);
......
...@@ -84,6 +84,8 @@ namespace hpp { ...@@ -84,6 +84,8 @@ namespace hpp {
WeighedStates_t orderedStates_; WeighedStates_t orderedStates_;
States_t waypoints_; States_t waypoints_;
virtual void initialize () {};
private: private:
/// Weak pointer to itself. /// Weak pointer to itself.
StateSelectorPtr_t wkPtr_; StateSelectorPtr_t wkPtr_;
......
...@@ -104,7 +104,10 @@ namespace hpp { ...@@ -104,7 +104,10 @@ namespace hpp {
Weight_t getWeight (const EdgePtr_t&edge); Weight_t getWeight (const EdgePtr_t&edge);
/// Constraint to project onto this state. /// Constraint to project onto this state.
ConstraintSetPtr_t configConstraint() const; ConstraintSetPtr_t configConstraint() const
{
return configConstraints_;
}
/// Add core::NumericalConstraint to the component. /// Add core::NumericalConstraint to the component.
virtual void addNumericalConstraintForPath (const NumericalConstraintPtr_t& nm, virtual void addNumericalConstraintForPath (const NumericalConstraintPtr_t& nm,
...@@ -156,6 +159,8 @@ namespace hpp { ...@@ -156,6 +159,8 @@ namespace hpp {
virtual void populateTooltip (dot::Tooltip& tp) const; virtual void populateTooltip (dot::Tooltip& tp) const;
virtual void initialize ();
private: private:
/// List of possible motions from this state (i.e. the outgoing /// List of possible motions from this state (i.e. the outgoing
/// vertices). /// vertices).
...@@ -163,8 +168,7 @@ namespace hpp { ...@@ -163,8 +168,7 @@ namespace hpp {
std::vector <EdgePtr_t> hiddenNeighbors_; std::vector <EdgePtr_t> hiddenNeighbors_;
/// Set of constraints to be statisfied. /// Set of constraints to be statisfied.
typedef Cache < ConstraintSetPtr_t > Constraint_t; ConstraintSetPtr_t configConstraints_;
Constraint_t* configConstraints_;
/// Stores the numerical constraints for path. /// Stores the numerical constraints for path.
NumericalConstraints_t numericalConstraintsForPath_; NumericalConstraints_t numericalConstraintsForPath_;
......
...@@ -71,6 +71,9 @@ namespace hpp { ...@@ -71,6 +71,9 @@ namespace hpp {
/// Get the constraint graph /// Get the constraint graph
graph::GraphPtr_t constraintGraph () const; graph::GraphPtr_t constraintGraph () const;
/// Should be called before any call on the graph is made.
void initConstraintGraph ();
/// \} /// \}
/// Create placement constraint /// Create placement constraint
......
...@@ -38,19 +38,14 @@ namespace hpp { ...@@ -38,19 +38,14 @@ namespace hpp {
namespace graph { namespace graph {
Edge::Edge (const std::string& name) : Edge::Edge (const std::string& name) :
GraphComponent (name), isShort_ (false), GraphComponent (name), isShort_ (false),
pathConstraints_ (new Constraint_t()), pathConstraints_ (),
configConstraints_ (new Constraint_t()), configConstraints_ (),
steeringMethod_ (new SteeringMethod_t()), steeringMethod_ (),
pathValidation_ (new PathValidation_t()) pathValidation_ ()
{} {}
Edge::~Edge () Edge::~Edge ()
{ {}
if (pathConstraints_ ) delete pathConstraints_;
if (configConstraints_) delete configConstraints_;
if (steeringMethod_ ) delete steeringMethod_;
if (pathValidation_ ) delete pathValidation_;
}
StatePtr_t Edge::to () const StatePtr_t Edge::to () const
{ {
...@@ -159,6 +154,12 @@ namespace hpp { ...@@ -159,6 +154,12 @@ namespace hpp {
state_ = to; state_ = to;
} }
void Edge::initialize ()
{
configConstraints_ = buildConfigConstraint ();
pathConstraints_ = buildPathConstraint ();
}
std::ostream& Edge::print (std::ostream& os) const std::ostream& Edge::print (std::ostream& os) const
{ {
os << "| | |-- "; os << "| | |-- ";
...@@ -181,13 +182,10 @@ namespace hpp { ...@@ -181,13 +182,10 @@ namespace hpp {
ConstraintSetPtr_t Edge::configConstraint() const ConstraintSetPtr_t Edge::configConstraint() const
{ {
if (!*configConstraints_) { return configConstraints_;
configConstraints_->set (buildConfigConstraint ());
}
return configConstraints_->get ();
} }
ConstraintSetPtr_t Edge::buildConfigConstraint() const ConstraintSetPtr_t Edge::buildConfigConstraint()
{ {
std::string n = "(" + name () + ")"; std::string n = "(" + name () + ")";
GraphPtr_t g = graph_.lock (); GraphPtr_t g = graph_.lock ();
...@@ -216,14 +214,10 @@ namespace hpp { ...@@ -216,14 +214,10 @@ namespace hpp {
ConstraintSetPtr_t Edge::pathConstraint() const ConstraintSetPtr_t Edge::pathConstraint() const
{ {
if (!*pathConstraints_) { return pathConstraints_;
ConstraintSetPtr_t pathConstraints (buildPathConstraint ());
pathConstraints_->set (pathConstraints);
}
return pathConstraints_->get ();
} }
ConstraintSetPtr_t Edge::buildPathConstraint() const ConstraintSetPtr_t Edge::buildPathConstraint()
{ {
std::string n = "(" + name () + ")"; std::string n = "(" + name () + ")";
GraphPtr_t g = graph_.lock (); GraphPtr_t g = graph_.lock ();
...@@ -244,16 +238,15 @@ namespace hpp { ...@@ -244,16 +238,15 @@ namespace hpp {
// Build steering method // Build steering method
const ProblemPtr_t& problem (g->problem()); const ProblemPtr_t& problem (g->problem());
steeringMethod_->set(problem->steeringMethod() steeringMethod_ = problem->steeringMethod()->innerSteeringMethod()->copy();
->innerSteeringMethod()->copy()); steeringMethod_->constraints (constraint);
steeringMethod_->get()->constraints (constraint);
// Build path validation and relative motion matrix // Build path validation and relative motion matrix
// TODO this path validation will not contain obstacles added after // TODO this path validation will not contain obstacles added after
// its creation. // its creation.
pathValidation_->set(problem->pathValidationFactory ()); pathValidation_ = problem->pathValidationFactory ();
relMotion_ = RelativeMotion::matrix (g->robot()); relMotion_ = RelativeMotion::matrix (g->robot());
RelativeMotion::fromConstraint (relMotion_, g->robot(), constraint); RelativeMotion::fromConstraint (relMotion_, g->robot(), constraint);
pathValidation_->get()->filterCollisionPairs (relMotion_); pathValidation_->filterCollisionPairs (relMotion_);
return constraint; return constraint;
} }
...@@ -273,12 +266,7 @@ namespace hpp { ...@@ -273,12 +266,7 @@ namespace hpp {
const const
{ {
using pinocchio::displayConfig; using pinocchio::displayConfig;
core::SteeringMethodPtr_t sm (steeringMethod_->get()); if (!steeringMethod_) {
if (!sm) {
buildPathConstraint ();
}
sm = (steeringMethod_->get());
if (!sm) {
std::ostringstream oss; std::ostringstream oss;
oss << "No steering method set in edge " << name () << "."; oss << "No steering method set in edge " << name () << ".";
throw std::runtime_error (oss.str ().c_str ()); throw std::runtime_error (oss.str ().c_str ());
...@@ -287,7 +275,7 @@ namespace hpp { ...@@ -287,7 +275,7 @@ namespace hpp {
constraints->configProjector ()->rightHandSideFromConfig(q1); constraints->configProjector ()->rightHandSideFromConfig(q1);
if (constraints->isSatisfied (q1)) { if (constraints->isSatisfied (q1)) {
if (constraints->isSatisfied (q2)) { if (constraints->isSatisfied (q2)) {
path = (*sm) (q1, q2); path = (*steeringMethod_) (q1, q2);
return (bool)path; return (bool)path;
} else { } else {
hppDout(info, "q2 = " << displayConfig (q2) hppDout(info, "q2 = " << displayConfig (q2)
...@@ -686,7 +674,13 @@ namespace hpp { ...@@ -686,7 +674,13 @@ namespace hpp {
g->insertHistogram (hist_); g->insertHistogram (hist_);
} }
ConstraintSetPtr_t LevelSetEdge::buildConfigConstraint() const void LevelSetEdge::initialize ()
{
Edge::initialize();
buildHistogram ();
}
ConstraintSetPtr_t LevelSetEdge::buildConfigConstraint()
{ {
std::string n = "(" + name () + ")"; std::string n = "(" + name () + ")";
GraphPtr_t g = graph_.lock (); GraphPtr_t g = graph_.lock ();
......
...@@ -47,6 +47,14 @@ namespace hpp { ...@@ -47,6 +47,14 @@ namespace hpp {
); );
} }
void Graph::initialize ()
{
hists_.clear ();
assert(components_.size() >= 1 && components_[0].lock() == wkPtr_.lock());
for (std::size_t i = 1; i < components_.size(); ++i)
components_[i].lock()->initialize();
}
StateSelectorPtr_t Graph::createNodeSelector (const std::string& name) StateSelectorPtr_t Graph::createNodeSelector (const std::string& name)
{ {
stateSelector_ = StateSelector::create (name); stateSelector_ = StateSelector::create (name);
......
...@@ -27,14 +27,12 @@ namespace hpp { ...@@ -27,14 +27,12 @@ namespace hpp {
namespace manipulation { namespace manipulation {
namespace graph { namespace graph {
State::State (const std::string& name) : State::State (const std::string& name) :
GraphComponent (name), configConstraints_ (new Constraint_t()), GraphComponent (name), configConstraints_ (),
isWaypoint_ (false) isWaypoint_ (false)
{} {}
State::~State () State::~State ()
{ {}
if (configConstraints_) delete configConstraints_;
}
StatePtr_t State::create (const std::string& name) StatePtr_t State::create (const std::string& name)
{ {
...@@ -107,23 +105,19 @@ namespace hpp { ...@@ -107,23 +105,19 @@ namespace hpp {
return os; return os;
} }
ConstraintSetPtr_t State::configConstraint() const void State::initialize()
{ {
if (!*configConstraints_) { std::string n = "(" + name () + ")";
std::string n = "(" + name () + ")"; GraphPtr_t g = graph_.lock ();
GraphPtr_t g = graph_.lock (); configConstraints_ = ConstraintSet::create (g->robot (), "Set " + n);
ConstraintSetPtr_t constraint = ConstraintSet::create (g->robot (), "Set " + n);
ConfigProjectorPtr_t proj = ConfigProjector::create(g->robot(), "proj " + n, g->errorThreshold(), g->maxIterations());
ConfigProjectorPtr_t proj = ConfigProjector::create(g->robot(), "proj " + n, g->errorThreshold(), g->maxIterations()); g->insertNumericalConstraints (proj);
g->insertNumericalConstraints (proj); insertNumericalConstraints (proj);
insertNumericalConstraints (proj); configConstraints_->addConstraint (proj);
constraint->addConstraint (proj);
g->insertLockedJoints (proj);
g->insertLockedJoints (proj); insertLockedJoints (proj);
insertLockedJoints (proj);
configConstraints_->set (constraint);
}
return configConstraints_->get ();
} }
void State::updateWeight (const EdgePtr_t& e, const Weight_t& w) void State::updateWeight (const EdgePtr_t& e, const Weight_t& w)
......
...@@ -184,6 +184,14 @@ namespace hpp { ...@@ -184,6 +184,14 @@ namespace hpp {
return constraintGraph_; return constraintGraph_;
} }
void ProblemSolver::initConstraintGraph ()
{
if (!constraintGraph_)
throw std::runtime_error ("The graph is not defined.");
initSteeringMethod();
constraintGraph_->initialize();
}
void ProblemSolver::createPlacementConstraint void ProblemSolver::createPlacementConstraint
(const std::string& name, const StringList_t& surface1, (const std::string& name, const StringList_t& surface1,
const StringList_t& surface2, const value_type& margin) const StringList_t& surface2, const value_type& margin)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment