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

Nodes in NodeSelector can be ordered via weights

parent 336d5383
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,8 @@ namespace hpp { ...@@ -34,7 +34,8 @@ namespace hpp {
static NodeSelectorPtr_t create(const std::string& name); static NodeSelectorPtr_t create(const std::string& name);
/// Create an empty node /// Create an empty node
NodePtr_t createNode (const std::string& name, bool waypoint = false); NodePtr_t createNode (const std::string& name, bool waypoint = false,
const int w = 0);
/// Returns the state of a configuration. /// Returns the state of a configuration.
NodePtr_t getNode(ConfigurationIn_t config) const; NodePtr_t getNode(ConfigurationIn_t config) const;
...@@ -43,10 +44,7 @@ namespace hpp { ...@@ -43,10 +44,7 @@ namespace hpp {
NodePtr_t getNode(RoadmapNodePtr_t node) const; NodePtr_t getNode(RoadmapNodePtr_t node) const;
/// Returns a list of all the nodes /// Returns a list of all the nodes
const Nodes_t& getNodes () const Nodes_t getNodes () const;
{
return orderedStates_;
}
/// Select randomly an outgoing edge of the given node. /// Select randomly an outgoing edge of the given node.
virtual EdgePtr_t chooseEdge(RoadmapNodePtr_t from) const; virtual EdgePtr_t chooseEdge(RoadmapNodePtr_t from) const;
...@@ -81,7 +79,9 @@ namespace hpp { ...@@ -81,7 +79,9 @@ namespace hpp {
virtual std::ostream& print (std::ostream& os) const; virtual std::ostream& print (std::ostream& os) const;
/// List of the states of one end-effector, ordered by priority. /// List of the states of one end-effector, ordered by priority.
Nodes_t orderedStates_; typedef std::pair <int, NodePtr_t> WeighedNode_t;
typedef std::list <WeighedNode_t> WeighedNodes_t;
WeighedNodes_t orderedStates_;
Nodes_t waypoints_; Nodes_t waypoints_;
private: private:
......
...@@ -130,9 +130,9 @@ namespace hpp { ...@@ -130,9 +130,9 @@ namespace hpp {
std::ostream& GuidedNodeSelector::dotPrint (std::ostream& os, dot::DrawingAttributes) const std::ostream& GuidedNodeSelector::dotPrint (std::ostream& os, dot::DrawingAttributes) const
{ {
for (Nodes_t::const_iterator it = orderedStates_.begin(); for (WeighedNodes_t::const_iterator it = orderedStates_.begin();
orderedStates_.end() != it; ++it) orderedStates_.end() != it; ++it)
(*it)->dotPrint (os); it->second->dotPrint (os);
return os; return os;
} }
...@@ -140,9 +140,9 @@ namespace hpp { ...@@ -140,9 +140,9 @@ namespace hpp {
{ {
os << "|-- "; os << "|-- ";
GraphComponent::print (os) << std::endl; GraphComponent::print (os) << std::endl;
for (Nodes_t::const_iterator it = orderedStates_.begin(); for (WeighedNodes_t::const_iterator it = orderedStates_.begin();
orderedStates_.end() != it; ++it) orderedStates_.end() != it; ++it)
os << *(*it); os << it->first << " " << *it->second;
return os; return os;
} }
} // namespace graph } // namespace graph
......
...@@ -40,23 +40,44 @@ namespace hpp { ...@@ -40,23 +40,44 @@ namespace hpp {
} }
NodePtr_t NodeSelector::createNode (const std::string& name, NodePtr_t NodeSelector::createNode (const std::string& name,
bool waypoint) bool waypoint, const int w)
{ {
NodePtr_t newNode = Node::create (name); NodePtr_t newNode = Node::create (name);
newNode->nodeSelector(wkPtr_); newNode->nodeSelector(wkPtr_);
newNode->parentGraph(graph_); newNode->parentGraph(graph_);
newNode->isWaypoint (waypoint); newNode->isWaypoint (waypoint);
if (waypoint) waypoints_.push_back(newNode); if (waypoint) waypoints_.push_back(newNode);
else orderedStates_.push_back(newNode); else {
bool found = false;
for (WeighedNodes_t::iterator it = orderedStates_.begin();
it != orderedStates_.end (); ++it) {
if (it->first < w) {
orderedStates_.insert (it, WeighedNode_t(w,newNode));
found = true;
break;
}
}
if (!found)
orderedStates_.push_back (WeighedNode_t(w,newNode));
}
return newNode; return newNode;
} }
Nodes_t NodeSelector::getNodes () const
{
Nodes_t ret;
for (WeighedNodes_t::const_iterator it = orderedStates_.begin();
it != orderedStates_.end (); ++it)
ret.push_back (it->second);
return ret;
}
NodePtr_t NodeSelector::getNode(ConfigurationIn_t config) const NodePtr_t NodeSelector::getNode(ConfigurationIn_t config) const
{ {
for (Nodes_t::const_iterator it = orderedStates_.begin(); for (WeighedNodes_t::const_iterator it = orderedStates_.begin();
orderedStates_.end() != it; ++it) { orderedStates_.end() != it; ++it) {
if ((*it)->contains(config)) if (it->second->contains(config))
return *it; return it->second;
} }
std::stringstream oss; std::stringstream oss;
oss << "A configuration has no node:" << model::displayConfig (config); oss << "A configuration has no node:" << model::displayConfig (config);
...@@ -95,9 +116,9 @@ namespace hpp { ...@@ -95,9 +116,9 @@ namespace hpp {
std::ostream& NodeSelector::dotPrint (std::ostream& os, dot::DrawingAttributes) const std::ostream& NodeSelector::dotPrint (std::ostream& os, dot::DrawingAttributes) const
{ {
for (Nodes_t::const_iterator it = orderedStates_.begin(); for (WeighedNodes_t::const_iterator it = orderedStates_.begin();
orderedStates_.end() != it; ++it) orderedStates_.end() != it; ++it)
(*it)->dotPrint (os); it->second->dotPrint (os);
return os; return os;
} }
...@@ -105,9 +126,9 @@ namespace hpp { ...@@ -105,9 +126,9 @@ namespace hpp {
{ {
os << "|-- "; os << "|-- ";
GraphComponent::print (os) << std::endl; GraphComponent::print (os) << std::endl;
for (Nodes_t::const_iterator it = orderedStates_.begin(); for (WeighedNodes_t::const_iterator it = orderedStates_.begin();
orderedStates_.end() != it; ++it) orderedStates_.end() != it; ++it)
os << *(*it); os << it->first << " " << *it->second;
return os; return os;
} }
} // namespace graph } // namespace graph
......
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