Changeset 956:141f9c0db4a3 in lemon for lemon/static_graph.h
- Timestamp:
- 03/06/10 15:35:12 (15 years ago)
- Branch:
- default
- Children:
- 957:f802439d2b58, 959:38213abd2911, 1041:f112c18bc304
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/static_graph.h
r834 r956 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 3 * This file is a part of LEMON, a generic C++ optimization library 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-20 085 * Copyright (C) 2003-2010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 32 32 public: 33 33 34 StaticDigraphBase() 35 : built(false), node_num(0), arc_num(0), 34 StaticDigraphBase() 35 : built(false), node_num(0), arc_num(0), 36 36 node_first_out(NULL), node_first_in(NULL), 37 arc_source(NULL), arc_target(NULL), 37 arc_source(NULL), arc_target(NULL), 38 38 arc_next_in(NULL), arc_next_out(NULL) {} 39 39 40 40 ~StaticDigraphBase() { 41 41 if (built) { … … 63 63 64 64 class Arc { 65 friend class StaticDigraphBase; 65 friend class StaticDigraphBase; 66 66 protected: 67 67 int id; … … 84 84 static void next(Arc& e) { --e.id; } 85 85 86 void firstOut(Arc& e, const Node& n) const { 87 e.id = node_first_out[n.id] != node_first_out[n.id + 1] ? 86 void firstOut(Arc& e, const Node& n) const { 87 e.id = node_first_out[n.id] != node_first_out[n.id + 1] ? 88 88 node_first_out[n.id] : -1; 89 89 } … … 114 114 typedef typename Digraph::Arc Arc; 115 115 116 ArcLess(const Digraph &_graph, const NodeRefMap& _nodeRef) 116 ArcLess(const Digraph &_graph, const NodeRefMap& _nodeRef) 117 117 : digraph(_graph), nodeRef(_nodeRef) {} 118 118 119 119 bool operator()(const Arc& left, const Arc& right) const { 120 120 return nodeRef[digraph.target(left)] < nodeRef[digraph.target(right)]; 121 121 } 122 122 private: … … 124 124 const NodeRefMap& nodeRef; 125 125 }; 126 126 127 127 public: 128 128 129 129 typedef True BuildTag; 130 130 131 131 void clear() { 132 132 if (built) { … … 142 142 arc_num = 0; 143 143 } 144 144 145 145 template <typename Digraph, typename NodeRefMap, typename ArcRefMap> 146 146 void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { … … 184 184 int target = nodeRef[digraph.target(*it)].id; 185 185 arcRef[*it] = Arc(arc_index); 186 arc_source[arc_index] = source; 186 arc_source[arc_index] = source; 187 187 arc_target[arc_index] = target; 188 188 arc_next_in[arc_index] = node_first_in[target]; … … 198 198 node_first_out[node_num] = arc_num; 199 199 } 200 200 201 201 template <typename ArcListIterator> 202 202 void build(int n, ArcListIterator first, ArcListIterator last) { … … 213 213 arc_next_out = new int[arc_num]; 214 214 arc_next_in = new int[arc_num]; 215 215 216 216 for (int i = 0; i != node_num; ++i) { 217 217 node_first_in[i] = -1; 218 } 219 218 } 219 220 220 int arc_index = 0; 221 221 for (int i = 0; i != node_num; ++i) { … … 283 283 /// Since this digraph structure is completely static, its nodes and arcs 284 284 /// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt> 285 /// and <tt>[0..arcNum()-1]</tt>, respectively. 285 /// and <tt>[0..arcNum()-1]</tt>, respectively. 286 286 /// The index of an item is the same as its ID, it can be obtained 287 287 /// using the corresponding \ref index() or \ref concepts::Digraph::id() … … 300 300 301 301 typedef ExtendedStaticDigraphBase Parent; 302 302 303 303 public: 304 304 305 305 /// \brief Constructor 306 306 /// … … 350 350 /// This method also makes possible to copy a digraph to a StaticDigraph 351 351 /// structure using \ref DigraphCopy. 352 /// 352 /// 353 353 /// \param digraph An existing digraph to be copied. 354 354 /// \param nodeRef The node references will be copied into this map. … … 371 371 Parent::build(digraph, nodeRef, arcRef); 372 372 } 373 373 374 374 /// \brief Build the digraph from an arc list. 375 375 /// … … 422 422 using Parent::fastNextOut; 423 423 using Parent::fastLastOut; 424 424 425 425 public: 426 426 … … 433 433 434 434 OutArcIt(const StaticDigraph& digraph, const Node& node) { 435 436 435 digraph.fastFirstOut(*this, node); 436 digraph.fastLastOut(last, node); 437 437 if (last == *this) *this = INVALID; 438 438 } … … 444 444 } 445 445 446 OutArcIt& operator++() { 446 OutArcIt& operator++() { 447 447 StaticDigraph::fastNextOut(*this); 448 448 if (last == *this) *this = INVALID; 449 return *this; 449 return *this; 450 450 } 451 451
Note: See TracChangeset
for help on using the changeset viewer.