NRP Core  1.4.1
ngraph.hpp
Go to the documentation of this file.
1 /*
2 *
3 * NGraph++ : a simple graph library
4 *
5 * Mathematical and Computational Sciences Division
6 * National Institute of Technology,
7 * Gaithersburg, MD USA
8 *
9 *
10 * This software was developed at the National Institute of Standards and
11 * Technology (NIST) by employees of the Federal Government in the course
12 * of their official duties. Pursuant to title 17 Section 105 of the
13 * United States Code, this software is not subject to copyright protection
14 * and is in the public domain. NIST assumes no responsibility whatsoever for
15 * its use by other parties, and makes no guarantees, expressed or implied,
16 * about its quality, reliability, or any other characteristic.
17 *
18 */
19 
20 #ifndef NGRAPH_H_
21 #define NGRAPH_H_
22 
23 // version 4.2
24 
25 
26 #include <iostream>
27 #include <set>
28 #include <map>
29 #include <utility> // for std::pair
30 #include <iterator> // for inserter()
31 #include <vector> // for exporting edge_list
32 #include <string>
33 #include <algorithm>
34 #include <sstream> // for I/O << and >> operators
35 #include "set_ops.hpp"
36 
37 
38 // TEMPLATE DIRECTED GRAPH (with in-out adjacency list)
39 //
40 //
41 // T is the vertex type
42 //
43 // An adjacency graph format lists for each vertex, a set of neighbors
44 // the it connects to (outlinks) and optionally another set of neighbors
45 // which connect to it. (The second set provides a quick way to find
46 // out who is pointing to you.)
47 //
48 // vertex {out-neighbors} {in-neighbors}
49 //
50 
76 namespace NGraph
77 {
78 
79 template <typename T>
80 class tGraph
81 {
82 
83  public:
84 
85  typedef T vertex;
86  typedef T value_type;
87  typedef std::pair<vertex,vertex> edge;
88  //typedef struct{ vertex from; vertex to;} edge;
89  typedef std::set<vertex> vertex_set;
90  typedef std::set<edge> edge_set;
91  typedef std::pair<vertex_set, vertex_set> in_out_edge_sets;
92  typedef std::map<vertex, in_out_edge_sets> adj_graph;
93 
94  typedef typename edge_set::iterator edge_iterator;
95  typedef typename edge_set::const_iterator const_edge_iterator;
96 
97  typedef typename vertex_set::iterator vertex_iterator;
98  typedef typename vertex_set::const_iterator const_vertex_iterator;
99 
101 
102  typedef typename vertex_set::iterator vertex_neighbor_iterator;
103  typedef typename vertex_set::const_iterator vertex_neighbor_const_iterator;
104 
105  private:
106 
107  adj_graph G_;
108  unsigned int num_edges_;
109  bool undirected_;
110 
111  public:
112 
113  //
114  //
115 
129  typedef typename adj_graph::iterator iterator;
130  typedef typename adj_graph::const_iterator const_iterator;
131 
134 
135  unsigned int num_vertices() const { return G_.size(); }
136  unsigned int num_nodes() const { return G_.size(); }
137  unsigned int num_edges() const { return num_edges_; }
138 
139  iterator begin() { return G_.begin(); }
140  const_iterator begin() const { return G_.begin(); }
141  iterator end() { return G_.end(); }
142  const_iterator end() const { return G_.end(); }
143 
144  void clear()
145  {
146  G_.clear();
147  num_edges_ = 0;
148  undirected_ = false;
149  }
150 
152  {
153  return out_neighbors(a).begin();
154  }
155 
157  {
158  return out_neighbors(a).begin();
159  }
160 
162  {
163  return out_neighbors(a).end();
164  }
165 
167  {
168  return out_neighbors(a).end();
169  }
170 
171 
172  tGraph(): G_(), num_edges_(0), undirected_(false){}
173  tGraph(std::istream &s): G_(), num_edges_(0), undirected_(false)
174  {
175  s >> *this;
176  }
177 
178  tGraph(const tGraph &B) : G_(B.G_), num_edges_(B.num_edges_),
179  undirected_(B.undirected_){}
180  tGraph(const edge_set &E)
181  {
182  for (typename edge_set::const_iterator p = E.begin();
183  p != E.end(); p++)
184  insert_edge(*p);
185  }
186 
187  bool is_undirected() const
188  {
189  return undirected_;
190  }
191 
192 
193  bool is_directed() const
194  {
195  return !undirected_;
196  }
197 
199  {
200  undirected_ = true;
201  }
202 
203  iterator find(const vertex &a)
204  {
205  return G_.find(a);
206  }
207 
208  const_iterator find(const vertex &a) const
209  {
210  return G_.find(a);
211  }
212 
213  const vertex_set &in_neighbors(const vertex &a) const
214  { return (find(a))->second.first;}
216  { return (G_[a]).first; }
217 
218  const vertex_set &out_neighbors(const vertex &a)const
219  {return find(a)->second.second;}
221  {return G_[a].second; }
222 
223 
224  unsigned int in_degree(const vertex &a) const
225  {
226  return in_neighbors(a).size();
227  }
228 
229  unsigned int out_degree(const vertex &a) const
230  {
231  return out_neighbors(a).size();
232  }
233 
234  unsigned int degree(const vertex &a) const
235  {
236  const_iterator p = find(a);
237  if (p == end())
238  return 0;
239  else
240  return degree(p);
241  }
242 
243 
244  bool isolated(const vertex &a) const
245  {
246  const_iterator p = find(a);
247  if ( p != end() )
248  return isolated(p) ;
249  else
250  return false;
251  }
252 
253  void insert_vertex(const vertex &a)
254  {
255  G_[a];
256  }
257 
259  const vertex_set &OUT)
260  {
261  typename adj_graph::iterator p = find(a);
262 
263  // return if "a" already in graph
264  if (p != G_.end())
265  {
266  // remove the old number of OUT vertices
267  num_edges_ -= p->second.second.size();
268  }
269 
270  G_[a] = make_pair(IN, OUT);
271  num_edges_ += OUT.size();
272  }
273 
274 
275 
277  {
278  if (pa==pb) return;
279  insert_edge(pa, pb);
280  }
281 
283  {
284  vertex a = node(pa);
285  vertex b = node(pb);
286 
287  if (is_undirected())
288  {
289  vertex smallest = ( a < b ? a : b);
290  //vertex biggest = ( a < b ? b : a);
291 
292  if (smallest == b)
293  {
294  std::swap(a,b);
295  std::swap(pa, pb);
296  }
297  }
298  unsigned int old_size = out_neighbors(pa).size();
299 
300  out_neighbors(pa).insert(b);
301  in_neighbors(pb).insert(a);
302 
303  unsigned int new_size = out_neighbors(pa).size();
304  if (new_size > old_size)
305  {
306  num_edges_++;
307  }
308 
309  }
310 
311  void insert_edge_noloop(const vertex &a, const vertex &b)
312  {
313  if (a==b) return;
314  insert_edge(a, b);
315  }
316 
317 
318  void insert_edge(const vertex &a, const vertex& b)
319  {
320  iterator pa = find(a);
321  if (pa == G_.end())
322  {
323  insert_vertex(a);
324  pa = find(a);
325  }
326 
327  iterator pb = find(b);
328  if (pb == G_.end())
329  {
330  insert_vertex(b);
331  pb = find(b);
332  }
333 
334  insert_edge( pa, pb );
335  }
336 
337  void insert_undirected_edge(const vertex &a, const vertex &b)
338  {
339  (a < b ) ? insert_edge(a,b) : insert_edge(b,a);
340  }
341 
342 
343  void insert_edge(const edge &E)
344  {
345  insert_edge(E.first, E.second);
346  }
347 
349  {
350  insert_undirected_edge(E.first, E.second);
351  }
352 
353 
354 
356  {
357  if (pa == end() || pb == end())
358  return false;
359 
360  vertex a = node(pa);
361  vertex b = node(pb);
362 
363  if ( is_undirected())
364  {
365  if (a > b)
366  {
367  std::swap(b,a);
368  std::swap(pb, pa);
369  }
370 
371  }
372  unsigned int old_size = out_neighbors(pa).size();
373  out_neighbors(pa).erase(b);
374  in_neighbors(pb).erase(a);
375  if (out_neighbors(pa).size() < old_size)
376  num_edges_ --;
377 
378  return true;
379  }
380 
381 
382  void remove_edge(const vertex &a, const vertex& b)
383  {
384  iterator pa = find(a);
385  if (pa == end())
386  return;
387  iterator pb = find(b);
388  if (pb == end())
389  return;
390  remove_edge( pa, pb );
391  }
392 
393  void remove_edge(const edge &E)
394  {
395  remove_edge(E.first, E.second);
396  }
397 
398  void remove_undirected_edge(const vertex &a, const vertex& b)
399  {
400  (a < b) ? remove_edge(a,b) : remove_edge(b,a);
401  }
402 
404  {
405  remove_undirected_edge(e.first, e.second);
406  }
407 
409  {
410  vertex_set out_edges = out_neighbors(pa);
411  vertex_set in_edges = in_neighbors(pa);
412 
413  //vertex_set & out_edges = out_neighbors(pa);
414  //vertex_set & in_edges = in_neighbors(pa);
415 
416  // remove out-going edges
417  for (typename vertex_set::iterator p = out_edges.begin();
418  p!=out_edges.end(); p++)
419  {
420  remove_edge(pa, find(*p));
421  }
422 
423 
424  // remove in-coming edges
425  for (typename vertex_set::iterator p = in_edges.begin();
426  p!=in_edges.end(); p++)
427  {
428  remove_edge(find(*p), pa);
429  }
430 
431 
432  G_.erase(node(pa));
433  }
434 
435 
437  {
438  for (typename vertex_set::const_iterator p=V.begin(); p!=V.end(); p++)
439  remove_vertex(*p);
440  }
441 
442 
443  void remove_vertex(const vertex &a)
444  {
445  iterator pa = find(a);
446  if (pa != G_.end())
447  remove_vertex( pa);
448 
449  }
450 
456  bool includes_vertex(const vertex &a) const
457  {
458  return (find(a) != G_.end());
459  }
460 
461 
468  bool includes_edge(const vertex &a, const vertex &b) const
469  {
470  return (includes_vertex(a)) ?
471  includes_elm(out_neighbors(a),b): false;
472 
473  //const vertex_set &out = out_neighbors(a);
474  // return ( out.find(b) != out.end());
475 
476  }
477 
478 
479  bool includes_edge(const edge& e) const
480  {
481  return includes_edge(e.first, e.second);
482  }
483 
484  // convert to a simple edge list for exporting
485  //
492  std::vector<edge> edge_list() const;
493 
494 /*
495  graph unions
496 */
497 
498  tGraph & plus_eq(const tGraph &B)
499  {
500 
501  for (const_iterator p=B.begin(); p != B.end(); p++)
502  {
503  const vertex &this_node = node(p);
504  insert_vertex(this_node);
505  const vertex_set &out = out_neighbors(p);
506  for (typename vertex_set::const_iterator q= out.begin(); q != out.end(); q++)
507  {
508  insert_edge(this_node, *q);
509  }
510  }
511  return *this;
512  }
513 
514  tGraph intersect(const tGraph &B) const
515  {
516  tGraph G;
517  for (const_iterator p=begin(); p != end(); p++)
518  {
519  const vertex &this_node = node(p);
520  if (B.includes_vertex(this_node))
521  G.insert_vertex(this_node);
522  {
523  const vertex_set &out = out_neighbors(p);
524  for (typename vertex_set::const_iterator q= out.begin();
525  q != out.end(); q++)
526  {
527  if (B.includes_edge(this_node, *q))
528  G.insert_edge(this_node, *q);
529  }
530  }
531  }
532  return G;
533  }
534 
535  tGraph operator*(const tGraph &B) const
536  {
537  return intersect(B);
538  }
539 
540 
541  tGraph minus(const tGraph &B) const
542  {
543  tGraph G;
544  for (const_iterator p=begin(); p != end(); p++)
545  {
546  const vertex &this_vertex = node(p);
547  if (isolated(p))
548  {
549  if (! B.isolated(this_vertex))
550  G.insert_vertex(this_vertex);\
551  }
552  else
553  {
554  const vertex_set &out = out_neighbors(p);
555  for (typename vertex_set::const_iterator q= out.begin();
556  q != out.end(); q++)
557  {
558  if (!B.includes_edge(this_vertex, *q))
559  G.insert_edge(this_vertex, *q);
560  }
561  }
562  }
563  return G;
564  }
565 
566  tGraph operator-(const tGraph &B) const
567  {
568  return minus(B);
569  }
570 
571 
572  tGraph plus(const tGraph &B) const
573  {
574  tGraph U(*this);
575 
576  U.plus_eq(B);
577  return U;
578  }
579 
580  tGraph operator+(const tGraph &B) const
581  {
582  return plus(B);
583  }
584 
585  tGraph & operator+=(const tGraph &B)
586  {
587  return plus_eq(B);
588  }
589 
590 
591 
592 #if 0
593 /*
594  union of two graphs
595 */
596  tGraph Union(const tGraph &B) const
597  {
598  tGraph U(B);
599  typedef std::vector<edge> VE;
600 
601  VE b = B.edge_list();
602  for (typename VE::cosnt_iterator e = b.begin(); e != b.end(); e++)
603  {
604  U.insert_edge(*e);
605  }
606  return U;
607  }
608 
609 /*
610  intersection of two graphs
611 */
612  tGraph intersect(const tGraph &B) const
613  {
614  tGraph I;
615  typedef std::vector<tGraph::edge> VE;
616 
617  VE b = B.edge_list();
618  for (typename VE::const_iterator e = b.begin(); e != b.end(); e++)
619  {
620  if (includes_edge(*e))
621  {
622  I.insert_edge(*e);
623  }
624  }
625 
626  for (typename tGraph::const_iterator p = B.begin(); p!=B.end();p++)
627  {
628  if (includes_vertex( node(p) ))
629  I.insert_vertex( node(p) );
630  }
631  return I;
632  }
633 
634 #endif
635 
636 
637 
638 
643  tGraph subgraph(const vertex_set &A) const
644  {
645  tGraph G;
646 
647  for (typename vertex_set::const_iterator p = A.begin(); p!=A.end(); p++)
648  {
649  const_iterator t = find(*p);
650  if (t != end())
651  {
652  vertex_set new_in = (A * in_neighbors(t));
653  vertex_set new_out = (A * out_neighbors(t));
654 
655  G.insert_new_vertex_inout_list(*p, new_in, new_out);
656  }
657  }
658  return G;
659  }
660 
661 
662  unsigned int subgraph_size(const vertex_set &A) const
663  {
664  unsigned int num_edges = 0;
665  for (typename vertex_set::const_iterator p = A.begin(); p!=A.end(); p++)
666  {
667  const_iterator pG = find(*p);
668  if (pG != this->end())
669  {
670  num_edges += intersection_size(A, out_neighbors(pG) );
671  }
672  }
673  return num_edges;
674  }
675 
676 
677  // we don't need to divide by two since we are only
678  // counting out-edges in subgraph_size()
679  //
680  double subgraph_sparsity(const vertex_set &A) const
681  {
682  double N = A.size();
683 
684  double sparsity = (A.size() ==1 ? 0.0 : subgraph_size(A)/(N * (N-1)));
685  if (is_undirected())
686  {
687  sparsity *= 2.0;
688  }
689  return sparsity;
690  }
691 
692  void print() const;
693 
694 
695 /* tGraph iterator methods */
696 
700 static const vertex &node(const_iterator p)
701 {
702  return p->first;
703 }
704 
705 static const vertex &node(iterator p)
706 {
707  return p->first;
708 }
709 
711 {
712  return *p;
713 }
714 
715 
717  { return (p->second).first; }
718 
720  { return (p->second).first; }
721 
723 {
724  return in_neighbors(p).begin();
725 }
726 
727 
729 {
730  return in_neighbors(p).end();
731 }
732 
733 
735  { return (p->second).second; }
736 
738 {
739  return out_neighbors(p).begin();
740 }
741 
742 
744 {
745  return out_neighbors(p).end();
746 }
747 
748 
750  { return (p->second).second; }
751 
753 {
754  return out_neighbors(p).begin();
755 }
756 
757 
758 static unsigned int num_edges(const_iterator p)
759  {
760  return out_neighbors(p).size();
761  }
762 
763 inline static unsigned int num_edges(iterator p)
764  {
765  return out_neighbors(p).size();
766  }
767 
772 inline static unsigned int out_degree(const_iterator p)
773  {
774  return (p->second).second.size();
775  }
776 
777 inline static unsigned int out_degree(iterator p)
778  {
779  return (p->second).second.size();
780  }
781 
786 inline static unsigned int in_degree(const_iterator p)
787  {
788  return (p->second).first.size();
789  }
790 
791 inline static unsigned int in_degree(iterator p)
792  {
793  return (p->second).first.size();
794  }
795 
796 inline static unsigned int degree(const_iterator p)
797  {
798  return in_neighbors(p).size() + out_neighbors(p).size();
799  }
800 
801 inline static unsigned int degree(iterator p)
802  {
803  return in_neighbors(p).size + out_neighbors(p).size();
804  }
805 
806 
807 inline static bool isolated(const_iterator p)
808 {
809  return (in_degree(p) == 0 && out_degree(p) == 0 );
810 }
811 
812 static bool isolated(iterator p)
813 {
814  return (in_degree(p) == 0 && out_degree(p) == 0 );
815 }
816 
817 
818 
823 {
824 
825  //std::cerr << "Graph::absorb(" << node(pa) << ", " << node(pb) << ")\n";
826 
827  if (pa == pb)
828  return;
829 
830 
831  // first remove edge (a,b) to avoid self-loops
832  remove_edge(pa, pb);
833 
834  // chnage edges (b,i) to a(i,j)
835  //
836  {
837  vertex_set b_out = out_neighbors(pb);
838  for (typename vertex_set::iterator p = b_out.begin();
839  p!=b_out.end(); p++)
840  {
841  iterator pi = find(*p);
842  remove_edge(pb, pi);
843  //std::cerr<<"\t remove_edge("<<node(pb)<< ", " << node(pi) <<")\n";
844  insert_edge(pa, pi);
845  //std::cerr<<"\t insert_edge("<<node(pa)<< ", " << node(pi) <<")\n";
846  }
847  }
848 
849  // change edges (i,b) to (i,a)
850  {
851  vertex_set b_in = in_neighbors(pb);
852  for (typename vertex_set::iterator p = b_in.begin();
853  p!=b_in.end(); p++)
854  {
855  iterator pi = find(*p);
856  remove_edge(pi, pb);
857  //std::cerr<<"\t remove_edge("<<node(pi)<< ", " << node(pb) <<")\n";
858  insert_edge(pi, pa);
859  //std::cerr<<"\t insert_edge("<<node(pi)<< ", " << node(pa) <<")\n";
860  }
861  }
862 
863 
864  //std::cout<<"\t about to remove vertex: "<< node(pb) << "\n";
865 
866  remove_vertex(pb);
867  //G_.erase( node(pb) );
868 
869  //std::cout<<"\t removed_vertex.\n";
870 
871 
872 }
873 
879 {
880  if (degree(pa) >= degree(pb))
881  {
882  absorb(pa, pb);
883  return pb;
884  }
885  else
886  {
887  absorb(pb, pa);
888  return pb;
889  }
890 }
891 
892 
894 {
895  iterator pa = find(a);
896  if (pa == end())
897  {
898  return b;
899  }
900 
901  iterator pb = find(b);
902  if (pb == end())
903  {
904  return a;
905  }
906 
907  iterator pc = smart_absorb(pa, pb);
908  return node(pc);
909 }
910 
911 
912 void absorb(vertex a, vertex b)
913 {
914  if (a == b)
915  return ;
916 
917  iterator pa = find(a);
918  if (pa == end())
919  return;
920 
921  iterator pb = find(b);
922  if (pb == end())
923  return;
924 
925  absorb( pa, pb );
926 }
927 
928 
929 static std::istream &read_line(std::istream &s, T &v1, T &v2,
930  std::string &line , line_type &t )
931 {
932 
933  // next non-empty text line, if possible
934 
935  while (getline(s, line) && line.size() < 1);
936 
937  // if at end-of-file, return empty line
938  if (s.eof())
939  {
940  t = EMPTY;
941  return s;
942  }
943 
944  // otherwise, check for a comment
945  if (line[0] == '%' || line[0] == '#')
946  {
947  t = COMMENT;
948  return s;
949  }
950 
951 
952  // if we are here, then we have a valid graph input line:
953  // either a single vertex or an edge
954  //
955  std::istringstream L(line);
956  L >> v1;
957  if (L.eof())
958  {
959  t = VERTEX;
960  }
961  else
962  {
963  L >> v2;
964  t = EDGE;
965  }
966 
967  return s;
968 }
969 
970 };
971 // end tGraph<T>
972 
973 // global functions
974 //
975 
976 
980 
981 
982 template <class T>
983 std::vector<typename tGraph<T>::edge> tGraph<T>::edge_list() const
984  {
985  //std::vector<tGraph::edge> E(num_edges());
986  std::vector<typename tGraph<T>::edge> E;
987 
988  for (typename tGraph::const_iterator p = begin(); p!=end(); p++)
989  {
990  const vertex &a = tGraph::node(p);
991  const vertex_set &out = tGraph::out_neighbors(p);
992  for (typename vertex_set::const_iterator t = out.begin();
993  t != out.end(); t++)
994  {
995  E.push_back( edge(a, *t));
996  }
997  }
998  return E;
999  }
1000 
1001 
1002 
1003 
1004 template <typename T>
1005 std::istream & operator>>(std::istream &s, tGraph<T> &G)
1006 {
1007  std::string line;
1008  T v1, v2;
1009  typename tGraph<T>::line_type t;
1010 
1011  while (tGraph<T>::read_line(s, v1, v2, line, t))
1012  {
1013  if (t == tGraph<T>::VERTEX)
1014  {
1015  G.insert_vertex(v1);
1016  }
1017  else if (t == tGraph<T>::EDGE)
1018  {
1019  G.insert_edge(v1, v2);
1020  }
1021  }
1022  return s;
1023 }
1024 
1025 template <typename T>
1026 std::ostream & operator<<(std::ostream &s, const tGraph<T> &G)
1027 {
1028  for (typename tGraph<T>::const_node_iterator p=G.begin(); p != G.end(); p++)
1029  {
1030  const typename tGraph<T>::vertex_set &out = tGraph<T>::out_neighbors(p);
1031  typename tGraph<T>::vertex v = p->first;
1032  if (out.size() == 0 && tGraph<T>::in_neighbors(p).size() == 0)
1033  {
1034  // v is an isolated node
1035  s << v << "\n";
1036  }
1037  else
1038  {
1039  for ( typename tGraph<T>::vertex_set::const_iterator q=out.begin();
1040  q!=out.end(); q++)
1041  s << v << " " << *q << "\n";
1042  }
1043  }
1044  return s;
1045 }
1046 
1047 
1048 template <typename T>
1049 void tGraph<T>::print() const
1050  {
1051 
1052  std::cerr << "# vertices: " << num_vertices() << "\n";
1053  std::cerr << "# edges: " << num_edges() << "\n";
1054 
1055  for (const_iterator p=G_.begin();
1056  p != G_.end(); p++)
1057  {
1058  const vertex_set &out = out_neighbors(p);
1059 
1060  for (typename vertex_set::const_iterator q=out.begin();
1061  q!=out.end(); q++)
1062  std::cerr << p->first << " --> " << *q << "\n";
1063  }
1064  std::cerr << std::endl;
1065 
1066  }
1067 
1068 }
1069 // namespace NGraph
1070 
1071 
1072 
1073 #endif
1074 // NGRAPH_H_
NGraph::tGraph::operator-
tGraph operator-(const tGraph &B) const
Definition: ngraph.hpp:566
NGraph::tGraph::node_iterator
iterator node_iterator
Definition: ngraph.hpp:132
NGraph::tGraph::adj_graph
std::map< vertex, in_out_edge_sets > adj_graph
Definition: ngraph.hpp:92
NGraph::tGraph::iterator
adj_graph::iterator iterator
Definition: ngraph.hpp:129
NGraph::tGraph::out_neighbors_begin
vertex_neighbor_const_iterator out_neighbors_begin(const vertex &a) const
Definition: ngraph.hpp:156
NGraph::tGraph::absorb
void absorb(iterator pa, iterator pb)
Definition: ngraph.hpp:822
NGraph::tGraph::remove_undirected_edge
void remove_undirected_edge(const vertex &a, const vertex &b)
Definition: ngraph.hpp:398
NGraph::tGraph::VERTEX
@ VERTEX
Definition: ngraph.hpp:100
NGraph::tGraph::insert_vertex
void insert_vertex(const vertex &a)
Definition: ngraph.hpp:253
NGraph::tGraph::includes_edge
bool includes_edge(const edge &e) const
Definition: ngraph.hpp:479
NGraph::tGraph::remove_edge
void remove_edge(const edge &E)
Definition: ngraph.hpp:393
NGraph::tGraph::vertex_iterator
vertex_set::iterator vertex_iterator
Definition: ngraph.hpp:97
NGraph::tGraph::tGraph
tGraph(const tGraph &B)
Definition: ngraph.hpp:178
NGraph::tGraph::tGraph
tGraph(std::istream &s)
Definition: ngraph.hpp:173
NGraph::tGraph::out_begin
static vertex_iterator out_begin(iterator p)
Definition: ngraph.hpp:752
NGraph::tGraph::const_node_iterator
const_iterator const_node_iterator
Definition: ngraph.hpp:133
NGraph::tGraph::degree
static unsigned int degree(const_iterator p)
Definition: ngraph.hpp:796
NGraph::tGraph::vertex_neighbor_iterator
vertex_set::iterator vertex_neighbor_iterator
Definition: ngraph.hpp:102
NGraph::tGraph::vertex
T vertex
Definition: ngraph.hpp:85
NGraph::tGraph::insert_edge
void insert_edge(const vertex &a, const vertex &b)
Definition: ngraph.hpp:318
NGraph::tGraph::begin
const_iterator begin() const
Definition: ngraph.hpp:140
NGraph::tGraph::const_edge_iterator
edge_set::const_iterator const_edge_iterator
Definition: ngraph.hpp:95
NGraph::iGraph
tGraph< int > iGraph
Definition: ngraph.hpp:978
NGraph::tGraph::remove_vertex_set
void remove_vertex_set(const vertex_set &V)
Definition: ngraph.hpp:436
NGraph::tGraph::subgraph_sparsity
double subgraph_sparsity(const vertex_set &A) const
Definition: ngraph.hpp:680
NGraph::tGraph::includes_vertex
bool includes_vertex(const vertex &a) const
Definition: ngraph.hpp:456
NGraph::tGraph::insert_edge
void insert_edge(const edge &E)
Definition: ngraph.hpp:343
NGraph::tGraph::out_begin
static const_vertex_iterator out_begin(const_iterator p)
Definition: ngraph.hpp:737
set_ops.hpp
NGraph::tGraph::in_out_edge_sets
std::pair< vertex_set, vertex_set > in_out_edge_sets
Definition: ngraph.hpp:91
NGraph::tGraph::set_undirected
void set_undirected()
Definition: ngraph.hpp:198
NGraph::tGraph::const_vertex_iterator
vertex_set::const_iterator const_vertex_iterator
Definition: ngraph.hpp:98
NGraph::tGraph::out_degree
static unsigned int out_degree(iterator p)
Definition: ngraph.hpp:777
NGraph::tGraph::edge_list
std::vector< edge > edge_list() const
Definition: ngraph.hpp:983
NGraph::tGraph::degree
unsigned int degree(const vertex &a) const
Definition: ngraph.hpp:234
NGraph::tGraph::edge_set
std::set< edge > edge_set
Definition: ngraph.hpp:90
NGraph::tGraph::in_neighbors
vertex_set & in_neighbors(const vertex &a)
Definition: ngraph.hpp:215
NGraph::tGraph::out_degree
unsigned int out_degree(const vertex &a) const
Definition: ngraph.hpp:229
NGraph::tGraph::begin
iterator begin()
Definition: ngraph.hpp:139
NGraph::tGraph::out_neighbors
static vertex_set & out_neighbors(iterator p)
Definition: ngraph.hpp:749
NGraph::tGraph::node
static const vertex & node(iterator p)
Definition: ngraph.hpp:705
NGraph::tGraph::in_end
static const_vertex_iterator in_end(const_iterator p)
Definition: ngraph.hpp:728
NGraph::tGraph::plus_eq
tGraph & plus_eq(const tGraph &B)
Definition: ngraph.hpp:498
NGraph::tGraph::smart_absorb
iterator smart_absorb(iterator pa, iterator pb)
Definition: ngraph.hpp:878
NGraph::tGraph::out_neighbors_end
vertex_neighbor_iterator out_neighbors_end(const vertex &a)
Definition: ngraph.hpp:161
NGraph::tGraph::clear
void clear()
Definition: ngraph.hpp:144
NGraph::tGraph::subgraph
tGraph subgraph(const vertex_set &A) const
Definition: ngraph.hpp:643
NGraph::tGraph::find
const_iterator find(const vertex &a) const
Definition: ngraph.hpp:208
NGraph::tGraph::node
static const vertex & node(const_vertex_iterator p)
Definition: ngraph.hpp:710
NGraph::tGraph::in_degree
static unsigned int in_degree(const_iterator p)
Definition: ngraph.hpp:786
NGraph::tGraph::is_undirected
bool is_undirected() const
Definition: ngraph.hpp:187
NGraph::tGraph::remove_vertex
void remove_vertex(iterator pa)
Definition: ngraph.hpp:408
NGraph::tGraph::vertex_set
std::set< vertex > vertex_set
Definition: ngraph.hpp:89
NGraph::tGraph::EMPTY
@ EMPTY
Definition: ngraph.hpp:100
NGraph::tGraph::remove_edge
void remove_edge(const vertex &a, const vertex &b)
Definition: ngraph.hpp:382
NGraph::tGraph::num_edges
static unsigned int num_edges(iterator p)
Definition: ngraph.hpp:763
NGraph::tGraph::isolated
static bool isolated(const_iterator p)
Definition: ngraph.hpp:807
NGraph::tGraph::vertex_neighbor_const_iterator
vertex_set::const_iterator vertex_neighbor_const_iterator
Definition: ngraph.hpp:103
NGraph::tGraph::subgraph_size
unsigned int subgraph_size(const vertex_set &A) const
Definition: ngraph.hpp:662
NGraph::tGraph::out_neighbors
vertex_set & out_neighbors(const vertex &a)
Definition: ngraph.hpp:220
NGraph::tGraph::tGraph
tGraph()
Definition: ngraph.hpp:172
NGraph::tGraph::isolated
static bool isolated(iterator p)
Definition: ngraph.hpp:812
NGraph::tGraph::edge_iterator
edge_set::iterator edge_iterator
Definition: ngraph.hpp:94
NGraph::tGraph::operator*
tGraph operator*(const tGraph &B) const
Definition: ngraph.hpp:535
NGraph::tGraph::node
static const vertex & node(const_iterator p)
Definition: ngraph.hpp:700
NGraph::tGraph::num_vertices
unsigned int num_vertices() const
Definition: ngraph.hpp:135
NGraph::tGraph::is_directed
bool is_directed() const
Definition: ngraph.hpp:193
NGraph::tGraph::in_neighbors
static vertex_set & in_neighbors(iterator p)
Definition: ngraph.hpp:719
NGraph::tGraph::out_degree
static unsigned int out_degree(const_iterator p)
Definition: ngraph.hpp:772
intersection_size
int intersection_size(const std::set< T > &A, const std::set< T > &B)
Definition: set_ops.hpp:138
NGraph::tGraph::const_iterator
adj_graph::const_iterator const_iterator
Definition: ngraph.hpp:130
NGraph::tGraph::num_edges
static unsigned int num_edges(const_iterator p)
Definition: ngraph.hpp:758
NGraph::tGraph::degree
static unsigned int degree(iterator p)
Definition: ngraph.hpp:801
NGraph::tGraph::in_neighbors
static const vertex_set & in_neighbors(const_iterator p)
Definition: ngraph.hpp:716
NGraph::tGraph::in_degree
unsigned int in_degree(const vertex &a) const
Definition: ngraph.hpp:224
NGraph::tGraph::intersect
tGraph intersect(const tGraph &B) const
Definition: ngraph.hpp:514
NGraph::tGraph::minus
tGraph minus(const tGraph &B) const
Definition: ngraph.hpp:541
NGraph::tGraph::out_neighbors
static const vertex_set & out_neighbors(const_iterator p)
Definition: ngraph.hpp:734
NGraph::tGraph::print
void print() const
Definition: ngraph.hpp:1049
NGraph::tGraph::smart_absorb
vertex smart_absorb(vertex a, vertex b)
Definition: ngraph.hpp:893
NGraph::tGraph::operator+=
tGraph & operator+=(const tGraph &B)
Definition: ngraph.hpp:585
NGraph::tGraph::includes_edge
bool includes_edge(const vertex &a, const vertex &b) const
Definition: ngraph.hpp:468
NGraph::tGraph::insert_new_vertex_inout_list
void insert_new_vertex_inout_list(const vertex &a, const vertex_set &IN, const vertex_set &OUT)
Definition: ngraph.hpp:258
NGraph::tGraph::end
const_iterator end() const
Definition: ngraph.hpp:142
NGraph::tGraph::in_degree
static unsigned int in_degree(iterator p)
Definition: ngraph.hpp:791
NGraph::tGraph::num_nodes
unsigned int num_nodes() const
Definition: ngraph.hpp:136
NGraph::operator>>
std::istream & operator>>(std::istream &s, tGraph< T > &G)
Definition: ngraph.hpp:1005
NGraph::tGraph::insert_edge
void insert_edge(iterator pa, iterator pb)
Definition: ngraph.hpp:282
NGraph
A mathematical graph object: a simple, directed, connected graph, where nodes are of arbitrary type (...
Definition: ngraph.hpp:76
NGraph::tGraph::tGraph
tGraph(const edge_set &E)
Definition: ngraph.hpp:180
NGraph::tGraph::out_neighbors_begin
vertex_neighbor_iterator out_neighbors_begin(const vertex &a)
Definition: ngraph.hpp:151
NGraph::tGraph::value_type
T value_type
Definition: ngraph.hpp:86
NGraph::tGraph::operator+
tGraph operator+(const tGraph &B) const
Definition: ngraph.hpp:580
NGraph::tGraph::remove_vertex
void remove_vertex(const vertex &a)
Definition: ngraph.hpp:443
NGraph::tGraph::remove_undirected_edge
void remove_undirected_edge(const edge &e)
Definition: ngraph.hpp:403
NGraph::tGraph::insert_edge_noloop
void insert_edge_noloop(const vertex &a, const vertex &b)
Definition: ngraph.hpp:311
NGraph::tGraph::in_neighbors
const vertex_set & in_neighbors(const vertex &a) const
Definition: ngraph.hpp:213
NGraph::tGraph::out_neighbors_end
vertex_neighbor_const_iterator out_neighbors_end(const vertex &a) const
Definition: ngraph.hpp:166
NGraph::tGraph::num_edges
unsigned int num_edges() const
Definition: ngraph.hpp:137
NGraph::tGraph::insert_undirected_edge
void insert_undirected_edge(const edge &E)
Definition: ngraph.hpp:348
NGraph::tGraph< ComputationalNode * >::line_type
line_type
Definition: ngraph.hpp:100
NGraph::sGraph
tGraph< std::string > sGraph
Definition: ngraph.hpp:979
NGraph::tGraph::insert_undirected_edge
void insert_undirected_edge(const vertex &a, const vertex &b)
Definition: ngraph.hpp:337
NGraph::tGraph::EDGE
@ EDGE
Definition: ngraph.hpp:100
NGraph::tGraph::isolated
bool isolated(const vertex &a) const
Definition: ngraph.hpp:244
includes_elm
bool includes_elm(const std::set< T > &A, constT &a)
Definition: set_ops.hpp:115
NGraph::tGraph
Definition: ngraph.hpp:80
NGraph::tGraph::read_line
static std::istream & read_line(std::istream &s, T &v1, T &v2, std::string &line, line_type &t)
Definition: ngraph.hpp:929
NGraph::tGraph::edge
std::pair< vertex, vertex > edge
Definition: ngraph.hpp:87
NGraph::tGraph::COMMENT
@ COMMENT
Definition: ngraph.hpp:100
NGraph::tGraph::insert_edge_noloop
void insert_edge_noloop(iterator pa, iterator pb)
Definition: ngraph.hpp:276
NGraph::operator<<
std::ostream & operator<<(std::ostream &s, const tGraph< T > &G)
Definition: ngraph.hpp:1026
NGraph::tGraph::in_begin
static const_vertex_iterator in_begin(const_iterator p)
Definition: ngraph.hpp:722
NGraph::tGraph::absorb
void absorb(vertex a, vertex b)
Definition: ngraph.hpp:912
NGraph::tGraph::remove_edge
bool remove_edge(iterator pa, iterator pb)
Definition: ngraph.hpp:355
NGraph::Graph
tGraph< unsigned int > Graph
Definition: ngraph.hpp:977
NGraph::tGraph::find
iterator find(const vertex &a)
Definition: ngraph.hpp:203
NGraph::tGraph::out_neighbors
const vertex_set & out_neighbors(const vertex &a) const
Definition: ngraph.hpp:218
NGraph::tGraph::end
iterator end()
Definition: ngraph.hpp:141
ComputationalNode
Base class implementing a node in the computational graph.
Definition: computational_node.h:31
NGraph::tGraph::plus
tGraph plus(const tGraph &B) const
Definition: ngraph.hpp:572
NGraph::tGraph::out_end
static const_vertex_iterator out_end(const_iterator p)
Definition: ngraph.hpp:743