1 #ifndef PPL_COMPOSITE_GRAPH_H_
2 #define PPL_COMPOSITE_GRAPH_H_
8 #include <containers/sequential/graph/algorithms/graph_input_output.h>
11 #define INVALID_ED ED{std::numeric_limits<size_t>::max(), std::numeric_limits<size_t>::max()}
26 template <
typename Vertex,
typename Edge>
122 virtual
VID AddVertex(const Vertex& _v) noexcept override;
132 virtual
ED AddEdge(const
VID _source, const
VID _target, const Edge& _w)
142 virtual
void DeleteEdge(const
VID _source, const
VID _target) noexcept override;
146 virtual
void DeleteEdge(
EI _iterator) noexcept override;
175 template <typename Vertex, typename Edge>
186 template <
typename Vertex,
typename Edge>
195 template <
typename Vertex,
typename Edge>
204 template <
typename Vertex,
typename Edge>
213 template <
typename Vertex,
typename Edge>
222 template <
typename Vertex,
typename Edge>
232 template <
typename Vertex,
typename Edge>
238 " option enabled in the Makefile!");
241 std::ofstream ofs(_filename);
242 ofs <<
"#####ENVFILESTART#####" << std::endl
244 <<
"#####ENVFILESTOP#####" << std::endl;
246 stapl::sequential::write_graph(*
this, ofs);
250 template <
typename Vertex,
typename Edge>
254 std::ostringstream out;
255 out <<
"Number of group vertices: " << this->get_num_vertices() << std::endl;
256 out <<
"Vertices in each individual graph:" << std::endl <<
"| ";
267 template <
typename Vertex,
typename Edge>
270 AddEdge(
const VID _source,
const VID _target,
const Edge& _lp) noexcept {
271 if(_source == _target)
275 if(_lp.GetWeight() == 0 or _lp.GetWeight() == 0)
283 std::vector<ED>& edgeDescriptors = edge.GetEdgeDescriptors();
285 const Vertex& sourceCfg = this->
GetVertex(_source),
288 size_t numInactiveRobots = 0;
291 for(
size_t i = 0; i < edgeDescriptors.size(); ++i) {
294 const VID individualSourceVID = sourceCfg.GetVID(i),
295 individualTargetVID = targetCfg.GetVID(i);
299 if(individualSourceVID == individualTargetVID) {
305 const bool verticesExist =
306 graph->find_vertex(individualSourceVID) != graph->end() and
307 graph->find_vertex(individualTargetVID) != graph->end();
313 const bool edgeExists = graph->IsEdge(individualSourceVID,
314 individualTargetVID);
318 <<
", " << individualTargetVID <<
") does "
319 <<
"not exist for robot "
320 << graph->GetRobot()->GetLabel() <<
".";
322 const bool consistent = edgeDescriptors[i].source() == individualSourceVID
323 and edgeDescriptors[i].target() == individualTargetVID;
326 <<
"Fetched from group cfg: ("
327 << individualSourceVID <<
", "
328 << individualTargetVID <<
"), fetched from "
330 << edgeDescriptors[i].source() <<
", "
331 << edgeDescriptors[i].target() <<
").";
337 <<
", " << individualTargetVID <<
") does "
338 <<
"not exist for robot "
339 << graph->GetRobot()->GetLabel() <<
".";
345 const auto edgeDescriptor = this->add_edge(_source, _target, edge);
346 const bool notNew = edgeDescriptor.id() ==
INVALID_EID;
349 std::cerr <<
"\nCompositeGraph::AddEdge: edge (" << _source <<
", "
350 << _target <<
") already exists, not adding."
357 this->find_edge(edgeDescriptor, vi, ei);
366 return edgeDescriptor;
370 template <
typename Vertex,
typename Edge>
378 <<
"match this composite graph.";
387 std::cerr <<
"\nCompositeGraph::AddVertex: vertex " << vi->descriptor()
388 <<
" already in graph"
390 return vi->descriptor();
396 auto robot = graph->GetRobot();
397 const VID individualVID = cfg.GetVID(i);
401 cfg.SetRobotCfg(robot, graph->AddVertex(cfg.GetRobotCfg(i)));
403 else if(graph->find_vertex(individualVID) == graph->end())
405 <<
" does not exist!";
409 const VID vid = this->add_vertex(cfg);
421 template <
typename Vertex,
typename Edge>
426 VI vi = this->find_vertex(_v);
427 if(vi == this->end())
429 " is not in the graph.");
435 for(
auto edge = vi->begin(); edge != vi->end(); edge = vi->begin())
444 for(
VI vertex = this->begin(); vertex != this->end(); ++vertex) {
447 EI edge = stapl::graph_find(vertex->begin(), vertex->end(),
448 stapl::eq_target<VID>(_v));
449 if(edge == vertex->end())
461 this->delete_vertex(vi->descriptor());
466 template <
typename Vertex,
typename Edge>
471 const ED edgeDescriptor(_source, _target);
475 const bool found = this->find_edge(edgeDescriptor, dummy, edgeIterator);
478 <<
") does not exist.";
483 template <
typename Vertex,
typename Edge>
491 auto& edge = _iterator->property();
492 auto& descriptors = edge.GetEdgeDescriptors();
497 this->delete_edge(_iterator->descriptor());
500 const VID source = _iterator->source(),
501 target = _iterator->target();
509 template <
typename Vertex,
typename Edge>
#define INVALID_ED
Definition: CompositeGraph.h:11
#define INVALID_VID
Definition: GenericStateGraph.h:23
#define INVALID_EID
Definition: GenericStateGraph.h:27
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
Definition: CompositeGraph.h:27
virtual EID AddEdge(const VID _source, const VID _target, const Edge &_w) noexcept
Definition: GenericStateGraph.h:698
virtual VID AddVertex(const Vertex &_v) noexcept override
Definition: CompositeGraph.h:373
BaseType::vertex_descriptor vertex_descriptor
Definition: CompositeGraph.h:44
BaseType::EID ED
Definition: CompositeGraph.h:38
STAPLGraph::vertex_descriptor VID
Definition: GenericStateGraph.h:83
RobotGroup *const m_group
The robot group.
Definition: CompositeGraph.h:163
GenericStateGraph< Vertex, Edge > BaseType
Definition: CompositeGraph.h:34
virtual size_t GetNumRobots() const noexcept
Get the number of robots for the group this graph is for.
Definition: CompositeGraph.h:216
virtual void DeleteVertex(const VID _v) noexcept override
Definition: CompositeGraph.h:424
CompositeGraph & operator=(CompositeGraph &&)=delete
virtual void WriteCompositeGraph(const std::string &_filename, Environment *const _env) const
Definition: CompositeGraph.h:235
std::string PrettyPrint() const
Definition: CompositeGraph.h:253
virtual IndividualGraph * GetIndividualGraph(const size_t _index)
Definition: CompositeGraph.h:199
CompositeGraph(RobotGroup *const _g=nullptr, std::vector< IndividualGraph * > _graphs={})
Construct a composite graph.
Definition: CompositeGraph.h:177
size_t m_timestamp
Tracks the number of changes to the graph.
Definition: GenericStateGraph.h:432
CompositeGraph & operator=(const CompositeGraph &)=delete
virtual void DeleteEdge(const VID _source, const VID _target) noexcept override
Definition: CompositeGraph.h:469
virtual void ClearHooks() noexcept override
Definition: CompositeGraph.h:512
Vertex::IndividualGraph IndividualGraph
Definition: CompositeGraph.h:36
virtual RobotGroup * GetGroup()
Get the robot group.
Definition: CompositeGraph.h:190
CompositeGraph(CompositeGraph &&)=delete
std::vector< IndividualGraph * > m_graphs
The individual graphs.
Definition: CompositeGraph.h:165
virtual void Write(const std::string &_filename, Environment *_env) const override
Definition: CompositeGraph.h:225
CompositeGraph< Vertex, Edge > CompositeGraphType
Definition: CompositeGraph.h:35
CompositeGraph(const CompositeGraph &)=delete
BaseType::edge_descriptor edge_descriptor
Definition: CompositeGraph.h:42
BaseType::vertex_iterator vertex_iterator
Definition: CompositeGraph.h:43
BaseType::adj_edge_iterator adj_edge_iterator
Definition: CompositeGraph.h:41
IndividualGraph::EdgeType IndividualEdge
Definition: CompositeGraph.h:39
Definition: Environment.h:137
const std::string & GetEnvFileName() const noexcept
Get the environment file name.
Definition: Environment.cpp:332
Definition: GenericStateGraph.h:67
std::function< void(VI)> VertexHook
Definition: GenericStateGraph.h:104
STAPLGraph::vertex_descriptor VID
Definition: GenericStateGraph.h:83
VertexSet m_allVIDs
Definition: GenericStateGraph.h:458
void ExecuteAddVertexHooks(const VI _iterator) noexcept
Definition: GenericStateGraph.h:1510
virtual void ClearHooks() noexcept
Definition: GenericStateGraph.h:1317
STAPLGraph::const_vertex_iterator CVI
Definition: GenericStateGraph.h:91
void ExecuteDeleteEdgeHooks(const EI _iterator) noexcept
Definition: GenericStateGraph.h:1558
void ExecuteAddEdgeHooks(const EI _iterator) noexcept
Definition: GenericStateGraph.h:1542
STAPLGraph::vertex_iterator VI
Definition: GenericStateGraph.h:89
STAPLGraph::edge_descriptor EID
Definition: GenericStateGraph.h:84
HookType
Definition: GenericStateGraph.h:106
std::function< void(EI)> EdgeHook
Definition: GenericStateGraph.h:105
STAPLGraph::adj_edge_iterator EI
Definition: GenericStateGraph.h:90
std::unordered_map< VID, VertexSet > m_predecessors
Definition: GenericStateGraph.h:454
stapl::sequential::graph< stapl::DIRECTED, stapl::NONMULTIEDGES, Vertex, Edge > STAPLGraph
Definition: GenericStateGraph.h:80
bool IsVertex(const VID _vid) const noexcept
Definition: GenericStateGraph.h:896
VP & GetVertex(T &_t) noexcept
Retrieve a reference to a vertex property by descriptor or iterator.
Definition: GenericStateGraph.h:1034
void ExecuteDeleteVertexHooks(const VI _iterator) noexcept
Definition: GenericStateGraph.h:1526
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