ROSE 0.11.145.192
GraphBoost.h
1// WARNING: Changes to this file must be contributed back to Sawyer or else they will
2// be clobbered by the next update from Sawyer. The Sawyer repository is at
3// https://gitlab.com/charger7534/sawyer.git.
4
5
6
7
8// Boost Graph Library (BGL) interface around Sawyer::Container::Graph
9#ifndef Sawyer_GraphBoost_H
10#define Sawyer_GraphBoost_H
11
12#include <Sawyer/Graph.h>
13#include <Sawyer/Sawyer.h>
14#include <boost/foreach.hpp>
15#include <boost/graph/graph_traits.hpp>
16#include <boost/graph/properties.hpp>
17
18namespace Sawyer {
19
52namespace Boost {
53
75template<class SawyerGraph, class BoostGraph>
76void sawyerGraphToBoostGraph(const SawyerGraph &sg, BoostGraph &bg /*out*/) {
77 bg = BoostGraph(sg.nVertices());
78 BOOST_FOREACH (const typename SawyerGraph::Edge &edge, sg.edges())
79 bg.add_edge(edge.source()->id(), edge.target()->id());
80}
81
82template<class SawyerGraph, class BoostGraph>
83BoostGraph sawyerGraphToBoostGraph(const SawyerGraph &sg) {
84 BoostGraph bg;
86 return bg;
87}
91// Iterators
93
94// BGL vertex and edge iterators, when dereferenced, yield a BGL vertex descriptor; BGL vertex descriptors are used to look up
95// property values in property maps. Since we want O(1) lookup times for properties, we'll use Sawyer vertex and edge ID
96// numbers as BGL vertex and edge descriptors. Therefore, we need to provide iterators which when dereferenced return a Sawyer
97// vertex or edge ID.
98//
99// Another reason for using Sawyer vertex and edge ID numbers as BGL vertex and edge descriptors is that BGL expects there to
100// exist a single vertex descriptor that represents "no vertex". We can use (size_t)(-1) for this, but we would not have been
101// able to use Sawyer "end" iterators since the end of one list is not equal to the end of another list.
102
103template<class V, class E, class VKey, class EKey, class Alloc>
105public:
106 // Five standard iterator types
107 using iterator_category = std::bidirectional_iterator_tag;
108 using value_type = const size_t;
109 using difference_type = std::ptrdiff_t;
110 using pointer = const size_t*;
111 using reference = const size_t&;
112
113private:
115 BaseIter base_;
116public:
118 VertexOuterIterator(const VertexOuterIterator &other): base_(other.base_) {}
119 explicit VertexOuterIterator(const BaseIter &base): base_(base) {}
120 VertexOuterIterator& operator=(const VertexOuterIterator &other) { base_ = other.base_; return *this; }
121 VertexOuterIterator& operator++() { ++base_; return *this; }
122 VertexOuterIterator& operator--() { --base_; return *this; }
123 VertexOuterIterator operator++(int) { VertexOuterIterator old = *this; ++base_; return old; }
124 VertexOuterIterator operator--(int) { VertexOuterIterator old = *this; --base_; return old; }
125 bool operator==(const VertexOuterIterator &other) const { return base_ == other.base_; }
126 bool operator!=(const VertexOuterIterator &other) const { return base_ != other.base_; }
127 const size_t& operator*() const { return base_->id(); }
128 // size_t* operator->() const; //no methods defined on size_t, so not needed
129};
130
131template<class V, class E, class VKey, class EKey, class Alloc>
133public:
134 // Five standard iterator types
135 using iterator_category = std::bidirectional_iterator_tag;
136 using value_type = const size_t;
137 using difference_type = std::ptrdiff_t;
138 using pointer = const size_t*;
139 using reference = const size_t&;
140
141private:
143 BaseIter base_;
144public:
146 ConstVertexOuterIterator(const ConstVertexOuterIterator &other): base_(other.base_) {}
148 explicit ConstVertexOuterIterator(const BaseIter &base): base_(base) {}
149 ConstVertexOuterIterator& operator=(const ConstVertexOuterIterator &other) { base_ = other.base_; return *this; }
150 ConstVertexOuterIterator& operator++() { ++base_; return *this; }
151 ConstVertexOuterIterator& operator--() { --base_; return *this; }
152 ConstVertexOuterIterator operator++(int) { ConstVertexOuterIterator old = *this; ++base_; return old; }
153 ConstVertexOuterIterator operator--(int) { ConstVertexOuterIterator old = *this; --base_; return old; }
154 bool operator==(const ConstVertexOuterIterator &other) const { return base_ == other.base_; }
155 bool operator!=(const ConstVertexOuterIterator &other) const { return base_ != other.base_; }
156 const size_t& operator*() const { return base_->id(); }
157 // size_t* operator->() const; //no methods defined on size_t, so not needed
158};
159
160template<class V, class E, class VKey, class EKey, class Alloc>
162public:
163 // Five standard iterator types
164 using iterator_category = std::bidirectional_iterator_tag;
165 using value_type = const size_t;
166 using difference_type = std::ptrdiff_t;
167 using pointer = const size_t*;
168 using reference = const size_t&;
169
170private:
172 BaseIter base_;
173public:
175 EdgeOuterIterator(const EdgeOuterIterator &other): base_(other.base_) {}
176 explicit EdgeOuterIterator(const BaseIter &base): base_(base) {}
177 EdgeOuterIterator& operator=(const EdgeOuterIterator &other) { base_ = other.base_; return *this; }
178 EdgeOuterIterator& operator++() { ++base_; return *this; }
179 EdgeOuterIterator& operator--() { --base_; return *this; }
180 EdgeOuterIterator operator++(int) { EdgeOuterIterator old = *this; ++base_; return old; }
181 EdgeOuterIterator operator--(int) { EdgeOuterIterator old = *this; --base_; return old; }
182 bool operator==(const EdgeOuterIterator &other) const { return base_ == other.base_; }
183 bool operator!=(const EdgeOuterIterator &other) const { return base_ != other.base_; }
184 const size_t& operator*() const { return base_->id(); }
185 // size_t* operator->() const; //no methods defined on size_t, so not needed
186};
187
188template<class V, class E, class VKey, class EKey, class Alloc>
190public:
191 // Five standard iterator types
192 using iterator_category = std::bidirectional_iterator_tag;
193 using value_type = const size_t;
194 using difference_type = std::ptrdiff_t;
195 using pointer = const size_t*;
196 using reference = const size_t&;
197
198private:
200 BaseIter base_;
201public:
203 ConstEdgeOuterIterator(const ConstEdgeOuterIterator &other): base_(other.base_) {}
204 ConstEdgeOuterIterator(const EdgeOuterIterator<V, E, VKey, EKey, Alloc> &other): base_(other.base_) {}
205 explicit ConstEdgeOuterIterator(const BaseIter &base): base_(base) {}
206 ConstEdgeOuterIterator& operator=(const ConstEdgeOuterIterator &other) { base_ = other.base_; return *this; }
207 ConstEdgeOuterIterator& operator++() { ++base_; return *this; }
208 ConstEdgeOuterIterator& operator--() { --base_; return *this; }
209 ConstEdgeOuterIterator operator++(int) { ConstEdgeOuterIterator old = *this; ++base_; return old; }
210 ConstEdgeOuterIterator operator--(int) { ConstEdgeOuterIterator old = *this; --base_; return old; }
211 bool operator==(const ConstEdgeOuterIterator &other) const { return base_ == other.base_; }
212 bool operator!=(const ConstEdgeOuterIterator &other) const { return base_ != other.base_; }
213 const size_t& operator*() const { return base_->id(); }
214 // size_t* operator->() const; //no methods defined on size_t, so not needed
215};
216
218// Internal properties
220
221// External properties can use the BGL mechanisms that are already defined, but we need something special for internal
222// properties. A BGL property map is simply a class that provides a lookup mechanism when given a vertex or edge descriptor, so
223// all we need is a class that will look up the user-supplied value for a vertex or edge.
224
225// User-defined value attached to a vertex.
226template<class Graph>
228 Graph &graph_;
229public:
230 typedef typename Graph::VertexValue ValueType;
231 VertexPropertyMap(Graph &graph): graph_(graph) {}
232 ValueType get(size_t vertexId) const {
233 return graph_.findVertex(vertexId)->value();
234 }
235 void put(size_t vertexId, const ValueType &value) {
236 graph_.findVertex(vertexId)->value() = value;
237 }
238 ValueType& at(size_t vertexId) {
239 return graph_.findVertex(vertexId)->value();
240 }
241 const ValueType& at(size_t vertexId) const {
242 return graph_.findVertex(vertexId)->value();
243 }
244};
245
246// Const user-defined value attached to a vertex.
247template<class Graph>
249 const Graph &graph_;
250public:
251 typedef typename Graph::VertexValue ValueType;
252 ConstVertexPropertyMap(const Graph &graph): graph_(graph) {}
253 ValueType get(size_t vertexId) const {
254 return graph_.findVertex(vertexId)->value();
255 }
256 const ValueType& at(size_t vertexId) const {
257 return graph_.findVertex(vertexId)->value();
258 }
259};
260
261// User-defined value attached to an edge. Graph is any non-const Sawyer::Container::Graph<>
262template<class Graph>
264 Graph &graph_;
265public:
266 typedef typename Graph::EdgeValue ValueType;
267 EdgePropertyMap(Graph &graph): graph_(graph) {}
268 ValueType get(size_t edgeId) const {
269 return graph_.findEdge(edgeId)->value();
270 }
271 void put(size_t edgeId, const ValueType &value) {
272 graph_.findEdge(edgeId)->value() = value;
273 }
274 ValueType& at(size_t edgeId) {
275 return graph_.findEdge(edgeId)->value();
276 }
277 const ValueType& at(size_t edgeId) const {
278 return graph_.findEdge(edgeId)->value();
279 }
280};
281
282// Const user-defined value attached to a vertex. Graph is any const Sawyer::Container::Graph<>
283template<class Graph>
285 const Graph &graph_;
286public:
287 typedef typename Graph::EdgeValue ValueType;
288 ConstEdgePropertyMap(const Graph &graph): graph_(graph) {}
289 ValueType get(size_t edgeId) const {
290 return graph_.findEdge(edgeId)->value();
291 }
292 const ValueType& at(size_t edgeId) const {
293 return graph_.findEdge(edgeId)->value();
294 }
295};
296
297// The ID (index) associated with each vertex. This is a read-only property since ID numbers are managed by the graph.
298template<class Graph>
300 const Graph &graph_;
301public:
302 ConstVertexIdPropertyMap(const Graph &graph): graph_(graph) {}
303 size_t get(size_t vertexId) const {
304 return vertexId;
305 }
306 const size_t& at(size_t vertexId) const {
307 return graph_.findVertex(vertexId)->id();
308 }
309};
310
311// The ID (index) associated with each edge. This is a read-only property since ID numbers are managed by the graph.
312template<class Graph>
314 const Graph &graph_;
315public:
316 ConstEdgeIdPropertyMap(const Graph &graph): graph_(graph) {}
317 size_t get(size_t edgeId) const {
318 return edgeId;
319 }
320 const size_t& at(size_t edgeId) const {
321 return graph_.findEdge(edgeId)->id();
322 }
323};
324
325// Tags for the user-defined vertex or edge value property. These are to access the user-defined data associated with each
326// vertex are value corresponding to the "V" and "E" template parameters for Sawyer::Container::Graph
328 typedef boost::vertex_property_tag kind;
329};
331 typedef boost::edge_property_tag kind;
332};
333
335 typedef boost::vertex_property_tag kind;
336};
337
338struct edge_id_t {
339 typedef boost::edge_property_tag kind;
340};
341
342} // namespace
343} // namespace
344
345
350namespace boost {
351
352
354// BGL trait classes
356
357#if 0 // [Robb P. Matzke 2014-05-23]: Temporarily disabled because it matches too much.
358// Including this file with boost/wave/util/cpp_include_paths.hpp causes problems because code like this:
359// using boost::multi_index::get;
360// return get<from>(pragma_once_files).find(filename) != pragma_once_files.end();
361// in wave matches these property_traits. E.g.,
362// boost::property_traits<Sawyer::Boost::VertexPropertyMap<boost::wave::util::from> >
363// and of course boost::wave::util::from has no VertexValue type. Someone with more boost property map and template
364// programming experience is needed. For now, users should instantiate their own Sawyer::Boost::VertexPropertyMap<> class
365// and use it to make their own specialization of boost::property_traits<>.
366
367template<class Graph>
368struct property_traits<Sawyer::Boost::VertexPropertyMap<Graph> > {
369 typedef typename Graph::VertexValue value_type;
370 typedef typename Graph::VertexValue &reference;
371 typedef size_t key_type; // vertex ID number
372 typedef boost::read_write_property_map_tag category;
373};
374
375template<class Graph>
376struct property_traits<Sawyer::Boost::ConstVertexPropertyMap<Graph> > {
377 typedef typename Graph::VertexValue value_type;
378 typedef typename Graph::VertexValue const &reference;
379 typedef size_t key_type; // vertex ID number
380 typedef boost::readable_property_map_tag category;
381};
382
383template<class Graph>
384struct property_traits<Sawyer::Boost::EdgePropertyMap<Graph> > {
385 typedef typename Graph::EdgeValue value_type;
386 typedef typename Graph::EdgeValue &reference;
387 typedef size_t key_type; // edge ID number
388 typedef boost::read_write_property_map_tag category;
389};
390
391template<class Graph>
392struct property_traits<Sawyer::Boost::ConstEdgePropertyMap<Graph> > {
393 typedef typename Graph::EdgeValue value_type;
394 typedef typename Graph::EdgeValue const &reference;
395 typedef size_t key_type; // edge ID number
396 typedef boost::readable_property_map_tag category;
397};
398
399template<class Graph>
400struct property_traits<Sawyer::Boost::ConstVertexIdPropertyMap<Graph> > {
401 typedef size_t value_type;
402 typedef const size_t &reference;
403 typedef size_t key_type; // vertex ID number
404 typedef boost::readable_property_map_tag category;
405};
406
407template<class Graph>
408struct property_traits<Sawyer::Boost::ConstEdgeIdPropertyMap<Graph> > {
409 typedef size_t value_type;
410 typedef const size_t &reference;
411 typedef size_t key_type; // vertex ID number
412 typedef boost::readable_property_map_tag category;
413};
414
415#endif
416
417
418template<class Graph>
419struct property_map<Graph, Sawyer::Boost::vertex_value_t> {
422};
423
424template<class Graph>
425struct property_map<Graph, Sawyer::Boost::edge_value_t> {
428};
429
430template<class Graph>
431struct property_map<Graph, Sawyer::Boost::vertex_id_t> {
434};
435
436template<class Graph>
437struct property_map<Graph, Sawyer::Boost::edge_id_t> {
440};
441
443// Access members of property maps
445
446//--- vertex value ---
447
448template<class Graph>
449typename Graph::VertexValue&
450get(Sawyer::Boost::VertexPropertyMap<Graph> &pmap, size_t key) {
451 return pmap.at(key);
452}
453
454template<class Graph>
455const typename Graph::VertexValue&
456get(const Sawyer::Boost::ConstVertexPropertyMap<Graph> &pmap, size_t key) {
457 return pmap.at(key);
458}
459
460template<class Graph>
461void
462put(Sawyer::Boost::VertexPropertyMap<Graph> &pmap, size_t key, const typename Graph::VertexValue &value) {
463 pmap.at(key) = value;
464}
465
466//--- edge value ---
467
468template<class Graph>
469typename Graph::EdgeValue&
471 return pmap.at(key);
472}
473
474template<class Graph>
475typename Graph::EdgeValue&
476get(const Sawyer::Boost::ConstEdgePropertyMap<Graph> &pmap, size_t key) {
477 return pmap.at(key);
478}
479
480template<class Graph>
481void
482put(Sawyer::Boost::EdgePropertyMap<Graph> &pmap, size_t key,
483 const typename Graph::EdgeValue &value) {
484 pmap.at(key) = value;
485}
486
487//--- vertex and edge ID (indices) ---
488
489template<class Graph>
490const size_t&
492 return pmap.at(key);
493}
494
495template<class Graph>
496const size_t&
497get(const Sawyer::Boost::ConstEdgeIdPropertyMap<Graph> &pmap, size_t key) {
498 return pmap.at(key);
499}
500
501
503// Graph traits
505
506template<class V, class E, class VKey, class EKey, class Alloc>
507struct graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> > {
508 typedef bidirectional_graph_tag traversal_category;
509
510 // Graph concepts
511 typedef size_t vertex_descriptor;
512 typedef size_t edge_descriptor;
513 typedef directed_tag directed_category;
514 typedef allow_parallel_edge_tag edge_parallel_category;
515 static size_t null_vertex() { return (size_t)(-1); }
516
517 // VertexListGraph concepts
519 typedef size_t vertices_size_type;
520
521 // EdgeListGraph concepts
523 typedef size_t edges_size_type;
524
525 // IncidenceGraph concepts
527 typedef size_t degree_size_type;
528
529 // BidirectionalGraph concepts
531
532 // MutablePropertyGraph concepts
533 typedef typename Sawyer::Container::Graph<V, E, VKey, EKey, Alloc>::VertexValue vertex_property_type;
534 typedef typename Sawyer::Container::Graph<V, E, VKey, EKey, Alloc>::EdgeValue edge_property_type;
535};
536
537template<class V, class E, class VKey, class EKey, class Alloc>
538struct graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> > {
539 typedef bidirectional_graph_tag traversal_category;
540
541 // Graph concepts
542 typedef size_t vertex_descriptor;
543 typedef size_t edge_descriptor;
544 typedef directed_tag directed_category;
545 typedef allow_parallel_edge_tag edge_parallel_category;
546
547 // VertexListGraph concepts
549 typedef size_t vertices_size_type;
550
551 // EdgeListGraph concepts
553 typedef size_t edges_size_type;
554
555 // IncidenceGraph concepts
557 typedef size_t degree_size_type;
558
559 // BidirectionalGraph concepts
561};
562
564// Graph concepts
566
567
568// BGL has a global entity that indicates no-vertex, but Sawyer doesn't--it has STL-like end() iterators.
569template<class V, class E, class VKey, class EKey, class Alloc>
570typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor
571null_vertex() {
572 return (size_t)(-1);
573}
574
575template<class V, class E, class VKey, class EKey, class Alloc>
576typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor
577null_vertex() {
578 return (size_t)(-1);
579}
580
582// VertexListGraph concepts
584
585template<class V, class E, class VKey, class EKey, class Alloc>
586std::pair<typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_iterator,
587 typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_iterator>
589 return std::make_pair(Sawyer::Boost::VertexOuterIterator<V, E, VKey, EKey, Alloc>(graph.vertices().begin()),
591}
592
593template<class V, class E, class VKey, class EKey, class Alloc>
594std::pair<typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_iterator,
595 typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_iterator>
599}
600
601template<class V, class E, class VKey, class EKey, class Alloc>
602typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertices_size_type
604 return graph.nVertices();
605}
606
607template<class V, class E, class VKey, class EKey, class Alloc>
608typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertices_size_type
609num_vertices(const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> &graph) {
610 return graph.nVertices();
611}
612
614// EdgeListGraph concepts
616
617template<class V, class E, class VKey, class EKey, class Alloc>
618std::pair<typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_iterator,
619 typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_iterator>
621 return std::make_pair(Sawyer::Boost::EdgeOuterIterator<V, E, VKey, EKey, Alloc>(graph.edges().begin()),
623}
624
625template<class V, class E, class VKey, class EKey, class Alloc>
626std::pair<typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_iterator,
627 typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_iterator>
629 return std::make_pair(Sawyer::Boost::ConstEdgeOuterIterator<V, E, VKey, EKey, Alloc>(graph.edges().begin()),
631}
632
633template<class V, class E, class VKey, class EKey, class Alloc>
634typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edges_size_type
636 return graph.nEdges();
637}
638
639template<class V, class E, class VKey, class EKey, class Alloc>
640typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edges_size_type
642 return graph.nEdges();
643}
644
646// IncidenceGraph concepts
648
649template<class V, class E, class VKey, class EKey, class Alloc>
650typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor
651source(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_descriptor edge,
653 return graph.findEdge(edge)->source()->id();
654}
655
656template<class V, class E, class VKey, class EKey, class Alloc>
657typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor
658source(typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_descriptor edge,
660 return graph.findEdge(edge)->source()->id();
661}
662
663template<class V, class E, class VKey, class EKey, class Alloc>
664typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor
665target(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_descriptor edge,
667 return graph.findEdge(edge)->target()->id();
668}
669
670template<class V, class E, class VKey, class EKey, class Alloc>
671typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor
672target(typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_descriptor edge,
674 return graph.findEdge(edge)->target()->id();
675}
676
677template<class V, class E, class VKey, class EKey, class Alloc>
678std::pair<typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::out_edge_iterator,
679 typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::out_edge_iterator>
680out_edges(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
685}
686
687template<class V, class E, class VKey, class EKey, class Alloc>
688std::pair<typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::out_edge_iterator,
689 typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::out_edge_iterator>
690out_edges(typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
695}
696
697template<class V, class E, class VKey, class EKey, class Alloc>
698typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::degree_size_type
699out_degree(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
701 return graph.findVertex(vertex)->nOutEdges();
702}
703
704template<class V, class E, class VKey, class EKey, class Alloc>
705typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::degree_size_type
706out_degree(typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
708 return graph.findVertex(vertex)->nOutEdges();
709}
710
712// BidirectionalGraph concepts
714
715template<class V, class E, class VKey, class EKey, class Alloc>
716std::pair<typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::in_edge_iterator,
717 typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::in_edge_iterator>
718in_edges(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
721 return std::make_pair(Sawyer::Boost::EdgeOuterIterator<V, E, VKey, EKey, Alloc>(v->inEdges().begin()),
723}
724
725template<class V, class E, class VKey, class EKey, class Alloc>
726std::pair<typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::in_edge_iterator,
727 typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::in_edge_iterator>
728in_edges(typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
733}
734
735template<class V, class E, class VKey, class EKey, class Alloc>
736typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::degree_size_type
737in_degree(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
739 return graph.findVertex(vertex)->nInEdges();
740}
741
742template<class V, class E, class VKey, class EKey, class Alloc>
743typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::degree_size_type
744in_degree(typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
746 return graph.findVertex(vertex)->nInEdges();
747}
748
749template<class V, class E, class VKey, class EKey, class Alloc>
750typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::degree_size_type
751degree(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
753 return in_degree(vertex) + out_degree(vertex);
754}
755
756template<class V, class E, class VKey, class EKey, class Alloc>
757typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::degree_size_type
758degree(typename graph_traits<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
760 return in_degree(vertex) + out_degree(vertex);
761}
762
764// PropertyMapGraph concepts
766
767template<class V, class E, class VKey, class EKey, class Alloc>
768typename property_map<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc>, Sawyer::Boost::vertex_value_t>::type
771}
772
773template<class V, class E, class VKey, class EKey, class Alloc>
774typename property_map<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc>, Sawyer::Boost::vertex_value_t>::const_type
777}
778
779template<class V, class E, class VKey, class EKey, class Alloc>
780typename property_map<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc>, Sawyer::Boost::edge_value_t>::type
783}
784
785template<class V, class E, class VKey, class EKey, class Alloc>
786typename property_map<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc>, Sawyer::Boost::edge_value_t>::const_type
789}
790
791template<class V, class E, class VKey, class EKey, class Alloc>
792typename property_map<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc>, Sawyer::Boost::vertex_id_t>::const_type
795}
796
797template<class V, class E, class VKey, class EKey, class Alloc>
798typename property_map<const Sawyer::Container::Graph<V, E, VKey, EKey, Alloc>, Sawyer::Boost::edge_id_t>::const_type
801}
802
804// MutableGraph concepts
806
807template<class V, class E, class VKey, class EKey, class Alloc>
808std::pair<typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_descriptor, bool>
809add_edge(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor source,
810 typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor target,
815 return std::make_pair(newEdge->id(), true);
816}
817
818template<class V, class E, class VKey, class EKey, class Alloc>
819void
820remove_edge(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor source,
821 typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor target,
825 graph.eraseEdges(src, tgt);
826}
827
828template<class V, class E, class VKey, class EKey, class Alloc>
829void
830remove_edge(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_descriptor edge,
832 graph.eraseEdge(graph.findEdge(edge));
833}
834
835template<class Predicate, class V, class E, class VKey, class EKey, class Alloc>
836void
837remove_edge_if(Predicate predicate,
840 while (edge != graph.edges().end()) {
841 if (predicate(edge->id())) {
842 edge = graph.eraseEdge(edge);
843 } else {
844 ++edge;
845 }
846 }
847}
848
849template<class Predicate, class V, class E, class VKey, class EKey, class Alloc>
850void
851remove_out_edge_if(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
852 Predicate predicate,
856 while (edge != v->outEdges().end()) {
857 if (predicate(edge->id())) {
858 edge = graph.eraseEdge(edge);
859 } else {
860 ++edge;
861 }
862 }
863}
864
865template<class Predicate, class V, class E, class VKey, class EKey, class Alloc>
866void
867remove_in_edge_if(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
868 Predicate predicate,
872 while (edge != v->inEdges().end()) {
873 if (predicate(edge->id())) {
874 edge = graph.eraseEdge(edge);
875 } else {
876 ++edge;
877 }
878 }
879}
880
881template<class V, class E, class VKey, class EKey, class Alloc>
882typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor
884 return graph.insertVertex(V())->id();
885}
886
887template<class V, class E, class VKey, class EKey, class Alloc>
888void
889clear_vertex(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
891 graph.clearEdges(graph.findVertex(vertex));
892}
893
894template<class V, class E, class VKey, class EKey, class Alloc>
895void
896remove_vertex(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor vertex,
898 graph.eraseVertex(graph.findVertex(vertex));
899}
900
901
903// MutablePropertyGraph concepts
905
906template<class V, class E, class VKey, class EKey, class Alloc>
907std::pair<typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_descriptor, bool>
908add_edge(typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor source,
909 typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor target,
910 typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::edge_property_type const &pval,
915 return std::make_pair(newEdge->id(), true);
916}
917
918template<class V, class E, class VKey, class EKey, class Alloc>
919typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_descriptor
920add_vertex(const typename graph_traits<Sawyer::Container::Graph<V, E, VKey, EKey, Alloc> >::vertex_property_type &pval,
922 return graph.insertVertex(pval)->id();
923}
924
925} // namespace
926#endif
Bidirectional edge node iterator.
Definition Graph.h:956
Bidirectional vertex node iterator.
Definition Graph.h:1057
Bidirectional edge node iterator.
Definition Graph.h:931
const VertexIterator & target()
Target vertex.
Definition Graph.h:1174
const VertexIterator & source()
Source vertex.
Definition Graph.h:1162
const size_t & id() const
Unique edge ID number.
Definition Graph.h:1152
Bidirectional vertex node iterator.
Definition Graph.h:1035
boost::iterator_range< EdgeIterator > inEdges()
List of incoming edges.
Definition Graph.h:1236
boost::iterator_range< EdgeIterator > outEdges()
List of outgoing edges.
Definition Graph.h:1257
size_t nInEdges() const
Number of incoming edges.
Definition Graph.h:1272
size_t nOutEdges() const
Number of outgoing edges.
Definition Graph.h:1279
const size_t & id() const
Unique vertex ID number.
Definition Graph.h:1225
Graph containing user-defined vertices and edges.
Definition Graph.h:634
E EdgeValue
User-level data associated with edges.
Definition Graph.h:637
void clearEdges()
Erase all edges, but leave all vertices.
Definition Graph.h:1998
EdgeIterator insertEdge(const VertexIterator &sourceVertex, const VertexIterator &targetVertex, const EdgeValue &value=EdgeValue())
Insert a new edge.
Definition Graph.h:1820
boost::iterator_range< EdgeIterator > edges()
Iterators for all edges.
Definition Graph.h:1647
EdgeIterator findEdge(size_t id)
Finds the edge with specified ID number.
Definition Graph.h:1694
VertexIterator findVertex(size_t id)
Finds the vertex with specified ID number.
Definition Graph.h:1585
size_t nVertices() const
Total number of vertices.
Definition Graph.h:1754
EdgeIterator eraseEdge(const EdgeIterator &edge)
Erases an edge.
Definition Graph.h:1880
boost::iterator_range< VertexIterator > vertices()
Iterators for all vertices.
Definition Graph.h:1538
VertexIterator insertVertex(const VertexValue &value=VertexValue())
Insert a new vertex.
Definition Graph.h:1790
V VertexValue
User-level data associated with vertices.
Definition Graph.h:636
void eraseEdges(const VertexIterator &source, const VertexIterator &target)
Erases all edges connecting two vertices.
Definition Graph.h:1932
size_t nEdges() const
Total number of edges.
Definition Graph.h:1764
VertexIterator eraseVertex(const VertexIterator &vertex)
Erases a vertex and its incident edges.
Definition Graph.h:1978
void sawyerGraphToBoostGraph(const SawyerGraph &sg, BoostGraph &bg)
Convert a Sawyer graph to a Boost graph.
Definition GraphBoost.h:76
bool get(const Word *words, size_t idx)
Return a single bit.
Sawyer support library.
This namespace contains template functions that operate on the ROSE AST.
Definition sageGeneric.h:38