test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
graph_util.h
Go to the documentation of this file.
1 #ifndef x_graph_util_h
2 #define x_graph_util_h
3 
6 #include <iostream>
7 #include <string>
8 
9 
10 
11 
12 
13 template<class N, class E>
14 void output(const graph<N,E> & g, const N & root)
15 {
16  graphwalker<N,E> w(g,root);
17  bool go=true;
18  while(go) {
19  std::cout << w.current().first << ' ';
20  go=w.next();
21  }
22  std::cout << std::endl;
23 }
24 
25 template<class N, class E>
26 void graph_combine(const graph<N,E> & g1, const graph<N,E> & g2,
27  const N & n1, const N & n2, const N & root,
29 {
30  result = g1;
31  result.replace(n1,n2);
32  //output(result,n2);
33  graphwalker<N,E> walker(g2,n2);
34  while (walker.next()) {
35  const N & parent = g2.nodeData((++walker.stack().rbegin())->first->first);
36  /*
37  N parent = g2.nodeData((++walker.stack().rbegin())->first->first);
38  N child = walker.current().first;
39  E edge = walker.current().second;
40  */
41  //std::cout << parent << ' ' << walker.current().first << ' ' << walker.current().second<< std::endl;
42  result.addEdge(parent, walker.current().first, walker.current().second);
43  //result.addEdge(parent,child,edge);
44  //result.dump_graph();
45  //output(result,n2);
46  }
47  result.replace(n2,root);
48  //output(result,root);
49 }
50 
51 
52 template<class N, class E>
53 void graph_tree_output(const graph<N,E> & g, const N & root, std::ostream & os)
54 {
55  graphwalker<N,E> w(g,root);
56  bool go=true;
57  unsigned int depth=0;
58  while (go) {
59  std::string s(2*depth,' ');
60  os << ' ' << s << w.current().first << '(' << w.current().second << ')' << std::endl;
61  if (go=w.firstChild()) {
62  ++depth;
63  }
64  else if(w.stack().size() >1 && w.nextSibling()) {
65  go=true;
66  }
67  else {
68  go=false;
69  while(w.parent()) {
70  --depth;
71  if (w.stack().size()>1 && w.nextSibling()) {
72  go=true;
73  break;
74  }
75  }
76  }
77 
78  }
79 }
80 #endif
const double w
Definition: UKUtility.cc:23
result_type parent()
Definition: graphwalker.h:172
const N & nodeData(const edge_type &) const
Definition: adjgraph.h:317
const stack_type & stack() const
Definition: graphwalker.h:65
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
const N & first
Definition: adjgraph.h:113
tuple result
Definition: mps_fire.py:84
result_type nextSibling()
Definition: graphwalker.h:157
result_type next()
Definition: graphwalker.h:185
Definition: adjgraph.h:12
#define N
Definition: blowfish.cc:9
result_type firstChild()
Definition: graphwalker.h:143
value_type current() const
Definition: graphwalker.h:109
bool replace(const N &oldNode, const N &newNode)
Definition: adjgraph.h:367
const E & second
Definition: adjgraph.h:114
void graph_tree_output(const graph< N, E > &g, const N &root, std::ostream &os)
Definition: graph_util.h:53
tuple cout
Definition: gather_cfg.py:145
void graph_combine(const graph< N, E > &g1, const graph< N, E > &g2, const N &n1, const N &n2, const N &root, graph< N, E > &result)
Definition: graph_util.h:26
void addEdge(const N &from, const N &to, const E &edge)
Definition: adjgraph.h:266