CMS 3D CMS Logo

GraphUtil.h
Go to the documentation of this file.
1 #ifndef DATA_FORMATS_MATH_GRAPH_UTIL_H
2 #define DATA_FORMATS_MATH_GRAPH_UTIL_H
3 
6 #include <iostream>
7 #include <string>
8 
9 template<class N, class E>
10  void output(const math::Graph<N,E> & g, const N & root)
11 {
12  math::GraphWalker<N,E> w(g,root);
13  bool go=true;
14  while(go) {
15  std::cout << w.current().first << ' ';
16  go=w.next();
17  }
18  std::cout << std::endl;
19 }
20 
21 template<class N, class E>
23  const N & n1, const N & n2, const N & root,
25 {
26  result = g1;
27  result.replace(n1,n2);
28  math::GraphWalker<N,E> walker(g2,n2);
29  while (walker.next()) {
30  const N & parent = g2.nodeData((++walker.stack().rbegin())->first->first);
31  result.addEdge(parent, walker.current().first, walker.current().second);
32  }
33  result.replace(n2,root);
34 }
35 
36 template<class N, class E>
37  void graph_tree_output(const math::Graph<N,E> & g, const N & root, std::ostream & os)
38 {
39  math::GraphWalker<N,E> w(g,root);
40  bool go=true;
41  unsigned int depth=0;
42  while (go) {
43  std::string s(2*depth,' ');
44  os << ' ' << s << w.current().first << '(' << w.current().second << ')' << std::endl;
45  go = w.firstChild();
46  if( go ) {
47  ++depth;
48  }
49  else if(w.stack().size() >1 && w.nextSibling()) {
50  go=true;
51  }
52  else {
53  go=false;
54  while(w.parent()) {
55  --depth;
56  if (w.stack().size()>1 && w.nextSibling()) {
57  go=true;
58  break;
59  }
60  }
61  }
62  }
63 }
64 
65 #endif
void addEdge(const N &from, const N &to, const E &edge)
Definition: Graph.h:261
const double w
Definition: UKUtility.cc:23
void graph_tree_output(const math::Graph< N, E > &g, const N &root, std::ostream &os)
Definition: GraphUtil.h:37
void output(const math::Graph< N, E > &g, const N &root)
Definition: GraphUtil.h:10
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
bool replace(const N &oldNode, const N &newNode)
Definition: Graph.h:356
result_type parent()
Definition: GraphWalker.h:143
const N & nodeData(const edge_type &) const
Definition: Graph.h:312
result_type next()
Definition: GraphWalker.h:154
result_type firstChild()
Definition: GraphWalker.h:118
result_type nextSibling()
Definition: GraphWalker.h:131
#define N
Definition: blowfish.cc:9
const stack_type & stack() const
Definition: GraphWalker.h:55
void graph_combine(const math::Graph< N, E > &g1, const math::Graph< N, E > &g2, const N &n1, const N &n2, const N &root, math::Graph< N, E > &result)
Definition: GraphUtil.h:22
value_type current() const
Definition: GraphWalker.h:93