0
4
0
| 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_CORE_H |
| 20 | 20 |
#define LEMON_CORE_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <algorithm> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/bits/enable_if.h> |
| 26 | 26 |
#include <lemon/bits/traits.h> |
| 27 |
#include <lemon/assert.h> |
|
| 27 | 28 |
|
| 28 | 29 |
///\file |
| 29 | 30 |
///\brief LEMON core utilities. |
| 30 | 31 |
/// |
| 31 | 32 |
///This header file contains core utilities for LEMON. |
| 32 | 33 |
///It is automatically included by all graph types, therefore it usually |
| 33 | 34 |
///do not have to be included directly. |
| 34 | 35 |
|
| 35 | 36 |
namespace lemon {
|
| 36 | 37 |
|
| 37 | 38 |
/// \brief Dummy type to make it easier to create invalid iterators. |
| 38 | 39 |
/// |
| 39 | 40 |
/// Dummy type to make it easier to create invalid iterators. |
| 40 | 41 |
/// See \ref INVALID for the usage. |
| 41 | 42 |
struct Invalid {
|
| 42 | 43 |
public: |
| 43 | 44 |
bool operator==(Invalid) { return true; }
|
| 44 | 45 |
bool operator!=(Invalid) { return false; }
|
| 45 | 46 |
bool operator< (Invalid) { return false; }
|
| 46 | 47 |
}; |
| 47 | 48 |
|
| 48 | 49 |
/// \brief Invalid iterators. |
| 49 | 50 |
/// |
| 50 | 51 |
/// \ref Invalid is a global type that converts to each iterator |
| 51 | 52 |
/// in such a way that the value of the target iterator will be invalid. |
| 52 | 53 |
#ifdef LEMON_ONLY_TEMPLATES |
| 53 | 54 |
const Invalid INVALID = Invalid(); |
| 54 | 55 |
#else |
| 55 | 56 |
extern const Invalid INVALID; |
| 56 | 57 |
#endif |
| 57 | 58 |
|
| 58 | 59 |
/// \addtogroup gutils |
| 59 | 60 |
/// @{
|
| 60 | 61 |
|
| 61 | 62 |
///Create convenience typedefs for the digraph types and iterators |
| 62 | 63 |
|
| 63 | 64 |
///This \c \#define creates convenient type definitions for the following |
| 64 | 65 |
///types of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt, |
| 65 | 66 |
///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, |
| 66 | 67 |
///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap. |
| 67 | 68 |
/// |
| 68 | 69 |
///\note If the graph type is a dependent type, ie. the graph type depend |
| 69 | 70 |
///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS() |
| 70 | 71 |
///macro. |
| 71 | 72 |
#define DIGRAPH_TYPEDEFS(Digraph) \ |
| 72 | 73 |
typedef Digraph::Node Node; \ |
| 73 | 74 |
typedef Digraph::NodeIt NodeIt; \ |
| 74 | 75 |
typedef Digraph::Arc Arc; \ |
| 75 | 76 |
typedef Digraph::ArcIt ArcIt; \ |
| 76 | 77 |
typedef Digraph::InArcIt InArcIt; \ |
| 77 | 78 |
typedef Digraph::OutArcIt OutArcIt; \ |
| 78 | 79 |
typedef Digraph::NodeMap<bool> BoolNodeMap; \ |
| 79 | 80 |
typedef Digraph::NodeMap<int> IntNodeMap; \ |
| 80 | 81 |
typedef Digraph::NodeMap<double> DoubleNodeMap; \ |
| 81 | 82 |
typedef Digraph::ArcMap<bool> BoolArcMap; \ |
| 82 | 83 |
typedef Digraph::ArcMap<int> IntArcMap; \ |
| 83 | 84 |
typedef Digraph::ArcMap<double> DoubleArcMap |
| 84 | 85 |
|
| 85 | 86 |
///Create convenience typedefs for the digraph types and iterators |
| 86 | 87 |
|
| 87 | 88 |
///\see DIGRAPH_TYPEDEFS |
| 88 | 89 |
/// |
| 89 | 90 |
///\note Use this macro, if the graph type is a dependent type, |
| 90 | 91 |
///ie. the graph type depend on a template parameter. |
| 91 | 92 |
#define TEMPLATE_DIGRAPH_TYPEDEFS(Digraph) \ |
| 92 | 93 |
typedef typename Digraph::Node Node; \ |
| 93 | 94 |
typedef typename Digraph::NodeIt NodeIt; \ |
| 94 | 95 |
typedef typename Digraph::Arc Arc; \ |
| 95 | 96 |
typedef typename Digraph::ArcIt ArcIt; \ |
| 96 | 97 |
typedef typename Digraph::InArcIt InArcIt; \ |
| 97 | 98 |
typedef typename Digraph::OutArcIt OutArcIt; \ |
| 98 | 99 |
typedef typename Digraph::template NodeMap<bool> BoolNodeMap; \ |
| 99 | 100 |
typedef typename Digraph::template NodeMap<int> IntNodeMap; \ |
| 100 | 101 |
typedef typename Digraph::template NodeMap<double> DoubleNodeMap; \ |
| 101 | 102 |
typedef typename Digraph::template ArcMap<bool> BoolArcMap; \ |
| 102 | 103 |
typedef typename Digraph::template ArcMap<int> IntArcMap; \ |
| 103 | 104 |
typedef typename Digraph::template ArcMap<double> DoubleArcMap |
| 104 | 105 |
|
| 105 | 106 |
///Create convenience typedefs for the graph types and iterators |
| 106 | 107 |
|
| 107 | 108 |
///This \c \#define creates the same convenient type definitions as defined |
| 108 | 109 |
///by \ref DIGRAPH_TYPEDEFS(Graph) and six more, namely it creates |
| 109 | 110 |
///\c Edge, \c EdgeIt, \c IncEdgeIt, \c BoolEdgeMap, \c IntEdgeMap, |
| 110 | 111 |
///\c DoubleEdgeMap. |
| 111 | 112 |
/// |
| 112 | 113 |
///\note If the graph type is a dependent type, ie. the graph type depend |
| 113 | 114 |
///on a template parameter, then use \c TEMPLATE_GRAPH_TYPEDEFS() |
| 114 | 115 |
///macro. |
| 115 | 116 |
#define GRAPH_TYPEDEFS(Graph) \ |
| 116 | 117 |
DIGRAPH_TYPEDEFS(Graph); \ |
| 117 | 118 |
typedef Graph::Edge Edge; \ |
| 118 | 119 |
typedef Graph::EdgeIt EdgeIt; \ |
| 119 | 120 |
typedef Graph::IncEdgeIt IncEdgeIt; \ |
| 120 | 121 |
typedef Graph::EdgeMap<bool> BoolEdgeMap; \ |
| 121 | 122 |
typedef Graph::EdgeMap<int> IntEdgeMap; \ |
| 122 | 123 |
typedef Graph::EdgeMap<double> DoubleEdgeMap |
| 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_DFS_H |
| 20 | 20 |
#define LEMON_DFS_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup search |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief DFS algorithm. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/list_graph.h> |
| 27 | 27 |
#include <lemon/bits/path_dump.h> |
| 28 | 28 |
#include <lemon/core.h> |
| 29 | 29 |
#include <lemon/error.h> |
| 30 |
#include <lemon/assert.h> |
|
| 31 | 30 |
#include <lemon/maps.h> |
| 32 | 31 |
#include <lemon/path.h> |
| 33 | 32 |
|
| 34 | 33 |
namespace lemon {
|
| 35 | 34 |
|
| 36 | 35 |
///Default traits class of Dfs class. |
| 37 | 36 |
|
| 38 | 37 |
///Default traits class of Dfs class. |
| 39 | 38 |
///\tparam GR Digraph type. |
| 40 | 39 |
template<class GR> |
| 41 | 40 |
struct DfsDefaultTraits |
| 42 | 41 |
{
|
| 43 | 42 |
///The type of the digraph the algorithm runs on. |
| 44 | 43 |
typedef GR Digraph; |
| 45 | 44 |
|
| 46 | 45 |
///\brief The type of the map that stores the predecessor |
| 47 | 46 |
///arcs of the %DFS paths. |
| 48 | 47 |
/// |
| 49 | 48 |
///The type of the map that stores the predecessor |
| 50 | 49 |
///arcs of the %DFS paths. |
| 51 | 50 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 52 | 51 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 53 | 52 |
///Instantiates a PredMap. |
| 54 | 53 |
|
| 55 | 54 |
///This function instantiates a PredMap. |
| 56 | 55 |
///\param g is the digraph, to which we would like to define the |
| 57 | 56 |
///PredMap. |
| 58 | 57 |
static PredMap *createPredMap(const Digraph &g) |
| 59 | 58 |
{
|
| 60 | 59 |
return new PredMap(g); |
| 61 | 60 |
} |
| 62 | 61 |
|
| 63 | 62 |
///The type of the map that indicates which nodes are processed. |
| 64 | 63 |
|
| 65 | 64 |
///The type of the map that indicates which nodes are processed. |
| 66 | 65 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 67 | 66 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
| 68 | 67 |
///Instantiates a ProcessedMap. |
| 69 | 68 |
|
| 70 | 69 |
///This function instantiates a ProcessedMap. |
| 71 | 70 |
///\param g is the digraph, to which |
| 72 | 71 |
///we would like to define the ProcessedMap |
| 73 | 72 |
#ifdef DOXYGEN |
| 74 | 73 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
| 75 | 74 |
#else |
| 76 | 75 |
static ProcessedMap *createProcessedMap(const Digraph &) |
| 77 | 76 |
#endif |
| 78 | 77 |
{
|
| 79 | 78 |
return new ProcessedMap(); |
| 80 | 79 |
} |
| 81 | 80 |
|
| 82 | 81 |
///The type of the map that indicates which nodes are reached. |
| 83 | 82 |
|
| 84 | 83 |
///The type of the map that indicates which nodes are reached. |
| 85 | 84 |
///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 86 | 85 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 87 | 86 |
///Instantiates a ReachedMap. |
| 88 | 87 |
|
| 89 | 88 |
///This function instantiates a ReachedMap. |
| 90 | 89 |
///\param g is the digraph, to which |
| 91 | 90 |
///we would like to define the ReachedMap. |
| 92 | 91 |
static ReachedMap *createReachedMap(const Digraph &g) |
| 93 | 92 |
{
|
| 94 | 93 |
return new ReachedMap(g); |
| 95 | 94 |
} |
| 96 | 95 |
|
| 97 | 96 |
///The type of the map that stores the distances of the nodes. |
| 98 | 97 |
|
| 99 | 98 |
///The type of the map that stores the distances of the nodes. |
| 100 | 99 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 101 | 100 |
typedef typename Digraph::template NodeMap<int> DistMap; |
| 102 | 101 |
///Instantiates a DistMap. |
| 103 | 102 |
|
| 104 | 103 |
///This function instantiates a DistMap. |
| 105 | 104 |
///\param g is the digraph, to which we would like to define the |
| 106 | 105 |
///DistMap. |
| 107 | 106 |
static DistMap *createDistMap(const Digraph &g) |
| 108 | 107 |
{
|
| 109 | 108 |
return new DistMap(g); |
| 110 | 109 |
} |
| 111 | 110 |
}; |
| 112 | 111 |
|
| 113 | 112 |
///%DFS algorithm class. |
| 114 | 113 |
|
| 115 | 114 |
///\ingroup search |
| 116 | 115 |
///This class provides an efficient implementation of the %DFS algorithm. |
| 117 | 116 |
/// |
| 118 | 117 |
///There is also a \ref dfs() "function-type interface" for the DFS |
| 119 | 118 |
///algorithm, which is convenient in the simplier cases and it can be |
| 120 | 119 |
///used easier. |
| 121 | 120 |
/// |
| 122 | 121 |
///\tparam GR The type of the digraph the algorithm runs on. |
| 123 | 122 |
///The default value is \ref ListDigraph. The value of GR is not used |
| 124 | 123 |
///directly by \ref Dfs, it is only passed to \ref DfsDefaultTraits. |
| 125 | 124 |
///\tparam TR Traits class to set various data types used by the algorithm. |
| 126 | 125 |
///The default traits class is |
| 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 |
///\ingroup lemon_io |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief \ref lgf-format "LEMON Graph Format" reader. |
| 22 | 22 |
|
| 23 | 23 |
|
| 24 | 24 |
#ifndef LEMON_LGF_READER_H |
| 25 | 25 |
#define LEMON_LGF_READER_H |
| 26 | 26 |
|
| 27 | 27 |
#include <iostream> |
| 28 | 28 |
#include <fstream> |
| 29 | 29 |
#include <sstream> |
| 30 | 30 |
|
| 31 | 31 |
#include <set> |
| 32 | 32 |
#include <map> |
| 33 | 33 |
|
| 34 |
#include <lemon/assert.h> |
|
| 35 | 34 |
#include <lemon/core.h> |
| 36 | 35 |
|
| 37 | 36 |
#include <lemon/lgf_writer.h> |
| 38 | 37 |
|
| 39 | 38 |
#include <lemon/concept_check.h> |
| 40 | 39 |
#include <lemon/concepts/maps.h> |
| 41 | 40 |
|
| 42 | 41 |
namespace lemon {
|
| 43 | 42 |
|
| 44 | 43 |
namespace _reader_bits {
|
| 45 | 44 |
|
| 46 | 45 |
template <typename Value> |
| 47 | 46 |
struct DefaultConverter {
|
| 48 | 47 |
Value operator()(const std::string& str) {
|
| 49 | 48 |
std::istringstream is(str); |
| 50 | 49 |
Value value; |
| 51 | 50 |
if (!(is >> value)) {
|
| 52 | 51 |
throw FormatError("Cannot read token");
|
| 53 | 52 |
} |
| 54 | 53 |
|
| 55 | 54 |
char c; |
| 56 | 55 |
if (is >> std::ws >> c) {
|
| 57 | 56 |
throw FormatError("Remaining characters in token");
|
| 58 | 57 |
} |
| 59 | 58 |
return value; |
| 60 | 59 |
} |
| 61 | 60 |
}; |
| 62 | 61 |
|
| 63 | 62 |
template <> |
| 64 | 63 |
struct DefaultConverter<std::string> {
|
| 65 | 64 |
std::string operator()(const std::string& str) {
|
| 66 | 65 |
return str; |
| 67 | 66 |
} |
| 68 | 67 |
}; |
| 69 | 68 |
|
| 70 | 69 |
template <typename _Item> |
| 71 | 70 |
class MapStorageBase {
|
| 72 | 71 |
public: |
| 73 | 72 |
typedef _Item Item; |
| 74 | 73 |
|
| 75 | 74 |
public: |
| 76 | 75 |
MapStorageBase() {}
|
| 77 | 76 |
virtual ~MapStorageBase() {}
|
| 78 | 77 |
|
| 79 | 78 |
virtual void set(const Item& item, const std::string& value) = 0; |
| 80 | 79 |
|
| 81 | 80 |
}; |
| 82 | 81 |
|
| 83 | 82 |
template <typename _Item, typename _Map, |
| 84 | 83 |
typename _Converter = DefaultConverter<typename _Map::Value> > |
| 85 | 84 |
class MapStorage : public MapStorageBase<_Item> {
|
| 86 | 85 |
public: |
| 87 | 86 |
typedef _Map Map; |
| 88 | 87 |
typedef _Converter Converter; |
| 89 | 88 |
typedef _Item Item; |
| 90 | 89 |
|
| 91 | 90 |
private: |
| 92 | 91 |
Map& _map; |
| 93 | 92 |
Converter _converter; |
| 94 | 93 |
|
| 95 | 94 |
public: |
| 96 | 95 |
MapStorage(Map& map, const Converter& converter = Converter()) |
| 97 | 96 |
: _map(map), _converter(converter) {}
|
| 98 | 97 |
virtual ~MapStorage() {}
|
| 99 | 98 |
|
| 100 | 99 |
virtual void set(const Item& item ,const std::string& value) {
|
| 101 | 100 |
_map.set(item, _converter(value)); |
| 102 | 101 |
} |
| 103 | 102 |
}; |
| 104 | 103 |
|
| 105 | 104 |
template <typename _Graph, bool _dir, typename _Map, |
| 106 | 105 |
typename _Converter = DefaultConverter<typename _Map::Value> > |
| 107 | 106 |
class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> {
|
| 108 | 107 |
public: |
| 109 | 108 |
typedef _Map Map; |
| 110 | 109 |
typedef _Converter Converter; |
| 111 | 110 |
typedef _Graph Graph; |
| 112 | 111 |
typedef typename Graph::Edge Item; |
| 113 | 112 |
static const bool dir = _dir; |
| 114 | 113 |
|
| 115 | 114 |
private: |
| 116 | 115 |
const Graph& _graph; |
| 117 | 116 |
Map& _map; |
| 118 | 117 |
Converter _converter; |
| 119 | 118 |
|
| 120 | 119 |
public: |
| 121 | 120 |
GraphArcMapStorage(const Graph& graph, Map& map, |
| 122 | 121 |
const Converter& converter = Converter()) |
| 123 | 122 |
: _graph(graph), _map(map), _converter(converter) {}
|
| 124 | 123 |
virtual ~GraphArcMapStorage() {}
|
| 125 | 124 |
|
| 126 | 125 |
virtual void set(const Item& item ,const std::string& value) {
|
| 127 | 126 |
_map.set(_graph.direct(item, dir), _converter(value)); |
| 128 | 127 |
} |
| 129 | 128 |
}; |
| 130 | 129 |
| 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 |
///\ingroup lemon_io |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief \ref lgf-format "LEMON Graph Format" writer. |
| 22 | 22 |
|
| 23 | 23 |
|
| 24 | 24 |
#ifndef LEMON_LGF_WRITER_H |
| 25 | 25 |
#define LEMON_LGF_WRITER_H |
| 26 | 26 |
|
| 27 | 27 |
#include <iostream> |
| 28 | 28 |
#include <fstream> |
| 29 | 29 |
#include <sstream> |
| 30 | 30 |
|
| 31 | 31 |
#include <algorithm> |
| 32 | 32 |
|
| 33 | 33 |
#include <vector> |
| 34 | 34 |
#include <functional> |
| 35 | 35 |
|
| 36 |
#include <lemon/assert.h> |
|
| 37 | 36 |
#include <lemon/core.h> |
| 38 | 37 |
#include <lemon/maps.h> |
| 39 | 38 |
|
| 40 | 39 |
#include <lemon/concept_check.h> |
| 41 | 40 |
#include <lemon/concepts/maps.h> |
| 42 | 41 |
|
| 43 | 42 |
namespace lemon {
|
| 44 | 43 |
|
| 45 | 44 |
namespace _writer_bits {
|
| 46 | 45 |
|
| 47 | 46 |
template <typename Value> |
| 48 | 47 |
struct DefaultConverter {
|
| 49 | 48 |
std::string operator()(const Value& value) {
|
| 50 | 49 |
std::ostringstream os; |
| 51 | 50 |
os << value; |
| 52 | 51 |
return os.str(); |
| 53 | 52 |
} |
| 54 | 53 |
}; |
| 55 | 54 |
|
| 56 | 55 |
template <typename T> |
| 57 | 56 |
bool operator<(const T&, const T&) {
|
| 58 | 57 |
throw FormatError("Label map is not comparable");
|
| 59 | 58 |
} |
| 60 | 59 |
|
| 61 | 60 |
template <typename _Map> |
| 62 | 61 |
class MapLess {
|
| 63 | 62 |
public: |
| 64 | 63 |
typedef _Map Map; |
| 65 | 64 |
typedef typename Map::Key Item; |
| 66 | 65 |
|
| 67 | 66 |
private: |
| 68 | 67 |
const Map& _map; |
| 69 | 68 |
|
| 70 | 69 |
public: |
| 71 | 70 |
MapLess(const Map& map) : _map(map) {}
|
| 72 | 71 |
|
| 73 | 72 |
bool operator()(const Item& left, const Item& right) {
|
| 74 | 73 |
return _map[left] < _map[right]; |
| 75 | 74 |
} |
| 76 | 75 |
}; |
| 77 | 76 |
|
| 78 | 77 |
template <typename _Graph, bool _dir, typename _Map> |
| 79 | 78 |
class GraphArcMapLess {
|
| 80 | 79 |
public: |
| 81 | 80 |
typedef _Map Map; |
| 82 | 81 |
typedef _Graph Graph; |
| 83 | 82 |
typedef typename Graph::Edge Item; |
| 84 | 83 |
|
| 85 | 84 |
private: |
| 86 | 85 |
const Graph& _graph; |
| 87 | 86 |
const Map& _map; |
| 88 | 87 |
|
| 89 | 88 |
public: |
| 90 | 89 |
GraphArcMapLess(const Graph& graph, const Map& map) |
| 91 | 90 |
: _graph(graph), _map(map) {}
|
| 92 | 91 |
|
| 93 | 92 |
bool operator()(const Item& left, const Item& right) {
|
| 94 | 93 |
return _map[_graph.direct(left, _dir)] < |
| 95 | 94 |
_map[_graph.direct(right, _dir)]; |
| 96 | 95 |
} |
| 97 | 96 |
}; |
| 98 | 97 |
|
| 99 | 98 |
template <typename _Item> |
| 100 | 99 |
class MapStorageBase {
|
| 101 | 100 |
public: |
| 102 | 101 |
typedef _Item Item; |
| 103 | 102 |
|
| 104 | 103 |
public: |
| 105 | 104 |
MapStorageBase() {}
|
| 106 | 105 |
virtual ~MapStorageBase() {}
|
| 107 | 106 |
|
| 108 | 107 |
virtual std::string get(const Item& item) = 0; |
| 109 | 108 |
virtual void sort(std::vector<Item>&) = 0; |
| 110 | 109 |
}; |
| 111 | 110 |
|
| 112 | 111 |
template <typename _Item, typename _Map, |
| 113 | 112 |
typename _Converter = DefaultConverter<typename _Map::Value> > |
| 114 | 113 |
class MapStorage : public MapStorageBase<_Item> {
|
| 115 | 114 |
public: |
| 116 | 115 |
typedef _Map Map; |
| 117 | 116 |
typedef _Converter Converter; |
| 118 | 117 |
typedef _Item Item; |
| 119 | 118 |
|
| 120 | 119 |
private: |
| 121 | 120 |
const Map& _map; |
| 122 | 121 |
Converter _converter; |
| 123 | 122 |
|
| 124 | 123 |
public: |
| 125 | 124 |
MapStorage(const Map& map, const Converter& converter = Converter()) |
| 126 | 125 |
: _map(map), _converter(converter) {}
|
| 127 | 126 |
virtual ~MapStorage() {}
|
| 128 | 127 |
|
| 129 | 128 |
virtual std::string get(const Item& item) {
|
| 130 | 129 |
return _converter(_map[item]); |
| 131 | 130 |
} |
| 132 | 131 |
virtual void sort(std::vector<Item>& items) {
|
0 comments (0 inline)