CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Public Attributes
GraphPath< N, E > Class Template Reference

#include <graph_path.h>

Public Types

typedef std::vector< pair< N, N > > chain_type
 
typedef set< std::vector< N > > paths_set
 
typedef std::map< segment_type, set< segment_type > > paths_type
 
typedef std::vector< std::vector< segment_type > > result_type
 
typedef pair< N, Nsegment_type
 

Public Member Functions

void calcPaths (const graph< N, E > &g, const N &root)
 
void findSegments (const N &n, set< segment_type > &result)
 
bool fromTo (const N &from, const N &to, std::vector< std::vector< N > > &result) const
 
 GraphPath (const graph< N, E > &g, const N &root)
 
bool paths2 (const segment_type &ft, result_type &result) const
 
void stream (std::ostream &)
 
void update (segment_type &s, result_type &r, int pos) const
 
 ~GraphPath ()
 

Public Attributes

paths_type paths_
 

Detailed Description

template<class N, class E>
class GraphPath< N, E >

Definition at line 13 of file graph_path.h.

Member Typedef Documentation

template<class N , class E >
typedef std::vector< pair<N,N> > GraphPath< N, E >::chain_type

Definition at line 20 of file graph_path.h.

template<class N , class E >
typedef set< std::vector<N> > GraphPath< N, E >::paths_set

Definition at line 19 of file graph_path.h.

template<class N , class E >
typedef std::map< segment_type, set< segment_type > > GraphPath< N, E >::paths_type

Definition at line 18 of file graph_path.h.

template<class N , class E >
typedef std::vector<std::vector<segment_type> > GraphPath< N, E >::result_type

Definition at line 21 of file graph_path.h.

template<class N , class E >
typedef pair<N,N> GraphPath< N, E >::segment_type

Definition at line 16 of file graph_path.h.

Constructor & Destructor Documentation

template<class N , class E >
GraphPath< N, E >::GraphPath ( const graph< N, E > &  g,
const N root 
)

Definition at line 204 of file graph_path.h.

References GraphPath< N, E >::calcPaths().

205 {
206  calcPaths(g,root);
207 }
void calcPaths(const graph< N, E > &g, const N &root)
Definition: graph_path.h:216
template<class N , class E >
GraphPath< N, E >::~GraphPath ( )
inline

Member Function Documentation

template<class N , class E >
void GraphPath< N, E >::calcPaths ( const graph< N, E > &  g,
const N n 
)

creates a lookup-table of starting-points of pathes between nodes n A and B A->B: A->X, A->Y, B->B (B->B denotes a direct connectino between A and B, A->X means that B can be reached from X directly while X can be reached from A) the lookup-table is stored in a std::map< pair<n,n>, set< pair<n,n> > (could be a multistd::map..)

Definition at line 216 of file graph_path.h.

References class-composition::children, GraphPath< N, E >::findSegments(), crabWrapper::key, GraphPath< N, E >::paths_, and groupFilesInBlocks::temp.

Referenced by GraphPath< N, E >::GraphPath(), and GraphPath< N, E >::~GraphPath().

