0
16
0
1
1
| 1 | 1 |
LEMON code without an explicit copyright is covered by the following |
| 2 | 2 |
copyright/license. |
| 3 | 3 |
|
| 4 |
Copyright (C) 2003- |
|
| 4 |
Copyright (C) 2003-2008 Egervary Jeno Kombinatorikus Optimalizalasi |
|
| 5 | 5 |
Kutatocsoport (Egervary Combinatorial Optimization Research Group, |
| 6 | 6 |
EGRES). |
| 7 | 7 |
|
| 8 | 8 |
Permission is hereby granted, free of charge, to any person or organization |
| 9 | 9 |
obtaining a copy of the software and accompanying documentation covered by |
| 10 | 10 |
this license (the "Software") to use, reproduce, display, distribute, |
| 11 | 11 |
execute, and transmit the Software, and to prepare derivative works of the |
| 12 | 12 |
Software, and to permit third-parties to whom the Software is furnished to |
| 13 | 13 |
do so, all subject to the following: |
| 14 | 14 |
|
| 15 | 15 |
The copyright notices in the Software and this entire statement, including |
| 16 | 16 |
the above license grant, this restriction and the following disclaimer, |
| 17 | 17 |
must be included in all copies of the Software, in whole or in part, and |
| 18 | 18 |
all derivative works of the Software, unless such copies or derivative |
| 19 | 19 |
works are solely in the form of machine-executable object code generated by |
| 20 | 20 |
a source language processor. |
| 21 | 21 |
|
| 22 | 22 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 23 | 23 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 24 | 24 |
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
| 25 | 25 |
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
| 26 | 26 |
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
| 27 | 27 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 28 | 28 |
DEALINGS IN THE SOFTWARE. |
| 29 | 29 |
|
| 30 | 30 |
=========================================================================== |
| 31 | 31 |
This license is a verbatim copy of the Boost Software License, Version 1.0. |
| 32 | 32 |
|
| 33 | 33 |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_ALTERATION_NOTIFIER_H |
| 20 | 20 |
#define LEMON_BITS_ALTERATION_NOTIFIER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <list> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/bits/utility.h> |
| 26 | 26 |
|
| 27 | 27 |
///\ingroup graphbits |
| 28 | 28 |
///\file |
| 29 | 29 |
///\brief Observer notifier for graph alteration observers. |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
|
| 33 | 33 |
/// \ingroup graphbits |
| 34 | 34 |
/// |
| 35 | 35 |
/// \brief Notifier class to notify observes about alterations in |
| 36 | 36 |
/// a container. |
| 37 | 37 |
/// |
| 38 | 38 |
/// The simple graph's can be refered as two containers, one node container |
| 39 | 39 |
/// and one edge container. But they are not standard containers they |
| 40 | 40 |
/// does not store values directly they are just key continars for more |
| 41 | 41 |
/// value containers which are the node and edge maps. |
| 42 | 42 |
/// |
| 43 | 43 |
/// The graph's node and edge sets can be changed as we add or erase |
| 44 | 44 |
/// nodes and edges in the graph. Lemon would like to handle easily |
| 45 | 45 |
/// that the node and edge maps should contain values for all nodes or |
| 46 | 46 |
/// edges. If we want to check on every indicing if the map contains |
| 47 | 47 |
/// the current indicing key that cause a drawback in the performance |
| 48 | 48 |
/// in the library. We use another solution we notify all maps about |
| 49 | 49 |
/// an alteration in the graph, which cause only drawback on the |
| 50 | 50 |
/// alteration of the graph. |
| 51 | 51 |
/// |
| 52 | 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. |
| 55 | 55 |
/// The \e maxId() function gives back an upper bound of the ids. |
| 56 | 56 |
/// |
| 57 | 57 |
/// For the proper functonality of this class, we should notify it |
| 58 | 58 |
/// about each alteration in the container. The alterations have four type |
| 59 | 59 |
/// as \e add(), \e erase(), \e build() and \e clear(). The \e add() and |
| 60 | 60 |
/// \e erase() signals that only one or few items added or erased to or |
| 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 | 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 |
| 66 | 66 |
/// first extend the container and just after that signal the alteration. |
| 67 | 67 |
/// |
| 68 | 68 |
/// The alteration can be observed with a class inherited from the |
| 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 | 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 |
| 74 | 74 |
/// an other alteration in the same notifier and should not |
| 75 | 75 |
/// detach any observer from the notifier. |
| 76 | 76 |
/// |
| 77 | 77 |
/// Alteration observers try to be exception safe. If an \e add() or |
| 78 | 78 |
/// a \e clear() function throws an exception then the remaining |
| 79 | 79 |
/// observeres will not be notified and the fulfilled additions will |
| 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 | 82 |
/// exception. Actullay, it can be throw only |
| 83 | 83 |
/// \ref AlterationObserver::ImmediateDetach ImmediateDetach |
| 84 | 84 |
/// exception which detach the observer from the notifier. |
| 85 | 85 |
/// |
| 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 | 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 |
| 91 | 91 |
/// degrees. The sub graph adaptors cannot signal the alterations because |
| 92 | 92 |
/// just a setting in the filter map can modify the graph and this cannot |
| 93 | 93 |
/// be watched in any way. |
| 94 | 94 |
/// |
| 95 | 95 |
/// \param _Container The container which is observed. |
| 96 | 96 |
/// \param _Item The item type which is obserbved. |
| 97 | 97 |
/// |
| 98 | 98 |
/// \author Balazs Dezso |
| 99 | 99 |
|
| 100 | 100 |
template <typename _Container, typename _Item> |
| 101 | 101 |
class AlterationNotifier {
|
| 102 | 102 |
public: |
| 103 | 103 |
|
| 104 | 104 |
typedef True Notifier; |
| 105 | 105 |
|
| 106 | 106 |
typedef _Container Container; |
| 107 | 107 |
typedef _Item Item; |
| 108 | 108 |
|
| 109 | 109 |
/// \brief Exception which can be called from \e clear() and |
| 110 | 110 |
/// \e erase(). |
| 111 | 111 |
/// |
| 112 | 112 |
/// From the \e clear() and \e erase() function only this |
| 113 | 113 |
/// exception is allowed to throw. The exception immediatly |
| 114 | 114 |
/// detaches the current observer from the notifier. Because the |
| 115 | 115 |
/// \e clear() and \e erase() should not throw other exceptions |
| 116 | 116 |
/// it can be used to invalidate the observer. |
| 117 | 117 |
struct ImmediateDetach {};
|
| 118 | 118 |
|
| 119 | 119 |
/// \brief ObserverBase is the base class for the observers. |
| 120 | 120 |
/// |
| 121 | 121 |
/// ObserverBase is the abstract base class for the observers. |
| 122 | 122 |
/// It will be notified about an item was inserted into or |
| 123 | 123 |
/// erased from the graph. |
| 124 | 124 |
/// |
| 125 | 125 |
/// The observer interface contains some pure virtual functions |
| 126 | 126 |
/// to override. The add() and erase() functions are |
| 127 | 127 |
/// to notify the oberver when one item is added or |
| 128 | 128 |
/// erased. |
| 129 | 129 |
/// |
| 130 | 130 |
/// The build() and clear() members are to notify the observer |
| 131 | 131 |
/// about the container is built from an empty container or |
| 132 | 132 |
/// is cleared to an empty container. |
| 133 | 133 |
/// |
| 134 | 134 |
/// \author Balazs Dezso |
| 135 | 135 |
|
| 136 | 136 |
class ObserverBase {
|
| 137 | 137 |
protected: |
| 138 | 138 |
typedef AlterationNotifier Notifier; |
| 139 | 139 |
|
| 140 | 140 |
friend class AlterationNotifier; |
| 141 | 141 |
|
| 142 | 142 |
/// \brief Default constructor. |
| 143 | 143 |
/// |
| 144 | 144 |
/// Default constructor for ObserverBase. |
| 145 | 145 |
/// |
| 146 | 146 |
ObserverBase() : _notifier(0) {}
|
| 147 | 147 |
|
| 148 | 148 |
/// \brief Constructor which attach the observer into notifier. |
| 149 | 149 |
/// |
| 150 | 150 |
/// Constructor which attach the observer into notifier. |
| 151 | 151 |
ObserverBase(AlterationNotifier& nf) {
|
| 152 | 152 |
attach(nf); |
| 153 | 153 |
} |
| 154 | 154 |
|
| 155 | 155 |
/// \brief Constructor which attach the obserever to the same notifier. |
| 156 | 156 |
/// |
| 157 | 157 |
/// Constructor which attach the obserever to the same notifier as |
| 158 | 158 |
/// the other observer is attached to. |
| 159 | 159 |
ObserverBase(const ObserverBase& copy) {
|
| 160 | 160 |
if (copy.attached()) {
|
| 161 | 161 |
attach(*copy.notifier()); |
| 162 | 162 |
} |
| 163 | 163 |
} |
| 164 | 164 |
|
| 165 | 165 |
/// \brief Destructor |
| 166 | 166 |
virtual ~ObserverBase() {
|
| 167 | 167 |
if (attached()) {
|
| 168 | 168 |
detach(); |
| 169 | 169 |
} |
| 170 | 170 |
} |
| 171 | 171 |
|
| 172 | 172 |
/// \brief Attaches the observer into an AlterationNotifier. |
| 173 | 173 |
/// |
| 174 | 174 |
/// This member attaches the observer into an AlterationNotifier. |
| 175 | 175 |
/// |
| 176 | 176 |
void attach(AlterationNotifier& nf) {
|
| 177 | 177 |
nf.attach(*this); |
| 178 | 178 |
} |
| 179 | 179 |
|
| 180 | 180 |
/// \brief Detaches the observer into an AlterationNotifier. |
| 181 | 181 |
/// |
| 182 | 182 |
/// This member detaches the observer from an AlterationNotifier. |
| 183 | 183 |
/// |
| 184 | 184 |
void detach() {
|
| 185 | 185 |
_notifier->detach(*this); |
| 186 | 186 |
} |
| 187 | 187 |
|
| 188 | 188 |
/// \brief Gives back a pointer to the notifier which the map |
| 189 | 189 |
/// attached into. |
| 190 | 190 |
/// |
| 191 | 191 |
/// This function gives back a pointer to the notifier which the map |
| 192 | 192 |
/// attached into. |
| 193 | 193 |
/// |
| 194 | 194 |
Notifier* notifier() const { return const_cast<Notifier*>(_notifier); }
|
| 195 | 195 |
|
| 196 | 196 |
/// Gives back true when the observer is attached into a notifier. |
| 197 | 197 |
bool attached() const { return _notifier != 0; }
|
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_ARRAY_MAP_H |
| 20 | 20 |
#define LEMON_BITS_ARRAY_MAP_H |
| 21 | 21 |
|
| 22 | 22 |
#include <memory> |
| 23 | 23 |
|
| 24 | 24 |
#include <lemon/bits/traits.h> |
| 25 | 25 |
#include <lemon/bits/alteration_notifier.h> |
| 26 | 26 |
#include <lemon/concept_check.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
/// \ingroup graphbits |
| 30 | 30 |
/// \file |
| 31 | 31 |
/// \brief Graph map based on the array storage. |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
/// \ingroup graphbits |
| 36 | 36 |
/// |
| 37 | 37 |
/// \brief Graph map based on the array storage. |
| 38 | 38 |
/// |
| 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 | 41 |
/// the map. This map uses the allocators to implement |
| 42 | 42 |
/// the container functionality. |
| 43 | 43 |
/// |
| 44 | 44 |
/// The template parameters are the Graph the current Item type and |
| 45 | 45 |
/// the Value type of the map. |
| 46 | 46 |
template <typename _Graph, typename _Item, typename _Value> |
| 47 | 47 |
class ArrayMap |
| 48 | 48 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
|
| 49 | 49 |
public: |
| 50 | 50 |
/// The graph type of the maps. |
| 51 | 51 |
typedef _Graph Graph; |
| 52 | 52 |
/// The item type of the map. |
| 53 | 53 |
typedef _Item Item; |
| 54 | 54 |
/// The reference map tag. |
| 55 | 55 |
typedef True ReferenceMapTag; |
| 56 | 56 |
|
| 57 | 57 |
/// The key type of the maps. |
| 58 | 58 |
typedef _Item Key; |
| 59 | 59 |
/// The value type of the map. |
| 60 | 60 |
typedef _Value Value; |
| 61 | 61 |
|
| 62 | 62 |
/// The const reference type of the map. |
| 63 | 63 |
typedef const _Value& ConstReference; |
| 64 | 64 |
/// The reference type of the map. |
| 65 | 65 |
typedef _Value& Reference; |
| 66 | 66 |
|
| 67 | 67 |
/// The notifier type. |
| 68 | 68 |
typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; |
| 69 | 69 |
|
| 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; |
| 75 | 75 |
|
| 76 | 76 |
public: |
| 77 | 77 |
|
| 78 | 78 |
/// \brief Graph initialized map constructor. |
| 79 | 79 |
/// |
| 80 | 80 |
/// Graph initialized map constructor. |
| 81 | 81 |
explicit ArrayMap(const Graph& graph) {
|
| 82 | 82 |
Parent::attach(graph.notifier(Item())); |
| 83 | 83 |
allocate_memory(); |
| 84 | 84 |
Notifier* nf = Parent::notifier(); |
| 85 | 85 |
Item it; |
| 86 | 86 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 87 | 87 |
int id = nf->id(it);; |
| 88 | 88 |
allocator.construct(&(values[id]), Value()); |
| 89 | 89 |
} |
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 | 92 |
/// \brief Constructor to use default value to initialize the map. |
| 93 | 93 |
/// |
| 94 | 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())); |
| 97 | 97 |
allocate_memory(); |
| 98 | 98 |
Notifier* nf = Parent::notifier(); |
| 99 | 99 |
Item it; |
| 100 | 100 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 101 | 101 |
int id = nf->id(it);; |
| 102 | 102 |
allocator.construct(&(values[id]), value); |
| 103 | 103 |
} |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
/// \brief Constructor to copy a map of the same map type. |
| 107 | 107 |
/// |
| 108 | 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; |
| 114 | 114 |
if (capacity == 0) return; |
| 115 | 115 |
values = allocator.allocate(capacity); |
| 116 | 116 |
Notifier* nf = Parent::notifier(); |
| 117 | 117 |
Item it; |
| 118 | 118 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 119 | 119 |
int id = nf->id(it);; |
| 120 | 120 |
allocator.construct(&(values[id]), copy.values[id]); |
| 121 | 121 |
} |
| 122 | 122 |
} |
| 123 | 123 |
|
| 124 | 124 |
/// \brief Assign operator. |
| 125 | 125 |
/// |
| 126 | 126 |
/// This operator assigns for each item in the map the |
| 127 | 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 | 130 |
/// the container of the map. |
| 131 | 131 |
ArrayMap& operator=(const ArrayMap& cmap) {
|
| 132 | 132 |
return operator=<ArrayMap>(cmap); |
| 133 | 133 |
} |
| 134 | 134 |
|
| 135 | 135 |
|
| 136 | 136 |
/// \brief Template assign operator. |
| 137 | 137 |
/// |
| 138 | 138 |
/// The given parameter should be conform to the ReadMap |
| 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 | 141 |
/// is assigned by the value of the given ReadMap. |
| 142 | 142 |
template <typename CMap> |
| 143 | 143 |
ArrayMap& operator=(const CMap& cmap) {
|
| 144 | 144 |
checkConcept<concepts::ReadMap<Key, _Value>, CMap>(); |
| 145 | 145 |
const typename Parent::Notifier* nf = Parent::notifier(); |
| 146 | 146 |
Item it; |
| 147 | 147 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 148 | 148 |
set(it, cmap[it]); |
| 149 | 149 |
} |
| 150 | 150 |
return *this; |
| 151 | 151 |
} |
| 152 | 152 |
|
| 153 | 153 |
/// \brief The destructor of the map. |
| 154 | 154 |
/// |
| 155 | 155 |
/// The destructor of the map. |
| 156 | 156 |
virtual ~ArrayMap() {
|
| 157 | 157 |
if (attached()) {
|
| 158 | 158 |
clear(); |
| 159 | 159 |
detach(); |
| 160 | 160 |
} |
| 161 | 161 |
} |
| 162 | 162 |
|
| 163 | 163 |
protected: |
| 164 | 164 |
|
| 165 | 165 |
using Parent::attach; |
| 166 | 166 |
using Parent::detach; |
| 167 | 167 |
using Parent::attached; |
| 168 | 168 |
|
| 169 | 169 |
public: |
| 170 | 170 |
|
| 171 | 171 |
/// \brief The subscript operator. |
| 172 | 172 |
/// |
| 173 | 173 |
/// The subscript operator. The map can be subscripted by the |
| 174 | 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 | 178 |
} |
| 179 | 179 |
|
| 180 | 180 |
/// \brief The const subscript operator. |
| 181 | 181 |
/// |
| 182 | 182 |
/// The const subscript operator. The map can be subscripted by the |
| 183 | 183 |
/// actual keys of the graph. |
| 184 | 184 |
const Value& operator[](const Key& key) const {
|
| 185 | 185 |
int id = Parent::notifier()->id(key); |
| 186 | 186 |
return values[id]; |
| 187 | 187 |
} |
| 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. |
| 193 | 193 |
void set(const Key& key, const Value& val) {
|
| 194 | 194 |
(*this)[key] = val; |
| 195 | 195 |
} |
| 196 | 196 |
|
| 197 | 197 |
protected: |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_BASE_EXTENDER_H |
| 20 | 20 |
#define LEMON_BITS_BASE_EXTENDER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/bits/invalid.h> |
| 23 | 23 |
#include <lemon/error.h> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/bits/map_extender.h> |
| 26 | 26 |
#include <lemon/bits/default_map.h> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/concept_check.h> |
| 29 | 29 |
#include <lemon/concepts/maps.h> |
| 30 | 30 |
|
| 31 | 31 |
///\ingroup digraphbits |
| 32 | 32 |
///\file |
| 33 | 33 |
///\brief Extenders for the digraph types |
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \ingroup digraphbits |
| 37 | 37 |
/// |
| 38 | 38 |
/// \brief BaseDigraph to BaseGraph extender |
| 39 | 39 |
template <typename Base> |
| 40 | 40 |
class UndirDigraphExtender : public Base {
|
| 41 | 41 |
|
| 42 | 42 |
public: |
| 43 | 43 |
|
| 44 | 44 |
typedef Base Parent; |
| 45 | 45 |
typedef typename Parent::Arc Edge; |
| 46 | 46 |
typedef typename Parent::Node Node; |
| 47 | 47 |
|
| 48 | 48 |
typedef True UndirectedTag; |
| 49 | 49 |
|
| 50 | 50 |
class Arc : public Edge {
|
| 51 | 51 |
friend class UndirDigraphExtender; |
| 52 | 52 |
|
| 53 | 53 |
protected: |
| 54 | 54 |
bool forward; |
| 55 | 55 |
|
| 56 | 56 |
Arc(const Edge &ue, bool _forward) : |
| 57 | 57 |
Edge(ue), forward(_forward) {}
|
| 58 | 58 |
|
| 59 | 59 |
public: |
| 60 | 60 |
Arc() {}
|
| 61 | 61 |
|
| 62 | 62 |
/// Invalid arc constructor |
| 63 | 63 |
Arc(Invalid i) : Edge(i), forward(true) {}
|
| 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 | 72 |
return forward<that.forward || |
| 73 | 73 |
(!(that.forward<forward) && Edge(*this)<Edge(that)); |
| 74 | 74 |
} |
| 75 | 75 |
}; |
| 76 | 76 |
|
| 77 | 77 |
|
| 78 | 78 |
|
| 79 | 79 |
using Parent::source; |
| 80 | 80 |
|
| 81 | 81 |
/// Source of the given Arc. |
| 82 | 82 |
Node source(const Arc &e) const {
|
| 83 | 83 |
return e.forward ? Parent::source(e) : Parent::target(e); |
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 | 86 |
using Parent::target; |
| 87 | 87 |
|
| 88 | 88 |
/// Target of the given Arc. |
| 89 | 89 |
Node target(const Arc &e) const {
|
| 90 | 90 |
return e.forward ? Parent::target(e) : Parent::source(e); |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
/// \brief Directed arc from an edge. |
| 94 | 94 |
/// |
| 95 | 95 |
/// Returns a directed arc corresponding to the specified Edge. |
| 96 | 96 |
/// If the given bool is true the given edge and the |
| 97 | 97 |
/// returned arc have the same source node. |
| 98 | 98 |
static Arc direct(const Edge &ue, bool d) {
|
| 99 | 99 |
return Arc(ue, d); |
| 100 | 100 |
} |
| 101 | 101 |
|
| 102 | 102 |
/// Returns whether the given directed arc is same orientation as the |
| 103 | 103 |
/// corresponding edge. |
| 104 | 104 |
/// |
| 105 | 105 |
/// \todo reference to the corresponding point of the undirected digraph |
| 106 | 106 |
/// concept. "What does the direction of an edge mean?" |
| 107 | 107 |
static bool direction(const Arc &e) { return e.forward; }
|
| 108 | 108 |
|
| 109 | 109 |
|
| 110 | 110 |
using Parent::first; |
| 111 | 111 |
using Parent::next; |
| 112 | 112 |
|
| 113 | 113 |
void first(Arc &e) const {
|
| 114 | 114 |
Parent::first(e); |
| 115 | 115 |
e.forward=true; |
| 116 | 116 |
} |
| 117 | 117 |
|
| 118 | 118 |
void next(Arc &e) const {
|
| 119 | 119 |
if( e.forward ) {
|
| 120 | 120 |
e.forward = false; |
| 121 | 121 |
} |
| 122 | 122 |
else {
|
| 123 | 123 |
Parent::next(e); |
| 124 | 124 |
e.forward = true; |
| 125 | 125 |
} |
| 126 | 126 |
} |
| 127 | 127 |
|
| 128 | 128 |
void firstOut(Arc &e, const Node &n) const {
|
| 129 | 129 |
Parent::firstIn(e,n); |
| 130 | 130 |
if( Edge(e) != INVALID ) {
|
| 131 | 131 |
e.forward = false; |
| 132 | 132 |
} |
| 133 | 133 |
else {
|
| 134 | 134 |
Parent::firstOut(e,n); |
| 135 | 135 |
e.forward = true; |
| 136 | 136 |
} |
| 137 | 137 |
} |
| 138 | 138 |
void nextOut(Arc &e) const {
|
| 139 | 139 |
if( ! e.forward ) {
|
| 140 | 140 |
Node n = Parent::target(e); |
| 141 | 141 |
Parent::nextIn(e); |
| 142 | 142 |
if( Edge(e) == INVALID ) {
|
| 143 | 143 |
Parent::firstOut(e, n); |
| 144 | 144 |
e.forward = true; |
| 145 | 145 |
} |
| 146 | 146 |
} |
| 147 | 147 |
else {
|
| 148 | 148 |
Parent::nextOut(e); |
| 149 | 149 |
} |
| 150 | 150 |
} |
| 151 | 151 |
|
| 152 | 152 |
void firstIn(Arc &e, const Node &n) const {
|
| 153 | 153 |
Parent::firstOut(e,n); |
| 154 | 154 |
if( Edge(e) != INVALID ) {
|
| 155 | 155 |
e.forward = false; |
| 156 | 156 |
} |
| 157 | 157 |
else {
|
| 158 | 158 |
Parent::firstIn(e,n); |
| 159 | 159 |
e.forward = true; |
| 160 | 160 |
} |
| 161 | 161 |
} |
| 162 | 162 |
void nextIn(Arc &e) const {
|
| 163 | 163 |
if( ! e.forward ) {
|
| 164 | 164 |
Node n = Parent::source(e); |
| 165 | 165 |
Parent::nextOut(e); |
| 166 | 166 |
if( Edge(e) == INVALID ) {
|
| 167 | 167 |
Parent::firstIn(e, n); |
| 168 | 168 |
e.forward = true; |
| 169 | 169 |
} |
| 170 | 170 |
} |
| 171 | 171 |
else {
|
| 172 | 172 |
Parent::nextIn(e); |
| 173 | 173 |
} |
| 174 | 174 |
} |
| 175 | 175 |
|
| 176 | 176 |
void firstInc(Edge &e, bool &d, const Node &n) const {
|
| 177 | 177 |
d = true; |
| 178 | 178 |
Parent::firstOut(e, n); |
| 179 | 179 |
if (e != INVALID) return; |
| 180 | 180 |
d = false; |
| 181 | 181 |
Parent::firstIn(e, n); |
| 182 | 182 |
} |
| 183 | 183 |
|
| 184 | 184 |
void nextInc(Edge &e, bool &d) const {
|
| 185 | 185 |
if (d) {
|
| 186 | 186 |
Node s = Parent::source(e); |
| 187 | 187 |
Parent::nextOut(e); |
| 188 | 188 |
if (e != INVALID) return; |
| 189 | 189 |
d = false; |
| 190 | 190 |
Parent::firstIn(e, s); |
| 191 | 191 |
} else {
|
| 192 | 192 |
Parent::nextIn(e); |
| 193 | 193 |
} |
| 194 | 194 |
} |
| 195 | 195 |
|
| 196 | 196 |
Node nodeFromId(int ix) const {
|
| 197 | 197 |
return Parent::nodeFromId(ix); |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_DEFAULT_MAP_H |
| 20 | 20 |
#define LEMON_BITS_DEFAULT_MAP_H |
| 21 | 21 |
|
| 22 | 22 |
|
| 23 | 23 |
#include <lemon/bits/array_map.h> |
| 24 | 24 |
#include <lemon/bits/vector_map.h> |
| 25 | 25 |
//#include <lemon/bits/debug_map.h> |
| 26 | 26 |
|
| 27 | 27 |
///\ingroup graphbits |
| 28 | 28 |
///\file |
| 29 | 29 |
///\brief Graph maps that construct and destruct their elements dynamically. |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
|
| 33 | 33 |
|
| 34 | 34 |
//#ifndef LEMON_USE_DEBUG_MAP |
| 35 | 35 |
|
| 36 | 36 |
template <typename _Graph, typename _Item, typename _Value> |
| 37 | 37 |
struct DefaultMapSelector {
|
| 38 | 38 |
typedef ArrayMap<_Graph, _Item, _Value> Map; |
| 39 | 39 |
}; |
| 40 | 40 |
|
| 41 | 41 |
// bool |
| 42 | 42 |
template <typename _Graph, typename _Item> |
| 43 | 43 |
struct DefaultMapSelector<_Graph, _Item, bool> {
|
| 44 | 44 |
typedef VectorMap<_Graph, _Item, bool> Map; |
| 45 | 45 |
}; |
| 46 | 46 |
|
| 47 | 47 |
// char |
| 48 | 48 |
template <typename _Graph, typename _Item> |
| 49 | 49 |
struct DefaultMapSelector<_Graph, _Item, char> {
|
| 50 | 50 |
typedef VectorMap<_Graph, _Item, char> Map; |
| 51 | 51 |
}; |
| 52 | 52 |
|
| 53 | 53 |
template <typename _Graph, typename _Item> |
| 54 | 54 |
struct DefaultMapSelector<_Graph, _Item, signed char> {
|
| 55 | 55 |
typedef VectorMap<_Graph, _Item, signed char> Map; |
| 56 | 56 |
}; |
| 57 | 57 |
|
| 58 | 58 |
template <typename _Graph, typename _Item> |
| 59 | 59 |
struct DefaultMapSelector<_Graph, _Item, unsigned char> {
|
| 60 | 60 |
typedef VectorMap<_Graph, _Item, unsigned char> Map; |
| 61 | 61 |
}; |
| 62 | 62 |
|
| 63 | 63 |
|
| 64 | 64 |
// int |
| 65 | 65 |
template <typename _Graph, typename _Item> |
| 66 | 66 |
struct DefaultMapSelector<_Graph, _Item, signed int> {
|
| 67 | 67 |
typedef VectorMap<_Graph, _Item, signed int> Map; |
| 68 | 68 |
}; |
| 69 | 69 |
|
| 70 | 70 |
template <typename _Graph, typename _Item> |
| 71 | 71 |
struct DefaultMapSelector<_Graph, _Item, unsigned int> {
|
| 72 | 72 |
typedef VectorMap<_Graph, _Item, unsigned int> Map; |
| 73 | 73 |
}; |
| 74 | 74 |
|
| 75 | 75 |
|
| 76 | 76 |
// short |
| 77 | 77 |
template <typename _Graph, typename _Item> |
| 78 | 78 |
struct DefaultMapSelector<_Graph, _Item, signed short> {
|
| 79 | 79 |
typedef VectorMap<_Graph, _Item, signed short> Map; |
| 80 | 80 |
}; |
| 81 | 81 |
|
| 82 | 82 |
template <typename _Graph, typename _Item> |
| 83 | 83 |
struct DefaultMapSelector<_Graph, _Item, unsigned short> {
|
| 84 | 84 |
typedef VectorMap<_Graph, _Item, unsigned short> Map; |
| 85 | 85 |
}; |
| 86 | 86 |
|
| 87 | 87 |
|
| 88 | 88 |
// long |
| 89 | 89 |
template <typename _Graph, typename _Item> |
| 90 | 90 |
struct DefaultMapSelector<_Graph, _Item, signed long> {
|
| 91 | 91 |
typedef VectorMap<_Graph, _Item, signed long> Map; |
| 92 | 92 |
}; |
| 93 | 93 |
|
| 94 | 94 |
template <typename _Graph, typename _Item> |
| 95 | 95 |
struct DefaultMapSelector<_Graph, _Item, unsigned long> {
|
| 96 | 96 |
typedef VectorMap<_Graph, _Item, unsigned long> Map; |
| 97 | 97 |
}; |
| 98 | 98 |
|
| 99 | 99 |
|
| 100 | 100 |
#if defined __GNUC__ && !defined __STRICT_ANSI__ |
| 101 | 101 |
|
| 102 | 102 |
// long long |
| 103 | 103 |
template <typename _Graph, typename _Item> |
| 104 | 104 |
struct DefaultMapSelector<_Graph, _Item, signed long long> {
|
| 105 | 105 |
typedef VectorMap<_Graph, _Item, signed long long> Map; |
| 106 | 106 |
}; |
| 107 | 107 |
|
| 108 | 108 |
template <typename _Graph, typename _Item> |
| 109 | 109 |
struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
|
| 110 | 110 |
typedef VectorMap<_Graph, _Item, unsigned long long> Map; |
| 111 | 111 |
}; |
| 112 | 112 |
|
| 113 | 113 |
#endif |
| 114 | 114 |
|
| 115 | 115 |
|
| 116 | 116 |
// float |
| 117 | 117 |
template <typename _Graph, typename _Item> |
| 118 | 118 |
struct DefaultMapSelector<_Graph, _Item, float> {
|
| 119 | 119 |
typedef VectorMap<_Graph, _Item, float> Map; |
| 120 | 120 |
}; |
| 121 | 121 |
|
| 122 | 122 |
|
| 123 | 123 |
// double |
| 124 | 124 |
template <typename _Graph, typename _Item> |
| 125 | 125 |
struct DefaultMapSelector<_Graph, _Item, double> {
|
| 126 | 126 |
typedef VectorMap<_Graph, _Item, double> Map; |
| 127 | 127 |
}; |
| 128 | 128 |
|
| 129 | 129 |
|
| 130 | 130 |
// long double |
| 131 | 131 |
template <typename _Graph, typename _Item> |
| 132 | 132 |
struct DefaultMapSelector<_Graph, _Item, long double> {
|
| 133 | 133 |
typedef VectorMap<_Graph, _Item, long double> Map; |
| 134 | 134 |
}; |
| 135 | 135 |
|
| 136 | 136 |
|
| 137 | 137 |
// pointer |
| 138 | 138 |
template <typename _Graph, typename _Item, typename _Ptr> |
| 139 | 139 |
struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
|
| 140 | 140 |
typedef VectorMap<_Graph, _Item, _Ptr*> Map; |
| 141 | 141 |
}; |
| 142 | 142 |
|
| 143 | 143 |
// #else |
| 144 | 144 |
|
| 145 | 145 |
// template <typename _Graph, typename _Item, typename _Value> |
| 146 | 146 |
// struct DefaultMapSelector {
|
| 147 | 147 |
// typedef DebugMap<_Graph, _Item, _Value> Map; |
| 148 | 148 |
// }; |
| 149 | 149 |
|
| 150 | 150 |
// #endif |
| 151 | 151 |
|
| 152 | 152 |
/// \e |
| 153 | 153 |
template <typename _Graph, typename _Item, typename _Value> |
| 154 | 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 | 164 |
DefaultMap(const Graph& graph, const Value& value) |
| 165 | 165 |
: Parent(graph, value) {}
|
| 166 | 166 |
|
| 167 | 167 |
DefaultMap& operator=(const DefaultMap& cmap) {
|
| 168 | 168 |
return operator=<DefaultMap>(cmap); |
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 | 171 |
template <typename CMap> |
| 172 | 172 |
DefaultMap& operator=(const CMap& cmap) {
|
| 173 | 173 |
Parent::operator=(cmap); |
| 174 | 174 |
return *this; |
| 175 | 175 |
} |
| 176 | 176 |
|
| 177 | 177 |
}; |
| 178 | 178 |
|
| 179 | 179 |
} |
| 180 | 180 |
|
| 181 | 181 |
#endif |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_GRAPH_EXTENDER_H |
| 20 | 20 |
#define LEMON_BITS_GRAPH_EXTENDER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/bits/invalid.h> |
| 23 | 23 |
#include <lemon/bits/utility.h> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/bits/map_extender.h> |
| 26 | 26 |
#include <lemon/bits/default_map.h> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/concept_check.h> |
| 29 | 29 |
#include <lemon/concepts/maps.h> |
| 30 | 30 |
|
| 31 | 31 |
///\ingroup graphbits |
| 32 | 32 |
///\file |
| 33 | 33 |
///\brief Extenders for the digraph types |
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \ingroup graphbits |
| 37 | 37 |
/// |
| 38 | 38 |
/// \brief Extender for the Digraphs |
| 39 | 39 |
template <typename Base> |
| 40 | 40 |
class DigraphExtender : public Base {
|
| 41 | 41 |
public: |
| 42 | 42 |
|
| 43 | 43 |
typedef Base Parent; |
| 44 | 44 |
typedef DigraphExtender Digraph; |
| 45 | 45 |
|
| 46 | 46 |
// Base extensions |
| 47 | 47 |
|
| 48 | 48 |
typedef typename Parent::Node Node; |
| 49 | 49 |
typedef typename Parent::Arc Arc; |
| 50 | 50 |
|
| 51 | 51 |
int maxId(Node) const {
|
| 52 | 52 |
return Parent::maxNodeId(); |
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 | 55 |
int maxId(Arc) const {
|
| 56 | 56 |
return Parent::maxArcId(); |
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 | 59 |
Node fromId(int id, Node) const {
|
| 60 | 60 |
return Parent::nodeFromId(id); |
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 | 63 |
Arc fromId(int id, Arc) const {
|
| 64 | 64 |
return Parent::arcFromId(id); |
| 65 | 65 |
} |
| 66 | 66 |
|
| 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 |
|
| 76 | 76 |
// Alterable extension |
| 77 | 77 |
|
| 78 | 78 |
typedef AlterationNotifier<DigraphExtender, Node> NodeNotifier; |
| 79 | 79 |
typedef AlterationNotifier<DigraphExtender, Arc> ArcNotifier; |
| 80 | 80 |
|
| 81 | 81 |
|
| 82 | 82 |
protected: |
| 83 | 83 |
|
| 84 | 84 |
mutable NodeNotifier node_notifier; |
| 85 | 85 |
mutable ArcNotifier arc_notifier; |
| 86 | 86 |
|
| 87 | 87 |
public: |
| 88 | 88 |
|
| 89 | 89 |
NodeNotifier& notifier(Node) const {
|
| 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 | 97 |
class NodeIt : public Node {
|
| 98 | 98 |
const Digraph* _digraph; |
| 99 | 99 |
public: |
| 100 | 100 |
|
| 101 | 101 |
NodeIt() {}
|
| 102 | 102 |
|
| 103 | 103 |
NodeIt(Invalid i) : Node(i) { }
|
| 104 | 104 |
|
| 105 | 105 |
explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) {
|
| 106 | 106 |
_digraph->first(static_cast<Node&>(*this)); |
| 107 | 107 |
} |
| 108 | 108 |
|
| 109 | 109 |
NodeIt(const Digraph& digraph, const Node& node) |
| 110 | 110 |
: Node(node), _digraph(&digraph) {}
|
| 111 | 111 |
|
| 112 | 112 |
NodeIt& operator++() {
|
| 113 | 113 |
_digraph->next(*this); |
| 114 | 114 |
return *this; |
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 | 117 |
}; |
| 118 | 118 |
|
| 119 | 119 |
|
| 120 | 120 |
class ArcIt : public Arc {
|
| 121 | 121 |
const Digraph* _digraph; |
| 122 | 122 |
public: |
| 123 | 123 |
|
| 124 | 124 |
ArcIt() { }
|
| 125 | 125 |
|
| 126 | 126 |
ArcIt(Invalid i) : Arc(i) { }
|
| 127 | 127 |
|
| 128 | 128 |
explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) {
|
| 129 | 129 |
_digraph->first(static_cast<Arc&>(*this)); |
| 130 | 130 |
} |
| 131 | 131 |
|
| 132 | 132 |
ArcIt(const Digraph& digraph, const Arc& arc) : |
| 133 | 133 |
Arc(arc), _digraph(&digraph) { }
|
| 134 | 134 |
|
| 135 | 135 |
ArcIt& operator++() {
|
| 136 | 136 |
_digraph->next(*this); |
| 137 | 137 |
return *this; |
| 138 | 138 |
} |
| 139 | 139 |
|
| 140 | 140 |
}; |
| 141 | 141 |
|
| 142 | 142 |
|
| 143 | 143 |
class OutArcIt : public Arc {
|
| 144 | 144 |
const Digraph* _digraph; |
| 145 | 145 |
public: |
| 146 | 146 |
|
| 147 | 147 |
OutArcIt() { }
|
| 148 | 148 |
|
| 149 | 149 |
OutArcIt(Invalid i) : Arc(i) { }
|
| 150 | 150 |
|
| 151 | 151 |
OutArcIt(const Digraph& digraph, const Node& node) |
| 152 | 152 |
: _digraph(&digraph) {
|
| 153 | 153 |
_digraph->firstOut(*this, node); |
| 154 | 154 |
} |
| 155 | 155 |
|
| 156 | 156 |
OutArcIt(const Digraph& digraph, const Arc& arc) |
| 157 | 157 |
: Arc(arc), _digraph(&digraph) {}
|
| 158 | 158 |
|
| 159 | 159 |
OutArcIt& operator++() {
|
| 160 | 160 |
_digraph->nextOut(*this); |
| 161 | 161 |
return *this; |
| 162 | 162 |
} |
| 163 | 163 |
|
| 164 | 164 |
}; |
| 165 | 165 |
|
| 166 | 166 |
|
| 167 | 167 |
class InArcIt : public Arc {
|
| 168 | 168 |
const Digraph* _digraph; |
| 169 | 169 |
public: |
| 170 | 170 |
|
| 171 | 171 |
InArcIt() { }
|
| 172 | 172 |
|
| 173 | 173 |
InArcIt(Invalid i) : Arc(i) { }
|
| 174 | 174 |
|
| 175 | 175 |
InArcIt(const Digraph& digraph, const Node& node) |
| 176 | 176 |
: _digraph(&digraph) {
|
| 177 | 177 |
_digraph->firstIn(*this, node); |
| 178 | 178 |
} |
| 179 | 179 |
|
| 180 | 180 |
InArcIt(const Digraph& digraph, const Arc& arc) : |
| 181 | 181 |
Arc(arc), _digraph(&digraph) {}
|
| 182 | 182 |
|
| 183 | 183 |
InArcIt& operator++() {
|
| 184 | 184 |
_digraph->nextIn(*this); |
| 185 | 185 |
return *this; |
| 186 | 186 |
} |
| 187 | 187 |
|
| 188 | 188 |
}; |
| 189 | 189 |
|
| 190 | 190 |
/// \brief Base node of the iterator |
| 191 | 191 |
/// |
| 192 | 192 |
/// Returns the base node (i.e. the source in this case) of the iterator |
| 193 | 193 |
Node baseNode(const OutArcIt &arc) const {
|
| 194 | 194 |
return Parent::source(arc); |
| 195 | 195 |
} |
| 196 | 196 |
/// \brief Running node of the iterator |
| 197 | 197 |
/// |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_MAP_EXTENDER_H |
| 20 | 20 |
#define LEMON_BITS_MAP_EXTENDER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iterator> |
| 23 | 23 |
|
| 24 | 24 |
#include <lemon/bits/traits.h> |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/concept_check.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
///\file |
| 30 | 30 |
///\brief Extenders for iterable maps. |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
/// \ingroup graphbits |
| 35 | 35 |
/// |
| 36 | 36 |
/// \brief Extender for maps |
| 37 | 37 |
template <typename _Map> |
| 38 | 38 |
class MapExtender : public _Map {
|
| 39 | 39 |
public: |
| 40 | 40 |
|
| 41 | 41 |
typedef _Map Parent; |
| 42 | 42 |
typedef MapExtender Map; |
| 43 | 43 |
|
| 44 | 44 |
|
| 45 | 45 |
typedef typename Parent::Graph Graph; |
| 46 | 46 |
typedef typename Parent::Key Item; |
| 47 | 47 |
|
| 48 | 48 |
typedef typename Parent::Key Key; |
| 49 | 49 |
typedef typename Parent::Value Value; |
| 50 | 50 |
|
| 51 | 51 |
class MapIt; |
| 52 | 52 |
class ConstMapIt; |
| 53 | 53 |
|
| 54 | 54 |
friend class MapIt; |
| 55 | 55 |
friend class ConstMapIt; |
| 56 | 56 |
|
| 57 | 57 |
public: |
| 58 | 58 |
|
| 59 | 59 |
MapExtender(const Graph& graph) |
| 60 | 60 |
: Parent(graph) {}
|
| 61 | 61 |
|
| 62 | 62 |
MapExtender(const Graph& graph, const Value& value) |
| 63 | 63 |
: Parent(graph, value) {}
|
| 64 | 64 |
|
| 65 | 65 |
MapExtender& operator=(const MapExtender& cmap) {
|
| 66 | 66 |
return operator=<MapExtender>(cmap); |
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 | 69 |
template <typename CMap> |
| 70 | 70 |
MapExtender& operator=(const CMap& cmap) {
|
| 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 |
|
| 83 | 83 |
MapIt(Invalid i) : Parent(i) { }
|
| 84 | 84 |
|
| 85 | 85 |
explicit MapIt(Map& _map) : map(_map) {
|
| 86 | 86 |
map.notifier()->first(*this); |
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 | 89 |
MapIt(const Map& _map, const Item& item) |
| 90 | 90 |
: Parent(item), map(_map) {}
|
| 91 | 91 |
|
| 92 | 92 |
MapIt& operator++() {
|
| 93 | 93 |
map.notifier()->next(*this); |
| 94 | 94 |
return *this; |
| 95 | 95 |
} |
| 96 | 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 | 102 |
return map[*this]; |
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
void set(const Value& value) {
|
| 106 | 106 |
map.set(*this, value); |
| 107 | 107 |
} |
| 108 | 108 |
|
| 109 | 109 |
protected: |
| 110 | 110 |
Map& map; |
| 111 | 111 |
|
| 112 | 112 |
}; |
| 113 | 113 |
|
| 114 | 114 |
class ConstMapIt : public Item {
|
| 115 | 115 |
public: |
| 116 | 116 |
|
| 117 | 117 |
typedef Item Parent; |
| 118 | 118 |
|
| 119 | 119 |
typedef typename Map::Value Value; |
| 120 | 120 |
|
| 121 | 121 |
ConstMapIt() {}
|
| 122 | 122 |
|
| 123 | 123 |
ConstMapIt(Invalid i) : Parent(i) { }
|
| 124 | 124 |
|
| 125 | 125 |
explicit ConstMapIt(Map& _map) : map(_map) {
|
| 126 | 126 |
map.notifier()->first(*this); |
| 127 | 127 |
} |
| 128 | 128 |
|
| 129 | 129 |
ConstMapIt(const Map& _map, const Item& item) |
| 130 | 130 |
: Parent(item), map(_map) {}
|
| 131 | 131 |
|
| 132 | 132 |
ConstMapIt& operator++() {
|
| 133 | 133 |
map.notifier()->next(*this); |
| 134 | 134 |
return *this; |
| 135 | 135 |
} |
| 136 | 136 |
|
| 137 | 137 |
typename MapTraits<Map>::ConstReturnValue operator*() const {
|
| 138 | 138 |
return map[*this]; |
| 139 | 139 |
} |
| 140 | 140 |
|
| 141 | 141 |
protected: |
| 142 | 142 |
const Map& map; |
| 143 | 143 |
}; |
| 144 | 144 |
|
| 145 | 145 |
class ItemIt : public Item {
|
| 146 | 146 |
public: |
| 147 | 147 |
|
| 148 | 148 |
typedef Item Parent; |
| 149 | 149 |
|
| 150 | 150 |
ItemIt() {}
|
| 151 | 151 |
|
| 152 | 152 |
ItemIt(Invalid i) : Parent(i) { }
|
| 153 | 153 |
|
| 154 | 154 |
explicit ItemIt(Map& _map) : map(_map) {
|
| 155 | 155 |
map.notifier()->first(*this); |
| 156 | 156 |
} |
| 157 | 157 |
|
| 158 | 158 |
ItemIt(const Map& _map, const Item& item) |
| 159 | 159 |
: Parent(item), map(_map) {}
|
| 160 | 160 |
|
| 161 | 161 |
ItemIt& operator++() {
|
| 162 | 162 |
map.notifier()->next(*this); |
| 163 | 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> |
| 176 | 176 |
class SubMapExtender : public _Map {
|
| 177 | 177 |
public: |
| 178 | 178 |
|
| 179 | 179 |
typedef _Map Parent; |
| 180 | 180 |
typedef SubMapExtender Map; |
| 181 | 181 |
|
| 182 | 182 |
typedef _Graph Graph; |
| 183 | 183 |
|
| 184 | 184 |
typedef typename Parent::Key Item; |
| 185 | 185 |
|
| 186 | 186 |
typedef typename Parent::Key Key; |
| 187 | 187 |
typedef typename Parent::Value Value; |
| 188 | 188 |
|
| 189 | 189 |
class MapIt; |
| 190 | 190 |
class ConstMapIt; |
| 191 | 191 |
|
| 192 | 192 |
friend class MapIt; |
| 193 | 193 |
friend class ConstMapIt; |
| 194 | 194 |
|
| 195 | 195 |
public: |
| 196 | 196 |
|
| 197 | 197 |
SubMapExtender(const Graph& _graph) |
| 1 | 1 |
|
| 2 | 2 |
/* -*- C++ -*- |
| 3 | 3 |
* |
| 4 | 4 |
* This file is a part of LEMON, a generic C++ optimization library |
| 5 | 5 |
* |
| 6 |
* Copyright (C) 2003- |
|
| 6 |
* Copyright (C) 2003-2008 |
|
| 7 | 7 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 8 | 8 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 9 | 9 |
* |
| 10 | 10 |
* Permission to use, modify and distribute this software is granted |
| 11 | 11 |
* provided that this copyright notice appears in all copies. For |
| 12 | 12 |
* precise terms see the accompanying LICENSE file. |
| 13 | 13 |
* |
| 14 | 14 |
* This software is provided "AS IS" with no warranty of any kind, |
| 15 | 15 |
* express or implied, and with no claim as to its suitability for any |
| 16 | 16 |
* purpose. |
| 17 | 17 |
* |
| 18 | 18 |
*/ |
| 19 | 19 |
|
| 20 | 20 |
#ifndef LEMON_BITS_TRAITS_H |
| 21 | 21 |
#define LEMON_BITS_TRAITS_H |
| 22 | 22 |
|
| 23 | 23 |
#include <lemon/bits/utility.h> |
| 24 | 24 |
|
| 25 | 25 |
///\file |
| 26 | 26 |
///\brief Traits for graphs and maps |
| 27 | 27 |
/// |
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
template <typename _Graph, typename _Item> |
| 31 | 31 |
class ItemSetTraits {};
|
| 32 | 32 |
|
| 33 | 33 |
|
| 34 | 34 |
template <typename Graph, typename Enable = void> |
| 35 | 35 |
struct NodeNotifierIndicator {
|
| 36 | 36 |
typedef InvalidType Type; |
| 37 | 37 |
}; |
| 38 | 38 |
template <typename Graph> |
| 39 | 39 |
struct NodeNotifierIndicator< |
| 40 | 40 |
Graph, |
| 41 | 41 |
typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type |
| 42 | 42 |
> {
|
| 43 | 43 |
typedef typename Graph::NodeNotifier Type; |
| 44 | 44 |
}; |
| 45 | 45 |
|
| 46 | 46 |
template <typename _Graph> |
| 47 | 47 |
class ItemSetTraits<_Graph, typename _Graph::Node> {
|
| 48 | 48 |
public: |
| 49 | 49 |
|
| 50 | 50 |
typedef _Graph Graph; |
| 51 | 51 |
|
| 52 | 52 |
typedef typename Graph::Node Item; |
| 53 | 53 |
typedef typename Graph::NodeIt ItemIt; |
| 54 | 54 |
|
| 55 | 55 |
typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier; |
| 56 | 56 |
|
| 57 | 57 |
template <typename _Value> |
| 58 | 58 |
class Map : public Graph::template NodeMap<_Value> {
|
| 59 | 59 |
public: |
| 60 | 60 |
typedef typename Graph::template NodeMap<_Value> Parent; |
| 61 | 61 |
typedef typename Graph::template NodeMap<_Value> Type; |
| 62 | 62 |
typedef typename Parent::Value Value; |
| 63 | 63 |
|
| 64 | 64 |
Map(const Graph& _digraph) : Parent(_digraph) {}
|
| 65 | 65 |
Map(const Graph& _digraph, const Value& _value) |
| 66 | 66 |
: Parent(_digraph, _value) {}
|
| 67 | 67 |
|
| 68 | 68 |
}; |
| 69 | 69 |
|
| 70 | 70 |
}; |
| 71 | 71 |
|
| 72 | 72 |
template <typename Graph, typename Enable = void> |
| 73 | 73 |
struct ArcNotifierIndicator {
|
| 74 | 74 |
typedef InvalidType Type; |
| 75 | 75 |
}; |
| 76 | 76 |
template <typename Graph> |
| 77 | 77 |
struct ArcNotifierIndicator< |
| 78 | 78 |
Graph, |
| 79 | 79 |
typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type |
| 80 | 80 |
> {
|
| 81 | 81 |
typedef typename Graph::ArcNotifier Type; |
| 82 | 82 |
}; |
| 83 | 83 |
|
| 84 | 84 |
template <typename _Graph> |
| 85 | 85 |
class ItemSetTraits<_Graph, typename _Graph::Arc> {
|
| 86 | 86 |
public: |
| 87 | 87 |
|
| 88 | 88 |
typedef _Graph Graph; |
| 89 | 89 |
|
| 90 | 90 |
typedef typename Graph::Arc Item; |
| 91 | 91 |
typedef typename Graph::ArcIt ItemIt; |
| 92 | 92 |
|
| 93 | 93 |
typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier; |
| 94 | 94 |
|
| 95 | 95 |
template <typename _Value> |
| 96 | 96 |
class Map : public Graph::template ArcMap<_Value> {
|
| 97 | 97 |
public: |
| 98 | 98 |
typedef typename Graph::template ArcMap<_Value> Parent; |
| 99 | 99 |
typedef typename Graph::template ArcMap<_Value> Type; |
| 100 | 100 |
typedef typename Parent::Value Value; |
| 101 | 101 |
|
| 102 | 102 |
Map(const Graph& _digraph) : Parent(_digraph) {}
|
| 103 | 103 |
Map(const Graph& _digraph, const Value& _value) |
| 104 | 104 |
: Parent(_digraph, _value) {}
|
| 105 | 105 |
}; |
| 106 | 106 |
|
| 107 | 107 |
}; |
| 108 | 108 |
|
| 109 | 109 |
template <typename Graph, typename Enable = void> |
| 110 | 110 |
struct EdgeNotifierIndicator {
|
| 111 | 111 |
typedef InvalidType Type; |
| 112 | 112 |
}; |
| 113 | 113 |
template <typename Graph> |
| 114 | 114 |
struct EdgeNotifierIndicator< |
| 115 | 115 |
Graph, |
| 116 | 116 |
typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type |
| 117 | 117 |
> {
|
| 118 | 118 |
typedef typename Graph::EdgeNotifier Type; |
| 119 | 119 |
}; |
| 120 | 120 |
|
| 121 | 121 |
template <typename _Graph> |
| 122 | 122 |
class ItemSetTraits<_Graph, typename _Graph::Edge> {
|
| 123 | 123 |
public: |
| 124 | 124 |
|
| 125 | 125 |
typedef _Graph Graph; |
| 126 | 126 |
|
| 127 | 127 |
typedef typename Graph::Edge Item; |
| 128 | 128 |
typedef typename Graph::EdgeIt ItemIt; |
| 129 | 129 |
|
| 130 | 130 |
typedef typename EdgeNotifierIndicator<Graph>::Type ItemNotifier; |
| 131 | 131 |
|
| 132 | 132 |
template <typename _Value> |
| 133 | 133 |
class Map : public Graph::template EdgeMap<_Value> {
|
| 134 | 134 |
public: |
| 135 | 135 |
typedef typename Graph::template EdgeMap<_Value> Parent; |
| 136 | 136 |
typedef typename Graph::template EdgeMap<_Value> Type; |
| 137 | 137 |
typedef typename Parent::Value Value; |
| 138 | 138 |
|
| 139 | 139 |
Map(const Graph& _digraph) : Parent(_digraph) {}
|
| 140 | 140 |
Map(const Graph& _digraph, const Value& _value) |
| 141 | 141 |
: Parent(_digraph, _value) {}
|
| 142 | 142 |
}; |
| 143 | 143 |
|
| 144 | 144 |
}; |
| 145 | 145 |
|
| 146 | 146 |
template <typename Map, typename Enable = void> |
| 147 | 147 |
struct MapTraits {
|
| 148 | 148 |
typedef False ReferenceMapTag; |
| 149 | 149 |
|
| 150 | 150 |
typedef typename Map::Key Key; |
| 151 | 151 |
typedef typename Map::Value Value; |
| 152 | 152 |
|
| 153 | 153 |
typedef const Value ConstReturnValue; |
| 154 | 154 |
typedef const Value ReturnValue; |
| 155 | 155 |
}; |
| 156 | 156 |
|
| 157 | 157 |
template <typename Map> |
| 158 | 158 |
struct MapTraits< |
| 159 | 159 |
Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > |
| 160 | 160 |
{
|
| 161 | 161 |
typedef True ReferenceMapTag; |
| 162 | 162 |
|
| 163 | 163 |
typedef typename Map::Key Key; |
| 164 | 164 |
typedef typename Map::Value Value; |
| 165 | 165 |
|
| 166 | 166 |
typedef typename Map::ConstReference ConstReturnValue; |
| 167 | 167 |
typedef typename Map::Reference ReturnValue; |
| 168 | 168 |
|
| 169 | 169 |
typedef typename Map::ConstReference ConstReference; |
| 170 | 170 |
typedef typename Map::Reference Reference; |
| 171 | 171 |
}; |
| 172 | 172 |
|
| 173 | 173 |
template <typename MatrixMap, typename Enable = void> |
| 174 | 174 |
struct MatrixMapTraits {
|
| 175 | 175 |
typedef False ReferenceMapTag; |
| 176 | 176 |
|
| 177 | 177 |
typedef typename MatrixMap::FirstKey FirstKey; |
| 178 | 178 |
typedef typename MatrixMap::SecondKey SecondKey; |
| 179 | 179 |
typedef typename MatrixMap::Value Value; |
| 180 | 180 |
|
| 181 | 181 |
typedef const Value ConstReturnValue; |
| 182 | 182 |
typedef const Value ReturnValue; |
| 183 | 183 |
}; |
| 184 | 184 |
|
| 185 | 185 |
template <typename MatrixMap> |
| 186 | 186 |
struct MatrixMapTraits< |
| 187 | 187 |
MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, |
| 188 | 188 |
void>::type > |
| 189 | 189 |
{
|
| 190 | 190 |
typedef True ReferenceMapTag; |
| 191 | 191 |
|
| 192 | 192 |
typedef typename MatrixMap::FirstKey FirstKey; |
| 193 | 193 |
typedef typename MatrixMap::SecondKey SecondKey; |
| 194 | 194 |
typedef typename MatrixMap::Value Value; |
| 195 | 195 |
|
| 196 | 196 |
typedef typename MatrixMap::ConstReference ConstReturnValue; |
| 197 | 197 |
typedef typename MatrixMap::Reference ReturnValue; |
| 198 | 198 |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_VECTOR_MAP_H |
| 20 | 20 |
#define LEMON_BITS_VECTOR_MAP_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <algorithm> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/bits/traits.h> |
| 26 | 26 |
#include <lemon/bits/utility.h> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/bits/alteration_notifier.h> |
| 29 | 29 |
|
| 30 | 30 |
#include <lemon/concept_check.h> |
| 31 | 31 |
#include <lemon/concepts/maps.h> |
| 32 | 32 |
|
| 33 | 33 |
///\ingroup graphbits |
| 34 | 34 |
/// |
| 35 | 35 |
///\file |
| 36 | 36 |
///\brief Vector based graph maps. |
| 37 | 37 |
namespace lemon {
|
| 38 | 38 |
|
| 39 | 39 |
/// \ingroup graphbits |
| 40 | 40 |
/// |
| 41 | 41 |
/// \brief Graph map based on the std::vector storage. |
| 42 | 42 |
/// |
| 43 | 43 |
/// The VectorMap template class is graph map structure what |
| 44 | 44 |
/// automatically updates the map when a key is added to or erased from |
| 45 | 45 |
/// the map. This map type uses the std::vector to store the values. |
| 46 | 46 |
/// |
| 47 | 47 |
/// \param Notifier The AlterationNotifier that will notify this map. |
| 48 | 48 |
/// \param Item The item type of the graph items. |
| 49 | 49 |
/// \param Value The value type of the map. |
| 50 | 50 |
/// |
| 51 | 51 |
/// \author Balazs Dezso |
| 52 | 52 |
template <typename _Graph, typename _Item, typename _Value> |
| 53 | 53 |
class VectorMap |
| 54 | 54 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
|
| 55 | 55 |
private: |
| 56 | 56 |
|
| 57 | 57 |
/// The container type of the map. |
| 58 | 58 |
typedef std::vector<_Value> Container; |
| 59 | 59 |
|
| 60 | 60 |
public: |
| 61 | 61 |
|
| 62 | 62 |
/// The graph type of the map. |
| 63 | 63 |
typedef _Graph Graph; |
| 64 | 64 |
/// The item type of the map. |
| 65 | 65 |
typedef _Item Item; |
| 66 | 66 |
/// The reference map tag. |
| 67 | 67 |
typedef True ReferenceMapTag; |
| 68 | 68 |
|
| 69 | 69 |
/// The key type of the map. |
| 70 | 70 |
typedef _Item Key; |
| 71 | 71 |
/// The value type of the map. |
| 72 | 72 |
typedef _Value Value; |
| 73 | 73 |
|
| 74 | 74 |
/// The notifier type. |
| 75 | 75 |
typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; |
| 76 | 76 |
|
| 77 | 77 |
/// The map type. |
| 78 | 78 |
typedef VectorMap Map; |
| 79 | 79 |
/// The base class of the map. |
| 80 | 80 |
typedef typename Notifier::ObserverBase Parent; |
| 81 | 81 |
|
| 82 | 82 |
/// The reference type of the map; |
| 83 | 83 |
typedef typename Container::reference Reference; |
| 84 | 84 |
/// The const reference type of the map; |
| 85 | 85 |
typedef typename Container::const_reference ConstReference; |
| 86 | 86 |
|
| 87 | 87 |
|
| 88 | 88 |
/// \brief Constructor to attach the new map into the notifier. |
| 89 | 89 |
/// |
| 90 | 90 |
/// It constructs a map and attachs it into the notifier. |
| 91 | 91 |
/// It adds all the items of the graph to the map. |
| 92 | 92 |
VectorMap(const Graph& graph) {
|
| 93 | 93 |
Parent::attach(graph.notifier(Item())); |
| 94 | 94 |
container.resize(Parent::notifier()->maxId() + 1); |
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
/// \brief Constructor uses given value to initialize the map. |
| 98 | 98 |
/// |
| 99 | 99 |
/// It constructs a map uses a given value to initialize the map. |
| 100 | 100 |
/// It adds all the items of the graph to the map. |
| 101 | 101 |
VectorMap(const Graph& graph, const Value& value) {
|
| 102 | 102 |
Parent::attach(graph.notifier(Item())); |
| 103 | 103 |
container.resize(Parent::notifier()->maxId() + 1, value); |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
/// \brief Copy constructor |
| 107 | 107 |
/// |
| 108 | 108 |
/// Copy constructor. |
| 109 | 109 |
VectorMap(const VectorMap& _copy) : Parent() {
|
| 110 | 110 |
if (_copy.attached()) {
|
| 111 | 111 |
Parent::attach(*_copy.notifier()); |
| 112 | 112 |
container = _copy.container; |
| 113 | 113 |
} |
| 114 | 114 |
} |
| 115 | 115 |
|
| 116 | 116 |
/// \brief Assign operator. |
| 117 | 117 |
/// |
| 118 | 118 |
/// This operator assigns for each item in the map the |
| 119 | 119 |
/// value mapped to the same item in the copied map. |
| 120 | 120 |
/// The parameter map should be indiced with the same |
| 121 | 121 |
/// itemset because this assign operator does not change |
| 122 | 122 |
/// the container of the map. |
| 123 | 123 |
VectorMap& operator=(const VectorMap& cmap) {
|
| 124 | 124 |
return operator=<VectorMap>(cmap); |
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 | 127 |
|
| 128 | 128 |
/// \brief Template assign operator. |
| 129 | 129 |
/// |
| 130 | 130 |
/// The given parameter should be conform to the ReadMap |
| 131 | 131 |
/// concecpt and could be indiced by the current item set of |
| 132 | 132 |
/// the NodeMap. In this case the value for each item |
| 133 | 133 |
/// is assigned by the value of the given ReadMap. |
| 134 | 134 |
template <typename CMap> |
| 135 | 135 |
VectorMap& operator=(const CMap& cmap) {
|
| 136 | 136 |
checkConcept<concepts::ReadMap<Key, _Value>, CMap>(); |
| 137 | 137 |
const typename Parent::Notifier* nf = Parent::notifier(); |
| 138 | 138 |
Item it; |
| 139 | 139 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 140 | 140 |
set(it, cmap[it]); |
| 141 | 141 |
} |
| 142 | 142 |
return *this; |
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 | 145 |
public: |
| 146 | 146 |
|
| 147 | 147 |
/// \brief The subcript operator. |
| 148 | 148 |
/// |
| 149 | 149 |
/// The subscript operator. The map can be subscripted by the |
| 150 | 150 |
/// actual items of the graph. |
| 151 | 151 |
Reference operator[](const Key& key) {
|
| 152 | 152 |
return container[Parent::notifier()->id(key)]; |
| 153 | 153 |
} |
| 154 | 154 |
|
| 155 | 155 |
/// \brief The const subcript operator. |
| 156 | 156 |
/// |
| 157 | 157 |
/// The const subscript operator. The map can be subscripted by the |
| 158 | 158 |
/// actual items of the graph. |
| 159 | 159 |
ConstReference operator[](const Key& key) const {
|
| 160 | 160 |
return container[Parent::notifier()->id(key)]; |
| 161 | 161 |
} |
| 162 | 162 |
|
| 163 | 163 |
|
| 164 | 164 |
/// \brief The setter function of the map. |
| 165 | 165 |
/// |
| 166 | 166 |
/// It the same as operator[](key) = value expression. |
| 167 | 167 |
void set(const Key& key, const Value& value) {
|
| 168 | 168 |
(*this)[key] = value; |
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 | 171 |
protected: |
| 172 | 172 |
|
| 173 | 173 |
/// \brief Adds a new key to the map. |
| 174 | 174 |
/// |
| 175 | 175 |
/// It adds a new key to the map. It called by the observer notifier |
| 176 | 176 |
/// and it overrides the add() member function of the observer base. |
| 177 | 177 |
virtual void add(const Key& key) {
|
| 178 | 178 |
int id = Parent::notifier()->id(key); |
| 179 | 179 |
if (id >= int(container.size())) {
|
| 180 | 180 |
container.resize(id + 1); |
| 181 | 181 |
} |
| 182 | 182 |
} |
| 183 | 183 |
|
| 184 | 184 |
/// \brief Adds more new keys to the map. |
| 185 | 185 |
/// |
| 186 | 186 |
/// It adds more new keys to the map. It called by the observer notifier |
| 187 | 187 |
/// and it overrides the add() member function of the observer base. |
| 188 | 188 |
virtual void add(const std::vector<Key>& keys) {
|
| 189 | 189 |
int max = container.size() - 1; |
| 190 | 190 |
for (int i = 0; i < int(keys.size()); ++i) {
|
| 191 | 191 |
int id = Parent::notifier()->id(keys[i]); |
| 192 | 192 |
if (id >= max) {
|
| 193 | 193 |
max = id; |
| 194 | 194 |
} |
| 195 | 195 |
} |
| 196 | 196 |
container.resize(max + 1); |
| 197 | 197 |
} |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_CONCEPT_DIGRAPH_H |
| 20 | 20 |
#define LEMON_CONCEPT_DIGRAPH_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup graph_concepts |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief The concept of directed graphs. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/bits/invalid.h> |
| 27 | 27 |
#include <lemon/bits/utility.h> |
| 28 | 28 |
#include <lemon/concepts/maps.h> |
| 29 | 29 |
#include <lemon/concept_check.h> |
| 30 | 30 |
#include <lemon/concepts/graph_components.h> |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
namespace concepts {
|
| 34 | 34 |
|
| 35 | 35 |
/// \ingroup graph_concepts |
| 36 | 36 |
/// |
| 37 | 37 |
/// \brief Class describing the concept of directed graphs. |
| 38 | 38 |
/// |
| 39 | 39 |
/// This class describes the \ref concept "concept" of the |
| 40 | 40 |
/// immutable directed digraphs. |
| 41 | 41 |
/// |
| 42 | 42 |
/// Note that actual digraph implementation like @ref ListDigraph or |
| 43 | 43 |
/// @ref SmartDigraph may have several additional functionality. |
| 44 | 44 |
/// |
| 45 | 45 |
/// \sa concept |
| 46 | 46 |
class Digraph {
|
| 47 | 47 |
private: |
| 48 | 48 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
| 49 | 49 |
|
| 50 | 50 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
| 51 | 51 |
/// |
| 52 | 52 |
Digraph(const Digraph &) {};
|
| 53 | 53 |
///\brief Assignment of \ref Digraph "Digraph"s to another ones are |
| 54 | 54 |
///\e not allowed. Use DigraphCopy() instead. |
| 55 | 55 |
|
| 56 | 56 |
///Assignment of \ref Digraph "Digraph"s to another ones are |
| 57 | 57 |
///\e not allowed. Use DigraphCopy() instead. |
| 58 | 58 |
|
| 59 | 59 |
void operator=(const Digraph &) {}
|
| 60 | 60 |
public: |
| 61 | 61 |
///\e |
| 62 | 62 |
|
| 63 | 63 |
/// Defalult constructor. |
| 64 | 64 |
|
| 65 | 65 |
/// Defalult constructor. |
| 66 | 66 |
/// |
| 67 | 67 |
Digraph() { }
|
| 68 | 68 |
/// Class for identifying a node of the digraph |
| 69 | 69 |
|
| 70 | 70 |
/// This class identifies a node of the digraph. It also serves |
| 71 | 71 |
/// as a base class of the node iterators, |
| 72 | 72 |
/// thus they will convert to this type. |
| 73 | 73 |
class Node {
|
| 74 | 74 |
public: |
| 75 | 75 |
/// Default constructor |
| 76 | 76 |
|
| 77 | 77 |
/// @warning The default constructor sets the iterator |
| 78 | 78 |
/// to an undefined value. |
| 79 | 79 |
Node() { }
|
| 80 | 80 |
/// Copy constructor. |
| 81 | 81 |
|
| 82 | 82 |
/// Copy constructor. |
| 83 | 83 |
/// |
| 84 | 84 |
Node(const Node&) { }
|
| 85 | 85 |
|
| 86 | 86 |
/// Invalid constructor \& conversion. |
| 87 | 87 |
|
| 88 | 88 |
/// This constructor initializes the iterator to be invalid. |
| 89 | 89 |
/// \sa Invalid for more details. |
| 90 | 90 |
Node(Invalid) { }
|
| 91 | 91 |
/// Equality operator |
| 92 | 92 |
|
| 93 | 93 |
/// Two iterators are equal if and only if they point to the |
| 94 | 94 |
/// same object or both are invalid. |
| 95 | 95 |
bool operator==(Node) const { return true; }
|
| 96 | 96 |
|
| 97 | 97 |
/// Inequality operator |
| 98 | 98 |
|
| 99 | 99 |
/// \sa operator==(Node n) |
| 100 | 100 |
/// |
| 101 | 101 |
bool operator!=(Node) const { return true; }
|
| 102 | 102 |
|
| 103 | 103 |
/// Artificial ordering operator. |
| 104 | 104 |
|
| 105 | 105 |
/// To allow the use of digraph descriptors as key type in std::map or |
| 106 | 106 |
/// similar associative container we require this. |
| 107 | 107 |
/// |
| 108 | 108 |
/// \note This operator only have to define some strict ordering of |
| 109 | 109 |
/// the items; this order has nothing to do with the iteration |
| 110 | 110 |
/// ordering of the items. |
| 111 | 111 |
bool operator<(Node) const { return false; }
|
| 112 | 112 |
|
| 113 | 113 |
}; |
| 114 | 114 |
|
| 115 | 115 |
/// This iterator goes through each node. |
| 116 | 116 |
|
| 117 | 117 |
/// This iterator goes through each node. |
| 118 | 118 |
/// Its usage is quite simple, for example you can count the number |
| 119 | 119 |
/// of nodes in digraph \c g of type \c Digraph like this: |
| 120 | 120 |
///\code |
| 121 | 121 |
/// int count=0; |
| 122 | 122 |
/// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count; |
| 123 | 123 |
///\endcode |
| 124 | 124 |
class NodeIt : public Node {
|
| 125 | 125 |
public: |
| 126 | 126 |
/// Default constructor |
| 127 | 127 |
|
| 128 | 128 |
/// @warning The default constructor sets the iterator |
| 129 | 129 |
/// to an undefined value. |
| 130 | 130 |
NodeIt() { }
|
| 131 | 131 |
/// Copy constructor. |
| 132 | 132 |
|
| 133 | 133 |
/// Copy constructor. |
| 134 | 134 |
/// |
| 135 | 135 |
NodeIt(const NodeIt& n) : Node(n) { }
|
| 136 | 136 |
/// Invalid constructor \& conversion. |
| 137 | 137 |
|
| 138 | 138 |
/// Initialize the iterator to be invalid. |
| 139 | 139 |
/// \sa Invalid for more details. |
| 140 | 140 |
NodeIt(Invalid) { }
|
| 141 | 141 |
/// Sets the iterator to the first node. |
| 142 | 142 |
|
| 143 | 143 |
/// Sets the iterator to the first node of \c g. |
| 144 | 144 |
/// |
| 145 | 145 |
NodeIt(const Digraph&) { }
|
| 146 | 146 |
/// Node -> NodeIt conversion. |
| 147 | 147 |
|
| 148 | 148 |
/// Sets the iterator to the node of \c the digraph pointed by |
| 149 | 149 |
/// the trivial iterator. |
| 150 | 150 |
/// This feature necessitates that each time we |
| 151 | 151 |
/// iterate the arc-set, the iteration order is the same. |
| 152 | 152 |
NodeIt(const Digraph&, const Node&) { }
|
| 153 | 153 |
/// Next node. |
| 154 | 154 |
|
| 155 | 155 |
/// Assign the iterator to the next node. |
| 156 | 156 |
/// |
| 157 | 157 |
NodeIt& operator++() { return *this; }
|
| 158 | 158 |
}; |
| 159 | 159 |
|
| 160 | 160 |
|
| 161 | 161 |
/// Class for identifying an arc of the digraph |
| 162 | 162 |
|
| 163 | 163 |
/// This class identifies an arc of the digraph. It also serves |
| 164 | 164 |
/// as a base class of the arc iterators, |
| 165 | 165 |
/// thus they will convert to this type. |
| 166 | 166 |
class Arc {
|
| 167 | 167 |
public: |
| 168 | 168 |
/// Default constructor |
| 169 | 169 |
|
| 170 | 170 |
/// @warning The default constructor sets the iterator |
| 171 | 171 |
/// to an undefined value. |
| 172 | 172 |
Arc() { }
|
| 173 | 173 |
/// Copy constructor. |
| 174 | 174 |
|
| 175 | 175 |
/// Copy constructor. |
| 176 | 176 |
/// |
| 177 | 177 |
Arc(const Arc&) { }
|
| 178 | 178 |
/// Initialize the iterator to be invalid. |
| 179 | 179 |
|
| 180 | 180 |
/// Initialize the iterator to be invalid. |
| 181 | 181 |
/// |
| 182 | 182 |
Arc(Invalid) { }
|
| 183 | 183 |
/// Equality operator |
| 184 | 184 |
|
| 185 | 185 |
/// Two iterators are equal if and only if they point to the |
| 186 | 186 |
/// same object or both are invalid. |
| 187 | 187 |
bool operator==(Arc) const { return true; }
|
| 188 | 188 |
/// Inequality operator |
| 189 | 189 |
|
| 190 | 190 |
/// \sa operator==(Arc n) |
| 191 | 191 |
/// |
| 192 | 192 |
bool operator!=(Arc) const { return true; }
|
| 193 | 193 |
|
| 194 | 194 |
/// Artificial ordering operator. |
| 195 | 195 |
|
| 196 | 196 |
/// To allow the use of digraph descriptors as key type in std::map or |
| 197 | 197 |
/// similar associative container we require this. |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup graph_concepts |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief The concept of Undirected Graphs. |
| 22 | 22 |
|
| 23 | 23 |
#ifndef LEMON_CONCEPT_GRAPH_H |
| 24 | 24 |
#define LEMON_CONCEPT_GRAPH_H |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/concepts/graph_components.h> |
| 27 | 27 |
#include <lemon/concepts/graph.h> |
| 28 | 28 |
#include <lemon/bits/utility.h> |
| 29 | 29 |
|
| 30 | 30 |
namespace lemon {
|
| 31 | 31 |
namespace concepts {
|
| 32 | 32 |
|
| 33 | 33 |
/// \ingroup graph_concepts |
| 34 | 34 |
/// |
| 35 | 35 |
/// \brief Class describing the concept of Undirected Graphs. |
| 36 | 36 |
/// |
| 37 | 37 |
/// This class describes the common interface of all Undirected |
| 38 | 38 |
/// Graphs. |
| 39 | 39 |
/// |
| 40 | 40 |
/// As all concept describing classes it provides only interface |
| 41 | 41 |
/// without any sensible implementation. So any algorithm for |
| 42 | 42 |
/// undirected graph should compile with this class, but it will not |
| 43 | 43 |
/// run properly, of course. |
| 44 | 44 |
/// |
| 45 | 45 |
/// The LEMON undirected graphs also fulfill the concept of |
| 46 | 46 |
/// directed graphs (\ref lemon::concepts::Digraph "Digraph |
| 47 | 47 |
/// Concept"). Each edges can be seen as two opposite |
| 48 | 48 |
/// directed arc and consequently the undirected graph can be |
| 49 | 49 |
/// seen as the direceted graph of these directed arcs. The |
| 50 | 50 |
/// Graph has the Edge inner class for the edges and |
| 51 | 51 |
/// the Arc type for the directed arcs. The Arc type is |
| 52 | 52 |
/// convertible to Edge or inherited from it so from a directed |
| 53 | 53 |
/// arc we can get the represented edge. |
| 54 | 54 |
/// |
| 55 | 55 |
/// In the sense of the LEMON each edge has a default |
| 56 | 56 |
/// direction (it should be in every computer implementation, |
| 57 | 57 |
/// because the order of edge's nodes defines an |
| 58 | 58 |
/// orientation). With the default orientation we can define that |
| 59 | 59 |
/// the directed arc is forward or backward directed. With the \c |
| 60 | 60 |
/// direction() and \c direct() function we can get the direction |
| 61 | 61 |
/// of the directed arc and we can direct an edge. |
| 62 | 62 |
/// |
| 63 | 63 |
/// The EdgeIt is an iterator for the edges. We can use |
| 64 | 64 |
/// the EdgeMap to map values for the edges. The InArcIt and |
| 65 | 65 |
/// OutArcIt iterates on the same edges but with opposite |
| 66 | 66 |
/// direction. The IncEdgeIt iterates also on the same edges |
| 67 | 67 |
/// as the OutArcIt and InArcIt but it is not convertible to Arc just |
| 68 | 68 |
/// to Edge. |
| 69 | 69 |
class Graph {
|
| 70 | 70 |
public: |
| 71 | 71 |
/// \brief The undirected graph should be tagged by the |
| 72 | 72 |
/// UndirectedTag. |
| 73 | 73 |
/// |
| 74 | 74 |
/// The undirected graph should be tagged by the UndirectedTag. This |
| 75 | 75 |
/// tag helps the enable_if technics to make compile time |
| 76 | 76 |
/// specializations for undirected graphs. |
| 77 | 77 |
typedef True UndirectedTag; |
| 78 | 78 |
|
| 79 | 79 |
/// \brief The base type of node iterators, |
| 80 | 80 |
/// or in other words, the trivial node iterator. |
| 81 | 81 |
/// |
| 82 | 82 |
/// This is the base type of each node iterator, |
| 83 | 83 |
/// thus each kind of node iterator converts to this. |
| 84 | 84 |
/// More precisely each kind of node iterator should be inherited |
| 85 | 85 |
/// from the trivial node iterator. |
| 86 | 86 |
class Node {
|
| 87 | 87 |
public: |
| 88 | 88 |
/// Default constructor |
| 89 | 89 |
|
| 90 | 90 |
/// @warning The default constructor sets the iterator |
| 91 | 91 |
/// to an undefined value. |
| 92 | 92 |
Node() { }
|
| 93 | 93 |
/// Copy constructor. |
| 94 | 94 |
|
| 95 | 95 |
/// Copy constructor. |
| 96 | 96 |
/// |
| 97 | 97 |
Node(const Node&) { }
|
| 98 | 98 |
|
| 99 | 99 |
/// Invalid constructor \& conversion. |
| 100 | 100 |
|
| 101 | 101 |
/// This constructor initializes the iterator to be invalid. |
| 102 | 102 |
/// \sa Invalid for more details. |
| 103 | 103 |
Node(Invalid) { }
|
| 104 | 104 |
/// Equality operator |
| 105 | 105 |
|
| 106 | 106 |
/// Two iterators are equal if and only if they point to the |
| 107 | 107 |
/// same object or both are invalid. |
| 108 | 108 |
bool operator==(Node) const { return true; }
|
| 109 | 109 |
|
| 110 | 110 |
/// Inequality operator |
| 111 | 111 |
|
| 112 | 112 |
/// \sa operator==(Node n) |
| 113 | 113 |
/// |
| 114 | 114 |
bool operator!=(Node) const { return true; }
|
| 115 | 115 |
|
| 116 | 116 |
/// Artificial ordering operator. |
| 117 | 117 |
|
| 118 | 118 |
/// To allow the use of graph descriptors as key type in std::map or |
| 119 | 119 |
/// similar associative container we require this. |
| 120 | 120 |
/// |
| 121 | 121 |
/// \note This operator only have to define some strict ordering of |
| 122 | 122 |
/// the items; this order has nothing to do with the iteration |
| 123 | 123 |
/// ordering of the items. |
| 124 | 124 |
bool operator<(Node) const { return false; }
|
| 125 | 125 |
|
| 126 | 126 |
}; |
| 127 | 127 |
|
| 128 | 128 |
/// This iterator goes through each node. |
| 129 | 129 |
|
| 130 | 130 |
/// This iterator goes through each node. |
| 131 | 131 |
/// Its usage is quite simple, for example you can count the number |
| 132 | 132 |
/// of nodes in graph \c g of type \c Graph like this: |
| 133 | 133 |
///\code |
| 134 | 134 |
/// int count=0; |
| 135 | 135 |
/// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; |
| 136 | 136 |
///\endcode |
| 137 | 137 |
class NodeIt : public Node {
|
| 138 | 138 |
public: |
| 139 | 139 |
/// Default constructor |
| 140 | 140 |
|
| 141 | 141 |
/// @warning The default constructor sets the iterator |
| 142 | 142 |
/// to an undefined value. |
| 143 | 143 |
NodeIt() { }
|
| 144 | 144 |
/// Copy constructor. |
| 145 | 145 |
|
| 146 | 146 |
/// Copy constructor. |
| 147 | 147 |
/// |
| 148 | 148 |
NodeIt(const NodeIt& n) : Node(n) { }
|
| 149 | 149 |
/// Invalid constructor \& conversion. |
| 150 | 150 |
|
| 151 | 151 |
/// Initialize the iterator to be invalid. |
| 152 | 152 |
/// \sa Invalid for more details. |
| 153 | 153 |
NodeIt(Invalid) { }
|
| 154 | 154 |
/// Sets the iterator to the first node. |
| 155 | 155 |
|
| 156 | 156 |
/// Sets the iterator to the first node of \c g. |
| 157 | 157 |
/// |
| 158 | 158 |
NodeIt(const Graph&) { }
|
| 159 | 159 |
/// Node -> NodeIt conversion. |
| 160 | 160 |
|
| 161 | 161 |
/// Sets the iterator to the node of \c the graph pointed by |
| 162 | 162 |
/// the trivial iterator. |
| 163 | 163 |
/// This feature necessitates that each time we |
| 164 | 164 |
/// iterate the arc-set, the iteration order is the same. |
| 165 | 165 |
NodeIt(const Graph&, const Node&) { }
|
| 166 | 166 |
/// Next node. |
| 167 | 167 |
|
| 168 | 168 |
/// Assign the iterator to the next node. |
| 169 | 169 |
/// |
| 170 | 170 |
NodeIt& operator++() { return *this; }
|
| 171 | 171 |
}; |
| 172 | 172 |
|
| 173 | 173 |
|
| 174 | 174 |
/// The base type of the edge iterators. |
| 175 | 175 |
|
| 176 | 176 |
/// The base type of the edge iterators. |
| 177 | 177 |
/// |
| 178 | 178 |
class Edge {
|
| 179 | 179 |
public: |
| 180 | 180 |
/// Default constructor |
| 181 | 181 |
|
| 182 | 182 |
/// @warning The default constructor sets the iterator |
| 183 | 183 |
/// to an undefined value. |
| 184 | 184 |
Edge() { }
|
| 185 | 185 |
/// Copy constructor. |
| 186 | 186 |
|
| 187 | 187 |
/// Copy constructor. |
| 188 | 188 |
/// |
| 189 | 189 |
Edge(const Edge&) { }
|
| 190 | 190 |
/// Initialize the iterator to be invalid. |
| 191 | 191 |
|
| 192 | 192 |
/// Initialize the iterator to be invalid. |
| 193 | 193 |
/// |
| 194 | 194 |
Edge(Invalid) { }
|
| 195 | 195 |
/// Equality operator |
| 196 | 196 |
|
| 197 | 197 |
/// Two iterators are equal if and only if they point to the |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup graph_concepts |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief The concept of graph components. |
| 22 | 22 |
|
| 23 | 23 |
|
| 24 | 24 |
#ifndef LEMON_CONCEPT_GRAPH_COMPONENTS_H |
| 25 | 25 |
#define LEMON_CONCEPT_GRAPH_COMPONENTS_H |
| 26 | 26 |
|
| 27 | 27 |
#include <lemon/bits/invalid.h> |
| 28 | 28 |
#include <lemon/concepts/maps.h> |
| 29 | 29 |
|
| 30 | 30 |
#include <lemon/bits/alteration_notifier.h> |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
namespace concepts {
|
| 34 | 34 |
|
| 35 | 35 |
/// \brief Skeleton class for graph Node and Arc types |
| 36 | 36 |
/// |
| 37 | 37 |
/// This class describes the interface of Node and Arc (and Edge |
| 38 | 38 |
/// in undirected graphs) subtypes of graph types. |
| 39 | 39 |
/// |
| 40 | 40 |
/// \note This class is a template class so that we can use it to |
| 41 | 41 |
/// create graph skeleton classes. The reason for this is than Node |
| 42 | 42 |
/// and Arc types should \em not derive from the same base class. |
| 43 | 43 |
/// For Node you should instantiate it with character 'n' and for Arc |
| 44 | 44 |
/// with 'a'. |
| 45 | 45 |
|
| 46 | 46 |
#ifndef DOXYGEN |
| 47 | 47 |
template <char _selector = '0'> |
| 48 | 48 |
#endif |
| 49 | 49 |
class GraphItem {
|
| 50 | 50 |
public: |
| 51 | 51 |
/// \brief Default constructor. |
| 52 | 52 |
/// |
| 53 | 53 |
/// \warning The default constructor is not required to set |
| 54 | 54 |
/// the item to some well-defined value. So you should consider it |
| 55 | 55 |
/// as uninitialized. |
| 56 | 56 |
GraphItem() {}
|
| 57 | 57 |
/// \brief Copy constructor. |
| 58 | 58 |
/// |
| 59 | 59 |
/// Copy constructor. |
| 60 | 60 |
/// |
| 61 | 61 |
GraphItem(const GraphItem &) {}
|
| 62 | 62 |
/// \brief Invalid constructor \& conversion. |
| 63 | 63 |
/// |
| 64 | 64 |
/// This constructor initializes the item to be invalid. |
| 65 | 65 |
/// \sa Invalid for more details. |
| 66 | 66 |
GraphItem(Invalid) {}
|
| 67 | 67 |
/// \brief Assign operator for nodes. |
| 68 | 68 |
/// |
| 69 | 69 |
/// The nodes are assignable. |
| 70 | 70 |
/// |
| 71 | 71 |
GraphItem& operator=(GraphItem const&) { return *this; }
|
| 72 | 72 |
/// \brief Equality operator. |
| 73 | 73 |
/// |
| 74 | 74 |
/// Two iterators are equal if and only if they represents the |
| 75 | 75 |
/// same node in the graph or both are invalid. |
| 76 | 76 |
bool operator==(GraphItem) const { return false; }
|
| 77 | 77 |
/// \brief Inequality operator. |
| 78 | 78 |
/// |
| 79 | 79 |
/// \sa operator==(const Node& n) |
| 80 | 80 |
/// |
| 81 | 81 |
bool operator!=(GraphItem) const { return false; }
|
| 82 | 82 |
|
| 83 | 83 |
/// \brief Artificial ordering operator. |
| 84 | 84 |
/// |
| 85 | 85 |
/// To allow the use of graph descriptors as key type in std::map or |
| 86 | 86 |
/// similar associative container we require this. |
| 87 | 87 |
/// |
| 88 | 88 |
/// \note This operator only have to define some strict ordering of |
| 89 | 89 |
/// the items; this order has nothing to do with the iteration |
| 90 | 90 |
/// ordering of the items. |
| 91 | 91 |
bool operator<(GraphItem) const { return false; }
|
| 92 | 92 |
|
| 93 | 93 |
template<typename _GraphItem> |
| 94 | 94 |
struct Constraints {
|
| 95 | 95 |
void constraints() {
|
| 96 | 96 |
_GraphItem i1; |
| 97 | 97 |
_GraphItem i2 = i1; |
| 98 | 98 |
_GraphItem i3 = INVALID; |
| 99 | 99 |
|
| 100 | 100 |
i1 = i2 = i3; |
| 101 | 101 |
|
| 102 | 102 |
bool b; |
| 103 | 103 |
// b = (ia == ib) && (ia != ib) && (ia < ib); |
| 104 | 104 |
b = (ia == ib) && (ia != ib); |
| 105 | 105 |
b = (ia == INVALID) && (ib != INVALID); |
| 106 | 106 |
b = (ia < ib); |
| 107 | 107 |
} |
| 108 | 108 |
|
| 109 | 109 |
const _GraphItem &ia; |
| 110 | 110 |
const _GraphItem &ib; |
| 111 | 111 |
}; |
| 112 | 112 |
}; |
| 113 | 113 |
|
| 114 | 114 |
/// \brief An empty base directed graph class. |
| 115 | 115 |
/// |
| 116 | 116 |
/// This class provides the minimal set of features needed for a |
| 117 | 117 |
/// directed graph structure. All digraph concepts have to be |
| 118 | 118 |
/// conform to this base directed graph. It just provides types |
| 119 | 119 |
/// for nodes and arcs and functions to get the source and the |
| 120 | 120 |
/// target of the arcs. |
| 121 | 121 |
class BaseDigraphComponent {
|
| 122 | 122 |
public: |
| 123 | 123 |
|
| 124 | 124 |
typedef BaseDigraphComponent Digraph; |
| 125 | 125 |
|
| 126 | 126 |
/// \brief Node class of the digraph. |
| 127 | 127 |
/// |
| 128 | 128 |
/// This class represents the Nodes of the digraph. |
| 129 | 129 |
/// |
| 130 | 130 |
typedef GraphItem<'n'> Node; |
| 131 | 131 |
|
| 132 | 132 |
/// \brief Arc class of the digraph. |
| 133 | 133 |
/// |
| 134 | 134 |
/// This class represents the Arcs of the digraph. |
| 135 | 135 |
/// |
| 136 | 136 |
typedef GraphItem<'e'> Arc; |
| 137 | 137 |
|
| 138 | 138 |
/// \brief Gives back the target node of an arc. |
| 139 | 139 |
/// |
| 140 | 140 |
/// Gives back the target node of an arc. |
| 141 | 141 |
/// |
| 142 | 142 |
Node target(const Arc&) const { return INVALID;}
|
| 143 | 143 |
|
| 144 | 144 |
/// \brief Gives back the source node of an arc. |
| 145 | 145 |
/// |
| 146 | 146 |
/// Gives back the source node of an arc. |
| 147 | 147 |
/// |
| 148 | 148 |
Node source(const Arc&) const { return INVALID;}
|
| 149 | 149 |
|
| 150 | 150 |
/// \brief Gives back the opposite node on the given arc. |
| 151 | 151 |
/// |
| 152 | 152 |
/// Gives back the opposite node on the given arc. |
| 153 | 153 |
Node oppositeNode(const Node&, const Arc&) const {
|
| 154 | 154 |
return INVALID; |
| 155 | 155 |
} |
| 156 | 156 |
|
| 157 | 157 |
template <typename _Digraph> |
| 158 | 158 |
struct Constraints {
|
| 159 | 159 |
typedef typename _Digraph::Node Node; |
| 160 | 160 |
typedef typename _Digraph::Arc Arc; |
| 161 | 161 |
|
| 162 | 162 |
void constraints() {
|
| 163 | 163 |
checkConcept<GraphItem<'n'>, Node>(); |
| 164 | 164 |
checkConcept<GraphItem<'a'>, Arc>(); |
| 165 | 165 |
{
|
| 166 | 166 |
Node n; |
| 167 | 167 |
Arc e(INVALID); |
| 168 | 168 |
n = digraph.source(e); |
| 169 | 169 |
n = digraph.target(e); |
| 170 | 170 |
n = digraph.oppositeNode(n, e); |
| 171 | 171 |
} |
| 172 | 172 |
} |
| 173 | 173 |
|
| 174 | 174 |
const _Digraph& digraph; |
| 175 | 175 |
}; |
| 176 | 176 |
}; |
| 177 | 177 |
|
| 178 | 178 |
/// \brief An empty base undirected graph class. |
| 179 | 179 |
/// |
| 180 | 180 |
/// This class provides the minimal set of features needed for an |
| 181 | 181 |
/// undirected graph structure. All undirected graph concepts have |
| 182 | 182 |
/// to be conform to this base graph. It just provides types for |
| 183 | 183 |
/// nodes, arcs and edges and functions to get the |
| 184 | 184 |
/// source and the target of the arcs and edges, |
| 185 | 185 |
/// conversion from arcs to edges and function to get |
| 186 | 186 |
/// both direction of the edges. |
| 187 | 187 |
class BaseGraphComponent : public BaseDigraphComponent {
|
| 188 | 188 |
public: |
| 189 | 189 |
typedef BaseDigraphComponent::Node Node; |
| 190 | 190 |
typedef BaseDigraphComponent::Arc Arc; |
| 191 | 191 |
/// \brief Undirected arc class of the graph. |
| 192 | 192 |
/// |
| 193 | 193 |
/// This class represents the edges of the graph. |
| 194 | 194 |
/// The undirected graphs can be used as a directed graph which |
| 195 | 195 |
/// for each arc contains the opposite arc too so the graph is |
| 196 | 196 |
/// bidirected. The edge represents two opposite |
| 197 | 197 |
/// directed arcs. |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <iostream> |
| 20 | 20 |
#include <vector> |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/concepts/digraph.h> |
| 23 | 23 |
#include <lemon/list_graph.h> |
| 24 | 24 |
//#include <lemon/smart_graph.h> |
| 25 | 25 |
//#include <lemon/full_graph.h> |
| 26 | 26 |
//#include <lemon/hypercube_graph.h> |
| 27 | 27 |
|
| 28 | 28 |
#include "test_tools.h" |
| 29 | 29 |
#include "digraph_test.h" |
| 30 | 30 |
#include "map_test.h" |
| 31 | 31 |
|
| 32 | 32 |
|
| 33 | 33 |
using namespace lemon; |
| 34 | 34 |
using namespace lemon::concepts; |
| 35 | 35 |
|
| 36 | 36 |
|
| 37 | 37 |
int main() {
|
| 38 | 38 |
{ // checking digraph components
|
| 39 | 39 |
checkConcept<BaseDigraphComponent, BaseDigraphComponent >(); |
| 40 | 40 |
|
| 41 | 41 |
checkConcept<IDableDigraphComponent<>, |
| 42 | 42 |
IDableDigraphComponent<> >(); |
| 43 | 43 |
|
| 44 | 44 |
checkConcept<IterableDigraphComponent<>, |
| 45 | 45 |
IterableDigraphComponent<> >(); |
| 46 | 46 |
|
| 47 | 47 |
checkConcept<MappableDigraphComponent<>, |
| 48 | 48 |
MappableDigraphComponent<> >(); |
| 49 | 49 |
|
| 50 | 50 |
} |
| 51 | 51 |
{ // checking skeleton digraphs
|
| 52 | 52 |
checkConcept<Digraph, Digraph>(); |
| 53 | 53 |
} |
| 54 | 54 |
{ // checking list digraph
|
| 55 | 55 |
checkConcept<Digraph, ListDigraph >(); |
| 56 | 56 |
checkConcept<AlterableDigraphComponent<>, ListDigraph>(); |
| 57 | 57 |
checkConcept<ExtendableDigraphComponent<>, ListDigraph>(); |
| 58 | 58 |
checkConcept<ClearableDigraphComponent<>, ListDigraph>(); |
| 59 | 59 |
checkConcept<ErasableDigraphComponent<>, ListDigraph>(); |
| 60 | 60 |
|
| 61 | 61 |
checkDigraph<ListDigraph>(); |
| 62 | 62 |
checkGraphNodeMap<ListDigraph>(); |
| 63 | 63 |
checkGraphArcMap<ListDigraph>(); |
| 64 | 64 |
} |
| 65 | 65 |
// { // checking smart digraph
|
| 66 | 66 |
// checkConcept<Digraph, SmartDigraph >(); |
| 67 | 67 |
|
| 68 | 68 |
// checkDigraph<SmartDigraph>(); |
| 69 | 69 |
// checkDigraphNodeMap<SmartDigraph>(); |
| 70 | 70 |
// checkDigraphArcMap<SmartDigraph>(); |
| 71 | 71 |
// } |
| 72 | 72 |
// { // checking full digraph
|
| 73 | 73 |
// checkConcept<Digraph, FullDigraph >(); |
| 74 | 74 |
// } |
| 75 | 75 |
// { // checking full digraph
|
| 76 | 76 |
// checkConcept<Digraph, HyperCubeDigraph >(); |
| 77 | 77 |
// } |
| 78 | 78 |
|
| 79 | 79 |
std::cout << __FILE__ ": All tests passed.\n"; |
| 80 | 80 |
|
| 81 | 81 |
return 0; |
| 82 | 82 |
} |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_TEST_GRAPH_TEST_H |
| 20 | 20 |
#define LEMON_TEST_GRAPH_TEST_H |
| 21 | 21 |
|
| 22 | 22 |
//#include <lemon/graph_utils.h> |
| 23 | 23 |
#include "test_tools.h" |
| 24 | 24 |
|
| 25 | 25 |
//! \ingroup misc |
| 26 | 26 |
//! \file |
| 27 | 27 |
//! \brief Some utility and test cases to test digraph classes. |
| 28 | 28 |
namespace lemon {
|
| 29 | 29 |
|
| 30 | 30 |
///Structure returned by \ref addPetersen(). |
| 31 | 31 |
|
| 32 | 32 |
///Structure returned by \ref addPetersen(). |
| 33 | 33 |
/// |
| 34 | 34 |
template<class Digraph> |
| 35 | 35 |
struct PetStruct |
| 36 | 36 |
{
|
| 37 | 37 |
///Vector containing the outer nodes. |
| 38 | 38 |
std::vector<typename Digraph::Node> outer; |
| 39 | 39 |
///Vector containing the inner nodes. |
| 40 | 40 |
std::vector<typename Digraph::Node> inner; |
| 41 | 41 |
///Vector containing the edges of the inner circle. |
| 42 | 42 |
std::vector<typename Digraph::Arc> incir; |
| 43 | 43 |
///Vector containing the edges of the outer circle. |
| 44 | 44 |
std::vector<typename Digraph::Arc> outcir; |
| 45 | 45 |
///Vector containing the chord edges. |
| 46 | 46 |
std::vector<typename Digraph::Arc> chords; |
| 47 | 47 |
}; |
| 48 | 48 |
|
| 49 | 49 |
|
| 50 | 50 |
|
| 51 | 51 |
///Adds a Petersen graph to \c G. |
| 52 | 52 |
|
| 53 | 53 |
///Adds a Petersen graph to \c G. |
| 54 | 54 |
///\return The nodes and edges of the generated graph. |
| 55 | 55 |
|
| 56 | 56 |
template<typename Digraph> |
| 57 | 57 |
PetStruct<Digraph> addPetersen(Digraph &G,int num = 5) |
| 58 | 58 |
{
|
| 59 | 59 |
PetStruct<Digraph> n; |
| 60 | 60 |
|
| 61 | 61 |
for(int i=0;i<num;i++) {
|
| 62 | 62 |
n.outer.push_back(G.addNode()); |
| 63 | 63 |
n.inner.push_back(G.addNode()); |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 | 66 |
for(int i=0;i<num;i++) {
|
| 67 | 67 |
n.chords.push_back(G.addArc(n.outer[i],n.inner[i])); |
| 68 | 68 |
n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num])); |
| 69 | 69 |
n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num])); |
| 70 | 70 |
} |
| 71 | 71 |
return n; |
| 72 | 72 |
} |
| 73 | 73 |
|
| 74 | 74 |
/// \brief Adds to the digraph the reverse pair of all edges. |
| 75 | 75 |
/// |
| 76 | 76 |
/// Adds to the digraph the reverse pair of all edges. |
| 77 | 77 |
/// |
| 78 | 78 |
template<class Digraph> |
| 79 | 79 |
void bidirDigraph(Digraph &G) |
| 80 | 80 |
{
|
| 81 | 81 |
typedef typename Digraph::Arc Arc; |
| 82 | 82 |
typedef typename Digraph::ArcIt ArcIt; |
| 83 | 83 |
|
| 84 | 84 |
std::vector<Arc> ee; |
| 85 | 85 |
|
| 86 | 86 |
for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e); |
| 87 | 87 |
|
| 88 | 88 |
for(typename std::vector<Arc>::iterator p=ee.begin();p!=ee.end();p++) |
| 89 | 89 |
G.addArc(G.target(*p),G.source(*p)); |
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 | 92 |
|
| 93 | 93 |
/// \brief Checks the bidirectioned Petersen graph. |
| 94 | 94 |
/// |
| 95 | 95 |
/// Checks the bidirectioned Petersen graph. |
| 96 | 96 |
/// |
| 97 | 97 |
template<class Digraph> |
| 98 | 98 |
void checkBidirPetersen(Digraph &G, int num = 5) |
| 99 | 99 |
{
|
| 100 | 100 |
typedef typename Digraph::Node Node; |
| 101 | 101 |
|
| 102 | 102 |
typedef typename Digraph::ArcIt ArcIt; |
| 103 | 103 |
typedef typename Digraph::NodeIt NodeIt; |
| 104 | 104 |
|
| 105 | 105 |
checkDigraphNodeList(G, 2 * num); |
| 106 | 106 |
checkDigraphArcList(G, 6 * num); |
| 107 | 107 |
|
| 108 | 108 |
for(NodeIt n(G);n!=INVALID;++n) {
|
| 109 | 109 |
checkDigraphInArcList(G, n, 3); |
| 110 | 110 |
checkDigraphOutArcList(G, n, 3); |
| 111 | 111 |
} |
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 | 114 |
template<class Digraph> void checkDigraphNodeList(Digraph &G, int nn) |
| 115 | 115 |
{
|
| 116 | 116 |
typename Digraph::NodeIt n(G); |
| 117 | 117 |
for(int i=0;i<nn;i++) {
|
| 118 | 118 |
check(n!=INVALID,"Wrong Node list linking."); |
| 119 | 119 |
++n; |
| 120 | 120 |
} |
| 121 | 121 |
check(n==INVALID,"Wrong Node list linking."); |
| 122 | 122 |
} |
| 123 | 123 |
|
| 124 | 124 |
template<class Digraph> |
| 125 | 125 |
void checkDigraphArcList(Digraph &G, int nn) |
| 126 | 126 |
{
|
| 127 | 127 |
typedef typename Digraph::ArcIt ArcIt; |
| 128 | 128 |
|
| 129 | 129 |
ArcIt e(G); |
| 130 | 130 |
for(int i=0;i<nn;i++) {
|
| 131 | 131 |
check(e!=INVALID,"Wrong Arc list linking."); |
| 132 | 132 |
++e; |
| 133 | 133 |
} |
| 134 | 134 |
check(e==INVALID,"Wrong Arc list linking."); |
| 135 | 135 |
} |
| 136 | 136 |
|
| 137 | 137 |
template<class Digraph> |
| 138 | 138 |
void checkDigraphOutArcList(Digraph &G, typename Digraph::Node n, int nn) |
| 139 | 139 |
{
|
| 140 | 140 |
typename Digraph::OutArcIt e(G,n); |
| 141 | 141 |
for(int i=0;i<nn;i++) {
|
| 142 | 142 |
check(e!=INVALID,"Wrong OutArc list linking."); |
| 143 | 143 |
check(n==G.source(e), "Wrong OutArc list linking."); |
| 144 | 144 |
++e; |
| 145 | 145 |
} |
| 146 | 146 |
check(e==INVALID,"Wrong OutArc list linking."); |
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 | 149 |
template<class Digraph> void |
| 150 | 150 |
checkDigraphInArcList(Digraph &G, typename Digraph::Node n, int nn) |
| 151 | 151 |
{
|
| 152 | 152 |
typename Digraph::InArcIt e(G,n); |
| 153 | 153 |
for(int i=0;i<nn;i++) {
|
| 154 | 154 |
check(e!=INVALID,"Wrong InArc list linking."); |
| 155 | 155 |
check(n==G.target(e), "Wrong InArc list linking."); |
| 156 | 156 |
++e; |
| 157 | 157 |
} |
| 158 | 158 |
check(e==INVALID,"Wrong InArc list linking."); |
| 159 | 159 |
} |
| 160 | 160 |
|
| 161 | 161 |
template <class Digraph> |
| 162 | 162 |
void checkDigraph() {
|
| 163 | 163 |
const int num = 5; |
| 164 | 164 |
Digraph G; |
| 165 | 165 |
addPetersen(G, num); |
| 166 | 166 |
bidirDigraph(G); |
| 167 | 167 |
checkBidirPetersen(G, num); |
| 168 | 168 |
} |
| 169 | 169 |
|
| 170 | 170 |
template <class Digraph> |
| 171 | 171 |
void checkDigraphIterators(const Digraph& digraph) {
|
| 172 | 172 |
typedef typename Digraph::Node Node; |
| 173 | 173 |
typedef typename Digraph::NodeIt NodeIt; |
| 174 | 174 |
typedef typename Digraph::Arc Arc; |
| 175 | 175 |
typedef typename Digraph::ArcIt ArcIt; |
| 176 | 176 |
typedef typename Digraph::InArcIt InArcIt; |
| 177 | 177 |
typedef typename Digraph::OutArcIt OutArcIt; |
| 178 | 178 |
// typedef ConArcIt<Digraph> ConArcIt; |
| 179 | 179 |
} |
| 180 | 180 |
|
| 181 | 181 |
///\file |
| 182 | 182 |
///\todo Check target(), source() as well; |
| 183 | 183 |
|
| 184 | 184 |
|
| 185 | 185 |
} //namespace lemon |
| 186 | 186 |
|
| 187 | 187 |
|
| 188 | 188 |
#endif |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <lemon/concepts/graph.h> |
| 20 | 20 |
#include <lemon/list_graph.h> |
| 21 | 21 |
// #include <lemon/smart_graph.h> |
| 22 | 22 |
// #include <lemon/full_graph.h> |
| 23 | 23 |
// #include <lemon/grid_graph.h> |
| 24 | 24 |
|
| 25 | 25 |
//#include <lemon/graph_utils.h> |
| 26 | 26 |
|
| 27 | 27 |
#include "test_tools.h" |
| 28 | 28 |
|
| 29 | 29 |
|
| 30 | 30 |
using namespace lemon; |
| 31 | 31 |
using namespace lemon::concepts; |
| 32 | 32 |
|
| 33 | 33 |
void check_concepts() {
|
| 34 | 34 |
|
| 35 | 35 |
{ // checking digraph components
|
| 36 | 36 |
checkConcept<BaseGraphComponent, BaseGraphComponent >(); |
| 37 | 37 |
|
| 38 | 38 |
checkConcept<IDableGraphComponent<>, |
| 39 | 39 |
IDableGraphComponent<> >(); |
| 40 | 40 |
|
| 41 | 41 |
checkConcept<IterableGraphComponent<>, |
| 42 | 42 |
IterableGraphComponent<> >(); |
| 43 | 43 |
|
| 44 | 44 |
checkConcept<MappableGraphComponent<>, |
| 45 | 45 |
MappableGraphComponent<> >(); |
| 46 | 46 |
|
| 47 | 47 |
} |
| 48 | 48 |
{
|
| 49 | 49 |
checkConcept<Graph, ListGraph>(); |
| 50 | 50 |
// checkConcept<Graph, SmartGraph>(); |
| 51 | 51 |
// checkConcept<Graph, FullGraph>(); |
| 52 | 52 |
// checkConcept<Graph, Graph>(); |
| 53 | 53 |
// checkConcept<Graph, GridGraph>(); |
| 54 | 54 |
} |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 | 57 |
template <typename Graph> |
| 58 | 58 |
void check_item_counts(Graph &g, int n, int e) {
|
| 59 | 59 |
int nn = 0; |
| 60 | 60 |
for (typename Graph::NodeIt it(g); it != INVALID; ++it) {
|
| 61 | 61 |
++nn; |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
check(nn == n, "Wrong node number."); |
| 65 | 65 |
// check(countNodes(g) == n, "Wrong node number."); |
| 66 | 66 |
|
| 67 | 67 |
int ee = 0; |
| 68 | 68 |
for (typename Graph::ArcIt it(g); it != INVALID; ++it) {
|
| 69 | 69 |
++ee; |
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 | 72 |
check(ee == 2*e, "Wrong arc number."); |
| 73 | 73 |
// check(countArcs(g) == 2*e, "Wrong arc number."); |
| 74 | 74 |
|
| 75 | 75 |
int uee = 0; |
| 76 | 76 |
for (typename Graph::EdgeIt it(g); it != INVALID; ++it) {
|
| 77 | 77 |
++uee; |
| 78 | 78 |
} |
| 79 | 79 |
|
| 80 | 80 |
check(uee == e, "Wrong edge number."); |
| 81 | 81 |
// check(countEdges(g) == e, "Wrong edge number."); |
| 82 | 82 |
} |
| 83 | 83 |
|
| 84 | 84 |
template <typename Graph> |
| 85 | 85 |
void print_items(Graph &g) {
|
| 86 | 86 |
|
| 87 | 87 |
typedef typename Graph::NodeIt NodeIt; |
| 88 | 88 |
typedef typename Graph::EdgeIt EdgeIt; |
| 89 | 89 |
typedef typename Graph::ArcIt ArcIt; |
| 90 | 90 |
|
| 91 | 91 |
std::cout << "Nodes" << std::endl; |
| 92 | 92 |
int i=0; |
| 93 | 93 |
for(NodeIt it(g); it!=INVALID; ++it, ++i) {
|
| 94 | 94 |
std::cout << " " << i << ": " << g.id(it) << std::endl; |
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
std::cout << "Edge" << std::endl; |
| 98 | 98 |
i=0; |
| 99 | 99 |
for(EdgeIt it(g); it!=INVALID; ++it, ++i) {
|
| 100 | 100 |
std::cout << " " << i << ": " << g.id(it) |
| 101 | 101 |
<< " (" << g.id(g.source(it)) << ", " << g.id(g.target(it))
|
| 102 | 102 |
<< ")" << std::endl; |
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
std::cout << "Arc" << std::endl; |
| 106 | 106 |
i=0; |
| 107 | 107 |
for(ArcIt it(g); it!=INVALID; ++it, ++i) {
|
| 108 | 108 |
std::cout << " " << i << ": " << g.id(it) |
| 109 | 109 |
<< " (" << g.id(g.source(it)) << ", " << g.id(g.target(it))
|
| 110 | 110 |
<< ")" << std::endl; |
| 111 | 111 |
} |
| 112 | 112 |
|
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 | 115 |
template <typename Graph> |
| 116 | 116 |
void check_graph() {
|
| 117 | 117 |
|
| 118 | 118 |
typedef typename Graph::Node Node; |
| 119 | 119 |
typedef typename Graph::Edge Edge; |
| 120 | 120 |
typedef typename Graph::Arc Arc; |
| 121 | 121 |
typedef typename Graph::NodeIt NodeIt; |
| 122 | 122 |
typedef typename Graph::EdgeIt EdgeIt; |
| 123 | 123 |
typedef typename Graph::ArcIt ArcIt; |
| 124 | 124 |
|
| 125 | 125 |
Graph g; |
| 126 | 126 |
|
| 127 | 127 |
check_item_counts(g,0,0); |
| 128 | 128 |
|
| 129 | 129 |
Node |
| 130 | 130 |
n1 = g.addNode(), |
| 131 | 131 |
n2 = g.addNode(), |
| 132 | 132 |
n3 = g.addNode(); |
| 133 | 133 |
|
| 134 | 134 |
Edge |
| 135 | 135 |
e1 = g.addEdge(n1, n2), |
| 136 | 136 |
e2 = g.addEdge(n2, n3); |
| 137 | 137 |
|
| 138 | 138 |
// print_items(g); |
| 139 | 139 |
|
| 140 | 140 |
check_item_counts(g,3,2); |
| 141 | 141 |
} |
| 142 | 142 |
|
| 143 | 143 |
// void checkGridGraph(const GridGraph& g, int w, int h) {
|
| 144 | 144 |
// check(g.width() == w, "Wrong width"); |
| 145 | 145 |
// check(g.height() == h, "Wrong height"); |
| 146 | 146 |
|
| 147 | 147 |
// for (int i = 0; i < w; ++i) {
|
| 148 | 148 |
// for (int j = 0; j < h; ++j) {
|
| 149 | 149 |
// check(g.col(g(i, j)) == i, "Wrong col"); |
| 150 | 150 |
// check(g.row(g(i, j)) == j, "Wrong row"); |
| 151 | 151 |
// } |
| 152 | 152 |
// } |
| 153 | 153 |
|
| 154 | 154 |
// for (int i = 0; i < w; ++i) {
|
| 155 | 155 |
// for (int j = 0; j < h - 1; ++j) {
|
| 156 | 156 |
// check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down"); |
| 157 | 157 |
// check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down"); |
| 158 | 158 |
// } |
| 159 | 159 |
// check(g.down(g(i, h - 1)) == INVALID, "Wrong down"); |
| 160 | 160 |
// } |
| 161 | 161 |
|
| 162 | 162 |
// for (int i = 0; i < w; ++i) {
|
| 163 | 163 |
// for (int j = 1; j < h; ++j) {
|
| 164 | 164 |
// check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up"); |
| 165 | 165 |
// check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up"); |
| 166 | 166 |
// } |
| 167 | 167 |
// check(g.up(g(i, 0)) == INVALID, "Wrong up"); |
| 168 | 168 |
// } |
| 169 | 169 |
|
| 170 | 170 |
// for (int j = 0; j < h; ++j) {
|
| 171 | 171 |
// for (int i = 0; i < w - 1; ++i) {
|
| 172 | 172 |
// check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right"); |
| 173 | 173 |
// check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right"); |
| 174 | 174 |
// } |
| 175 | 175 |
// check(g.right(g(w - 1, j)) == INVALID, "Wrong right"); |
| 176 | 176 |
// } |
| 177 | 177 |
|
| 178 | 178 |
// for (int j = 0; j < h; ++j) {
|
| 179 | 179 |
// for (int i = 1; i < w; ++i) {
|
| 180 | 180 |
// check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left"); |
| 181 | 181 |
// check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left"); |
| 182 | 182 |
// } |
| 183 | 183 |
// check(g.left(g(0, j)) == INVALID, "Wrong left"); |
| 184 | 184 |
// } |
| 185 | 185 |
// } |
| 186 | 186 |
|
| 187 | 187 |
int main() {
|
| 188 | 188 |
check_concepts(); |
| 189 | 189 |
|
| 190 | 190 |
check_graph<ListGraph>(); |
| 191 | 191 |
// check_graph<SmartGraph>(); |
| 192 | 192 |
|
| 193 | 193 |
// {
|
| 194 | 194 |
// FullGraph g(5); |
| 195 | 195 |
// check_item_counts(g, 5, 10); |
| 196 | 196 |
// } |
| 197 | 197 |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 |
* Copyright (C) 2003- |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_TEST_MAP_TEST_H |
| 20 | 20 |
#define LEMON_TEST_MAP_TEST_H |
| 21 | 21 |
|
| 22 | 22 |
|
| 23 | 23 |
#include <vector> |
| 24 | 24 |
#include <lemon/maps.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "test_tools.h" |
| 27 | 27 |
|
| 28 | 28 |
|
| 29 | 29 |
//! \ingroup misc |
| 30 | 30 |
//! \file |
| 31 | 31 |
//! \brief Some utilities to test map classes. |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
|
| 36 | 36 |
|
| 37 | 37 |
template <typename Graph> |
| 38 | 38 |
void checkGraphNodeMap() {
|
| 39 | 39 |
Graph graph; |
| 40 | 40 |
const int num = 16; |
| 41 | 41 |
|
| 42 | 42 |
typedef typename Graph::Node Node; |
| 43 | 43 |
|
| 44 | 44 |
std::vector<Node> nodes; |
| 45 | 45 |
for (int i = 0; i < num; ++i) {
|
| 46 | 46 |
nodes.push_back(graph.addNode()); |
| 47 | 47 |
} |
| 48 | 48 |
typedef typename Graph::template NodeMap<int> IntNodeMap; |
| 49 | 49 |
IntNodeMap map(graph, 42); |
| 50 | 50 |
for (int i = 0; i < int(nodes.size()); ++i) {
|
| 51 | 51 |
check(map[nodes[i]] == 42, "Wrong map constructor."); |
| 52 | 52 |
} |
| 53 | 53 |
for (int i = 0; i < num; ++i) {
|
| 54 | 54 |
nodes.push_back(graph.addNode()); |
| 55 | 55 |
map[nodes.back()] = 23; |
| 56 | 56 |
} |
| 57 | 57 |
map = constMap<Node>(12); |
| 58 | 58 |
for (int i = 0; i < int(nodes.size()); ++i) {
|
| 59 | 59 |
check(map[nodes[i]] == 12, "Wrong map constructor."); |
| 60 | 60 |
} |
| 61 | 61 |
graph.clear(); |
| 62 | 62 |
nodes.clear(); |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 | 65 |
template <typename Graph> |
| 66 | 66 |
void checkGraphArcMap() {
|
| 67 | 67 |
Graph graph; |
| 68 | 68 |
const int num = 16; |
| 69 | 69 |
|
| 70 | 70 |
typedef typename Graph::Node Node; |
| 71 | 71 |
typedef typename Graph::Arc Arc; |
| 72 | 72 |
|
| 73 | 73 |
std::vector<Node> nodes; |
| 74 | 74 |
for (int i = 0; i < num; ++i) {
|
| 75 | 75 |
nodes.push_back(graph.addNode()); |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 | 78 |
std::vector<Arc> edges; |
| 79 | 79 |
for (int i = 0; i < num; ++i) {
|
| 80 | 80 |
for (int j = 0; j < i; ++j) {
|
| 81 | 81 |
edges.push_back(graph.addArc(nodes[i], nodes[j])); |
| 82 | 82 |
} |
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 | 85 |
typedef typename Graph::template ArcMap<int> IntArcMap; |
| 86 | 86 |
IntArcMap map(graph, 42); |
| 87 | 87 |
|
| 88 | 88 |
for (int i = 0; i < int(edges.size()); ++i) {
|
| 89 | 89 |
check(map[edges[i]] == 42, "Wrong map constructor."); |
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 | 92 |
for (int i = 0; i < num; ++i) {
|
| 93 | 93 |
for (int j = i + 1; j < num; ++j) {
|
| 94 | 94 |
edges.push_back(graph.addArc(nodes[i], nodes[j])); |
| 95 | 95 |
map[edges.back()] = 23; |
| 96 | 96 |
} |
| 97 | 97 |
} |
| 98 | 98 |
map = constMap<Arc>(12); |
| 99 | 99 |
for (int i = 0; i < int(edges.size()); ++i) {
|
| 100 | 100 |
check(map[edges[i]] == 12, "Wrong map constructor."); |
| 101 | 101 |
} |
| 102 | 102 |
graph.clear(); |
| 103 | 103 |
edges.clear(); |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
template <typename Graph> |
| 107 | 107 |
void checkGraphEdgeMap() {
|
| 108 | 108 |
Graph graph; |
| 109 | 109 |
const int num = 16; |
| 110 | 110 |
|
| 111 | 111 |
typedef typename Graph::Node Node; |
| 112 | 112 |
typedef typename Graph::Edge Edge; |
| 113 | 113 |
|
| 114 | 114 |
std::vector<Node> nodes; |
| 115 | 115 |
for (int i = 0; i < num; ++i) {
|
| 116 | 116 |
nodes.push_back(graph.addNode()); |
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 | 119 |
std::vector<Edge> edges; |
| 120 | 120 |
for (int i = 0; i < num; ++i) {
|
| 121 | 121 |
for (int j = 0; j < i; ++j) {
|
| 122 | 122 |
edges.push_back(graph.addEdge(nodes[i], nodes[j])); |
| 123 | 123 |
} |
| 124 | 124 |
} |
| 125 | 125 |
|
| 126 | 126 |
typedef typename Graph::template EdgeMap<int> IntEdgeMap; |
| 127 | 127 |
IntEdgeMap map(graph, 42); |
| 128 | 128 |
|
| 129 | 129 |
for (int i = 0; i < int(edges.size()); ++i) {
|
| 130 | 130 |
check(map[edges[i]] == 42, "Wrong map constructor."); |
| 131 | 131 |
} |
| 132 | 132 |
|
| 133 | 133 |
for (int i = 0; i < num; ++i) {
|
| 134 | 134 |
for (int j = i + 1; j < num; ++j) {
|
| 135 | 135 |
edges.push_back(graph.addEdge(nodes[i], nodes[j])); |
| 136 | 136 |
map[edges.back()] = 23; |
| 137 | 137 |
} |
| 138 | 138 |
} |
| 139 | 139 |
map = constMap<Edge>(12); |
| 140 | 140 |
for (int i = 0; i < int(edges.size()); ++i) {
|
| 141 | 141 |
check(map[edges[i]] == 12, "Wrong map constructor."); |
| 142 | 142 |
} |
| 143 | 143 |
graph.clear(); |
| 144 | 144 |
edges.clear(); |
| 145 | 145 |
} |
| 146 | 146 |
|
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 | 149 |
#endif |
0 comments (0 inline)