Changeset 209:765619b7cbb2 in lemon for lemon/bits
- Timestamp:
- 07/13/08 20:51:02 (17 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- lemon/bits
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/alteration_notifier.h
r157 r209 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 5 * Copyright (C) 2003-2008 … … 33 33 /// \ingroup graphbits 34 34 /// 35 /// \brief Notifier class to notify observes about alterations in 35 /// \brief Notifier class to notify observes about alterations in 36 36 /// a container. 37 37 /// … … 50 50 /// alteration of the graph. 51 51 /// 52 /// This class provides an interface to the container. The \e first() and \e 52 /// This class provides an interface to the container. The \e first() and \e 53 53 /// next() member functions make possible to iterate on the keys of the 54 54 /// container. The \e id() function returns an integer id for each key. … … 61 61 /// from the graph. If all items are erased from the graph or from an empty 62 62 /// graph a new graph is builded then it can be signaled with the 63 /// clear() and build() members. Important rule that if we erase items 63 /// clear() and build() members. Important rule that if we erase items 64 64 /// from graph we should first signal the alteration and after that erase 65 65 /// them from the container, on the other way on item addition we should … … 69 69 /// \e ObserverBase nested class. The signals can be handled with 70 70 /// overriding the virtual functions defined in the base class. The 71 /// observer base can be attached to the notifier with the 71 /// observer base can be attached to the notifier with the 72 72 /// \e attach() member and can be detached with detach() function. The 73 73 /// alteration handlers should not call any function which signals … … 80 80 /// be rolled back by calling the \e erase() or \e clear() 81 81 /// functions. Thence the \e erase() and \e clear() should not throw 82 /// exception. Actullay, it can be throw only 82 /// exception. Actullay, it can be throw only 83 83 /// \ref AlterationObserver::ImmediateDetach ImmediateDetach 84 84 /// exception which detach the observer from the notifier. … … 86 86 /// There are some place when the alteration observing is not completly 87 87 /// reliable. If we want to carry out the node degree in the graph 88 /// as in the \ref InDegMap and we use the reverseEdge that cause 88 /// as in the \ref InDegMap and we use the reverseEdge that cause 89 89 /// unreliable functionality. Because the alteration observing signals 90 90 /// only erasing and adding but not the reversing it will stores bad … … 105 105 typedef _Item Item; 106 106 107 /// \brief Exception which can be called from \e clear() and 107 /// \brief Exception which can be called from \e clear() and 108 108 /// \e erase(). 109 109 /// … … 128 128 /// The build() and clear() members are to notify the observer 129 129 /// about the container is built from an empty container or 130 /// is cleared to an empty container. 130 /// is cleared to an empty container. 131 131 132 132 class ObserverBase { … … 139 139 /// 140 140 /// Default constructor for ObserverBase. 141 /// 141 /// 142 142 ObserverBase() : _notifier(0) {} 143 143 … … 152 152 /// 153 153 /// Constructor which attach the obserever to the same notifier as 154 /// the other observer is attached to. 154 /// the other observer is attached to. 155 155 ObserverBase(const ObserverBase& copy) { 156 156 if (copy.attached()) { 157 157 attach(*copy.notifier()); 158 159 } 160 158 } 159 } 160 161 161 /// \brief Destructor 162 162 virtual ~ObserverBase() { … … 171 171 /// 172 172 void attach(AlterationNotifier& nf) { 173 174 } 175 173 nf.attach(*this); 174 } 175 176 176 /// \brief Detaches the observer into an AlterationNotifier. 177 177 /// … … 181 181 _notifier->detach(*this); 182 182 } 183 184 /// \brief Gives back a pointer to the notifier which the map 183 184 /// \brief Gives back a pointer to the notifier which the map 185 185 /// attached into. 186 186 /// … … 189 189 /// 190 190 Notifier* notifier() const { return const_cast<Notifier*>(_notifier); } 191 191 192 192 /// Gives back true when the observer is attached into a notifier. 193 193 bool attached() const { return _notifier != 0; } … … 198 198 199 199 protected: 200 200 201 201 Notifier* _notifier; 202 202 typename std::list<ObserverBase*>::iterator _index; … … 210 210 virtual void add(const Item&) = 0; 211 211 212 /// \brief The member function to notificate the observer about 212 /// \brief The member function to notificate the observer about 213 213 /// more item is added to the container. 214 214 /// … … 223 223 /// The erase() member function notificates the observer about an 224 224 /// item is erased from the container. It have to be overrided in 225 /// the subclasses. 225 /// the subclasses. 226 226 virtual void erase(const Item&) = 0; 227 227 228 /// \brief The member function to notificate the observer about 228 /// \brief The member function to notificate the observer about 229 229 /// more item is erased from the container. 230 230 /// … … 248 248 /// The clear() member function notificates the observer about all 249 249 /// items are erased from the container. It have to be overrided in 250 /// the subclasses. 250 /// the subclasses. 251 251 virtual void clear() = 0; 252 252 253 253 }; 254 254 255 255 protected: 256 256 257 257 const Container* container; 258 258 259 typedef std::list<ObserverBase*> Observers; 259 typedef std::list<ObserverBase*> Observers; 260 260 Observers _observers; 261 261 262 262 263 263 public: 264 264 265 265 /// \brief Default constructor. 266 266 /// 267 /// The default constructor of the AlterationNotifier. 267 /// The default constructor of the AlterationNotifier. 268 268 /// It creates an empty notifier. 269 AlterationNotifier() 269 AlterationNotifier() 270 270 : container(0) {} 271 271 … … 273 273 /// 274 274 /// Constructor with the observed container parameter. 275 AlterationNotifier(const Container& _container) 275 AlterationNotifier(const Container& _container) 276 276 : container(&_container) {} 277 277 278 /// \brief Copy Constructor of the AlterationNotifier. 279 /// 280 /// Copy constructor of the AlterationNotifier. 278 /// \brief Copy Constructor of the AlterationNotifier. 279 /// 280 /// Copy constructor of the AlterationNotifier. 281 281 /// It creates only an empty notifier because the copiable 282 282 /// notifier's observers have to be registered still into that notifier. 283 AlterationNotifier(const AlterationNotifier& _notifier) 283 AlterationNotifier(const AlterationNotifier& _notifier) 284 284 : container(_notifier.container) {} 285 285 286 286 /// \brief Destructor. 287 /// 287 /// 288 288 /// Destructor of the AlterationNotifier. 289 289 /// … … 291 291 typename Observers::iterator it; 292 292 for (it = _observers.begin(); it != _observers.end(); ++it) { 293 293 (*it)->_notifier = 0; 294 294 } 295 295 } … … 339 339 return container->maxId(Item()); 340 340 } 341 341 342 342 protected: 343 343 … … 345 345 observer._index = _observers.insert(_observers.begin(), &observer); 346 346 observer._notifier = this; 347 } 347 } 348 348 349 349 void detach(ObserverBase& observer) { … … 354 354 355 355 public: 356 357 /// \brief Notifies all the registed observers about an item added to 358 /// the container. 359 /// 360 /// It notifies all the registed observers about an item added to 361 /// the container. 362 /// 356 357 /// \brief Notifies all the registed observers about an item added to 358 /// the container. 359 /// 360 /// It notifies all the registed observers about an item added to 361 /// the container. 362 /// 363 363 void add(const Item& item) { 364 364 typename Observers::reverse_iterator it; … … 374 374 throw; 375 375 } 376 } 377 378 /// \brief Notifies all the registed observers about more item added to 379 /// the container. 380 /// 381 /// It notifies all the registed observers about more item added to 382 /// the container. 383 /// 376 } 377 378 /// \brief Notifies all the registed observers about more item added to 379 /// the container. 380 /// 381 /// It notifies all the registed observers about more item added to 382 /// the container. 383 /// 384 384 void add(const std::vector<Item>& items) { 385 385 typename Observers::reverse_iterator it; … … 395 395 throw; 396 396 } 397 } 398 399 /// \brief Notifies all the registed observers about an item erased from 400 /// the container. 401 /// 402 /// It notifies all the registed observers about an item erased from 403 /// the container. 404 /// 397 } 398 399 /// \brief Notifies all the registed observers about an item erased from 400 /// the container. 401 /// 402 /// It notifies all the registed observers about an item erased from 403 /// the container. 404 /// 405 405 void erase(const Item& item) throw() { 406 406 typename Observers::iterator it = _observers.begin(); … … 417 417 } 418 418 419 /// \brief Notifies all the registed observers about more item erased 419 /// \brief Notifies all the registed observers about more item erased 420 420 /// from the container. 421 /// 422 /// It notifies all the registed observers about more item erased from 423 /// the container. 424 /// 421 /// 422 /// It notifies all the registed observers about more item erased from 423 /// the container. 424 /// 425 425 void erase(const std::vector<Item>& items) { 426 426 typename Observers::iterator it = _observers.begin(); … … 437 437 } 438 438 439 /// \brief Notifies all the registed observers about the container is 439 /// \brief Notifies all the registed observers about the container is 440 440 /// built. 441 /// 441 /// 442 442 /// Notifies all the registed observers about the container is built 443 443 /// from an empty container. … … 457 457 } 458 458 459 /// \brief Notifies all the registed observers about all items are 459 /// \brief Notifies all the registed observers about all items are 460 460 /// erased. 461 461 /// -
lemon/bits/array_map.h
r107 r209 1 /* -*- C++-*-2 * 3 * This file is a part of LEMON, a generic C++ optimization library 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 39 39 /// The ArrayMap template class is graph map structure what 40 40 /// automatically updates the map when a key is added to or erased from 41 /// the map. This map uses the allocators to implement 41 /// the map. This map uses the allocators to implement 42 42 /// the container functionality. 43 43 /// … … 45 45 /// the Value type of the map. 46 46 template <typename _Graph, typename _Item, typename _Value> 47 class ArrayMap 47 class ArrayMap 48 48 : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { 49 49 public: 50 /// The graph type of the maps. 50 /// The graph type of the maps. 51 51 typedef _Graph Graph; 52 52 /// The item type of the map. … … 70 70 /// The MapBase of the Map which imlements the core regisitry function. 71 71 typedef typename Notifier::ObserverBase Parent; 72 72 73 73 private: 74 74 typedef std::allocator<Value> Allocator; … … 85 85 Item it; 86 86 for (nf->first(it); it != INVALID; nf->next(it)) { 87 88 89 } 90 } 91 92 /// \brief Constructor to use default value to initialize the map. 93 /// 94 /// It constructs a map and initialize all of the the map. 87 int id = nf->id(it);; 88 allocator.construct(&(values[id]), Value()); 89 } 90 } 91 92 /// \brief Constructor to use default value to initialize the map. 93 /// 94 /// It constructs a map and initialize all of the the map. 95 95 ArrayMap(const Graph& graph, const Value& value) { 96 96 Parent::attach(graph.notifier(Item())); … … 99 99 Item it; 100 100 for (nf->first(it); it != INVALID; nf->next(it)) { 101 102 103 } 101 int id = nf->id(it);; 102 allocator.construct(&(values[id]), value); 103 } 104 104 } 105 105 106 106 /// \brief Constructor to copy a map of the same map type. 107 107 /// 108 /// Constructor to copy a map of the same map type. 108 /// Constructor to copy a map of the same map type. 109 109 ArrayMap(const ArrayMap& copy) : Parent() { 110 110 if (copy.attached()) { 111 111 attach(*copy.notifier()); 112 112 } 113 113 capacity = copy.capacity; … … 117 117 Item it; 118 118 for (nf->first(it); it != INVALID; nf->next(it)) { 119 120 119 int id = nf->id(it);; 120 allocator.construct(&(values[id]), copy.values[id]); 121 121 } 122 122 } … … 125 125 /// 126 126 /// This operator assigns for each item in the map the 127 /// value mapped to the same item in the copied map. 127 /// value mapped to the same item in the copied map. 128 128 /// The parameter map should be indiced with the same 129 129 /// itemset because this assign operator does not change 130 /// the container of the map. 130 /// the container of the map. 131 131 ArrayMap& operator=(const ArrayMap& cmap) { 132 132 return operator=<ArrayMap>(cmap); … … 139 139 /// concecpt and could be indiced by the current item set of 140 140 /// the NodeMap. In this case the value for each item 141 /// is assigned by the value of the given ReadMap. 141 /// is assigned by the value of the given ReadMap. 142 142 template <typename CMap> 143 143 ArrayMap& operator=(const CMap& cmap) { … … 152 152 153 153 /// \brief The destructor of the map. 154 /// 154 /// 155 155 /// The destructor of the map. 156 virtual ~ArrayMap() { 156 virtual ~ArrayMap() { 157 157 if (attached()) { 158 159 160 } 161 } 162 158 clear(); 159 detach(); 160 } 161 } 162 163 163 protected: 164 164 … … 169 169 public: 170 170 171 /// \brief The subscript operator. 171 /// \brief The subscript operator. 172 172 /// 173 173 /// The subscript operator. The map can be subscripted by the 174 /// actual keys of the graph. 174 /// actual keys of the graph. 175 175 Value& operator[](const Key& key) { 176 176 int id = Parent::notifier()->id(key); 177 177 return values[id]; 178 } 179 178 } 179 180 180 /// \brief The const subscript operator. 181 181 /// 182 182 /// The const subscript operator. The map can be subscripted by the 183 /// actual keys of the graph. 183 /// actual keys of the graph. 184 184 const Value& operator[](const Key& key) const { 185 185 int id = Parent::notifier()->id(key); … … 188 188 189 189 /// \brief Setter function of the map. 190 /// 190 /// 191 191 /// Setter function of the map. Equivalent with map[key] = val. 192 192 /// This is a compatibility feature with the not dereferable maps. … … 198 198 199 199 /// \brief Adds a new key to the map. 200 /// 200 /// 201 201 /// It adds a new key to the map. It called by the observer notifier 202 /// and it overrides the add() member function of the observer base. 202 /// and it overrides the add() member function of the observer base. 203 203 virtual void add(const Key& key) { 204 204 Notifier* nf = Parent::notifier(); 205 205 int id = nf->id(key); 206 206 if (id >= capacity) { 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 207 int new_capacity = (capacity == 0 ? 1 : capacity); 208 while (new_capacity <= id) { 209 new_capacity <<= 1; 210 } 211 Value* new_values = allocator.allocate(new_capacity); 212 Item it; 213 for (nf->first(it); it != INVALID; nf->next(it)) { 214 int jd = nf->id(it);; 215 if (id != jd) { 216 allocator.construct(&(new_values[jd]), values[jd]); 217 allocator.destroy(&(values[jd])); 218 } 219 } 220 if (capacity != 0) allocator.deallocate(values, capacity); 221 values = new_values; 222 capacity = new_capacity; 223 223 } 224 224 allocator.construct(&(values[id]), Value()); … … 226 226 227 227 /// \brief Adds more new keys to the map. 228 /// 228 /// 229 229 /// It adds more new keys to the map. It called by the observer notifier 230 /// and it overrides the add() member function of the observer base. 230 /// and it overrides the add() member function of the observer base. 231 231 virtual void add(const std::vector<Key>& keys) { 232 232 Notifier* nf = Parent::notifier(); 233 233 int max_id = -1; 234 234 for (int i = 0; i < int(keys.size()); ++i) { 235 236 237 238 235 int id = nf->id(keys[i]); 236 if (id > max_id) { 237 max_id = id; 238 } 239 239 } 240 240 if (max_id >= capacity) { 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 241 int new_capacity = (capacity == 0 ? 1 : capacity); 242 while (new_capacity <= max_id) { 243 new_capacity <<= 1; 244 } 245 Value* new_values = allocator.allocate(new_capacity); 246 Item it; 247 for (nf->first(it); it != INVALID; nf->next(it)) { 248 int id = nf->id(it); 249 bool found = false; 250 for (int i = 0; i < int(keys.size()); ++i) { 251 int jd = nf->id(keys[i]); 252 if (id == jd) { 253 found = true; 254 break; 255 } 256 } 257 if (found) continue; 258 allocator.construct(&(new_values[id]), values[id]); 259 allocator.destroy(&(values[id])); 260 } 261 if (capacity != 0) allocator.deallocate(values, capacity); 262 values = new_values; 263 capacity = new_capacity; 264 264 } 265 265 for (int i = 0; i < int(keys.size()); ++i) { 266 267 268 } 269 } 270 266 int id = nf->id(keys[i]); 267 allocator.construct(&(values[id]), Value()); 268 } 269 } 270 271 271 /// \brief Erase a key from the map. 272 272 /// 273 273 /// Erase a key from the map. It called by the observer notifier 274 /// and it overrides the erase() member function of the observer base. 274 /// and it overrides the erase() member function of the observer base. 275 275 virtual void erase(const Key& key) { 276 276 int id = Parent::notifier()->id(key); … … 281 281 /// 282 282 /// Erase more keys from the map. It called by the observer notifier 283 /// and it overrides the erase() member function of the observer base. 283 /// and it overrides the erase() member function of the observer base. 284 284 virtual void erase(const std::vector<Key>& keys) { 285 285 for (int i = 0; i < int(keys.size()); ++i) { 286 287 286 int id = Parent::notifier()->id(keys[i]); 287 allocator.destroy(&(values[id])); 288 288 } 289 289 } 290 290 291 291 /// \brief Buildes the map. 292 /// 292 /// 293 293 /// It buildes the map. It called by the observer notifier 294 /// and it overrides the build() member function of the observer base. 294 /// and it overrides the build() member function of the observer base. 295 295 virtual void build() { 296 296 Notifier* nf = Parent::notifier(); … … 298 298 Item it; 299 299 for (nf->first(it); it != INVALID; nf->next(it)) { 300 301 302 } 300 int id = nf->id(it);; 301 allocator.construct(&(values[id]), Value()); 302 } 303 303 } 304 304 … … 306 306 /// 307 307 /// It erase all items from the map. It called by the observer notifier 308 /// and it overrides the clear() member function of the observer base. 309 virtual void clear() { 308 /// and it overrides the clear() member function of the observer base. 309 virtual void clear() { 310 310 Notifier* nf = Parent::notifier(); 311 311 if (capacity != 0) { 312 313 314 315 316 } 317 318 312 Item it; 313 for (nf->first(it); it != INVALID; nf->next(it)) { 314 int id = nf->id(it); 315 allocator.destroy(&(values[id])); 316 } 317 allocator.deallocate(values, capacity); 318 capacity = 0; 319 319 } 320 320 } 321 321 322 322 private: 323 323 324 324 void allocate_memory() { 325 325 int max_id = Parent::notifier()->maxId(); 326 326 if (max_id == -1) { 327 328 329 327 capacity = 0; 328 values = 0; 329 return; 330 330 } 331 331 capacity = 1; 332 332 while (capacity <= max_id) { 333 334 } 335 values = allocator.allocate(capacity); 336 } 333 capacity <<= 1; 334 } 335 values = allocator.allocate(capacity); 336 } 337 337 338 338 int capacity; … … 340 340 Allocator allocator; 341 341 342 }; 342 }; 343 343 344 344 } 345 345 346 #endif 346 #endif -
lemon/bits/base_extender.h
r107 r209 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 5 * Copyright (C) 2003-2008 … … 64 64 65 65 bool operator==(const Arc &that) const { 66 66 return forward==that.forward && Edge(*this)==Edge(that); 67 67 } 68 68 bool operator!=(const Arc &that) const { 69 69 return forward!=that.forward || Edge(*this)!=Edge(that); 70 70 } 71 71 bool operator<(const Arc &that) const { 72 73 72 return forward<that.forward || 73 (!(that.forward<forward) && Edge(*this)<Edge(that)); 74 74 } 75 75 }; … … 118 118 void next(Arc &e) const { 119 119 if( e.forward ) { 120 120 e.forward = false; 121 121 } 122 122 else { 123 124 123 Parent::next(e); 124 e.forward = true; 125 125 } 126 126 } … … 129 129 Parent::firstIn(e,n); 130 130 if( Edge(e) != INVALID ) { 131 131 e.forward = false; 132 132 } 133 133 else { 134 135 134 Parent::firstOut(e,n); 135 e.forward = true; 136 136 } 137 137 } 138 138 void nextOut(Arc &e) const { 139 139 if( ! e.forward ) { 140 141 142 143 144 145 140 Node n = Parent::target(e); 141 Parent::nextIn(e); 142 if( Edge(e) == INVALID ) { 143 Parent::firstOut(e, n); 144 e.forward = true; 145 } 146 146 } 147 147 else { 148 148 Parent::nextOut(e); 149 149 } 150 150 } … … 153 153 Parent::firstOut(e,n); 154 154 if( Edge(e) != INVALID ) { 155 155 e.forward = false; 156 156 } 157 157 else { 158 159 158 Parent::firstIn(e,n); 159 e.forward = true; 160 160 } 161 161 } 162 162 void nextIn(Arc &e) const { 163 163 if( ! e.forward ) { 164 165 166 167 168 169 164 Node n = Parent::source(e); 165 Parent::nextOut(e); 166 if( Edge(e) == INVALID ) { 167 Parent::firstIn(e, n); 168 e.forward = true; 169 } 170 170 } 171 171 else { 172 172 Parent::nextIn(e); 173 173 } 174 174 } … … 184 184 void nextInc(Edge &e, bool &d) const { 185 185 if (d) { 186 187 188 189 190 191 } else { 192 186 Node s = Parent::source(e); 187 Parent::nextOut(e); 188 if (e != INVALID) return; 189 d = false; 190 Parent::firstIn(e, s); 191 } else { 192 Parent::nextIn(e); 193 193 } 194 194 } … … 241 241 Arc findArc(Node s, Node t, Arc p = INVALID) const { 242 242 if (p == INVALID) { 243 244 245 246 243 Edge arc = Parent::findArc(s, t); 244 if (arc != INVALID) return direct(arc, true); 245 arc = Parent::findArc(t, s); 246 if (arc != INVALID) return direct(arc, false); 247 247 } else if (direction(p)) { 248 249 250 251 if (arc != INVALID) return direct(arc, false); 252 } else { 253 254 if (arc != INVALID) return direct(arc, false); 248 Edge arc = Parent::findArc(s, t, p); 249 if (arc != INVALID) return direct(arc, true); 250 arc = Parent::findArc(t, s); 251 if (arc != INVALID) return direct(arc, false); 252 } else { 253 Edge arc = Parent::findArc(t, s, p); 254 if (arc != INVALID) return direct(arc, false); 255 255 } 256 256 return INVALID; … … 268 268 if (arc != INVALID) return arc; 269 269 arc = Parent::findArc(t, s); 270 if (arc != INVALID) return arc; 270 if (arc != INVALID) return arc; 271 271 } else { 272 272 Edge arc = Parent::findArc(t, s, p); 273 if (arc != INVALID) return arc; 273 if (arc != INVALID) return arc; 274 274 } 275 275 } else { … … 300 300 Red() {} 301 301 Red(const Node& node) : Node(node) { 302 LEMON_ASSERT(Parent::red(node) || node == INVALID, 303 302 LEMON_ASSERT(Parent::red(node) || node == INVALID, 303 typename Parent::NodeSetError()); 304 304 } 305 305 Red& operator=(const Node& node) { 306 LEMON_ASSERT(Parent::red(node) || node == INVALID, 307 306 LEMON_ASSERT(Parent::red(node) || node == INVALID, 307 typename Parent::NodeSetError()); 308 308 Node::operator=(node); 309 309 return *this; … … 332 332 Blue() {} 333 333 Blue(const Node& node) : Node(node) { 334 335 334 LEMON_ASSERT(Parent::blue(node) || node == INVALID, 335 typename Parent::NodeSetError()); 336 336 } 337 337 Blue& operator=(const Node& node) { 338 LEMON_ASSERT(Parent::blue(node) || node == INVALID, 339 338 LEMON_ASSERT(Parent::blue(node) || node == INVALID, 339 typename Parent::NodeSetError()); 340 340 Node::operator=(node); 341 341 return *this; … … 354 354 Parent::nextBlue(static_cast<Node&>(node)); 355 355 } 356 356 357 357 int id(const Blue& node) const { 358 358 return Parent::redId(node); … … 368 368 void firstInc(Edge& arc, bool& dir, const Node& node) const { 369 369 if (Parent::red(node)) { 370 371 372 } else { 373 374 370 Parent::firstFromRed(arc, node); 371 dir = true; 372 } else { 373 Parent::firstFromBlue(arc, node); 374 dir = static_cast<Edge&>(arc) == INVALID; 375 375 } 376 376 } 377 377 void nextInc(Edge& arc, bool& dir) const { 378 378 if (dir) { 379 380 } else { 381 382 379 Parent::nextFromRed(arc); 380 } else { 381 Parent::nextFromBlue(arc); 382 if (arc == INVALID) dir = true; 383 383 } 384 384 } … … 390 390 391 391 Arc(const Edge& arc, bool _forward) 392 392 : Edge(arc), forward(_forward) {} 393 393 394 394 public: … … 396 396 Arc (Invalid) : Edge(INVALID), forward(true) {} 397 397 bool operator==(const Arc& i) const { 398 398 return Edge::operator==(i) && forward == i.forward; 399 399 } 400 400 bool operator!=(const Arc& i) const { 401 401 return Edge::operator!=(i) || forward != i.forward; 402 402 } 403 403 bool operator<(const Arc& i) const { 404 return Edge::operator<(i) || 405 404 return Edge::operator<(i) || 405 (!(i.forward<forward) && Edge(*this)<Edge(i)); 406 406 } 407 407 }; … … 414 414 void next(Arc& arc) const { 415 415 if (!arc.forward) { 416 416 Parent::next(static_cast<Edge&>(arc)); 417 417 } 418 418 arc.forward = !arc.forward; … … 421 421 void firstOut(Arc& arc, const Node& node) const { 422 422 if (Parent::red(node)) { 423 424 425 } else { 426 427 423 Parent::firstFromRed(arc, node); 424 arc.forward = true; 425 } else { 426 Parent::firstFromBlue(arc, node); 427 arc.forward = static_cast<Edge&>(arc) == INVALID; 428 428 } 429 429 } 430 430 void nextOut(Arc& arc) const { 431 431 if (arc.forward) { 432 433 } else { 434 432 Parent::nextFromRed(arc); 433 } else { 434 Parent::nextFromBlue(arc); 435 435 arc.forward = static_cast<Edge&>(arc) == INVALID; 436 436 } … … 439 439 void firstIn(Arc& arc, const Node& node) const { 440 440 if (Parent::blue(node)) { 441 442 arc.forward = true; 443 } else { 444 445 441 Parent::firstFromBlue(arc, node); 442 arc.forward = true; 443 } else { 444 Parent::firstFromRed(arc, node); 445 arc.forward = static_cast<Edge&>(arc) == INVALID; 446 446 } 447 447 } 448 448 void nextIn(Arc& arc) const { 449 449 if (arc.forward) { 450 451 } else { 452 453 450 Parent::nextFromBlue(arc); 451 } else { 452 Parent::nextFromRed(arc); 453 arc.forward = static_cast<Edge&>(arc) == INVALID; 454 454 } 455 455 } … … 463 463 464 464 int id(const Arc& arc) const { 465 return (Parent::id(static_cast<const Edge&>(arc)) << 1) + 465 return (Parent::id(static_cast<const Edge&>(arc)) << 1) + 466 466 (arc.forward ? 0 : 1); 467 467 } -
lemon/bits/bezier.h
r184 r209 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 5 * Copyright (C) 2003-2008 … … 45 45 Bezier1() {} 46 46 Bezier1(Point _p1, Point _p2) :p1(_p1), p2(_p2) {} 47 47 48 48 Point operator()(double t) const 49 49 { … … 55 55 return Bezier1(p1,conv(p1,p2,t)); 56 56 } 57 57 58 58 Bezier1 after(double t) const 59 59 { … … 88 88 return Bezier2(p1,q,conv(q,r,t)); 89 89 } 90 90 91 91 Bezier2 after(double t) const 92 92 { … … 111 111 Bezier3(Point _p1, Point _p2, Point _p3, Point _p4) 112 112 : p1(_p1), p2(_p2), p3(_p3), p4(_p4) {} 113 Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)), 114 113 Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)), 114 p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {} 115 115 Bezier3(const Bezier2 &b) : p1(b.p1), p2(conv(b.p1,b.p2,2.0/3.0)), 116 117 118 Point operator()(double t) const 116 p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {} 117 118 Point operator()(double t) const 119 119 { 120 120 // return Bezier2(conv(p1,p2,t),conv(p2,p3,t),conv(p3,p4,t))(t); 121 121 return ((1-t)*(1-t)*(1-t))*p1+(3*t*(1-t)*(1-t))*p2+ 122 122 (3*t*t*(1-t))*p3+(t*t*t)*p4; 123 123 } 124 124 Bezier3 before(double t) const … … 132 132 return Bezier3(p1,p,a,c); 133 133 } 134 134 135 135 Bezier3 after(double t) const 136 136 { … … 147 147 Bezier2 grad() const { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); } 148 148 Bezier2 norm() const { return Bezier2(3.0*rot90(p2-p1), 149 150 149 3.0*rot90(p3-p2), 150 3.0*rot90(p4-p3)); } 151 151 Point grad(double t) const { return grad()(t); } 152 152 Point norm(double t) const { return rot90(grad(t)); } 153 153 154 154 template<class R,class F,class S,class D> 155 R recSplit(F &_f,const S &_s,D _d) const 155 R recSplit(F &_f,const S &_s,D _d) const 156 156 { 157 157 const Point a=(p1+p2)/2; … … 165 165 return _s(f1,f2); 166 166 } 167 167 168 168 }; 169 169 -
lemon/bits/default_map.h
r107 r209 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 5 * Copyright (C) 2003-2008 … … 30 30 31 31 namespace lemon { 32 33 32 33 34 34 //#ifndef LEMON_USE_DEBUG_MAP 35 35 … … 141 141 }; 142 142 143 // #else 143 // #else 144 144 145 145 // template <typename _Graph, typename _Item, typename _Value> … … 148 148 // }; 149 149 150 // #endif 150 // #endif 151 151 152 152 /// \e 153 153 template <typename _Graph, typename _Item, typename _Value> 154 class DefaultMap 154 class DefaultMap 155 155 : public DefaultMapSelector<_Graph, _Item, _Value>::Map { 156 156 public: 157 157 typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent; 158 158 typedef DefaultMap<_Graph, _Item, _Value> Map; 159 159 160 160 typedef typename Parent::Graph Graph; 161 161 typedef typename Parent::Value Value; 162 162 163 163 explicit DefaultMap(const Graph& graph) : Parent(graph) {} 164 DefaultMap(const Graph& graph, const Value& value) 164 DefaultMap(const Graph& graph, const Value& value) 165 165 : Parent(graph, value) {} 166 166 -
lemon/bits/graph_extender.h
r125 r209 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 5 * Copyright (C) 2003-2008 … … 67 67 Node oppositeNode(const Node &node, const Arc &arc) const { 68 68 if (node == Parent::source(arc)) 69 69 return Parent::target(arc); 70 70 else if(node == Parent::target(arc)) 71 71 return Parent::source(arc); 72 72 else 73 73 return INVALID; 74 74 } 75 75 … … 90 90 return node_notifier; 91 91 } 92 92 93 93 ArcNotifier& notifier(Arc) const { 94 94 return arc_notifier; 95 95 } 96 96 97 class NodeIt : public Node { 97 class NodeIt : public Node { 98 98 const Digraph* _digraph; 99 99 public: … … 104 104 105 105 explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) { 106 107 } 108 109 NodeIt(const Digraph& digraph, const Node& node) 110 111 112 NodeIt& operator++() { 113 114 return *this; 115 } 116 117 }; 118 119 120 class ArcIt : public Arc { 106 _digraph->first(static_cast<Node&>(*this)); 107 } 108 109 NodeIt(const Digraph& digraph, const Node& node) 110 : Node(node), _digraph(&digraph) {} 111 112 NodeIt& operator++() { 113 _digraph->next(*this); 114 return *this; 115 } 116 117 }; 118 119 120 class ArcIt : public Arc { 121 121 const Digraph* _digraph; 122 122 public: … … 127 127 128 128 explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) { 129 130 } 131 132 ArcIt(const Digraph& digraph, const Arc& arc) : 133 134 135 ArcIt& operator++() { 136 137 return *this; 138 } 139 140 }; 141 142 143 class OutArcIt : public Arc { 129 _digraph->first(static_cast<Arc&>(*this)); 130 } 131 132 ArcIt(const Digraph& digraph, const Arc& arc) : 133 Arc(arc), _digraph(&digraph) { } 134 135 ArcIt& operator++() { 136 _digraph->next(*this); 137 return *this; 138 } 139 140 }; 141 142 143 class OutArcIt : public Arc { 144 144 const Digraph* _digraph; 145 145 public: … … 149 149 OutArcIt(Invalid i) : Arc(i) { } 150 150 151 OutArcIt(const Digraph& digraph, const Node& node) 152 153 154 } 155 156 OutArcIt(const Digraph& digraph, const Arc& arc) 157 158 159 OutArcIt& operator++() { 160 161 return *this; 162 } 163 164 }; 165 166 167 class InArcIt : public Arc { 151 OutArcIt(const Digraph& digraph, const Node& node) 152 : _digraph(&digraph) { 153 _digraph->firstOut(*this, node); 154 } 155 156 OutArcIt(const Digraph& digraph, const Arc& arc) 157 : Arc(arc), _digraph(&digraph) {} 158 159 OutArcIt& operator++() { 160 _digraph->nextOut(*this); 161 return *this; 162 } 163 164 }; 165 166 167 class InArcIt : public Arc { 168 168 const Digraph* _digraph; 169 169 public: … … 173 173 InArcIt(Invalid i) : Arc(i) { } 174 174 175 InArcIt(const Digraph& digraph, const Node& node) 176 177 178 } 179 180 InArcIt(const Digraph& digraph, const Arc& arc) : 181 182 183 InArcIt& operator++() { 184 185 return *this; 175 InArcIt(const Digraph& digraph, const Node& node) 176 : _digraph(&digraph) { 177 _digraph->firstIn(*this, node); 178 } 179 180 InArcIt(const Digraph& digraph, const Arc& arc) : 181 Arc(arc), _digraph(&digraph) {} 182 183 InArcIt& operator++() { 184 _digraph->nextIn(*this); 185 return *this; 186 186 } 187 187 … … 216 216 } 217 217 218 218 219 219 template <typename _Value> 220 class NodeMap 220 class NodeMap 221 221 : public MapExtender<DefaultMap<Digraph, Node, _Value> > { 222 222 public: … … 224 224 typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent; 225 225 226 explicit NodeMap(const Digraph& digraph) 227 228 NodeMap(const Digraph& digraph, const _Value& value) 229 226 explicit NodeMap(const Digraph& digraph) 227 : Parent(digraph) {} 228 NodeMap(const Digraph& digraph, const _Value& value) 229 : Parent(digraph, value) {} 230 230 231 231 NodeMap& operator=(const NodeMap& cmap) { 232 232 return operator=<NodeMap>(cmap); 233 233 } 234 234 … … 236 236 NodeMap& operator=(const CMap& cmap) { 237 237 Parent::operator=(cmap); 238 238 return *this; 239 239 } 240 240 … … 242 242 243 243 template <typename _Value> 244 class ArcMap 244 class ArcMap 245 245 : public MapExtender<DefaultMap<Digraph, Arc, _Value> > { 246 246 public: … … 248 248 typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; 249 249 250 explicit ArcMap(const Digraph& digraph) 251 252 ArcMap(const Digraph& digraph, const _Value& value) 253 250 explicit ArcMap(const Digraph& digraph) 251 : Parent(digraph) {} 252 ArcMap(const Digraph& digraph, const _Value& value) 253 : Parent(digraph, value) {} 254 254 255 255 ArcMap& operator=(const ArcMap& cmap) { 256 256 return operator=<ArcMap>(cmap); 257 257 } 258 258 … … 260 260 ArcMap& operator=(const CMap& cmap) { 261 261 Parent::operator=(cmap); 262 262 return *this; 263 263 } 264 264 }; … … 270 270 return node; 271 271 } 272 272 273 273 Arc addArc(const Node& from, const Node& to) { 274 274 Arc arc = Parent::addArc(from, to); … … 294 294 Parent::firstOut(arc, node); 295 295 while (arc != INVALID ) { 296 297 298 } 296 erase(arc); 297 Parent::firstOut(arc, node); 298 } 299 299 300 300 Parent::firstIn(arc, node); 301 301 while (arc != INVALID ) { 302 303 302 erase(arc); 303 Parent::firstIn(arc, node); 304 304 } 305 305 … … 307 307 Parent::erase(node); 308 308 } 309 309 310 310 void erase(const Arc& arc) { 311 311 notifier(Arc()).erase(arc); … … 316 316 node_notifier.setContainer(*this); 317 317 arc_notifier.setContainer(*this); 318 } 319 318 } 319 320 320 321 321 ~DigraphExtender() { … … 328 328 /// 329 329 /// \brief Extender for the Graphs 330 template <typename Base> 330 template <typename Base> 331 331 class GraphExtender : public Base { 332 332 public: 333 333 334 334 typedef Base Parent; 335 335 typedef GraphExtender Graph; … … 341 341 typedef typename Parent::Edge Edge; 342 342 343 // Graph extension 343 // Graph extension 344 344 345 345 int maxId(Node) const { … … 369 369 Node oppositeNode(const Node &n, const Edge &e) const { 370 370 if( n == Parent::u(e)) 371 371 return Parent::v(e); 372 372 else if( n == Parent::v(e)) 373 373 return Parent::u(e); 374 374 else 375 375 return INVALID; 376 376 } 377 377 … … 403 403 return node_notifier; 404 404 } 405 405 406 406 ArcNotifier& notifier(Arc) const { 407 407 return arc_notifier; … … 414 414 415 415 416 class NodeIt : public Node { 416 class NodeIt : public Node { 417 417 const Graph* _graph; 418 418 public: … … 423 423 424 424 explicit NodeIt(const Graph& graph) : _graph(&graph) { 425 426 } 427 428 NodeIt(const Graph& graph, const Node& node) 429 430 431 NodeIt& operator++() { 432 433 return *this; 434 } 435 436 }; 437 438 439 class ArcIt : public Arc { 425 _graph->first(static_cast<Node&>(*this)); 426 } 427 428 NodeIt(const Graph& graph, const Node& node) 429 : Node(node), _graph(&graph) {} 430 431 NodeIt& operator++() { 432 _graph->next(*this); 433 return *this; 434 } 435 436 }; 437 438 439 class ArcIt : public Arc { 440 440 const Graph* _graph; 441 441 public: … … 446 446 447 447 explicit ArcIt(const Graph& graph) : _graph(&graph) { 448 449 } 450 451 ArcIt(const Graph& graph, const Arc& arc) : 452 453 454 ArcIt& operator++() { 455 456 return *this; 457 } 458 459 }; 460 461 462 class OutArcIt : public Arc { 448 _graph->first(static_cast<Arc&>(*this)); 449 } 450 451 ArcIt(const Graph& graph, const Arc& arc) : 452 Arc(arc), _graph(&graph) { } 453 454 ArcIt& operator++() { 455 _graph->next(*this); 456 return *this; 457 } 458 459 }; 460 461 462 class OutArcIt : public Arc { 463 463 const Graph* _graph; 464 464 public: … … 468 468 OutArcIt(Invalid i) : Arc(i) { } 469 469 470 OutArcIt(const Graph& graph, const Node& node) 471 472 473 } 474 475 OutArcIt(const Graph& graph, const Arc& arc) 476 477 478 OutArcIt& operator++() { 479 480 return *this; 481 } 482 483 }; 484 485 486 class InArcIt : public Arc { 470 OutArcIt(const Graph& graph, const Node& node) 471 : _graph(&graph) { 472 _graph->firstOut(*this, node); 473 } 474 475 OutArcIt(const Graph& graph, const Arc& arc) 476 : Arc(arc), _graph(&graph) {} 477 478 OutArcIt& operator++() { 479 _graph->nextOut(*this); 480 return *this; 481 } 482 483 }; 484 485 486 class InArcIt : public Arc { 487 487 const Graph* _graph; 488 488 public: … … 492 492 InArcIt(Invalid i) : Arc(i) { } 493 493 494 InArcIt(const Graph& graph, const Node& node) 495 496 497 } 498 499 InArcIt(const Graph& graph, const Arc& arc) : 500 501 502 InArcIt& operator++() { 503 504 return *this; 505 } 506 507 }; 508 509 510 class EdgeIt : public Parent::Edge { 494 InArcIt(const Graph& graph, const Node& node) 495 : _graph(&graph) { 496 _graph->firstIn(*this, node); 497 } 498 499 InArcIt(const Graph& graph, const Arc& arc) : 500 Arc(arc), _graph(&graph) {} 501 502 InArcIt& operator++() { 503 _graph->nextIn(*this); 504 return *this; 505 } 506 507 }; 508 509 510 class EdgeIt : public Parent::Edge { 511 511 const Graph* _graph; 512 512 public: … … 517 517 518 518 explicit EdgeIt(const Graph& graph) : _graph(&graph) { 519 520 } 521 522 EdgeIt(const Graph& graph, const Edge& edge) : 523 524 525 EdgeIt& operator++() { 526 527 return *this; 519 _graph->first(static_cast<Edge&>(*this)); 520 } 521 522 EdgeIt(const Graph& graph, const Edge& edge) : 523 Edge(edge), _graph(&graph) { } 524 525 EdgeIt& operator++() { 526 _graph->next(*this); 527 return *this; 528 528 } 529 529 … … 541 541 542 542 IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) { 543 543 _graph->firstInc(*this, _direction, node); 544 544 } 545 545 546 546 IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node) 547 548 547 : _graph(&graph), Edge(edge) { 548 _direction = (_graph->source(edge) == node); 549 549 } 550 550 551 551 IncEdgeIt& operator++() { 552 553 return *this; 552 _graph->nextInc(*this, _direction); 553 return *this; 554 554 } 555 555 }; … … 599 599 600 600 template <typename _Value> 601 class NodeMap 601 class NodeMap 602 602 : public MapExtender<DefaultMap<Graph, Node, _Value> > { 603 603 public: … … 605 605 typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent; 606 606 607 NodeMap(const Graph& graph) 608 609 NodeMap(const Graph& graph, const _Value& value) 610 607 NodeMap(const Graph& graph) 608 : Parent(graph) {} 609 NodeMap(const Graph& graph, const _Value& value) 610 : Parent(graph, value) {} 611 611 612 612 NodeMap& operator=(const NodeMap& cmap) { 613 613 return operator=<NodeMap>(cmap); 614 614 } 615 615 … … 617 617 NodeMap& operator=(const CMap& cmap) { 618 618 Parent::operator=(cmap); 619 619 return *this; 620 620 } 621 621 … … 623 623 624 624 template <typename _Value> 625 class ArcMap 625 class ArcMap 626 626 : public MapExtender<DefaultMap<Graph, Arc, _Value> > { 627 627 public: … … 629 629 typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; 630 630 631 ArcMap(const Graph& graph) 632 633 ArcMap(const Graph& graph, const _Value& value) 634 631 ArcMap(const Graph& graph) 632 : Parent(graph) {} 633 ArcMap(const Graph& graph, const _Value& value) 634 : Parent(graph, value) {} 635 635 636 636 ArcMap& operator=(const ArcMap& cmap) { 637 637 return operator=<ArcMap>(cmap); 638 638 } 639 639 … … 641 641 ArcMap& operator=(const CMap& cmap) { 642 642 Parent::operator=(cmap); 643 643 return *this; 644 644 } 645 645 }; … … 647 647 648 648 template <typename _Value> 649 class EdgeMap 649 class EdgeMap 650 650 : public MapExtender<DefaultMap<Graph, Edge, _Value> > { 651 651 public: … … 653 653 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; 654 654 655 EdgeMap(const Graph& graph) 656 657 658 EdgeMap(const Graph& graph, const _Value& value) 659 655 EdgeMap(const Graph& graph) 656 : Parent(graph) {} 657 658 EdgeMap(const Graph& graph, const _Value& value) 659 : Parent(graph, value) {} 660 660 661 661 EdgeMap& operator=(const EdgeMap& cmap) { 662 662 return operator=<EdgeMap>(cmap); 663 663 } 664 664 … … 666 666 EdgeMap& operator=(const CMap& cmap) { 667 667 Parent::operator=(cmap); 668 668 return *this; 669 669 } 670 670 … … 684 684 std::vector<Arc> ev; 685 685 ev.push_back(Parent::direct(edge, true)); 686 ev.push_back(Parent::direct(edge, false)); 686 ev.push_back(Parent::direct(edge, false)); 687 687 notifier(Arc()).add(ev); 688 688 return edge; 689 689 } 690 690 691 691 void clear() { 692 692 notifier(Arc()).clear(); … … 697 697 698 698 template <typename Graph, typename NodeRefMap, typename EdgeRefMap> 699 void build(const Graph& graph, NodeRefMap& nodeRef, 699 void build(const Graph& graph, NodeRefMap& nodeRef, 700 700 EdgeRefMap& edgeRef) { 701 701 Parent::build(graph, nodeRef, edgeRef); … … 709 709 Parent::firstOut(arc, node); 710 710 while (arc != INVALID ) { 711 712 713 } 711 erase(arc); 712 Parent::firstOut(arc, node); 713 } 714 714 715 715 Parent::firstIn(arc, node); 716 716 while (arc != INVALID ) { 717 718 717 erase(arc); 718 Parent::firstIn(arc, node); 719 719 } 720 720 … … 726 726 std::vector<Arc> av; 727 727 av.push_back(Parent::direct(edge, true)); 728 av.push_back(Parent::direct(edge, false)); 728 av.push_back(Parent::direct(edge, false)); 729 729 notifier(Arc()).erase(av); 730 730 notifier(Edge()).erase(edge); … … 733 733 734 734 GraphExtender() { 735 node_notifier.setContainer(*this); 735 node_notifier.setContainer(*this); 736 736 arc_notifier.setContainer(*this); 737 737 edge_notifier.setContainer(*this); 738 } 738 } 739 739 740 740 ~GraphExtender() { 741 741 edge_notifier.clear(); 742 742 arc_notifier.clear(); 743 node_notifier.clear(); 744 } 743 node_notifier.clear(); 744 } 745 745 746 746 }; -
lemon/bits/invalid.h
r49 r209 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 5 * Copyright (C) 2003-2008 … … 35 35 bool operator< (Invalid) { return false; } 36 36 }; 37 37 38 38 /// \brief Invalid iterators. 39 39 /// … … 53 53 54 54 #endif 55 55 -
lemon/bits/map_extender.h
r107 r209 1 /* -*- C++-*-2 * 3 * This file is a part of LEMON, a generic C++ optimization library 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 33 33 34 34 /// \ingroup graphbits 35 /// 35 /// 36 36 /// \brief Extender for maps 37 37 template <typename _Map> … … 57 57 public: 58 58 59 MapExtender(const Graph& graph) 59 MapExtender(const Graph& graph) 60 60 : Parent(graph) {} 61 61 62 MapExtender(const Graph& graph, const Value& value) 62 MapExtender(const Graph& graph, const Value& value) 63 63 : Parent(graph, value) {} 64 64 … … 71 71 Parent::operator=(cmap); 72 72 return *this; 73 } 73 } 74 74 75 75 class MapIt : public Item { 76 76 public: 77 77 78 78 typedef Item Parent; 79 79 typedef typename Map::Value Value; 80 80 81 81 MapIt() {} 82 82 … … 87 87 } 88 88 89 MapIt(const Map& _map, const Item& item) 90 91 92 MapIt& operator++() { 93 94 return *this; 95 } 96 89 MapIt(const Map& _map, const Item& item) 90 : Parent(item), map(_map) {} 91 92 MapIt& operator++() { 93 map.notifier()->next(*this); 94 return *this; 95 } 96 97 97 typename MapTraits<Map>::ConstReturnValue operator*() const { 98 98 return map[*this]; 99 99 } 100 100 101 101 typename MapTraits<Map>::ReturnValue operator*() { 102 103 } 104 102 return map[*this]; 103 } 104 105 105 void set(const Value& value) { 106 107 } 108 106 map.set(*this, value); 107 } 108 109 109 protected: 110 110 Map& map; 111 111 112 112 }; 113 113 … … 118 118 119 119 typedef typename Map::Value Value; 120 120 121 121 ConstMapIt() {} 122 122 … … 127 127 } 128 128 129 ConstMapIt(const Map& _map, const Item& item) 130 131 132 ConstMapIt& operator++() { 133 134 return *this; 129 ConstMapIt(const Map& _map, const Item& item) 130 : Parent(item), map(_map) {} 131 132 ConstMapIt& operator++() { 133 map.notifier()->next(*this); 134 return *this; 135 135 } 136 136 137 137 typename MapTraits<Map>::ConstReturnValue operator*() const { 138 138 return map[*this]; 139 139 } 140 140 … … 145 145 class ItemIt : public Item { 146 146 public: 147 148 typedef Item Parent; 149 147 148 typedef Item Parent; 149 150 150 ItemIt() {} 151 151 … … 156 156 } 157 157 158 ItemIt(const Map& _map, const Item& item) 159 160 161 ItemIt& operator++() { 162 163 return *this; 158 ItemIt(const Map& _map, const Item& item) 159 : Parent(item), map(_map) {} 160 161 ItemIt& operator++() { 162 map.notifier()->next(*this); 163 return *this; 164 164 } 165 165 166 166 protected: 167 167 const Map& map; 168 168 169 169 }; 170 170 }; 171 171 172 172 /// \ingroup graphbits 173 /// 173 /// 174 174 /// \brief Extender for maps which use a subset of the items. 175 175 template <typename _Graph, typename _Map> … … 195 195 public: 196 196 197 SubMapExtender(const Graph& _graph) 197 SubMapExtender(const Graph& _graph) 198 198 : Parent(_graph), graph(_graph) {} 199 199 200 SubMapExtender(const Graph& _graph, const Value& _value) 200 SubMapExtender(const Graph& _graph, const Value& _value) 201 201 : Parent(_graph, _value), graph(_graph) {} 202 202 … … 213 213 } 214 214 return *this; 215 } 215 } 216 216 217 217 class MapIt : public Item { 218 218 public: 219 219 220 220 typedef Item Parent; 221 221 typedef typename Map::Value Value; 222 222 223 223 MapIt() {} 224 224 … … 229 229 } 230 230 231 MapIt(const Map& _map, const Item& item) 232 233 234 MapIt& operator++() { 235 236 return *this; 237 } 238 231 MapIt(const Map& _map, const Item& item) 232 : Parent(item), map(_map) {} 233 234 MapIt& operator++() { 235 map.graph.next(*this); 236 return *this; 237 } 238 239 239 typename MapTraits<Map>::ConstReturnValue operator*() const { 240 240 return map[*this]; 241 241 } 242 242 243 243 typename MapTraits<Map>::ReturnValue operator*() { 244 245 } 246 244 return map[*this]; 245 } 246 247 247 void set(const Value& value) { 248 249 } 250 248 map.set(*this, value); 249 } 250 251 251 protected: 252 252 Map& map; 253 253 254 254 }; 255 255 … … 260 260 261 261 typedef typename Map::Value Value; 262 262 263 263 ConstMapIt() {} 264 264 … … 269 269 } 270 270 271 ConstMapIt(const Map& _map, const Item& item) 272 273 274 ConstMapIt& operator++() { 275 276 return *this; 271 ConstMapIt(const Map& _map, const Item& item) 272 : Parent(item), map(_map) {} 273 274 ConstMapIt& operator++() { 275 map.graph.next(*this); 276 return *this; 277 277 } 278 278 279 279 typename MapTraits<Map>::ConstReturnValue operator*() const { 280 280 return map[*this]; 281 281 } 282 282 … … 287 287 class ItemIt : public Item { 288 288 public: 289 290 typedef Item Parent; 291 289 290 typedef Item Parent; 291 292 292 ItemIt() {} 293 293 … … 298 298 } 299 299 300 ItemIt(const Map& _map, const Item& item) 301 302 303 ItemIt& operator++() { 304 305 return *this; 300 ItemIt(const Map& _map, const Item& item) 301 : Parent(item), map(_map) {} 302 303 ItemIt& operator++() { 304 map.graph.next(*this); 305 return *this; 306 306 } 307 307 308 308 protected: 309 309 const Map& map; 310 311 }; 312 310 311 }; 312 313 313 private: 314 314 315 315 const Graph& graph; 316 316 317 317 }; 318 318 -
lemon/bits/path_dump.h
r100 r209 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 5 * Copyright (C) 2003-2008 … … 54 54 RevArcIt() {} 55 55 RevArcIt(Invalid) : path(0), current(INVALID) {} 56 RevArcIt(const PredMapPath& _path) 56 RevArcIt(const PredMapPath& _path) 57 57 : path(&_path), current(_path.target) { 58 58 if (path->predMap[current] == INVALID) current = INVALID; … … 69 69 } 70 70 71 bool operator==(const RevArcIt& e) const { 72 return current == e.current; 71 bool operator==(const RevArcIt& e) const { 72 return current == e.current; 73 73 } 74 74 75 75 bool operator!=(const RevArcIt& e) const { 76 return current != e.current; 76 return current != e.current; 77 77 } 78 78 79 bool operator<(const RevArcIt& e) const { 80 return current < e.current; 79 bool operator<(const RevArcIt& e) const { 80 return current < e.current; 81 81 } 82 82 83 83 private: 84 84 const PredMapPath* path; … … 102 102 typedef _PredMatrixMap PredMatrixMap; 103 103 104 PredMatrixMapPath(const Digraph& _digraph, 104 PredMatrixMapPath(const Digraph& _digraph, 105 105 const PredMatrixMap& _predMatrixMap, 106 typename Digraph::Node _source, 106 typename Digraph::Node _source, 107 107 typename Digraph::Node _target) 108 : digraph(_digraph), predMatrixMap(_predMatrixMap), 108 : digraph(_digraph), predMatrixMap(_predMatrixMap), 109 109 source(_source), target(_target) {} 110 110 … … 128 128 RevArcIt() {} 129 129 RevArcIt(Invalid) : path(0), current(INVALID) {} 130 RevArcIt(const PredMatrixMapPath& _path) 130 RevArcIt(const PredMatrixMapPath& _path) 131 131 : path(&_path), current(_path.target) { 132 if (path->predMatrixMap(path->source, current) == INVALID) 132 if (path->predMatrixMap(path->source, current) == INVALID) 133 133 current = INVALID; 134 134 } … … 139 139 140 140 RevArcIt& operator++() { 141 current = 141 current = 142 142 path->digraph.source(path->predMatrixMap(path->source, current)); 143 if (path->predMatrixMap(path->source, current) == INVALID) 143 if (path->predMatrixMap(path->source, current) == INVALID) 144 144 current = INVALID; 145 145 return *this; 146 146 } 147 147 148 bool operator==(const RevArcIt& e) const { 149 return current == e.current; 148 bool operator==(const RevArcIt& e) const { 149 return current == e.current; 150 150 } 151 151 152 152 bool operator!=(const RevArcIt& e) const { 153 return current != e.current; 153 return current != e.current; 154 154 } 155 155 156 bool operator<(const RevArcIt& e) const { 157 return current < e.current; 156 bool operator<(const RevArcIt& e) const { 157 return current < e.current; 158 158 } 159 159 160 160 private: 161 161 const PredMatrixMapPath* path; -
lemon/bits/traits.h
r184 r209 1 2 /* -*- C++ -*- 3 * 4 * This file is a part of LEMON, a generic C++ optimization library 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 5 4 * 6 5 * Copyright (C) 2003-2008 … … 30 29 template <typename _Graph, typename _Item> 31 30 class ItemSetTraits {}; 32 31 33 32 34 33 template <typename Graph, typename Enable = void> … … 38 37 template <typename Graph> 39 38 struct NodeNotifierIndicator< 40 Graph, 39 Graph, 41 40 typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type 42 > { 41 > { 43 42 typedef typename Graph::NodeNotifier Type; 44 43 }; … … 47 46 class ItemSetTraits<_Graph, typename _Graph::Node> { 48 47 public: 49 48 50 49 typedef _Graph Graph; 51 50 … … 58 57 class Map : public Graph::template NodeMap<_Value> { 59 58 public: 60 typedef typename Graph::template NodeMap<_Value> Parent; 61 typedef typename Graph::template NodeMap<_Value> Type; 59 typedef typename Graph::template NodeMap<_Value> Parent; 60 typedef typename Graph::template NodeMap<_Value> Type; 62 61 typedef typename Parent::Value Value; 63 62 64 63 Map(const Graph& _digraph) : Parent(_digraph) {} 65 Map(const Graph& _digraph, const Value& _value) 66 64 Map(const Graph& _digraph, const Value& _value) 65 : Parent(_digraph, _value) {} 67 66 68 67 }; … … 76 75 template <typename Graph> 77 76 struct ArcNotifierIndicator< 78 Graph, 77 Graph, 79 78 typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type 80 > { 79 > { 81 80 typedef typename Graph::ArcNotifier Type; 82 81 }; … … 85 84 class ItemSetTraits<_Graph, typename _Graph::Arc> { 86 85 public: 87 86 88 87 typedef _Graph Graph; 89 88 … … 96 95 class Map : public Graph::template ArcMap<_Value> { 97 96 public: 98 typedef typename Graph::template ArcMap<_Value> Parent; 99 typedef typename Graph::template ArcMap<_Value> Type; 97 typedef typename Graph::template ArcMap<_Value> Parent; 98 typedef typename Graph::template ArcMap<_Value> Type; 100 99 typedef typename Parent::Value Value; 101 100 102 101 Map(const Graph& _digraph) : Parent(_digraph) {} 103 Map(const Graph& _digraph, const Value& _value) 104 102 Map(const Graph& _digraph, const Value& _value) 103 : Parent(_digraph, _value) {} 105 104 }; 106 105 … … 113 112 template <typename Graph> 114 113 struct EdgeNotifierIndicator< 115 Graph, 114 Graph, 116 115 typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type 117 > { 116 > { 118 117 typedef typename Graph::EdgeNotifier Type; 119 118 }; … … 122 121 class ItemSetTraits<_Graph, typename _Graph::Edge> { 123 122 public: 124 123 125 124 typedef _Graph Graph; 126 125 … … 133 132 class Map : public Graph::template EdgeMap<_Value> { 134 133 public: 135 typedef typename Graph::template EdgeMap<_Value> Parent; 136 typedef typename Graph::template EdgeMap<_Value> Type; 134 typedef typename Graph::template EdgeMap<_Value> Parent; 135 typedef typename Graph::template EdgeMap<_Value> Type; 137 136 typedef typename Parent::Value Value; 138 137 139 138 Map(const Graph& _digraph) : Parent(_digraph) {} 140 Map(const Graph& _digraph, const Value& _value) 141 139 Map(const Graph& _digraph, const Value& _value) 140 : Parent(_digraph, _value) {} 142 141 }; 143 142 … … 157 156 template <typename Map> 158 157 struct MapTraits< 159 Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 158 Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 160 159 { 161 160 typedef True ReferenceMapTag; 162 161 163 162 typedef typename Map::Key Key; 164 163 typedef typename Map::Value Value; … … 167 166 typedef typename Map::Reference ReturnValue; 168 167 169 typedef typename Map::ConstReference ConstReference; 168 typedef typename Map::ConstReference ConstReference; 170 169 typedef typename Map::Reference Reference; 171 170 }; … … 185 184 template <typename MatrixMap> 186 185 struct MatrixMapTraits< 187 MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 188 void>::type > 186 MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 187 void>::type > 189 188 { 190 189 typedef True ReferenceMapTag; 191 190 192 191 typedef typename MatrixMap::FirstKey FirstKey; 193 192 typedef typename MatrixMap::SecondKey SecondKey; … … 197 196 typedef typename MatrixMap::Reference ReturnValue; 198 197 199 typedef typename MatrixMap::ConstReference ConstReference; 198 typedef typename MatrixMap::ConstReference ConstReference; 200 199 typedef typename MatrixMap::Reference Reference; 201 200 }; … … 210 209 template <typename Graph> 211 210 struct NodeNumTagIndicator< 212 Graph, 211 Graph, 213 212 typename enable_if<typename Graph::NodeNumTag, void>::type 214 213 > { … … 223 222 template <typename Graph> 224 223 struct EdgeNumTagIndicator< 225 Graph, 224 Graph, 226 225 typename enable_if<typename Graph::EdgeNumTag, void>::type 227 226 > { … … 236 235 template <typename Graph> 237 236 struct FindEdgeTagIndicator< 238 Graph, 237 Graph, 239 238 typename enable_if<typename Graph::FindEdgeTag, void>::type 240 239 > { … … 249 248 template <typename Graph> 250 249 struct UndirectedTagIndicator< 251 Graph, 250 Graph, 252 251 typename enable_if<typename Graph::UndirectedTag, void>::type 253 252 > { … … 262 261 template <typename Graph> 263 262 struct BuildTagIndicator< 264 Graph, 263 Graph, 265 264 typename enable_if<typename Graph::BuildTag, void>::type 266 265 > { -
lemon/bits/utility.h
r117 r209 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 5 * Copyright (C) 2003-2008 … … 84 84 85 85 /**************** enable_if from BOOST ****************/ 86 86 87 87 template <typename Type, typename T = void> 88 88 struct exists { … … 90 90 }; 91 91 92 92 93 93 template <bool B, class T = void> 94 94 struct enable_if_c { … … 99 99 struct enable_if_c<false, T> {}; 100 100 101 template <class Cond, class T = void> 101 template <class Cond, class T = void> 102 102 struct enable_if : public enable_if_c<Cond::value, T> {}; 103 103 … … 110 110 struct lazy_enable_if_c<false, T> {}; 111 111 112 template <class Cond, class T> 112 template <class Cond, class T> 113 113 struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {}; 114 114 … … 122 122 struct disable_if_c<true, T> {}; 123 123 124 template <class Cond, class T = void> 124 template <class Cond, class T = void> 125 125 struct disable_if : public disable_if_c<Cond::value, T> {}; 126 126 … … 133 133 struct lazy_disable_if_c<true, T> {}; 134 134 135 template <class Cond, class T> 135 template <class Cond, class T> 136 136 struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {}; 137 137 -
lemon/bits/vector_map.h
r157 r209 1 /* -*- C++-*-2 * 3 * This file is a part of LEMON, a generic C++ optimization library 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 50 50 /// \todo Fix the doc: there is _Graph parameter instead of _Notifier. 51 51 template <typename _Graph, typename _Item, typename _Value> 52 class VectorMap 52 class VectorMap 53 53 : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { 54 54 private: 55 55 56 56 /// The container type of the map. 57 typedef std::vector<_Value> Container; 57 typedef std::vector<_Value> Container; 58 58 59 59 public: 60 60 61 /// The graph type of the map. 61 /// The graph type of the map. 62 62 typedef _Graph Graph; 63 63 /// The item type of the map. … … 94 94 } 95 95 96 /// \brief Constructor uses given value to initialize the map. 97 /// 98 /// It constructs a map uses a given value to initialize the map. 96 /// \brief Constructor uses given value to initialize the map. 97 /// 98 /// It constructs a map uses a given value to initialize the map. 99 99 /// It adds all the items of the graph to the map. 100 100 VectorMap(const Graph& graph, const Value& value) { … … 108 108 VectorMap(const VectorMap& _copy) : Parent() { 109 109 if (_copy.attached()) { 110 111 110 Parent::attach(*_copy.notifier()); 111 container = _copy.container; 112 112 } 113 113 } … … 116 116 /// 117 117 /// This operator assigns for each item in the map the 118 /// value mapped to the same item in the copied map. 118 /// value mapped to the same item in the copied map. 119 119 /// The parameter map should be indiced with the same 120 120 /// itemset because this assign operator does not change 121 /// the container of the map. 121 /// the container of the map. 122 122 VectorMap& operator=(const VectorMap& cmap) { 123 123 return operator=<VectorMap>(cmap); … … 130 130 /// concecpt and could be indiced by the current item set of 131 131 /// the NodeMap. In this case the value for each item 132 /// is assigned by the value of the given ReadMap. 132 /// is assigned by the value of the given ReadMap. 133 133 template <typename CMap> 134 134 VectorMap& operator=(const CMap& cmap) { … … 141 141 return *this; 142 142 } 143 143 144 144 public: 145 145 … … 147 147 /// 148 148 /// The subscript operator. The map can be subscripted by the 149 /// actual items of the graph. 149 /// actual items of the graph. 150 150 Reference operator[](const Key& key) { 151 151 return container[Parent::notifier()->id(key)]; 152 } 153 152 } 153 154 154 /// \brief The const subcript operator. 155 155 /// 156 156 /// The const subscript operator. The map can be subscripted by the 157 /// actual items of the graph. 157 /// actual items of the graph. 158 158 ConstReference operator[](const Key& key) const { 159 159 return container[Parent::notifier()->id(key)]; … … 171 171 172 172 /// \brief Adds a new key to the map. 173 /// 173 /// 174 174 /// It adds a new key to the map. It called by the observer notifier 175 /// and it overrides the add() member function of the observer base. 175 /// and it overrides the add() member function of the observer base. 176 176 virtual void add(const Key& key) { 177 177 int id = Parent::notifier()->id(key); 178 178 if (id >= int(container.size())) { 179 179 container.resize(id + 1); 180 180 } 181 181 } 182 182 183 183 /// \brief Adds more new keys to the map. 184 /// 184 /// 185 185 /// It adds more new keys to the map. It called by the observer notifier 186 /// and it overrides the add() member function of the observer base. 186 /// and it overrides the add() member function of the observer base. 187 187 virtual void add(const std::vector<Key>& keys) { 188 188 int max = container.size() - 1; … … 199 199 /// 200 200 /// Erase a key from the map. It called by the observer notifier 201 /// and it overrides the erase() member function of the observer base. 201 /// and it overrides the erase() member function of the observer base. 202 202 virtual void erase(const Key& key) { 203 203 container[Parent::notifier()->id(key)] = Value(); … … 207 207 /// 208 208 /// Erase more keys from the map. It called by the observer notifier 209 /// and it overrides the erase() member function of the observer base. 209 /// and it overrides the erase() member function of the observer base. 210 210 virtual void erase(const std::vector<Key>& keys) { 211 211 for (int i = 0; i < int(keys.size()); ++i) { 212 213 } 214 } 215 212 container[Parent::notifier()->id(keys[i])] = Value(); 213 } 214 } 215 216 216 /// \brief Buildes the map. 217 /// 217 /// 218 218 /// It buildes the map. It called by the observer notifier 219 219 /// and it overrides the build() member function of the observer base. 220 virtual void build() { 220 virtual void build() { 221 221 int size = Parent::notifier()->maxId() + 1; 222 222 container.reserve(size); … … 227 227 /// 228 228 /// It erase all items from the map. It called by the observer notifier 229 /// and it overrides the clear() member function of the observer base. 230 virtual void clear() { 229 /// and it overrides the clear() member function of the observer base. 230 virtual void clear() { 231 231 container.clear(); 232 232 } 233 233 234 234 private: 235 235 236 236 Container container; 237 237
Note: See TracChangeset
for help on using the changeset viewer.