1 #ifndef DIRECTEDGRAPH_H
2 #define DIRECTEDGRAPH_H 1
3 
4 #include "Common/ContigNode.h"
5 #include "Graph/Properties.h"
6 #include <algorithm>
7 #include <cassert>
8 #include <utility>
9 #include <vector>
10 
11 /** A directed graph. */
12 template <typename VertexProp = no_property,
13 		 typename EdgeProp = no_property>
14 class DirectedGraph
15 {
16 	class Vertex;
17 	typedef typename std::vector<Vertex> Vertices;
18 	class Edge;
19 	typedef typename std::vector<Edge> Edges;
20 
21   public:
22 	// Graph
23 	typedef ContigNode vertex_descriptor;
24 
25 	// IncidenceGraph
26 	typedef std::pair<vertex_descriptor, vertex_descriptor>
27 		edge_descriptor;
28 	typedef unsigned degree_size_type;
29 
30 	// BidirectionalGraph
31 	typedef void in_edge_iterator;
32 
33 	// VertexListGraph
34 	typedef unsigned vertices_size_type;
35 
36 	// EdgeListGraph
37 	typedef unsigned edges_size_type;
38 
39 	// PropertyGraph
40 	typedef VertexProp vertex_bundled;
41 	typedef VertexProp vertex_property_type;
42 	typedef EdgeProp edge_bundled;
43 	typedef EdgeProp edge_property_type;
44 
45 	typedef boost::directed_tag directed_category;
46 	typedef boost::allow_parallel_edge_tag edge_parallel_category;
47 	struct traversal_category
48 		: boost::incidence_graph_tag,
49 		boost::adjacency_graph_tag,
50 		boost::vertex_list_graph_tag,
51 		boost::edge_list_graph_tag { };
52 
53 /** Iterate through the vertices of this graph. */
54 class vertex_iterator
55 	: public std::iterator<std::input_iterator_tag,
56 		const vertex_descriptor>
57 {
58   public:
vertex_iterator()59 	vertex_iterator() { }
vertex_iterator(vertices_size_type v)60 	explicit vertex_iterator(vertices_size_type v) : m_v(v) { }
61 	const vertex_descriptor& operator *() const { return m_v; }
62 
63 	bool operator ==(const vertex_iterator& it) const
64 	{
65 		return m_v == it.m_v;
66 	}
67 
68 	bool operator !=(const vertex_iterator& it) const
69 	{
70 		return m_v != it.m_v;
71 	}
72 
73 	vertex_iterator& operator ++() { ++m_v; return *this; }
74 	vertex_iterator operator ++(int)
75 	{
76 		vertex_iterator it = *this;
77 		++*this;
78 		return it;
79 	}
80 
81   private:
82 	vertex_descriptor m_v;
83 };
84 
85 /** Iterate through the out-edges. */
86 class out_edge_iterator
87 	: public std::iterator<std::input_iterator_tag, edge_descriptor>
88 {
89 	typedef typename Edges::const_iterator const_iterator;
90 
91   public:
out_edge_iterator()92 	out_edge_iterator() { }
out_edge_iterator(const const_iterator & it,vertex_descriptor src)93 	out_edge_iterator(const const_iterator& it,
94 			vertex_descriptor src) : m_it(it), m_src(src) { }
95 
96 	edge_descriptor operator *() const
97 	{
98 		return edge_descriptor(m_src, m_it->target());
99 	}
100 
101 	bool operator ==(const out_edge_iterator& it) const
102 	{
103 		return m_it == it.m_it;
104 	}
105 
106 	bool operator !=(const out_edge_iterator& it) const
107 	{
108 		return m_it != it.m_it;
109 	}
110 
111 	out_edge_iterator& operator ++() { ++m_it; return *this; }
112 	out_edge_iterator operator ++(int)
113 	{
114 		out_edge_iterator it = *this;
115 		++*this;
116 		return it;
117 	}
118 
get_property()119 	const edge_property_type& get_property() const
120 	{
121 		return m_it->get_property();
122 	}
123 
124   private:
125 	const_iterator m_it;
126 	vertex_descriptor m_src;
127 };
128 
129 /** Iterate through adjacent vertices. */
130 class adjacency_iterator : public Edges::const_iterator
131 {
132 	typedef typename Edges::const_iterator It;
133   public:
adjacency_iterator()134 	adjacency_iterator() { }
adjacency_iterator(const It & it)135 	adjacency_iterator(const It& it) : It(it) { }
136 
137 	vertex_descriptor operator*() const
138 	{
139 		return It::operator*().target();
140 	}
141 
get_property()142 	const edge_property_type& get_property() const
143 	{
144 		return It::operator*().get_property();
145 	}
146 };
147 
148 /** Iterate through edges. */
149 class edge_iterator
150 	: public std::iterator<std::input_iterator_tag, edge_descriptor>
151 {
nextVertex()152 	void nextVertex()
153 	{
154 		vertex_iterator vlast = m_g->vertices().second;
155 		for (; m_vit != vlast; ++m_vit) {
156 			std::pair<adjacency_iterator, adjacency_iterator>
157 				adj = m_g->adjacent_vertices(*m_vit);
158 			if (adj.first != adj.second) {
159 				m_eit = adj.first;
160 				return;
161 			}
162 		}
163 		// Set m_eit to a known value.
164 		static const adjacency_iterator s_eitNULL;
165 		m_eit = s_eitNULL;
166 	}
167 
168   public:
edge_iterator()169 	edge_iterator() { }
edge_iterator(const DirectedGraph * g,const vertex_iterator & vit)170 	edge_iterator(const DirectedGraph* g, const vertex_iterator& vit)
171 		: m_g(g), m_vit(vit)
172 	{
173 		nextVertex();
174 	}
175 
176 	edge_descriptor operator*() const
177 	{
178 		return edge_descriptor(*m_vit, *m_eit);
179 	}
180 
get_property()181 	const edge_property_type& get_property() const
182 	{
183 		return m_eit->get_property();
184 	}
185 
186 	bool operator==(const edge_iterator& it) const
187 	{
188 		return m_vit == it.m_vit && m_eit == it.m_eit;
189 	}
190 
191 	bool operator!=(const edge_iterator& it) const
192 	{
193 		return !(*this == it);
194 	}
195 
196 	edge_iterator& operator++()
197 	{
198 		if (++m_eit == m_g->adjacent_vertices(*m_vit).second) {
199 			++m_vit;
200 			nextVertex();
201 		}
202 		return *this;
203 	}
204 
205 	edge_iterator operator++(int)
206 	{
207 		edge_iterator it = *this;
208 		++*this;
209 		return it;
210 	}
211 
212   private:
213 	const DirectedGraph* m_g;
214 	vertex_iterator m_vit;
215 	adjacency_iterator m_eit;
216 };
217 
218   private:
219 /** A vertex and its properties. */
220 class Vertex
221 {
222   public:
Vertex()223 	Vertex() { }
Vertex(const vertex_property_type & p)224 	Vertex(const vertex_property_type& p) : m_prop(p) { }
225 
226 	/** Return the properties of this vertex. */
get_property()227 	const vertex_property_type& get_property() const
228 	{
229 		return m_prop;
230 	}
231 
232 	/** Returns an iterator-range to the out edges of vertex u. */
233 	std::pair<out_edge_iterator, out_edge_iterator>
out_edges(vertex_descriptor u)234 	out_edges(vertex_descriptor u) const
235 	{
236 		return make_pair(out_edge_iterator(m_edges.begin(), u),
237 				out_edge_iterator(m_edges.end(), u));
238 	}
239 
240 	/** Returns an iterator-range to the adjacent vertices. */
241 	std::pair<adjacency_iterator, adjacency_iterator>
adjacent_vertices()242 	adjacent_vertices() const
243 	{
244 		return make_pair(m_edges.begin(), m_edges.end());
245 	}
246 
247 	/** Return the number of outgoing edges. */
out_degree()248 	degree_size_type out_degree() const
249 	{
250 		return m_edges.size();
251 	}
252 
253 	/** Add an edge to this vertex. */
add_edge(vertex_descriptor v,const edge_property_type & ep)254 	bool add_edge(vertex_descriptor v, const edge_property_type& ep)
255 	{
256 		m_edges.push_back(Edge(v, ep));
257 		return true;
258 	}
259 
260 	/** Remove the edge to v from this vertex. */
remove_edge(vertex_descriptor v)261 	void remove_edge(vertex_descriptor v)
262 	{
263 		m_edges.erase(remove(m_edges.begin(), m_edges.end(), v),
264 				m_edges.end());
265 	}
266 
267 	/** Remove all out edges from this vertex. */
clear_out_edges()268 	void clear_out_edges()
269 	{
270 		m_edges.clear();
271 	}
272 
273 	/** Return the properties of the edge with target v. */
274 	edge_property_type& operator[](vertex_descriptor v)
275 	{
276 		typename Edges::iterator it
277 			= find(m_edges.begin(), m_edges.end(), v);
278 		assert(it != m_edges.end());
279 		return it->get_property();
280 	}
281 
282 	/** Return the properties of the edge with target v. */
283 	const edge_property_type& operator[](vertex_descriptor v) const
284 	{
285 		typename Edges::const_iterator it
286 			= find(m_edges.begin(), m_edges.end(), v);
287 		assert(it != m_edges.end());
288 		return it->get_property();
289 	}
290 
291 	/** Return true if edge (u,v) exists. */
edge(vertex_descriptor v)292 	bool edge(vertex_descriptor v) const
293 	{
294 		return count(m_edges.begin(), m_edges.end(), v) > 0;
295 	}
296 
297 	/** Remove edges that satisfy the predicate. */
298 	template <typename Predicate>
remove_edge_if(vertex_descriptor u,Predicate predicate)299 	void remove_edge_if(vertex_descriptor u, Predicate predicate)
300 	{
301 		typename Edges::iterator out = m_edges.begin();
302 		for (typename Edges::iterator it = m_edges.begin();
303 				it != m_edges.end(); ++it) {
304 			if (!predicate(edge_descriptor(u, it->target()))) {
305 				if (out != it)
306 					*out = *it;
307 				++out;
308 			}
309 		}
310 		m_edges.erase(out, m_edges.end());
311 	}
312 
313   private:
314 	Edges m_edges;
315 	vertex_property_type m_prop;
316 };
317 
318 /** A directed edge. */
319 class Edge
320 {
321   public:
Edge(vertex_descriptor v,const edge_property_type & ep)322 	explicit Edge(vertex_descriptor v, const edge_property_type& ep)
323 		: m_target(v), m_ep(ep) { }
324 
325 	/** Returns the target vertex of this edge. */
target()326 	vertex_descriptor target() const { return m_target; }
327 
328 	/** Return true if the target of this edge is v. */
329 	bool operator ==(const vertex_descriptor& v) const
330 	{
331 		return m_target == v;
332 	}
333 
get_property()334 	edge_property_type& get_property() { return m_ep; }
get_property()335 	const edge_property_type& get_property() const { return m_ep; }
336 
337   private:
338 	/** The target vertex of this edge. */
339 	vertex_descriptor m_target;
340 	edge_property_type m_ep;
341 };
342 
343   public:
344 	/** Create an empty graph. */
DirectedGraph()345 	DirectedGraph() { }
346 
347 	/** Create a graph with n vertices and zero edges. */
DirectedGraph(vertices_size_type n)348 	DirectedGraph(vertices_size_type n) : m_vertices(n) { }
349 
350 	/** Swap this graph with graph x. */
swap(DirectedGraph & x)351 	void swap(DirectedGraph& x)
352 	{
353 		m_vertices.swap(x.m_vertices);
354 		m_removed.swap(x.m_removed);
355 	}
356 
357 	/** Return properties of vertex u. */
358 	const vertex_property_type& operator[](vertex_descriptor u) const
359 	{
360 		vertices_size_type ui = get(vertex_index, *this, u);
361 		assert(ui < num_vertices());
362 		return m_vertices[ui].get_property();
363 	}
364 
365 	/** Returns an iterator-range to the vertices. */
vertices()366 	std::pair<vertex_iterator, vertex_iterator> vertices() const
367 	{
368 		return make_pair(vertex_iterator(0),
369 			vertex_iterator(num_vertices()));
370 	}
371 
372 	/** Remove all the edges and vertices from this graph. */
clear()373 	void clear() { m_vertices.clear(); m_removed.clear(); }
374 
375 	/** Add a vertex to this graph. */
376 	vertex_descriptor add_vertex(
377 			const vertex_property_type& vp = vertex_property_type())
378 	{
379 		m_vertices.push_back(Vertex(vp));
380 		return vertex_descriptor(num_vertices() - 1);
381 	}
382 
383 	/** Returns an iterator-range to the out edges of vertex u. */
384 	std::pair<out_edge_iterator, out_edge_iterator>
out_edges(vertex_descriptor u)385 	out_edges(vertex_descriptor u) const
386 	{
387 		vertices_size_type ui = get(vertex_index, *this, u);
388 		assert(ui < num_vertices());
389 		return m_vertices[ui].out_edges(u);
390 	}
391 
392 	/** Returns an iterator-range to the adjacent vertices of
393 	 * vertex u. */
394 	std::pair<adjacency_iterator, adjacency_iterator>
adjacent_vertices(vertex_descriptor u)395 	adjacent_vertices(vertex_descriptor u) const
396 	{
397 		vertices_size_type ui = get(vertex_index, *this, u);
398 		assert(ui < num_vertices());
399 		return m_vertices[ui].adjacent_vertices();
400 	}
401 
402 	/** Adds edge (u,v) to this graph. */
403 	std::pair<edge_descriptor, bool>
404 	add_edge(vertex_descriptor u, vertex_descriptor v,
405 			const edge_property_type& ep = edge_property_type())
406 	{
407 		vertices_size_type ui = get(vertex_index, *this, u);
408 		assert(ui < num_vertices());
409 		assert(get(vertex_index, *this, v) < num_vertices());
410 		return make_pair(edge_descriptor(u, v),
411 				m_vertices[ui].add_edge(v, ep));
412 	}
413 
414 	/** Remove the edge (u,v) from this graph. */
remove_edge(vertex_descriptor u,vertex_descriptor v)415 	void remove_edge(vertex_descriptor u, vertex_descriptor v)
416 	{
417 		vertices_size_type ui = get(vertex_index, *this, u);
418 		assert(ui < num_vertices());
419 		m_vertices[ui].remove_edge(v);
420 	}
421 
422 	/** Remove the edge e from this graph. */
remove_edge(edge_descriptor e)423 	void remove_edge(edge_descriptor e)
424 	{
425 		remove_edge(e.first, e.second);
426 	}
427 
428 	/** Remove all out edges from vertex u. */
clear_out_edges(vertex_descriptor u)429 	void clear_out_edges(vertex_descriptor u)
430 	{
431 		vertices_size_type ui = get(vertex_index, *this, u);
432 		assert(ui < num_vertices());
433 		m_vertices[ui].clear_out_edges();
434 	}
435 
436 	/** Remove all edges to and from vertex u from this graph.
437 	 * O(V+E) */
clear_vertex(vertex_descriptor u)438 	void clear_vertex(vertex_descriptor u)
439 	{
440 		clear_out_edges(u);
441 		std::pair<adjacency_iterator, adjacency_iterator>
442 			adj = adjacent_vertices(u);
443 		for (adjacency_iterator v = adj.first; v != adj.second; ++v)
444 			remove_edge(*v, u);
445 	}
446 
447 	/** Set the vertex_removed property. */
put(vertex_removed_t,vertex_descriptor u,bool flag)448 	void put(vertex_removed_t, vertex_descriptor u, bool flag)
449 	{
450 		vertices_size_type ui = get(vertex_index, *this, u);
451 		if (ui >= m_removed.size())
452 			m_removed.resize(ui + 1);
453 		m_removed[ui] = flag;
454 	}
455 
456 	/** Remove vertex u from this graph. It is assumed that there
457 	 * are no edges to or from vertex u. It is best to call
458 	 * clear_vertex before remove_vertex.
459 	 */
remove_vertex(vertex_descriptor u)460 	void remove_vertex(vertex_descriptor u)
461 	{
462 		put(vertex_removed, u, true);
463 	}
464 
465 	/** Return the number of vertices. */
num_vertices()466 	vertices_size_type num_vertices() const
467 	{
468 		return m_vertices.size();
469 	}
470 
471 	/** Return the number of edges. */
num_edges()472 	edges_size_type num_edges() const
473 	{
474 		edges_size_type n = 0;
475 		std::pair<vertex_iterator, vertex_iterator> vit = vertices();
476 		for (vertex_iterator v = vit.first; v != vit.second; ++v)
477 			n += out_degree(*v);
478 		return n;
479 	}
480 
481 	/** Return the out degree of vertex u. */
out_degree(vertex_descriptor u)482 	degree_size_type out_degree(vertex_descriptor u) const
483 	{
484 		vertices_size_type ui = get(vertex_index, *this, u);
485 		assert(ui < num_vertices());
486 		return m_vertices[ui].out_degree();
487 	}
488 
489 	/** Return the nth vertex. */
vertex(vertices_size_type n)490 	static vertex_descriptor vertex(vertices_size_type n)
491 	{
492 		return vertex_descriptor(n);
493 	}
494 
495 	/** Iterate through the edges of this graph. */
edges()496 	std::pair<edge_iterator, edge_iterator> edges() const
497 	{
498 		std::pair<vertex_iterator, vertex_iterator> vit = vertices();
499 		return make_pair(edge_iterator(this, vit.first),
500 				edge_iterator(this, vit.second));
501 	}
502 
503 	/** Return the edge (u,v) if it exists and a flag indicating
504 	 * whether the edge exists.
505 	 */
edge(vertex_descriptor u,vertex_descriptor v)506 	std::pair<edge_descriptor, bool> edge(
507 			vertex_descriptor u, vertex_descriptor v) const
508 	{
509 		vertices_size_type ui = get(vertex_index, *this, u);
510 		assert(ui < num_vertices());
511 		return make_pair(edge_descriptor(u, v),
512 				m_vertices[ui].edge(v));
513 	}
514 
515 	/** Return properties of edge e. */
516 	edge_property_type& operator[](edge_descriptor e)
517 	{
518 		vertices_size_type ui = get(vertex_index, *this, e.first);
519 		assert(ui < num_vertices());
520 		return m_vertices[ui][e.second];
521 	}
522 
523 	/** Return properties of edge e. */
524 	const edge_property_type& operator[](edge_descriptor e) const
525 	{
526 		vertices_size_type ui = get(vertex_index, *this, e.first);
527 		assert(ui < num_vertices());
528 		return m_vertices[ui][e.second];
529 	}
530 
531 	/** Remove edges that satisfy the predicate. */
532 	template <typename Predicate>
remove_edge_if(Predicate predicate)533 	void remove_edge_if(Predicate predicate)
534 	{
535 		unsigned i = 0;
536 		for (typename Vertices::iterator it = m_vertices.begin();
537 				it != m_vertices.end(); ++it)
538 			it->remove_edge_if(vertex(i++), predicate);
539 	}
540 
541 	/** Return true if this vertex has been removed. */
is_removed(vertex_descriptor u)542 	bool is_removed(vertex_descriptor u) const
543 	{
544 		vertices_size_type ui = get(vertex_index, *this, u);
545 		return ui < m_removed.size() ? m_removed[ui] : false;
546 	}
547 
548   protected:
549 
550 	/** Copy constructors */
551 	DirectedGraph(const DirectedGraph&) = default;
552 	DirectedGraph(DirectedGraph&&) = default;
553 	DirectedGraph& operator=(const DirectedGraph&) = default;
554 	DirectedGraph& operator=(DirectedGraph&&) = default;
555 
556   private:
557 
558 	/** The set of vertices. */
559 	Vertices m_vertices;
560 
561 	/** Flags indicating vertices that have been removed. */
562 	std::vector<bool> m_removed;
563 };
564 
565 namespace std {
566 	template <typename VertexProp, typename EdgeProp>
swap(DirectedGraph<VertexProp,EdgeProp> & a,DirectedGraph<VertexProp,EdgeProp> & b)567 	inline void swap(DirectedGraph<VertexProp, EdgeProp>& a,
568 			DirectedGraph<VertexProp, EdgeProp>& b) { a.swap(b); }
569 }
570 
571 // IncidenceGraph
572 
573 template <typename VP, typename EP>
574 std::pair<
575 	typename DirectedGraph<VP, EP>::out_edge_iterator,
576 	typename DirectedGraph<VP, EP>::out_edge_iterator>
out_edges(typename DirectedGraph<VP,EP>::vertex_descriptor u,const DirectedGraph<VP,EP> & g)577 out_edges(
578 		typename DirectedGraph<VP, EP>::vertex_descriptor u,
579 		const DirectedGraph<VP, EP>& g)
580 {
581 	return g.out_edges(u);
582 }
583 
584 template <typename VP, typename EP>
585 typename DirectedGraph<VP, EP>::degree_size_type
out_degree(typename DirectedGraph<VP,EP>::vertex_descriptor u,const DirectedGraph<VP,EP> & g)586 out_degree(
587 		typename DirectedGraph<VP, EP>::vertex_descriptor u,
588 		const DirectedGraph<VP, EP>& g)
589 {
590 	return g.out_degree(u);
591 }
592 
593 // AdjacencyGraph
594 
595 template <typename VP, typename EP>
596 std::pair<
597 	typename DirectedGraph<VP, EP>::adjacency_iterator,
598 	typename DirectedGraph<VP, EP>::adjacency_iterator>
adjacent_vertices(typename DirectedGraph<VP,EP>::vertex_descriptor u,const DirectedGraph<VP,EP> & g)599 adjacent_vertices(
600 		typename DirectedGraph<VP, EP>::vertex_descriptor u,
601 		const DirectedGraph<VP, EP>& g)
602 {
603 	return g.adjacent_vertices(u);
604 }
605 
606 // VertexListGraph
607 
608 template <typename VP, typename EP>
609 typename DirectedGraph<VP, EP>::vertices_size_type
num_vertices(const DirectedGraph<VP,EP> & g)610 num_vertices(const DirectedGraph<VP, EP>& g)
611 {
612 	return g.num_vertices();
613 }
614 
615 template <typename VP, typename EP>
616 typename DirectedGraph<VP, EP>::vertex_descriptor
vertex(typename DirectedGraph<VP,EP>::vertices_size_type ui,const DirectedGraph<VP,EP> & g)617 vertex(typename DirectedGraph<VP, EP>::vertices_size_type ui, const DirectedGraph<VP, EP>& g)
618 {
619 	return g.vertex(ui);
620 }
621 
622 template <typename VP, typename EP>
623 std::pair<typename DirectedGraph<VP, EP>::vertex_iterator,
624 	typename DirectedGraph<VP, EP>::vertex_iterator>
vertices(const DirectedGraph<VP,EP> & g)625 vertices(const DirectedGraph<VP, EP>& g)
626 {
627 	return g.vertices();
628 }
629 
630 // EdgeListGraph
631 
632 template <typename VP, typename EP>
633 typename DirectedGraph<VP, EP>::edges_size_type
num_edges(const DirectedGraph<VP,EP> & g)634 num_edges(const DirectedGraph<VP, EP>& g)
635 {
636 	return g.num_edges();
637 }
638 
639 template <typename VP, typename EP>
640 std::pair<typename DirectedGraph<VP, EP>::edge_iterator,
641 	typename DirectedGraph<VP, EP>::edge_iterator>
edges(const DirectedGraph<VP,EP> & g)642 edges(const DirectedGraph<VP, EP>& g)
643 {
644 	return g.edges();
645 }
646 
647 // AdjacencyMatrix
648 
649 template <typename VP, typename EP>
650 std::pair<typename DirectedGraph<VP, EP>::edge_descriptor, bool>
edge(typename DirectedGraph<VP,EP>::vertex_descriptor u,typename DirectedGraph<VP,EP>::vertex_descriptor v,const DirectedGraph<VP,EP> & g)651 edge(
652 	typename DirectedGraph<VP, EP>::vertex_descriptor u,
653 	typename DirectedGraph<VP, EP>::vertex_descriptor v,
654 	const DirectedGraph<VP, EP>& g)
655 {
656 	return g.edge(u, v);
657 }
658 
659 // VertexMutableGraph
660 
661 template <typename VP, typename EP>
662 typename DirectedGraph<VP, EP>::vertex_descriptor
add_vertex(DirectedGraph<VP,EP> & g)663 add_vertex(DirectedGraph<VP, EP>& g)
664 {
665 	return g.add_vertex();
666 }
667 
668 template <typename VP, typename EP>
669 void
remove_vertex(typename DirectedGraph<VP,EP>::vertex_descriptor u,DirectedGraph<VP,EP> & g)670 remove_vertex(
671 		typename DirectedGraph<VP, EP>::vertex_descriptor u,
672 		DirectedGraph<VP, EP>& g)
673 {
674 	g.remove_vertex(u);
675 }
676 
677 // EdgeMutableGraph
678 
679 template <typename VP, typename EP>
680 void
clear_vertex(typename DirectedGraph<VP,EP>::vertex_descriptor u,DirectedGraph<VP,EP> & g)681 clear_vertex(
682 		typename DirectedGraph<VP, EP>::vertex_descriptor u,
683 		DirectedGraph<VP, EP>& g)
684 {
685 	g.clear_vertex(u);
686 }
687 
688 template <typename VP, typename EP>
689 std::pair<typename DirectedGraph<VP, EP>::edge_descriptor, bool>
add_edge(typename DirectedGraph<VP,EP>::vertex_descriptor u,typename DirectedGraph<VP,EP>::vertex_descriptor v,DirectedGraph<VP,EP> & g)690 add_edge(
691 	typename DirectedGraph<VP, EP>::vertex_descriptor u,
692 	typename DirectedGraph<VP, EP>::vertex_descriptor v,
693 	DirectedGraph<VP, EP>& g)
694 {
695 	return g.add_edge(u, v);
696 }
697 
698 template <typename VP, typename EP>
699 void
remove_edge(typename DirectedGraph<VP,EP>::vertex_descriptor u,typename DirectedGraph<VP,EP>::vertex_descriptor v,DirectedGraph<VP,EP> & g)700 remove_edge(
701 	typename DirectedGraph<VP, EP>::vertex_descriptor u,
702 	typename DirectedGraph<VP, EP>::vertex_descriptor v,
703 	DirectedGraph<VP, EP>& g)
704 {
705 	g.remove_edge(u, v);
706 }
707 
708 template <typename VP, typename EP>
709 void
remove_edge(typename DirectedGraph<VP,EP>::edge_descriptor e,DirectedGraph<VP,EP> & g)710 remove_edge(
711 		typename DirectedGraph<VP, EP>::edge_descriptor e,
712 		DirectedGraph<VP, EP>& g)
713 {
714 	g.remove_edge(e);
715 }
716 
717 // MutableIncidenceGraph
718 
719 template <typename VP, typename EP>
720 void
clear_out_edges(typename DirectedGraph<VP,EP>::vertex_descriptor u,DirectedGraph<VP,EP> & g)721 clear_out_edges(
722 		typename DirectedGraph<VP, EP>::vertex_descriptor u,
723 		DirectedGraph<VP, EP>& g)
724 {
725 	g.clear_out_edges(u);
726 }
727 
728 // MutableEdgeListGraph
729 
730 template <typename VP, typename EP, class Predicate>
731 void
remove_edge_if(Predicate predicate,DirectedGraph<VP,EP> & g)732 remove_edge_if(Predicate predicate, DirectedGraph<VP, EP>& g)
733 {
734 	g.remove_edge_if(predicate);
735 }
736 
737 // PropertyGraph
738 
739 /** Return true if this vertex has been removed. */
740 template <typename VP, typename EP>
get(vertex_removed_t,const DirectedGraph<VP,EP> & g,typename DirectedGraph<VP,EP>::vertex_descriptor u)741 bool get(vertex_removed_t, const DirectedGraph<VP, EP>& g,
742 		typename DirectedGraph<VP, EP>::vertex_descriptor u)
743 {
744 	return g.is_removed(u);
745 }
746 
747 template <typename VP, typename EP>
put(vertex_removed_t tag,DirectedGraph<VP,EP> & g,typename DirectedGraph<VP,EP>::vertex_descriptor u,bool flag)748 void put(vertex_removed_t tag, DirectedGraph<VP, EP>& g,
749 		typename DirectedGraph<VP, EP>::vertex_descriptor u,
750 		bool flag)
751 {
752 	g.put(tag, u, flag);
753 }
754 
755 /** Return the edge properties of the edge iterator eit. */
756 template <typename VP, typename EP>
757 const typename DirectedGraph<VP, EP>::edge_property_type&
get(edge_bundle_t,const DirectedGraph<VP,EP> &,typename DirectedGraph<VP,EP>::edge_iterator eit)758 get(edge_bundle_t, const DirectedGraph<VP, EP>&,
759 		typename DirectedGraph<VP, EP>::edge_iterator eit)
760 {
761 	return eit.get_property();
762 }
763 
764 /** Return the edge properties of the out-edge iterator eit. */
765 template <typename VP, typename EP>
766 const typename DirectedGraph<VP, EP>::edge_property_type&
get(edge_bundle_t,const DirectedGraph<VP,EP> &,typename DirectedGraph<VP,EP>::out_edge_iterator eit)767 get(edge_bundle_t, const DirectedGraph<VP, EP>&,
768 		typename DirectedGraph<VP, EP>::out_edge_iterator eit)
769 {
770 	return eit.get_property();
771 }
772 
773 // PropertyGraph
774 
775 template <typename VP, typename EP>
776 const VP&
get(vertex_bundle_t,const DirectedGraph<VP,EP> & g,typename DirectedGraph<VP,EP>::vertex_descriptor u)777 get(vertex_bundle_t, const DirectedGraph<VP, EP>& g,
778 		typename DirectedGraph<VP, EP>::vertex_descriptor u)
779 {
780 	return g[u];
781 }
782 
783 template <typename VP, typename EP>
784 const EP&
get(edge_bundle_t,const DirectedGraph<VP,EP> & g,typename DirectedGraph<VP,EP>::edge_descriptor e)785 get(edge_bundle_t, const DirectedGraph<VP, EP>& g,
786 		typename DirectedGraph<VP, EP>::edge_descriptor e)
787 {
788 	return g[e];
789 }
790 
791 // PropertyGraph vertex_index
792 
793 namespace boost {
794 template <typename VP, typename EP>
795 struct property_map<DirectedGraph<VP, EP>, vertex_index_t>
796 {
797 	typedef ContigNodeIndexMap type;
798 	typedef type const_type;
799 };
800 }
801 
802 template <typename VP, typename EP>
803 ContigNodeIndexMap
804 get(vertex_index_t, const DirectedGraph<VP, EP>&)
805 {
806 	return ContigNodeIndexMap();
807 }
808 
809 template <typename VP, typename EP>
810 ContigNodeIndexMap::reference
811 get(vertex_index_t tag, const DirectedGraph<VP, EP>& g,
812 		typename DirectedGraph<VP, EP>::vertex_descriptor u)
813 {
814 	return get(get(tag, g), u);
815 }
816 
817 // VertexMutablePropertyGraph
818 
819 template <typename VP, typename EP>
820 typename DirectedGraph<VP, EP>::vertex_descriptor
821 add_vertex(const VP& vp, DirectedGraph<VP, EP>& g)
822 {
823 	return g.add_vertex(vp);
824 }
825 
826 // EdgeMutablePropertyGraph
827 
828 template <typename VP, typename EP>
829 std::pair<typename DirectedGraph<VP, EP>::edge_descriptor, bool>
830 add_edge(
831 	typename DirectedGraph<VP, EP>::vertex_descriptor u,
832 	typename DirectedGraph<VP, EP>::vertex_descriptor v,
833 	const typename DirectedGraph<VP, EP>::edge_property_type& ep,
834 	DirectedGraph<VP, EP>& g)
835 {
836 	return g.add_edge(u, v, ep);
837 }
838 
839 // NamedGraph
840 
841 template <typename VP, typename EP>
842 typename DirectedGraph<VP, EP>::vertex_descriptor
843 find_vertex(const std::string& name, const DirectedGraph<VP, EP>&)
844 {
845 	return find_vertex(name, g_contigNames);
846 }
847 
848 template <typename VP, typename EP>
849 typename DirectedGraph<VP, EP>::vertex_descriptor
850 find_vertex(const std::string& name, bool sense,
851 		const DirectedGraph<VP, EP>&)
852 {
853 	return find_vertex(name, sense, g_contigNames);
854 }
855 
856 #endif
857