1 |
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
2 |
2 |
*
|
3 |
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
4 |
4 |
*
|
5 |
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_EDGE_SET_H
|
20 |
20 |
#define LEMON_EDGE_SET_H
|
21 |
21 |
|
22 |
22 |
#include <lemon/core.h>
|
23 |
23 |
#include <lemon/bits/edge_set_extender.h>
|
24 |
24 |
|
25 |
|
/// \ingroup semi_adaptors
|
|
25 |
/// \ingroup graphs
|
26 |
26 |
/// \file
|
27 |
27 |
/// \brief ArcSet and EdgeSet classes.
|
28 |
28 |
///
|
29 |
29 |
/// Graphs which use another graph's node-set as own.
|
30 |
30 |
namespace lemon {
|
31 |
31 |
|
32 |
32 |
template <typename GR>
|
33 |
33 |
class ListArcSetBase {
|
34 |
34 |
public:
|
35 |
35 |
|
36 |
36 |
typedef typename GR::Node Node;
|
37 |
37 |
typedef typename GR::NodeIt NodeIt;
|
38 |
38 |
|
39 |
39 |
protected:
|
40 |
40 |
|
41 |
41 |
struct NodeT {
|
42 |
42 |
int first_out, first_in;
|
43 |
43 |
NodeT() : first_out(-1), first_in(-1) {}
|
44 |
44 |
};
|
45 |
45 |
|
46 |
46 |
typedef typename ItemSetTraits<GR, Node>::
|
47 |
47 |
template Map<NodeT>::Type NodesImplBase;
|
48 |
48 |
|
49 |
49 |
NodesImplBase* _nodes;
|
... |
... |
@@ -209,49 +209,49 @@
|
209 |
209 |
class NodeMap : public GR::template NodeMap<V> {
|
210 |
210 |
typedef typename GR::template NodeMap<V> Parent;
|
211 |
211 |
|
212 |
212 |
public:
|
213 |
213 |
|
214 |
214 |
explicit NodeMap(const ListArcSetBase<GR>& arcset)
|
215 |
215 |
: Parent(*arcset._graph) {}
|
216 |
216 |
|
217 |
217 |
NodeMap(const ListArcSetBase<GR>& arcset, const V& value)
|
218 |
218 |
: Parent(*arcset._graph, value) {}
|
219 |
219 |
|
220 |
220 |
NodeMap& operator=(const NodeMap& cmap) {
|
221 |
221 |
return operator=<NodeMap>(cmap);
|
222 |
222 |
}
|
223 |
223 |
|
224 |
224 |
template <typename CMap>
|
225 |
225 |
NodeMap& operator=(const CMap& cmap) {
|
226 |
226 |
Parent::operator=(cmap);
|
227 |
227 |
return *this;
|
228 |
228 |
}
|
229 |
229 |
};
|
230 |
230 |
|
231 |
231 |
};
|
232 |
232 |
|
233 |
|
/// \ingroup semi_adaptors
|
|
233 |
/// \ingroup graphs
|
234 |
234 |
///
|
235 |
235 |
/// \brief Digraph using a node set of another digraph or graph and
|
236 |
236 |
/// an own arc set.
|
237 |
237 |
///
|
238 |
238 |
/// This structure can be used to establish another directed graph
|
239 |
239 |
/// over a node set of an existing one. This class uses the same
|
240 |
240 |
/// Node type as the underlying graph, and each valid node of the
|
241 |
241 |
/// original graph is valid in this arc set, therefore the node
|
242 |
242 |
/// objects of the original graph can be used directly with this
|
243 |
243 |
/// class. The node handling functions (id handling, observing, and
|
244 |
244 |
/// iterators) works equivalently as in the original graph.
|
245 |
245 |
///
|
246 |
246 |
/// This implementation is based on doubly-linked lists, from each
|
247 |
247 |
/// node the outgoing and the incoming arcs make up lists, therefore
|
248 |
248 |
/// one arc can be erased in constant time. It also makes possible,
|
249 |
249 |
/// that node can be removed from the underlying graph, in this case
|
250 |
250 |
/// all arcs incident to the given node is erased from the arc set.
|
251 |
251 |
///
|
252 |
252 |
/// \param GR The type of the graph which shares its node set with
|
253 |
253 |
/// this class. Its interface must conform to the
|
254 |
254 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
|
255 |
255 |
/// concept.
|
256 |
256 |
///
|
257 |
257 |
/// This class fully conforms to the \ref concepts::Digraph
|
... |
... |
@@ -633,49 +633,49 @@
|
633 |
633 |
class NodeMap : public GR::template NodeMap<V> {
|
634 |
634 |
typedef typename GR::template NodeMap<V> Parent;
|
635 |
635 |
|
636 |
636 |
public:
|
637 |
637 |
|
638 |
638 |
explicit NodeMap(const ListEdgeSetBase<GR>& arcset)
|
639 |
639 |
: Parent(*arcset._graph) {}
|
640 |
640 |
|
641 |
641 |
NodeMap(const ListEdgeSetBase<GR>& arcset, const V& value)
|
642 |
642 |
: Parent(*arcset._graph, value) {}
|
643 |
643 |
|
644 |
644 |
NodeMap& operator=(const NodeMap& cmap) {
|
645 |
645 |
return operator=<NodeMap>(cmap);
|
646 |
646 |
}
|
647 |
647 |
|
648 |
648 |
template <typename CMap>
|
649 |
649 |
NodeMap& operator=(const CMap& cmap) {
|
650 |
650 |
Parent::operator=(cmap);
|
651 |
651 |
return *this;
|
652 |
652 |
}
|
653 |
653 |
};
|
654 |
654 |
|
655 |
655 |
};
|
656 |
656 |
|
657 |
|
/// \ingroup semi_adaptors
|
|
657 |
/// \ingroup graphs
|
658 |
658 |
///
|
659 |
659 |
/// \brief Graph using a node set of another digraph or graph and an
|
660 |
660 |
/// own edge set.
|
661 |
661 |
///
|
662 |
662 |
/// This structure can be used to establish another graph over a
|
663 |
663 |
/// node set of an existing one. This class uses the same Node type
|
664 |
664 |
/// as the underlying graph, and each valid node of the original
|
665 |
665 |
/// graph is valid in this arc set, therefore the node objects of
|
666 |
666 |
/// the original graph can be used directly with this class. The
|
667 |
667 |
/// node handling functions (id handling, observing, and iterators)
|
668 |
668 |
/// works equivalently as in the original graph.
|
669 |
669 |
///
|
670 |
670 |
/// This implementation is based on doubly-linked lists, from each
|
671 |
671 |
/// node the incident edges make up lists, therefore one edge can be
|
672 |
672 |
/// erased in constant time. It also makes possible, that node can
|
673 |
673 |
/// be removed from the underlying graph, in this case all edges
|
674 |
674 |
/// incident to the given node is erased from the arc set.
|
675 |
675 |
///
|
676 |
676 |
/// \param GR The type of the graph which shares its node set
|
677 |
677 |
/// with this class. Its interface must conform to the
|
678 |
678 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
|
679 |
679 |
/// concept.
|
680 |
680 |
///
|
681 |
681 |
/// This class fully conforms to the \ref concepts::Graph "Graph"
|
... |
... |
@@ -892,49 +892,49 @@
|
892 |
892 |
typedef typename GR::template NodeMap<V> Parent;
|
893 |
893 |
|
894 |
894 |
public:
|
895 |
895 |
|
896 |
896 |
explicit NodeMap(const SmartArcSetBase<GR>& arcset)
|
897 |
897 |
: Parent(*arcset._graph) { }
|
898 |
898 |
|
899 |
899 |
NodeMap(const SmartArcSetBase<GR>& arcset, const V& value)
|
900 |
900 |
: Parent(*arcset._graph, value) { }
|
901 |
901 |
|
902 |
902 |
NodeMap& operator=(const NodeMap& cmap) {
|
903 |
903 |
return operator=<NodeMap>(cmap);
|
904 |
904 |
}
|
905 |
905 |
|
906 |
906 |
template <typename CMap>
|
907 |
907 |
NodeMap& operator=(const CMap& cmap) {
|
908 |
908 |
Parent::operator=(cmap);
|
909 |
909 |
return *this;
|
910 |
910 |
}
|
911 |
911 |
};
|
912 |
912 |
|
913 |
913 |
};
|
914 |
914 |
|
915 |
915 |
|
916 |
|
/// \ingroup semi_adaptors
|
|
916 |
/// \ingroup graphs
|
917 |
917 |
///
|
918 |
918 |
/// \brief Digraph using a node set of another digraph or graph and
|
919 |
919 |
/// an own arc set.
|
920 |
920 |
///
|
921 |
921 |
/// This structure can be used to establish another directed graph
|
922 |
922 |
/// over a node set of an existing one. This class uses the same
|
923 |
923 |
/// Node type as the underlying graph, and each valid node of the
|
924 |
924 |
/// original graph is valid in this arc set, therefore the node
|
925 |
925 |
/// objects of the original graph can be used directly with this
|
926 |
926 |
/// class. The node handling functions (id handling, observing, and
|
927 |
927 |
/// iterators) works equivalently as in the original graph.
|
928 |
928 |
///
|
929 |
929 |
/// \param GR The type of the graph which shares its node set with
|
930 |
930 |
/// this class. Its interface must conform to the
|
931 |
931 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
|
932 |
932 |
/// concept.
|
933 |
933 |
///
|
934 |
934 |
/// This implementation is slightly faster than the \c ListArcSet,
|
935 |
935 |
/// because it uses continuous storage for arcs and it uses just
|
936 |
936 |
/// single-linked lists for enumerate outgoing and incoming
|
937 |
937 |
/// arcs. Therefore the arcs cannot be erased from the arc sets.
|
938 |
938 |
///
|
939 |
939 |
/// \warning If a node is erased from the underlying graph and this
|
940 |
940 |
/// node is the source or target of one arc in the arc set, then
|
... |
... |
@@ -1236,49 +1236,49 @@
|
1236 |
1236 |
class NodeMap : public GR::template NodeMap<V> {
|
1237 |
1237 |
typedef typename GR::template NodeMap<V> Parent;
|
1238 |
1238 |
|
1239 |
1239 |
public:
|
1240 |
1240 |
|
1241 |
1241 |
explicit NodeMap(const SmartEdgeSetBase<GR>& arcset)
|
1242 |
1242 |
: Parent(*arcset._graph) { }
|
1243 |
1243 |
|
1244 |
1244 |
NodeMap(const SmartEdgeSetBase<GR>& arcset, const V& value)
|
1245 |
1245 |
: Parent(*arcset._graph, value) { }
|
1246 |
1246 |
|
1247 |
1247 |
NodeMap& operator=(const NodeMap& cmap) {
|
1248 |
1248 |
return operator=<NodeMap>(cmap);
|
1249 |
1249 |
}
|
1250 |
1250 |
|
1251 |
1251 |
template <typename CMap>
|
1252 |
1252 |
NodeMap& operator=(const CMap& cmap) {
|
1253 |
1253 |
Parent::operator=(cmap);
|
1254 |
1254 |
return *this;
|
1255 |
1255 |
}
|
1256 |
1256 |
};
|
1257 |
1257 |
|
1258 |
1258 |
};
|
1259 |
1259 |
|
1260 |
|
/// \ingroup semi_adaptors
|
|
1260 |
/// \ingroup graphs
|
1261 |
1261 |
///
|
1262 |
1262 |
/// \brief Graph using a node set of another digraph or graph and an
|
1263 |
1263 |
/// own edge set.
|
1264 |
1264 |
///
|
1265 |
1265 |
/// This structure can be used to establish another graph over a
|
1266 |
1266 |
/// node set of an existing one. This class uses the same Node type
|
1267 |
1267 |
/// as the underlying graph, and each valid node of the original
|
1268 |
1268 |
/// graph is valid in this arc set, therefore the node objects of
|
1269 |
1269 |
/// the original graph can be used directly with this class. The
|
1270 |
1270 |
/// node handling functions (id handling, observing, and iterators)
|
1271 |
1271 |
/// works equivalently as in the original graph.
|
1272 |
1272 |
///
|
1273 |
1273 |
/// \param GR The type of the graph which shares its node set
|
1274 |
1274 |
/// with this class. Its interface must conform to the
|
1275 |
1275 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph"
|
1276 |
1276 |
/// concept.
|
1277 |
1277 |
///
|
1278 |
1278 |
/// This implementation is slightly faster than the \c ListEdgeSet,
|
1279 |
1279 |
/// because it uses continuous storage for edges and it uses just
|
1280 |
1280 |
/// single-linked lists for enumerate incident edges. Therefore the
|
1281 |
1281 |
/// edges cannot be erased from the edge sets.
|
1282 |
1282 |
///
|
1283 |
1283 |
/// \warning If a node is erased from the underlying graph and this
|
1284 |
1284 |
/// node is incident to one edge in the edge set, then the edge set
|