217 {
218  // find n(ode) in g(raph) and all its children (get rid of the
219  // multiconnections ...
220  //set< pair<N,E> > nodes;
221  pair<bool,graph<N,E>::neighbour_range> childRange = g.nodes(n);
222  if (!childRange.first)
223  return;
224 
225  set<N> children;
226  typename set< pair<N,E> >::const_iterator nit = childRange.second.first;
227  for(; nit!=childRange.second.second; ++nit)
228  children.insert(nit->first);
229 
230  // iterate over children and ..
231  typename set<N>::iterator cit = children.begin();
232  for(; cit!=children.end(); ++cit) {
233  segment_type key = segment_type(n,*cit); // create new direct path-segment
234  segment_type direct = segment_type(*cit,*cit);
235  set< segment_type > temp;
236  temp.insert(direct); // add direct connection as first member of set,
237  // but not as <A,B> but as <B,B> to mark a direct connection
238  //if(n != *cit) {
239  paths_.insert(std::make_pair(key,temp));
240  findSegments(n,temp); // look for previous segments leading to n
241  typename set< segment_type >::iterator sit = temp.begin();
242  for (; sit!=temp.end(); ++sit) { // iterator over already linked segments
243  if (sit->first != key.second) // don't insert <B,B> as key!
244  paths_[segment_type(sit->first,key.second)].insert(*sit);
245  }
246  //}
247  //calcPath(g,*cit);
248  }
249  for(cit=children.begin();cit!=children.end();++cit) {
250  //if (n != * cit)
251  calcPaths(g,*cit);
252  }
253 }
void findSegments(const N &n, set< segment_type > &result)
Definition: graph_path.h:257
pair< N, N > segment_type
Definition: graph_path.h:16
void calcPaths(const graph< N, E > &g, const N &root)
Definition: graph_path.h:216
paths_type paths_
Definition: graph_path.h:38
template<class N , class E >
void GraphPath< N, E >::findSegments ( const N n,
set< segment_type > &  result 
)

Definition at line 257 of file graph_path.h.

References GraphPath< N, E >::paths_.

Referenced by GraphPath< N, E >::calcPaths(), and GraphPath< N, E >::~GraphPath().

258 {
259  typename paths_type::iterator pit = paths_.begin();
260  for (; pit!=paths_.end(); ++pit) {
261  if (pit->first.second == n)
262  result.insert(pit->first);
263  }
264 }
paths_type paths_
Definition: graph_path.h:38
template<class N , class E >
bool GraphPath< N, E >::fromTo ( const N from,
const N to,
std::vector< std::vector< N > > &  result 
) const

Definition at line 94 of file graph_path.h.

References plotBeamSpotDB::first, N, GraphPath< N, E >::paths2(), mps_fire::result, edmPickEvents::target, and findQualityFiles::v.

Referenced by GraphPath< N, E >::~GraphPath().

95 {
96  result_type tres;
97  bool rslt=false;
98  if (paths2(segment_type(from,to),tres)) {
99  typename result_type::iterator rit = tres.begin(); // iterator over std::vector< std::vector<seg_t> >
100  for (; rit!=tres.end(); ++rit) {
101  N & target = (*rit)[0].second;
102  typename std::vector<segment_type>::reverse_iterator pit = rit->rbegin();
103  typename std::vector<segment_type>::reverse_iterator pend = rit->rend();
104  --pend;
105  std::vector<N> v(1,(*rit)[0].first); // <A,X> -> <A>
106  //std::cout << pit->first << '-';
107  ++pit;
108  for(; pit!=pend; ++pit) {
109  v.push_back(pit->second);
110  //std::cout << pit->second << '-';
111  }
112  //std::cout << target << std::endl;
113  v.push_back(target);
114  result.push_back(v);
115  }
116 
117  rslt=true;
118  }
119 
120  return rslt;
121 }
pair< N, N > segment_type
Definition: graph_path.h:16
std::vector< std::vector< segment_type > > result_type
Definition: graph_path.h:21
#define N
Definition: blowfish.cc:9
bool paths2(const segment_type &ft, result_type &result) const
Definition: graph_path.h:125
template<class N , class E >
bool GraphPath< N, E >::paths2 ( const segment_type ft,
result_type result 
) const
  • false, if no (directed!) path between fromTo.first and fromTo.second, p = empty set
  • true, if (directed!) paths exist between fromTo.first an fromTo.second, p = set of pathnodes

Definition at line 125 of file graph_path.h.

References mps_fire::i, GraphPath< N, E >::paths_, GraphPath< N, E >::update(), and findQualityFiles::v.

Referenced by GraphPath< N, E >::fromTo(), and GraphPath< N, E >::~GraphPath().

