CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  math::GraphWalker<N, E> w(g, root);
12  bool go = true;
13  while (go) {
14  std::cout << w.current().first << ' ';
15  go = w.next();
16  }
17  std::cout << std::endl;
18 }
19 
20 template <class N, class E>
22  const math::Graph<N, E>& g2,
23  const N& n1,
24  const N& n2,
25  const N& root,
27  result = g1;
28  result.replace(n1, n2);
29  math::GraphWalker<N, E> walker(g2, n2);
30  while (walker.next()) {
31  const N& parent = g2.nodeData((++walker.stack().rbegin())->first->first);
32  result.addEdge(parent, walker.current().first, walker.current().second);
33  }
34  result.replace(n2, root);
35 }
36 
37 template <class N, class E>
38 void graph_tree_output(const math::Graph<N, E>& g, const N& root, std::ostream& os) {
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  } else if (w.stack().size() > 1 && w.nextSibling()) {
49  go = true;
50  } else {
51  go = false;
52  while (w.parent()) {
53  --depth;
54  if (w.stack().size() > 1 && w.nextSibling()) {
55  go = true;
56  break;
57  }
58  }
59  }
60  }
61 }
62 
63 #endif
void addEdge(const N &from, const N &to, const E &edge)
Definition: Graph.h:231
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:38
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
tuple result
Definition: mps_fire.py:311
bool replace(const N &oldNode, const N &newNode)
Definition: Graph.h:310
result_type parent()
Definition: GraphWalker.h:130
const N & nodeData(const edge_type &) const
Definition: Graph.h:272
result_type next()
Definition: GraphWalker.h:140
result_type firstChild()
Definition: GraphWalker.h:108
result_type nextSibling()
Definition: GraphWalker.h:119
#define N
Definition: blowfish.cc:9
const stack_type & stack() const
Definition: GraphWalker.h:55
tuple cout
Definition: gather_cfg.py:144
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:21
value_type current() const
Definition: GraphWalker.h:86