1 #ifndef PPL_COMPOSITE_EDGE_H_
2 #define PPL_COMPOSITE_EDGE_H_
9 #include "containers/sequential/graph/graph_util.h"
22 template <
typename GraphType>
34 typedef stapl::edge_descriptor_impl<size_t>
ED;
94 virtual
void Clear() noexcept;
110 virtual
void Write(std::ostream& _os) const;
187 virtual
double Weight() const noexcept;
215 double m_weight{std::numeric_limits<double>::infinity()};
232 template <
typename GraphType>
236 : m_groupMap(_g), m_group(_g->GetGroup()),
240 for(
auto intermediate : _intermediates) {
250 template <
typename GraphType>
254 : m_group(_g), m_weight(_w), m_intermediates(_intermediates) {
263 template <
typename GraphType>
270 <<
"same robot group.";
278 template <
typename GraphType>
282 return m_intermediates;
286 template <
typename GraphType>
290 return m_intermediates;
294 template <
typename GraphType>
298 return m_intermediates.size();
302 template <
typename GraphType>
306 m_intermediates = _path;
311 template <
typename GraphType>
318 if(m_group != _other.m_group)
323 if(!m_groupMap and !_other.m_groupMap)
327 if(!m_groupMap or !_other.m_groupMap)
331 for(
size_t i = 0; i < m_groupMap->GetGroup()->Size(); ++i) {
333 const auto& ed1 = m_edges[i],
334 & ed2 = _other.m_edges[i];
340 const auto robot1 = m_groupMap->GetGroup()->GetRobot(i),
341 robot2 = _other.m_groupMap->GetGroup()->GetRobot(i);
342 if(*GetEdge(robot1) != *_other.GetEdge(robot2))
350 template <
typename GraphType>
354 return !(*
this == _other);
358 template <
typename GraphType>
363 return GetWeight() < _other.GetWeight();
368 template <
typename GraphType>
376 template <
typename GraphType>
385 template <
typename GraphType>
396 template <
typename GraphType>
399 Write(std::ostream& _os)
const {
401 _os << m_intermediates.size() <<
" ";
402 for(
auto& cfg : m_intermediates)
404 _os << std::scientific << std::setprecision(16) << m_weight;
407 _os.unsetf(std::ios_base::floatfield);
410 template <
typename GraphType>
419 template <
typename GraphType>
426 <<
"composite graph.";
428 const size_t index = m_groupMap->GetGroup()->GetGroupIndex(_robot);
429 m_edges[index] = _ed;
433 template <
typename GraphType>
437 const size_t index = m_group->GetGroupIndex(_robot);
438 SetEdge(index, std::move(_edge));
442 template <
typename GraphType>
446 m_localEdges[robotIndex] = std::move(_edge);
451 template <
typename GraphType>
454 GetEdge(
const size_t _robotIndex) {
455 return const_cast<IndividualEdge*
>(GetEdge(m_group->GetRobot(_robotIndex)));
459 template <
typename GraphType>
462 GetEdge(
const size_t _robotIndex)
const {
463 return GetEdge(m_group->GetRobot(_robotIndex));
467 template <
typename GraphType>
475 template <
typename GraphType>
479 const size_t index = m_group->GetGroupIndex(_robot);
481 const ED& descriptor = m_edges.at(index);
483 return &m_groupMap->GetIndividualGraph(index)->GetEdge(descriptor.source(),
484 descriptor.target());
487 return &m_localEdges.at(index);
489 catch(
const std::out_of_range&) {
491 << index <<
" (" << _robot <<
"), which is"
492 <<
" either stationary for this composite edge"
493 <<
"or not in the group.";
498 template <
typename GraphType>
499 std::vector<typename CompositeEdge<GraphType>::ED>&
506 template <
typename GraphType>
507 std::vector<typename CompositeEdge<GraphType>::IndividualEdge>&
514 template <
typename GraphType>
518 m_localEdges.clear();
522 template <
typename GraphType>
526 return m_group->Size();
529 template <
typename GraphType>
530 std::unordered_set<Robot*>
534 std::unordered_set<Robot*> actives;
536 for(
size_t i = 0; i < m_edges.size(); ++i) {
540 auto roadmap = m_groupMap->GetIndividualGraph(i);
542 typename GraphType::CEI ei;
543 typename GraphType::CVI vi;
544 roadmap->find_edge(m_edges[i], vi, ei);
546 if(ei->source() != ei->target()) {
547 actives.insert(m_group->GetRobot(i));
553 template <
typename GraphType>
557 m_timesteps = _timesteps;
560 template <
typename GraphType>
569 template <
typename GraphType>
580 template <
typename GraphType>
589 template <
typename GraphType>
593 return m_edges.begin();
597 template <
typename GraphType>
601 return m_edges.end();
605 template <
typename GraphType>
608 begin() const noexcept {
609 return m_edges.begin();
613 template <
typename GraphType>
616 end() const noexcept {
617 return m_edges.end();
std::ostream & operator<<(std::ostream &_os, const CompositeEdge< GraphType > &_w)
Definition: CompositeEdge.h:412
#define INVALID_ED
Definition: CompositeGraph.h:11
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
Definition: CompositeEdge.h:23
virtual size_t GetNumRobots() const noexcept
Get the number of robots given in this group local plan.
Definition: CompositeEdge.h:525
virtual void SetTimeSteps(size_t _timesteps)
Set the number of timesteps along this composite edge.
Definition: CompositeEdge.h:556
virtual std::unordered_set< Robot * > GetActiveRobots()
Definition: CompositeEdge.h:532
virtual void SetEdge(Robot *const _robot, const ED _ed)
Definition: CompositeEdge.h:422
RobotGroup * m_group
The robot group that this edge belongs to.
Definition: CompositeEdge.h:212
virtual bool operator==(const CompositeEdge &_w) const noexcept
Definition: CompositeEdge.h:314
GraphType::EdgeType IndividualEdge
Definition: CompositeEdge.h:31
std::vector< IndividualEdge > m_localEdges
Note that any edges added to m_localEdges must be valid and complete.
Definition: CompositeEdge.h:222
size_t m_timesteps
The number of timesteps along this edge.
Definition: CompositeEdge.h:224
CompositePath & GetIntermediates() noexcept
Get the composite state intermediates.
Definition: CompositeEdge.h:281
void SetIntermediates(const CompositePath &_cfgs)
Set the composite state intermediates.
Definition: CompositeEdge.h:305
std::vector< ED >::iterator iterator
Definition: CompositeEdge.h:194
virtual EdgeWeight GetWeight() const noexcept
Get the numeric weight for this edge.
Definition: CompositeEdge.h:371
virtual iterator begin() noexcept
Definition: CompositeEdge.h:592
virtual void Clear() noexcept
Reset the states of this object.
Definition: CompositeEdge.h:388
std::vector< CompositeStateType > CompositePath
Definition: CompositeEdge.h:38
virtual CompositeEdge operator+(const CompositeEdge &_other) const
Definition: CompositeEdge.h:572
void SetGroupGraph(GroupGraphType *const &_g)
Definition: CompositeEdge.h:266
double m_weight
The edge weight.
Definition: CompositeEdge.h:215
virtual double Weight() const noexcept
Get the weight of the plan.
Definition: CompositeEdge.h:583
std::vector< ED >::const_iterator const_iterator
Definition: CompositeEdge.h:195
GraphType::CfgType IndividualCfg
Definition: CompositeEdge.h:30
CompositeGraph< CompositeStateType, CompositeEdge > GroupGraphType
Definition: CompositeEdge.h:37
GroupGraphType * m_groupMap
The composite graph that this edge is in.
Definition: CompositeEdge.h:210
virtual std::vector< ED > & GetEdgeDescriptors() noexcept
Definition: CompositeEdge.h:501
virtual void Write(std::ostream &_os) const
Definition: CompositeEdge.h:399
std::vector< ED > m_edges
Descriptors of the individual edges.
Definition: CompositeEdge.h:219
CompositeState< GraphType > CompositeStateType
Definition: CompositeEdge.h:36
virtual IndividualEdge * GetEdge(Robot *const _robot)
Definition: CompositeEdge.h:470
CompositeEdge(GroupGraphType *const &_g=nullptr, const double _w=0.0, const CompositePath &_intermediates=CompositePath())
Definition: CompositeEdge.h:234
virtual void SetWeight(const EdgeWeight _w) noexcept
Definition: CompositeEdge.h:379
std::vector< IndividualEdge > & GetLocalEdges() noexcept
Get a vector of local edges in the plan.
Definition: CompositeEdge.h:509
const size_t GetNumIntermediates() noexcept
Get the number of composite intermediates along this edge.
Definition: CompositeEdge.h:297
double EdgeWeight
Definition: CompositeEdge.h:33
virtual bool operator<(const CompositeEdge &_other) const noexcept
Definition: CompositeEdge.h:362
stapl::edge_descriptor_impl< size_t > ED
Definition: CompositeEdge.h:34
virtual size_t GetTimeSteps() const
Get the number of timesteps along this composite edge.
Definition: CompositeEdge.h:563
virtual iterator end() noexcept
Definition: CompositeEdge.h:600
void ClearLocalEdges() noexcept
Clear all local edges in the plan.
Definition: CompositeEdge.h:517
CompositePath m_intermediates
Composite state intermediates.
Definition: CompositeEdge.h:217
virtual bool operator!=(const CompositeEdge &_w) const noexcept
Definition: CompositeEdge.h:353
Definition: CompositeGraph.h:27
virtual RobotGroup * GetGroup()
Get the robot group.
Definition: CompositeGraph.h:190
Definition: CompositeState.h:26
A group of one or more robots.
Definition: RobotGroup.h:17
size_t Size() const noexcept
Get the number of robots in the group.
Definition: RobotGroup.cpp:128
Definition: PMPLExceptions.h:62