Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
graph_infos.hpp
Go to the documentation of this file.
1 
2 
8 #ifndef GRAPH_INFOS_HPP
9 #define GRAPH_INFOS_HPP
10 
11 #include <vector>
12 
13 #include "utils/utils.hpp"
14 #include "utils/exceptions.hpp"
15 #include "utils/graph_typedefs.hpp"
17 #include "utils/scaffolding_typedefs.hpp"
18 #include "utils/predicates.hpp"
19 #include "utils/scoring.hpp"
20 
21 namespace scaffold{ namespace graph_infos{
22  using namespace predicates;
23  using namespace scoring;
24 
26  template<class Graph, class Information>
28  {
29  protected:
30  const Graph& g;
31  Information payload;
32  bool up_to_date = false;
33  public:
35  StructuralInfo(const Graph& _g): g(_g) {}
37  StructuralInfo(const Graph& _g, const Information& _payload): g(_g), payload(_payload), up_to_date(true) {}
38 
40 
43  virtual void update(const bool force = false) = 0;
44 
46  void invalidate()
47  {
48  up_to_date = false;
49  }
50 
52  bool is_valid() const
53  {
54  return up_to_date;
55  }
56 
58  const Information& get()
59  {
60  if(!up_to_date) update();
61  return payload;
62  }
63 
65 
66  const Information& get_const() const
67  {
68  if(!up_to_date) throw except::info_not_up_to_date();
69  return payload;
70  // TODO: find a sane way to output a description of the information here,
71  // unfortunately, c++ forbids static virtual members :/
72  }
73  };
74 
75 
76  template<class Graph>
77  using ComponentsAndNum = std::pair<ComponentMap<Graph>, unsigned>;
78 
80  template<class Graph>
81  class ComponentInfo : public StructuralInfo<Graph, ComponentsAndNum<Graph> >{
82  private:
87  bool num_up_to_date = false;
88  bool consolidated = false;
89 
90 
92 
104  unsigned merge_from(const ComponentMap<Graph>& source,
105  unsigned num_comps = payload.second,
106  const Matching<Graph>* const vert_translate = NULL)
107  {
108  boost::unordered_map<unsigned, unsigned> comp_translate;
109  for(const auto& i: source){
110  // i is a pair (v,c) such that c is the component number of v in source
111  const Vertex<Graph>& v = i.first;
112  unsigned comp_of_v = i.second;
113  // step1: get the component translation of comp_of_v, creating a new translation to num_comps if necessary
114  const auto emplace_result = comp_translate.emplace(comp_of_v, num_comps);
115  // if the emplace was performed, we'll have a bigger number of components in our component map
116  if(emplace_result.second) ++num_comps;
117  // step2: update the component of v
118  comp_of_v = emplace_result.first->second;
119  // step3: translate v if requested
120  const Vertex<Graph> translated_v = vert_translate ? vert_translate->at(v) : v;
121  // step4: insert the new mapping of v to its component
122  payload.first[translated_v] = comp_of_v;
123  }// for each source vertex
124  return num_comps;
125  }
126 
128 
129  void consolidate(const unsigned offset = 0)
130  {
131  if(!consolidated || (offset != 0) || !num_up_to_date){
132  assert(up_to_date);
133  payload.second = merge_from(payload.first, offset, NULL);
134  num_up_to_date = true;
135  consolidated = true;
136  }
137  }
138 
140  void change_component(const Vertex<Graph>& v, const unsigned comp, const unsigned avoid = UINT_MAX)
141  {
142  ComponentMap<Graph>& components = payload.first;
143  VertexQueue<Graph> next;
144  next.push(v);
145  while(!next.empty()){
146  while(components.at(next.front()) == avoid) next.pop();
147  const Vertex<Graph>& w = next.front();
148  components[w] = comp;
149  for(auto range = boost::adjacent_vertices(w, g); range.first != range.second; ++range.first){
150  const Vertex<Graph>& x = *range.first;
151  const unsigned x_comp = components.at(x);
152  // don't go to vertices of "avoid" or vertices that we've seen before
153  if((x_comp != avoid) && (x_comp != comp)) next.push(x);
154  }
155  next.pop(); // pop w
156  }
157  }
158 
159  public:
160 
162  void update(const bool force = false)
163  {
164  if(force || !up_to_date){
165  if(boost::num_vertices(g) == 0){
166  payload.first.clear();
167  payload.second = 0;
168  } else payload.second = graph_parameters::num_connected_components<Graph>(g, payload.first);
169  up_to_date = true;
170  num_up_to_date = true;
171  // TODO: make sure boost outputs consolidated component maps
172  consolidated = true;
173  }
174  }
175 
177 
180  void read_from_infos(const ComponentInfo<Graph>& infos, const Matching<Graph>& translate)
181  {
182  payload.first.clear();
183 
184  // if the new info is up to date, then copy its component map, translating the vertices
185  up_to_date = infos.up_to_date;
186  if(up_to_date)
187  for(const auto& i: infos.payload.first) payload.first.emplace(translate.at(i.first), i.second);
188 
189  num_up_to_date &= infos.num_up_to_date;
190  if(num_up_to_date)
191  payload.second = infos.payload.second;
192  }
193 
195 
197  {
198  if(num_up_to_date) --payload.second;
199  consolidated = false;
200  }
201 
203  void update_disjoint_union(const ComponentInfo<Graph>& info, const Matching<Graph>& translate)
204  {
205  up_to_date &= info.up_to_date;
206  // if the component map of both infos is up to date, we can consolidate & merge
207  if(up_to_date){
208  consolidate();
209 
210  assert(num_up_to_date);
211  // merge the component maps & update the component number
212  payload.second = merge_from(info.payload.first, payload.second, &translate);
213  num_up_to_date = true;
214  consolidated = true;
215  }
216  num_up_to_date &= info.num_up_to_date;
217  if(num_up_to_date && info.num_up_to_date)
218  payload.second += info.payload.second;
219  }
220 
222  void add_vertex(const Vertex<Graph>& u)
223  {
224  if(up_to_date && num_up_to_date && consolidated){
225  payload.first[u] = payload.second;
226  } else {
227  up_to_date = false;
228  consolidated = false;
229  }
230  ++payload.second;
231  }
232 
234  void add_edge(const Vertex<Graph>& u, const Vertex<Graph>& v)
235  {
236  // if u & v are in the same component, then adding the edge uv does not disturb the component setup
237  if(up_to_date){
238  ComponentMap<Graph>& components = payload.first;
239  const unsigned u_comp = components.at(u);
240  if(u_comp != components.at(v)){
241  // update the component map from v, avoiding vertices of component u_comp
242  change_component(v, u_comp, u_comp);
243  // we'll have 1 less connected component
244  --payload.second;
245  }
246  } else num_up_to_date = false;
247  }
248 
250  void delete_edge(const VertexPair<Graph>& uv, const bool is_bridge)
251  {
252  // if e is a bridge, then its deletion increases the number of cc's
253  if(is_bridge){
254  if(consolidated)
255  change_component(uv.second, payload.second);
256  else
257  up_to_date = false;
258 
259  ++payload.second;
260  }
261  } // function
262 
264  bool num_is_valid() const
265  {
266  return num_up_to_date;
267  }
268 
270  const unsigned get_num()
271  {
272  if(!num_up_to_date) update();
273  return payload.second;
274  }
275 
277  const unsigned get_num_const() const
278  {
279  if(!num_up_to_date) throw except::info_not_up_to_date();
280  return payload.second;
281  }
282 
283  };
284 
285 
286 
287 
288 
289 
291  template<class Graph>
292  class MaxDegreeInfo: public StructuralInfo<Graph, VertexAndDegree<Graph> >{
297 
299  void update_from_vertex(const Vertex<Graph>& u){
300  const unsigned u_deg = boost::degree(u, g);
301  if(u_deg > payload.second)
302  payload = VertexAndDegree<Graph>(u, u_deg);
303  }
304  public:
306  void update(const bool force = false)
307  {
308  if(force || !up_to_date){
309  if(boost::num_edges(g) == 0){
310  payload.second = 0;
311  if(boost::num_vertices(g))
312  payload.first = *(boost::vertices(g).first);
313  } else payload = graph_parameters::get_max_degree(g);
314  up_to_date = true;
315  }
316  }
317 
319 
322  void read_from_infos(const MaxDegreeInfo<Graph>& infos, const Matching<Graph>& translate)
323  {
324  // if the new info is up to date, then copy its component map, translating the vertices
325  up_to_date = infos.up_to_date;
326  if(up_to_date){
327  payload.first = translate.at(infos.payload.first);
328  payload.second = infos.payload.second;
329  }
330  }
331 
333  void read_from_split_off_component(const MaxDegreeInfo<Graph>& info, const Matching<Graph>& translate)
334  {
335  // if the max-degree vertex is in the component that has been split off, translate it and store it
336  const typename Matching<Graph>::const_iterator i = translate.find(info.payload.first);
337  if(i != translate.cend()){
338  payload.first = i->second;
339  payload.second = info.payload.second;
340  up_to_date = true;
341  } else up_to_date = false;
342  }
343 
345  void update_disjoint_union(const MaxDegreeInfo<Graph>& info, const Matching<Graph>& translate)
346  {
347  up_to_date &= info.up_to_date;
348  if(up_to_date){
349  if(info.payload.second > payload.second)
350  payload = VertexAndDegree<Graph>(translate.at(info.payload.first), info.payload.second);
351  }
352  }
353 
355  void add_edge(const Vertex<Graph>& u, const Vertex<Graph>& v)
356  {
357  if(up_to_date){
358  update_from_vertex(u);
359  update_from_vertex(v);
360  }
361  }
362 
364  void delete_edge(const Vertex<Graph>& u, const Vertex<Graph>& v)
365  {
366  add_edge(u, v);
367  } // function
368 
369  };
370 
371 
372 
373 
374 
375 
376 
377 
379  template<class Graph>
380  class BridgeInfo: public StructuralInfo<Graph, BridgeMap<Graph> >{
382  using StructuralInfo<Graph, BridgeMap<Graph> >::up_to_date;
385  public:
387  void update(const bool force = false)
388  {
389  if(force || !up_to_date){
390  if(boost::num_edges(g)){
391  DEBUG5(std::cout << "running bridge finder"<<std::endl);
392  payload.clear();
393  mark_bridges(g, payload);
394  up_to_date = true;
395  } else {
396  payload.clear();
397  up_to_date = true;
398  }
399  }
400  }
401 
403 
406  void read_from_infos(const BridgeInfo<Graph>& infos, const Matching<Graph>& translate)
407  {
408  payload.clear();
409  // if the new info is up to date, then copy its component map, translating the vertices
410  up_to_date = infos.up_to_date;
411  update_disjoint_union(infos, translate);
412  }
413 
415  void read_from_split_off_component(const BridgeInfo<Graph>& info, const Matching<Graph>& translate)
416  {
417  up_to_date = false;
418  }
419 
421  void update_disjoint_union(const BridgeInfo<Graph>& info, const Matching<Graph>& translate)
422  {
423  up_to_date &= info.up_to_date;
424  if(up_to_date)
425  for(const auto& i: info.payload)
426  payload.emplace(std::piecewise_construct,
427  std::tuple<Vertex<Graph>, Vertex<Graph> >(translate.at(i.first.first), translate.at(i.first.second)),
428  std::tuple<unsigned>(i.second));
429  }
430 
432  void add_edge(const Vertex<Graph>& u, const Vertex<Graph>& v)
433  {
434  up_to_date = false;
435  }
436 
438  void delete_edge(const VertexPair<Graph>& uv)
439  {
440  if(up_to_date){
441  const typename BridgeMap<Graph>::iterator uv_iter = payload.find(uv);
442  // if uv is a bridge, then deleting it does not change the bridge property of anyone else
443  if(uv_iter != payload.cend())
444  payload.erase(uv_iter);
445  else // if uv is not a bridge, then anyone could become a bridge after deleting uv
446  up_to_date = false;
447  }
448  }
449 
451  bool is_bridge(const Vertex<Graph>& u, const Vertex<Graph>& v)
452  {
453  update();
454  return contains(payload, VertexPair<Graph>(u, v)) || contains(payload, VertexPair<Graph>(v, u));
455  }
457  bool is_bridge_const(const Vertex<Graph>& u, const Vertex<Graph>& v) const
458  {
459  if(!up_to_date) throw except::info_not_up_to_date();
460  return contains(payload, VertexPair<Graph>(u, v)) || contains(payload, VertexPair<Graph>(v, u));
461  }
462 
463  protected:
465 
466  template<class EdgePredicate = TruePredicate<Edge<Graph> > >
467  void _get_non_bridges(std::list<WeightedBridge<Graph>>& non_bridges, const EdgePredicate& predicate) const
468  {
469  for(EdgeIterRange<Graph> er = boost::edges(g); er.first != er.second; ++er.first){
470  const Edge<Graph>& e = *er.first;
471  if(predicate(e)){
472  const EdgeProperty<Graph>& e_info = g[e];
473  const Vertex<Graph>& u = boost::source(e, g);
474  const Vertex<Graph>& v = boost::target(e, g);
475  const VertexPair<Graph> uv(u, v);
476  if(!contains(payload, uv) && !contains(payload, VertexPair<Graph>(v, u)))
477  non_bridges.emplace_back(uv, e_info.weight);
478  }
479  }// for
480  DEBUG5(std::cout << "found "<<non_bridges.size()<<" non-bridges"<<std::endl);
481  }// function
482  public:
483 
485  template<class EdgePredicate = TruePredicate<Edge<Graph> > >
486  void get_non_bridges(std::list<WeightedBridge<Graph>>& non_bridges, const EdgePredicate& predicate = EdgePredicate())
487  {
488  if(!up_to_date) update();
489  _get_non_bridges(non_bridges, predicate);
490  }
491 
493  template<class EdgePredicate = TruePredicate<Edge<Graph> > >
494  void get_non_bridges_const(std::list<WeightedBridge<Graph>>& non_bridges, const EdgePredicate& predicate = EdgePredicate()) const
495  {
496  if(!up_to_date) throw except::info_not_up_to_date();
497  _get_non_bridges(non_bridges, predicate);
498  }
499 
500 
501  protected:
503 
504  template<class EdgePredicate = TruePredicate<Edge<Graph> > >
505  const WeightedBridge<Graph> _get_cheapest_nonbridge(const EdgePredicate& predicate) const
506  {
507  std::list<WeightedBridge<Graph>> non_bridges;
508  _get_non_bridges(non_bridges, predicate);
509 
510  assert(!non_bridges.empty());
511 
512  return *(std::min_element(non_bridges.cbegin(), non_bridges.cend()));
513  }
514  public:
515 
517 #warning TODO: explain what 'lightest bridge' means for the documentation
518  template<class EdgePredicate = TruePredicate<Edge<Graph> > >
519  const WeightedBridge<Graph> get_cheapest_nonbridge(const EdgePredicate& predicate = EdgePredicate())
520  {
521  if(!up_to_date) update();
522  return _get_cheapest_nonbridge(predicate);
523  }
524 
526  template<class EdgePredicate = TruePredicate<Edge<Graph> > >
527  const WeightedBridge<Graph> get_cheapest_nonbridge(const EdgePredicate& predicate = EdgePredicate()) const
528  {
529  if(!up_to_date) throw except::info_not_up_to_date();
530  return _get_cheapest_nonbridge(predicate);
531  }
532 
533  protected:
535  bool _has_incident_nonbridge(const Vertex<Graph>& u) const
536  {
537  for(AdjIterRange<Graph> r = boost::adjacent_vertices(u, g); r.first != r.second; ++r.first){
538  const Vertex<Graph>& v = *r.first;
539  if(!contains(payload, VertexPair<Graph>(u, v)) && !contains(payload, VertexPair<Graph>(v, u))) return true;
540  }// for
541  return false;
542  }
543  public:
544 
546  bool has_incident_nonbridge(const Vertex<Graph>& u)
547  {
548  if(!up_to_date) update();
549  return _has_incident_nonbridge(u);
550  }
551 
553  bool has_incident_nonbridge_const(const Vertex<Graph>& v) const
554  {
555  if(!up_to_date) throw except::info_not_up_to_date();
556  return _has_incident_nonbridge(v);
557  }
558 
559  protected:
561  template<class Scoring = IdentityScore<VertexPair<Graph> > >
562  const WeightedBridge<Graph>* _get_best_bridge(const Scoring& score) const
563  {
564  // get the best bridge
565  WeightedBridge<Graph>* best_b = NULL;
566  unsigned best_score = UINT_MAX;
567  for(cBridgeIter<Graph> bi = payload.cbegin(); bi != payload.cend(); ++bi){
568  const VertexPair<Graph>& b = bi->first;
569  const unsigned new_score = score(bi->second);
570  if(new_score < best_score){
571  best_score = new_score;
572  best_b = bi;
573  }// if
574  }// for
575  return best_b;
576  }
577  public:
578 
580  template<class Scoring = IdentityScore<VertexPair<Graph> > >
581  const WeightedBridge<Graph>* get_best_bridge(const Scoring& score = Scoring())
582  {
583  if(!up_to_date) update();
584  return _get_best_bridge(score);
585  }
586 
588  template<class Scoring = IdentityScore<VertexPair<Graph> > >
589  const WeightedBridge<Graph>* get_best_bridge(const Scoring& score = Scoring()) const
590  {
591  if(!up_to_date) throw except::info_not_up_to_date();
592  return _get_best_bridge(score);
593  }
594 
595  };
596 
597 
598 
599 
600 
601 
603  template<class Graph>
604  struct GraphInfos{
605  // keep a reference to the graph
606  const Graph& g;
607  ComponentInfo<Graph> comps;
608  MaxDegreeInfo<Graph> max_deg;
609  BridgeInfo<Graph> bridges;
610 
612  GraphInfos(const Graph& _g, const bool update_values = false): g(_g), comps(_g), max_deg(_g), bridges(_g)
613  {
614  if(update_values) update_all();
615  }
616 
618  GraphInfos(const Graph& _g, const GraphInfos& infos, const Matching<Graph>& translate):
619  g(_g),
620  comps(g, infos.comps, translate),
621  max_deg(g, infos.max_deg, translate),
622  bridges(g, infos.bridges, translate)
623  {
624  }
625 
626 
629  {
630  comps.invalidate();
631  max_deg.invalidate();
632  bridges.invalidate();
633  }
634 
635  // =============== update routines =====================
636 
638  void update_all(const bool force = false)
639  {
640  // TODO: all 3 can be updated at the same time with a slight modification of the bridge finder
641  comps.update(force);
642  max_deg.update(force);
643  bridges.update(force);
644  }
645 
647  void add_vertex(const Vertex<Graph>& u)
648  {
649  // adding a vertex changes only the component infos
650  comps.add_vertex(u);
651  }
652 
654  void add_edge(const Vertex<Graph>& u, const Vertex<Graph>& v)
655  {
656  comps.add_edge(u, v);
657  max_deg.add_edge(u, v);
658  bridges.add_edge(u, v);
659  }
660 
662  void delete_edge(const VertexPair<Graph>& uv)
663  {
664  max_deg.delete_edge(uv.first, uv.second);
665  bridges.delete_edge(uv);
666  // note: if the bridges are still valid, uv is a bridge; otherwise, no conclusion on the components can be made
667  comps.delete_edge(uv, bridges.is_valid());
668  } // function
669 
671 
677  void read_from_infos(const GraphInfos<Graph>& infos, const Matching<Graph>& translate)
678  {
679  max_deg.read_from_infos(infos.max_deg, translate);
680  comps.read_from_infos(infos.comps, translate);
681  bridges.read_from_infos(infos.bridges, translate);
682  }
683 
685 
688  void read_from_split_off_component(const GraphInfos<Graph>& infos, const Matching<Graph>& translate)
689  {
690  max_deg.read_from_split_off_component(infos.max_deg, translate);
691  comps.read_from_split_off_component(infos.comps);
692  bridges.read_from_split_off_component(infos.bridges, translate);
693  }
694 
696 
699  void update_disjoint_union(const GraphInfos<Graph>& infos, const Matching<Graph>& translate)
700  {
701  max_deg.update_disjoint_union(infos.max_deg, translate);
702  comps.update_disjoint_union(infos.comps, translate);
703  bridges.update_disjoint_union(infos.bridges, translate);
704  }
705 
706  // ================== get values =====================
707 
708  protected:
711  {
712  if(max_deg.get().second <= 2){
713  const unsigned V = boost::num_vertices(g);
714  const unsigned E = boost::num_edges(g);
715  const unsigned cycles = E + cc - V;
716  const unsigned paths = V - E;
717  return PathsAndCycles(paths, cycles);
718  } else throw except::invalid_assumption("graph is not degree-2");
719  }
720  public:
721 
724  {
725  return _get_paths_and_cycles(comps.get_num());
726  }// function
727 
730  {
731  return _get_paths_and_cycles(comps.get_num_const());
732  }// function
733 
735  unsigned get_FES()
736  {
737  return compute_FES(boost::num_vertices(g), boost::num_edges(g), comps.get_num());
738  }
739 
741  unsigned get_FES_const() const
742  {
743  return compute_FES(num_vertices(g), num_edges(g), comps.get_num_const());
744  }
745 
747  bool is_acyclic()
748  {
749  if(comps.num_is_valid())
750  return (get_FES_const() == 0);
751  else
752  return bridges.get().size() == boost::num_edges(*g);
753  }// function
754 
756  bool is_acyclic_const() const
757  {
758  if(comps.num_is_valid())
759  return (get_FES_const() == 0);
760  else
761  return bridges.get_const().size() == boost::num_edges(*g);
762  }
763 
764  protected:
767  {
768  const unsigned E = boost::num_edges(*g);
769  // if g has no edges, it's solved
770  if(E == 0) return true;
771  // if g contains only the matching, it's solved
772  const unsigned V = boost::num_vertices(*g);
773  if(V >= 2 * E) return true;
774  return false;
775  }
776  public:
779  {
780  if(is_max_deg_two_easy_cases()) return true;
781  return (max_deg.get().second < 3);
782  }// function
783 
785  bool is_max_deg_two_const() const
786  {
787  if(is_max_deg_two_easy_cases()) return true;
788  return (max_deg.get_const().second < 3);
789  }
790 
791 
792  }; // class
793 
794 }} // namespace
795 
796 
797 #endif
a graph property for the maximum degree in g
Definition: graph_infos.hpp:292
PathsAndCycles _get_paths_and_cycles(const unsigned cc)
get the number of paths and cycles in the graph, assuming its max degree is 2
Definition: graph_infos.hpp:710
const WeightedBridge< Graph > * get_best_bridge(const Scoring &score=Scoring()) const
get non-matching bridge that minimizes the given scoring function without updating the bridge map ...
Definition: graph_infos.hpp:589
void delete_edge(const VertexPair< Graph > &uv)
react to deletion of edge uv
Definition: graph_infos.hpp:662
a graph property for the set of bridges in g
Definition: graph_infos.hpp:380
void read_from_split_off_component(const GraphInfos< Graph > &infos, const Matching< Graph > &translate)
react to splitting off this connected component g from a graph h
Definition: graph_infos.hpp:688
StructuralInfo(const Graph &_g)
constructor
Definition: graph_infos.hpp:35
unsigned paths
maximum number of paths that a solution graph should consist of
Definition: command_line.hpp:56
void read_from_infos(const GraphInfos< Graph > &infos, const Matching< Graph > &translate)
update the infos from the graph h of which g has just been copied
Definition: graph_infos.hpp:677
bool up_to_date
indicate whether the property needs to be recomputed due to changes in the graph
Definition: graph_infos.hpp:32
void read_from_infos(const BridgeInfo< Graph > &infos, const Matching< Graph > &translate)
read from translated information
Definition: graph_infos.hpp:406
unsigned cycles
maximum number of cycles that a solution graph should consist of
Definition: command_line.hpp:58
bool is_max_deg_two_easy_cases() const
return whether g has maximum degree 2 using only queries to |V| and |E|
Definition: graph_infos.hpp:766
unsigned get_FES_const() const
return the feedback edge set number of the graph without updating its infos
Definition: graph_infos.hpp:741
void read_from_infos(const MaxDegreeInfo< Graph > &infos, const Matching< Graph > &translate)
read from translated information
Definition: graph_infos.hpp:322
const Graph & g
a reference to the graph
Definition: graph_infos.hpp:30
Definition: read_adj_list.hpp:22
bool has_incident_nonbridge_const(const Vertex< Graph > &v) const
return whether a vertex has an incident nonbridge without updating the bridge map ...
Definition: graph_infos.hpp:553
bool _has_incident_nonbridge(const Vertex< Graph > &u) const
return whether a vertex has an incident nonbridge
Definition: graph_infos.hpp:535
an exception for the case that a graph property is read that is not up to date
Definition: exceptions.hpp:17
const WeightedBridge< Graph > get_cheapest_nonbridge(const EdgePredicate &predicate=EdgePredicate())
return the lightest non-bridge, updating the bridge map if necessary
Definition: graph_infos.hpp:519
void update(const bool force=false)
update the connected components
Definition: graph_infos.hpp:162
Information payload
the actual graph property
Definition: graph_infos.hpp:31
void add_edge(const Vertex< Graph > &u, const Vertex< Graph > &v)
react to addition of edge uv
Definition: graph_infos.hpp:654
StructuralInfo(const Graph &_g, const Information &_payload)
constructor
Definition: graph_infos.hpp:37
PathsAndCycles get_paths_and_cycles()
get the number of paths and cycles in the graph, assuming its max degree is 2, updating infos if nece...
Definition: graph_infos.hpp:723
const unsigned get_num_const() const
return the number of connected components without updating
Definition: graph_infos.hpp:277
a graph property for the number of connected components and a map of vertices to components (represen...
Definition: graph_infos.hpp:81
bool is_valid() const
return whether the property is up-to-date
Definition: graph_infos.hpp:52
const WeightedBridge< Graph > get_cheapest_nonbridge(const EdgePredicate &predicate=EdgePredicate()) const
return the lightest non-bridge without updating the bridge map
Definition: graph_infos.hpp:527
void read_from_split_off_component(const ComponentInfo< Graph > &info)
react to splitting off a connected component of the graph g
Definition: graph_infos.hpp:196
void delete_edge(const Vertex< Graph > &u, const Vertex< Graph > &v)
react to the deletion of the edge uv
Definition: graph_infos.hpp:364
void read_from_split_off_component(const BridgeInfo< Graph > &info, const Matching< Graph > &translate)
read from given infos, assuming that g is a single connected component that has been split off ...
Definition: graph_infos.hpp:415
void delete_edge(const VertexPair< Graph > &uv, const bool is_bridge)
react to the deletion of the edge uv, depending on whether it was a bridge or not ...
Definition: graph_infos.hpp:250
const WeightedBridge< Graph > * get_best_bridge(const Scoring &score=Scoring())
get non-matching bridge that minimizes the given scoring function, updating the bridge map if necessa...
Definition: graph_infos.hpp:581
an exception for the case that some assumption that is made is not true
Definition: exceptions.hpp:30
const WeightedBridge< Graph > _get_cheapest_nonbridge(const EdgePredicate &predicate) const
return the non-bridge of least weight
Definition: graph_infos.hpp:505
bool is_max_deg_two()
return whether the graph has max degree 2, updating its max-degree info if necessary ...
Definition: graph_infos.hpp:778
void update(const bool force=false)
update bridges
Definition: graph_infos.hpp:387
const WeightedBridge< Graph > * _get_best_bridge(const Scoring &score) const
get non-matching bridge that minimizes the given scoring function
Definition: graph_infos.hpp:562
bool is_acyclic_const() const
return whether the graph is acyclic without updating its infos
Definition: graph_infos.hpp:756
prototype class for structural graph properties
Definition: graph_infos.hpp:27
void read_from_split_off_component(const MaxDegreeInfo< Graph > &info, const Matching< Graph > &translate)
read from given infos, assuming that g is a single connected component that has been split off ...
Definition: graph_infos.hpp:333
bool is_bridge_const(const Vertex< Graph > &u, const Vertex< Graph > &v) const
return whether the edge uv is a bridge, avoiding updating the bridge map
Definition: graph_infos.hpp:457
void update_disjoint_union(const MaxDegreeInfo< Graph > &info, const Matching< Graph > &translate)
update infos, assuming that g is the disjoint union of a graph with our infos and a graph with the gi...
Definition: graph_infos.hpp:345
unsigned get_FES()
return the feedback edge set number of the graph, updating its infos if necessary ...
Definition: graph_infos.hpp:735
void add_edge(const Vertex< Graph > &u, const Vertex< Graph > &v)
react to addition of the edge uv
Definition: graph_infos.hpp:355
void update(const bool force=false)
update the max degree
Definition: graph_infos.hpp:306
void read_from_infos(const ComponentInfo< Graph > &infos, const Matching< Graph > &translate)
read from translated information
Definition: graph_infos.hpp:180
void delete_edge(const VertexPair< Graph > &uv)
react to the deletion of the edge uv
Definition: graph_infos.hpp:438
bool num_is_valid() const
return whether the number of connected components is up to date
Definition: graph_infos.hpp:264
GraphInfos(const Graph &_g, const bool update_values=false)
constructor: needs a graph to initalize the EdgeHasher of the bridgs; updates all values on construct...
Definition: graph_infos.hpp:612
bool is_acyclic()
return whether the graph is acyclic, updating its infos if necessary
Definition: graph_infos.hpp:747
void add_vertex(const Vertex< Graph > &u)
react to the addition of a single vertex u to g
Definition: graph_infos.hpp:222
void update_disjoint_union(const ComponentInfo< Graph > &info, const Matching< Graph > &translate)
react to forming the disjoint union of g with a graph h, given the corresponding property of h ...
Definition: graph_infos.hpp:203
const VertexAndDegree< Graph > & get()
get the current value of the property, updating if necessary
Definition: graph_infos.hpp:58
bool is_max_deg_two_const() const
return whether the graph has max degree 2 without updating infos
Definition: graph_infos.hpp:785
void update_disjoint_union(const BridgeInfo< Graph > &info, const Matching< Graph > &translate)
update infos, assuming that g is the disjoint union of a graph with our infos and a graph with the gi...
Definition: graph_infos.hpp:421
void invalidate_all()
invalidate all infos
Definition: graph_infos.hpp:628
PathsAndCycles get_paths_and_cycles_const() const
get the number of paths and cycles in the graph, assuming its max degree is 2, without updating the i...
Definition: graph_infos.hpp:729
bool is_bridge(const Vertex< Graph > &u, const Vertex< Graph > &v)
return whether the edge uv is a bridge, updating the infos if necessary
Definition: graph_infos.hpp:451
bool has_incident_nonbridge(const Vertex< Graph > &u)
return whether a vertex has an incident nonbridge, updating the bridge map if necessary ...
Definition: graph_infos.hpp:546
void add_edge(const Vertex< Graph > &u, const Vertex< Graph > &v)
react to the addition of the edge uv to g
Definition: graph_infos.hpp:234
void invalidate()
set the property to "not up-to-date"
Definition: graph_infos.hpp:46
void add_vertex(const Vertex< Graph > &u)
react to addition of vertex u
Definition: graph_infos.hpp:647
void get_non_bridges_const(std::list< WeightedBridge< Graph >> &non_bridges, const EdgePredicate &predicate=EdgePredicate()) const
return the set of non-bridges without updating the bridge map
Definition: graph_infos.hpp:494
const unsigned get_num()
return the number of connected components, updating if necessary
Definition: graph_infos.hpp:270
bool contains(const Set &s, const Element &el)
a more readable containment check
Definition: utils.hpp:171
void update_disjoint_union(const GraphInfos< Graph > &infos, const Matching< Graph > &translate)
react to forming a disjoint union with g with another graph h, given the infos of h and a translate m...
Definition: graph_infos.hpp:699
GraphInfos(const Graph &_g, const GraphInfos &infos, const Matching< Graph > &translate)
constructor
Definition: graph_infos.hpp:618
void _get_non_bridges(std::list< WeightedBridge< Graph >> &non_bridges, const EdgePredicate &predicate) const
store all non-bridges with their weights in the parameter
Definition: graph_infos.hpp:467
void update_all(const bool force=false)
update all values
Definition: graph_infos.hpp:638
void get_non_bridges(std::list< WeightedBridge< Graph >> &non_bridges, const EdgePredicate &predicate=EdgePredicate())
return the set of non-bridges in g, updating the bridge map if necessary
Definition: graph_infos.hpp:486
const Information & get_const() const
get the current value of the property without updating
Definition: graph_infos.hpp:66
an accumulator class for different graph properties
Definition: graph_infos.hpp:604
void add_edge(const Vertex< Graph > &u, const Vertex< Graph > &v)
react to the addition of the edge uv to g
Definition: graph_infos.hpp:432
Definition: graph_typedefs.hpp:26