Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
embedding.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file embedding.cpp
1 /* This software is distributed under the GNU Lesser General Public License */
2 //==========================================================================
3 //
4 // embedding.cpp
5 //
6 //==========================================================================
7 // $Id: embedding.cpp,v 1.18 2002/10/04 08:07:36 chris Exp $
8 
9 #include <GTL/embedding.h>
10 
11 #ifdef __GTL_MSVCC
12 # ifdef _DEBUG
13 # ifndef SEARCH_MEMORY_LEAKS_ENABLED
14 # error SEARCH NOT ENABLED
15 # endif
16 # define new DEBUG_NEW
17 # undef THIS_FILE
18  static char THIS_FILE[] = __FILE__;
19 # endif // _DEBUG
20 #endif // __GTL_MSVCC
21 
23 
25 {
26  init (*(em.G));
27 
28  node n;
29  forall_nodes (n, *G) {
30  adj_list::const_iterator it = em.adj[n].begin();
31  adj_list::const_iterator end = em.adj[n].end();
32 
33  for (; it != end; ++it) {
34  pos (n, *it) = push_back (n, *it);
35  }
36  }
37 
38  self.insert (self.begin(), em.self.begin(), em.self.end());
39  multi.insert (multi.begin(), em.multi.begin(), em.multi.begin());
40 }
41 
42 
45 {
46  node n;
47  if (G != 0) {
48  forall_nodes (n, *G) {
49  adj[n].erase (adj[n].begin(), adj[n].end());
50  }
51  }
52 
53  self.erase (self.begin(), self.end());
54  multi.erase (multi.begin(), multi.end());
55 
56  init (*(em.G));
57 
58  forall_nodes (n, *G) {
61 
62  for (; it != end; ++it) {
63  pos (n, *it) = push_back (n, *it);
64  }
65  }
66 
67  self.insert (self.begin(), em.self.begin(), em.self.end());
68  multi.insert (multi.begin(), em.multi.begin(), em.multi.begin());
69 
70  return *this;
71 }
72 
73 
74 void
76 {
77  adj.init (my_G);
78 
79  //
80  // There is a problem with node/edge maps of iterators with Visual C++
81  // which I donīt fully understand at the moment. Anyway the init for the
82  // maps below is only needed to allocate memory, which is done anyway, when
83  // values are assigned to it.
84  //
85 
86 #ifndef __GTL_MSVCC
87  s_pos.init (my_G);
88  t_pos.init (my_G);
89 #endif
90  G = &my_G;
91 }
92 
93 
96 {
97  return adj[n].insert (adj[n].end(), e);
98 }
99 
100 
103 {
104  return adj[n].insert (adj[n].begin(), e);
105 }
106 
107 
110 {
111  if (e.source() == n) {
112  return s_pos[e];
113  } else if (e.target() == n) {
114  return t_pos[e];
115  } else {
116  assert (false);
117  // this should not happen.
118  return s_pos[e];
119  }
120 }
121 
122 
123 void
125 {
126  node n = e.source();
127  s_pos[e] = t_pos[e] = adj[n].insert (adj[n].begin(), e);
128 }
129 
130 
131 void
133 {
134  adj[n].reverse();
135 }
136 
137 
138 edge
140 {
141  iterator it = pos (n, e);
142  ++it;
143 
144  if (it == adj[n].end()) {
145  ++it;
146  }
147 
148  return *it;
149 }
150 
151 
152 edge
154 {
155  iterator it = pos (n, e);
156  --it;
157 
158  if (it == adj[n].end()) {
159  --it;
160  }
161 
162  return *it;
163 }
164 
165 bool
167 {
168  node n;
169  forall_nodes (n ,*G) {
170  iterator it, end;
171 
172  for (it = adj[n].begin(), end = adj[n].end(); it != end; ++it) {
173  edge curr = *it;
174  node other = n.opposite (curr);
175 
176  edge prev = cyclic_prev (n, curr);
177  edge next = cyclic_next (n, prev);
178  assert (next == curr);
179 
180  while (other != n) {
181  curr = cyclic_next (other, curr);
182  other = other.opposite (curr);
183  }
184  if (curr != prev) {
185  return false;
186  }
187 
188  }
189  }
190 
191  return true;
192 }
193 
194 
195 void
197 {
198  st_number::iterator n_it = st.begin();
199  st_number::iterator n_end = st.end();
200  iterator it, end;
201 
202  for (; n_it != n_end; ++n_it) {
203  node n = *n_it;
204  os << "[" << st[n] << "]::";
205 
206  it = adj[n].begin();
207  end = adj[n].end();
208 
209  for (; it != end; ++it) {
210  os << "[" << st[n.opposite (*it)] << "]";
211  }
212 
213  os << endl;
214  }
215 
216  os << "SELFLOOPS:" << endl;
217  list<edge>::iterator e_it, e_end;
218  for (e_it = self.begin(), e_end = self.end(); e_it != e_end; ++e_it) {
219  os << st[(*e_it).source()] << "---" << st[(*e_it).target()] << endl;
220  }
221 
222  os << "MULTIPLE EDGES:" << endl;
223  for (e_it = multi.begin(), e_end = multi.end(); e_it != e_end; ++e_it) {
224  os << st[(*e_it).source()] << "---" << st[(*e_it).target()] << endl;
225  }
226 }
227 
228 GTL_EXTERN ostream& operator<< (ostream& os, planar_embedding& em)
229 {
230  graph::node_iterator n_it = em.G->nodes_begin();
231  graph::node_iterator n_end = em.G->nodes_end();
233 
234  for (; n_it != n_end; ++n_it) {
235  node n = *n_it;
236  os << n << ":: ";
237 
238  it = em.adj[n].begin();
239  end = em.adj[n].end();
240 
241  for (; it != end; ++it) {
242  os << n.opposite (*it) << "*";
243  }
244 
245  os << endl;
246  }
247 
248  os << "SELFLOOPS:" << endl;
249  list<edge>::iterator e_it, e_end;
250  for (e_it = em.self.begin(), e_end = em.self.end(); e_it != e_end; ++e_it) {
251  os << *e_it << endl;
252  }
253 
254  os << "MULTIPLE EDGES:" << endl;
255  for (e_it = em.multi.begin(), e_end = em.multi.end(); e_it != e_end; ++e_it) {
256  os << *e_it << endl;
257  }
258 
259  return os;
260 }
261 
263 
264 //--------------------------------------------------------------------------
265 // end of file
266 //--------------------------------------------------------------------------