126 {
127  typename paths_type::const_iterator git = paths_.find(ft);
128  if (git==paths_.end()) {
129  result.clear();
130  return false;
131  }
132 
133  std::vector<segment_type> v;
134  v.push_back(git->first);
135  result.push_back(v); // starting point; the set will be enlarged & the std::vectors inside
136  // get pushed_back as new path-segments appear ...
137 
138  // find a possible direct-connetion:
139  //set<segment_type>::iterator direct_it =
140 
141  bool goOn(true);
142 
143  while(goOn) {
144  //FIXME: use size_type whenever possible ..
145  int u = result.size();
146  int i;
147  int cntdwn=u;
148  for (i=0; i<u; ++i) {
149  segment_type & upd_seg = result[i].back();
150  if (upd_seg.first!=upd_seg.second) // only update result if not <X,X> !!
151  update(upd_seg,result,i); // adds new paths ..
152  else
153  --cntdwn;
154  }
155  goOn = bool(cntdwn);
156 
157  //std::cout << "0.--: cntdwn=" << cntdwn << std::endl;
158  /* PRINT THE RESULT
159  result_type::iterator rit = result.begin();
160  for(; rit!=result.end(); ++rit) {
161  std::vector<segment_type>::iterator pit = rit->begin();
162  for(; pit!=rit->end(); ++pit) {
163  std::cout << "[" << pit->first << "," << pit->second << "] ";
164  }
165  std::cout << std::endl;
166  }
167  std::cout << "===========" << std::endl;
168  */
169  }
170  return true;
171 }
pair< N, N > segment_type
Definition: graph_path.h:16
void update(segment_type &s, result_type &r, int pos) const
Definition: graph_path.h:175
paths_type paths_
Definition: graph_path.h:38
template<class N , class E >
void GraphPath< N, E >::stream ( std::ostream &  os)

Definition at line 267 of file graph_path.h.

References GraphPath< N, E >::paths_.

Referenced by GraphPath< N, E >::~GraphPath().

268 {
269  typename paths_type::iterator it = paths_.begin();
270  for(; it!=paths_.end(); ++it) {
271  os << "[" << it->first.first << "->" << it->first.second << "] : ";
272  typename set<segment_type>::iterator sit = it->second.begin();
273  os << "< ";
274  for(; sit!=it->second.end();++sit) {
275  os << " [" << sit->first << "->" << sit->second << "] ";
276  }
277  os << " >" << std::endl;
278 
279  }
280 }
paths_type paths_
Definition: graph_path.h:38
template<class N , class E >
void GraphPath< N, E >::update ( segment_type s,
result_type r,
int  pos 
) const

Definition at line 175 of file graph_path.h.

References MessageLogger_cfi::cerr, cmsRelvalreport::exit, GraphPath< N, E >::paths_, and findQualityFiles::v.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), dqm-mbProfile.Profile::finish(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), GraphPath< N, E >::paths2(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), Vispa.Gui.PortConnection.PointToPointConnection::updateConnection(), and GraphPath< N, E >::~GraphPath().

176 {
177  // s ... segment, which is used to find its children
178  // result ... std::vector of path-std::vectors
179  // u ... path in result which is currently under observation, s is it's 'back'
180  const set<segment_type> & segs = paths_.find(s)->second;
181  typename set<segment_type>::const_iterator segit = segs.begin();
182 
183  if (segs.size()==0) {
184  cerr << "you should never get here: GraphPath::update(...)" << std::endl;
185  exit(1);
186  }
187  /*
188  std::cout << "1. s=" << s.first << " " << s.second
189  << " aseg=" << segit->first << " " << segit->second << std::endl;
190  */
191  std::vector<segment_type> temp_pth = result[u];
192  ++segit;
193  for (; segit!=segs.end(); ++segit) { // create new pathes (whenever a the path-tree is branching)
194  std::vector<segment_type> v = temp_pth;
195  v.push_back(*segit);
196  result.push_back(v);
197  }
198  temp_pth.push_back(*segs.begin()); // just append the first new segment to the existing one (also, when no branch!)
199  result[u]=temp_pth;
200 }
paths_type paths_
Definition: graph_path.h:38

Member Data Documentation

template<class N , class E >
paths_type GraphPath< N, E >::paths_