0
17
0
1
1
1
1
| 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 |
///\file |
| 20 | 20 |
///\brief Some basic non inline function and static global data. |
| 21 | 21 |
|
| 22 | 22 |
#include<lemon/tolerance.h> |
| 23 | 23 |
#include<lemon/bits/invalid.h> |
| 24 | 24 |
namespace lemon {
|
| 25 | 25 |
|
| 26 | 26 |
float Tolerance<float>::def_epsilon = 1e-4; |
| 27 | 27 |
double Tolerance<double>::def_epsilon = 1e-10; |
| 28 | 28 |
long double Tolerance<long double>::def_epsilon = 1e-14; |
| 29 | 29 |
|
| 30 | 30 |
#ifndef LEMON_ONLY_TEMPLATES |
| 31 | 31 |
const Invalid INVALID = Invalid(); |
| 32 | 32 |
#endif |
| 33 | 33 |
|
| 34 | 34 |
} //namespace lemon |
| 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_INVALID_H |
| 20 | 20 |
#define LEMON_BITS_INVALID_H |
| 21 | 21 |
|
| 22 | 22 |
///\file |
| 23 | 23 |
///\brief Definition of INVALID. |
| 24 | 24 |
|
| 25 | 25 |
namespace lemon {
|
| 26 | 26 |
|
| 27 | 27 |
/// \brief Dummy type to make it easier to create invalid iterators. |
| 28 | 28 |
/// |
| 29 | 29 |
/// See \ref INVALID for the usage. |
| 30 | 30 |
struct Invalid {
|
| 31 | 31 |
public: |
| 32 | 32 |
bool operator==(Invalid) { return true; }
|
| 33 | 33 |
bool operator!=(Invalid) { return false; }
|
| 34 | 34 |
bool operator< (Invalid) { return false; }
|
| 35 | 35 |
}; |
| 36 | 36 |
|
| 37 | 37 |
/// \brief Invalid iterators. |
| 38 | 38 |
/// |
| 39 | 39 |
/// \ref Invalid is a global type that converts to each iterator |
| 40 | 40 |
/// in such a way that the value of the target iterator will be invalid. |
| 41 | 41 |
|
| 42 | 42 |
//Some people didn't like this: |
| 43 | 43 |
//const Invalid &INVALID = *(Invalid *)0; |
| 44 | 44 |
|
| 45 | 45 |
#ifdef LEMON_ONLY_TEMPLATES |
| 46 | 46 |
const Invalid INVALID = Invalid(); |
| 47 | 47 |
#else |
| 48 | 48 |
extern const Invalid INVALID; |
| 49 | 49 |
#endif |
| 50 | 50 |
|
| 51 | 51 |
} //namespace lemon |
| 52 | 52 |
|
| 53 | 53 |
#endif |
| 54 | 54 |
|
| 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 |
// This file contains a modified version of the enable_if library from BOOST. |
| 20 | 20 |
// See the appropriate copyright notice below. |
| 21 | 21 |
|
| 22 | 22 |
// Boost enable_if library |
| 23 | 23 |
|
| 24 | 24 |
// Copyright 2003 � The Trustees of Indiana University. |
| 25 | 25 |
|
| 26 | 26 |
// Use, modification, and distribution is subject to the Boost Software |
| 27 | 27 |
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 28 | 28 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 29 | 29 |
|
| 30 | 30 |
// Authors: Jaakko J�rvi (jajarvi at osl.iu.edu) |
| 31 | 31 |
// Jeremiah Willcock (jewillco at osl.iu.edu) |
| 32 | 32 |
// Andrew Lumsdaine (lums at osl.iu.edu) |
| 33 | 33 |
|
| 34 | 34 |
|
| 35 | 35 |
#ifndef LEMON_BITS_UTILITY_H |
| 36 | 36 |
#define LEMON_BITS_UTILITY_H |
| 37 | 37 |
|
| 38 | 38 |
///\file |
| 39 | 39 |
///\brief Miscellaneous basic utilities |
| 40 | 40 |
/// |
| 41 | 41 |
///\todo Please rethink the organisation of the basic files like this. |
| 42 | 42 |
///E.g. this file might be merged with invalid.h. |
| 43 | 43 |
|
| 44 | 44 |
|
| 45 | 45 |
namespace lemon |
| 46 | 46 |
{
|
| 47 | 47 |
|
| 48 | 48 |
/// Basic type for defining "tags". A "YES" condition for \c enable_if. |
| 49 | 49 |
|
| 50 | 50 |
/// Basic type for defining "tags". A "YES" condition for \c enable_if. |
| 51 | 51 |
/// |
| 52 | 52 |
///\sa False |
| 53 | 53 |
/// |
| 54 | 54 |
/// \todo This should go to a separate "basic_types.h" (or something) |
| 55 | 55 |
/// file. |
| 56 | 56 |
struct True {
|
| 57 | 57 |
///\e |
| 58 | 58 |
static const bool value = true; |
| 59 | 59 |
}; |
| 60 | 60 |
|
| 61 | 61 |
/// Basic type for defining "tags". A "NO" condition for \c enable_if. |
| 62 | 62 |
|
| 63 | 63 |
/// Basic type for defining "tags". A "NO" condition for \c enable_if. |
| 64 | 64 |
/// |
| 65 | 65 |
///\sa True |
| 66 | 66 |
struct False {
|
| 67 | 67 |
///\e |
| 68 | 68 |
static const bool value = false; |
| 69 | 69 |
}; |
| 70 | 70 |
|
| 71 | 71 |
|
| 72 | 72 |
struct InvalidType {
|
| 73 | 73 |
}; |
| 74 | 74 |
|
| 75 | 75 |
template <typename T> |
| 76 | 76 |
struct Wrap {
|
| 77 | 77 |
const T &value; |
| 78 | 78 |
Wrap(const T &t) : value(t) {}
|
| 79 | 79 |
}; |
| 80 | 80 |
|
| 81 | 81 |
/**************** dummy class to avoid ambiguity ****************/ |
| 82 | 82 |
|
| 83 | 83 |
template<int T> struct dummy { dummy(int) {} };
|
| 84 | 84 |
|
| 85 | 85 |
/**************** enable_if from BOOST ****************/ |
| 86 | 86 |
|
| 87 | 87 |
template <typename Type, typename T = void> |
| 88 | 88 |
struct exists {
|
| 89 | 89 |
typedef T type; |
| 90 | 90 |
}; |
| 91 | 91 |
|
| 92 | 92 |
|
| 93 | 93 |
template <bool B, class T = void> |
| 94 | 94 |
struct enable_if_c {
|
| 95 | 95 |
typedef T type; |
| 96 | 96 |
}; |
| 97 | 97 |
|
| 98 | 98 |
template <class T> |
| 99 | 99 |
struct enable_if_c<false, T> {};
|
| 100 | 100 |
|
| 101 | 101 |
template <class Cond, class T = void> |
| 102 | 102 |
struct enable_if : public enable_if_c<Cond::value, T> {};
|
| 103 | 103 |
|
| 104 | 104 |
template <bool B, class T> |
| 105 | 105 |
struct lazy_enable_if_c {
|
| 106 | 106 |
typedef typename T::type type; |
| 107 | 107 |
}; |
| 108 | 108 |
|
| 109 | 109 |
template <class T> |
| 110 | 110 |
struct lazy_enable_if_c<false, T> {};
|
| 111 | 111 |
|
| 112 | 112 |
template <class Cond, class T> |
| 113 | 113 |
struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
|
| 114 | 114 |
|
| 115 | 115 |
|
| 116 | 116 |
template <bool B, class T = void> |
| 117 | 117 |
struct disable_if_c {
|
| 118 | 118 |
typedef T type; |
| 119 | 119 |
}; |
| 120 | 120 |
|
| 121 | 121 |
template <class T> |
| 122 | 122 |
struct disable_if_c<true, T> {};
|
| 123 | 123 |
|
| 124 | 124 |
template <class Cond, class T = void> |
| 125 | 125 |
struct disable_if : public disable_if_c<Cond::value, T> {};
|
| 126 | 126 |
|
| 127 | 127 |
template <bool B, class T> |
| 128 | 128 |
struct lazy_disable_if_c {
|
| 129 | 129 |
typedef typename T::type type; |
| 130 | 130 |
}; |
| 131 | 131 |
|
| 132 | 132 |
template <class T> |
| 133 | 133 |
struct lazy_disable_if_c<true, T> {};
|
| 134 | 134 |
|
| 135 | 135 |
template <class Cond, class T> |
| 136 | 136 |
struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
|
| 137 | 137 |
|
| 138 | 138 |
} // namespace lemon |
| 139 | 139 |
|
| 140 | 140 |
#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 |
// This file contains a modified version of the concept checking |
| 20 | 20 |
// utility from BOOST. |
| 21 | 21 |
// See the appropriate copyright notice below. |
| 22 | 22 |
|
| 23 | 23 |
// (C) Copyright Jeremy Siek 2000. |
| 24 | 24 |
// Distributed under the Boost Software License, Version 1.0. (See |
| 25 | 25 |
// accompanying file LICENSE_1_0.txt or copy at |
| 26 | 26 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 27 | 27 |
// |
| 28 | 28 |
// Revision History: |
| 29 | 29 |
// 05 May 2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek) |
| 30 | 30 |
// 02 April 2001: Removed limits header altogether. (Jeremy Siek) |
| 31 | 31 |
// 01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock) |
| 32 | 32 |
// |
| 33 | 33 |
|
| 34 | 34 |
// See http://www.boost.org/libs/concept_check for documentation. |
| 35 | 35 |
|
| 36 | 36 |
#ifndef LEMON_CONCEPT_CHECKS_H |
| 37 | 37 |
#define LEMON_CONCEPT_CHECKS_H |
| 38 | 38 |
|
| 39 | 39 |
namespace lemon {
|
| 40 | 40 |
|
| 41 | 41 |
/* |
| 42 | 42 |
"inline" is used for ignore_unused_variable_warning() |
| 43 | 43 |
and function_requires() to make sure there is no |
| 44 | 44 |
overtarget with g++. |
| 45 | 45 |
*/ |
| 46 | 46 |
|
| 47 | 47 |
template <class T> inline void ignore_unused_variable_warning(const T&) { }
|
| 48 | 48 |
|
| 49 | 49 |
template <class Concept> |
| 50 | 50 |
inline void function_requires() |
| 51 | 51 |
{
|
| 52 | 52 |
#if !defined(NDEBUG) |
| 53 | 53 |
void (Concept::*x)() = & Concept::constraints; |
| 54 | 54 |
ignore_unused_variable_warning(x); |
| 55 | 55 |
#endif |
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 | 58 |
template <typename Concept, typename Type> |
| 59 | 59 |
inline void checkConcept() {
|
| 60 | 60 |
#if !defined(NDEBUG) |
| 61 | 61 |
typedef typename Concept::template Constraints<Type> ConceptCheck; |
| 62 | 62 |
void (ConceptCheck::*x)() = & ConceptCheck::constraints; |
| 63 | 63 |
ignore_unused_variable_warning(x); |
| 64 | 64 |
#endif |
| 65 | 65 |
} |
| 66 | 66 |
|
| 67 | 67 |
#define BOOST_CLASS_REQUIRE(type_var, ns, concept) \ |
| 68 | 68 |
typedef void (ns::concept <type_var>::* func##type_var##concept)(); \ |
| 69 | 69 |
template <func##type_var##concept Tp1_> \ |
| 70 | 70 |
struct concept_checking_##type_var##concept { }; \
|
| 71 | 71 |
typedef concept_checking_##type_var##concept< \ |
| 72 | 72 |
BOOST_FPTR ns::concept<type_var>::constraints> \ |
| 73 | 73 |
concept_checking_typedef_##type_var##concept |
| 74 | 74 |
|
| 75 | 75 |
#define BOOST_CLASS_REQUIRE2(type_var1, type_var2, ns, concept) \ |
| 76 | 76 |
typedef void (ns::concept <type_var1,type_var2>::* \ |
| 77 | 77 |
func##type_var1##type_var2##concept)(); \ |
| 78 | 78 |
template <func##type_var1##type_var2##concept Tp1_> \ |
| 79 | 79 |
struct concept_checking_##type_var1##type_var2##concept { }; \
|
| 80 | 80 |
typedef concept_checking_##type_var1##type_var2##concept< \ |
| 81 | 81 |
BOOST_FPTR ns::concept<type_var1,type_var2>::constraints> \ |
| 82 | 82 |
concept_checking_typedef_##type_var1##type_var2##concept |
| 83 | 83 |
|
| 84 | 84 |
#define BOOST_CLASS_REQUIRE3(tv1, tv2, tv3, ns, concept) \ |
| 85 | 85 |
typedef void (ns::concept <tv1,tv2,tv3>::* \ |
| 86 | 86 |
func##tv1##tv2##tv3##concept)(); \ |
| 87 | 87 |
template <func##tv1##tv2##tv3##concept Tp1_> \ |
| 88 | 88 |
struct concept_checking_##tv1##tv2##tv3##concept { }; \
|
| 89 | 89 |
typedef concept_checking_##tv1##tv2##tv3##concept< \ |
| 90 | 90 |
BOOST_FPTR ns::concept<tv1,tv2,tv3>::constraints> \ |
| 91 | 91 |
concept_checking_typedef_##tv1##tv2##tv3##concept |
| 92 | 92 |
|
| 93 | 93 |
#define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \ |
| 94 | 94 |
typedef void (ns::concept <tv1,tv2,tv3,tv4>::* \ |
| 95 | 95 |
func##tv1##tv2##tv3##tv4##concept)(); \ |
| 96 | 96 |
template <func##tv1##tv2##tv3##tv4##concept Tp1_> \ |
| 97 | 97 |
struct concept_checking_##tv1##tv2##tv3##tv4##concept { }; \
|
| 98 | 98 |
typedef concept_checking_##tv1##tv2##tv3##tv4##concept< \ |
| 99 | 99 |
BOOST_FPTR ns::concept<tv1,tv2,tv3,tv4>::constraints> \ |
| 100 | 100 |
concept_checking_typedef_##tv1##tv2##tv3##tv4##concept |
| 101 | 101 |
|
| 102 | 102 |
|
| 103 | 103 |
} // namespace lemon |
| 104 | 104 |
|
| 105 | 105 |
#endif // LEMON_CONCEPT_CHECKS_H |
| 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_MAPS_H |
| 20 | 20 |
#define LEMON_CONCEPT_MAPS_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/bits/utility.h> |
| 23 | 23 |
#include <lemon/concept_check.h> |
| 24 | 24 |
|
| 25 | 25 |
///\ingroup concept |
| 26 | 26 |
///\file |
| 27 | 27 |
///\brief Map concepts checking classes for testing and documenting. |
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
namespace concepts {
|
| 32 | 32 |
|
| 33 | 33 |
/// \addtogroup concept |
| 34 | 34 |
/// @{
|
| 35 | 35 |
|
| 36 | 36 |
/// Readable map concept |
| 37 | 37 |
|
| 38 | 38 |
/// Readable map concept. |
| 39 | 39 |
/// |
| 40 | 40 |
template<typename K, typename T> |
| 41 | 41 |
class ReadMap |
| 42 | 42 |
{
|
| 43 | 43 |
public: |
| 44 | 44 |
/// The key type of the map. |
| 45 | 45 |
typedef K Key; |
| 46 | 46 |
/// The value type of the map. (The type of objects associated with the keys). |
| 47 | 47 |
typedef T Value; |
| 48 | 48 |
|
| 49 | 49 |
/// Returns the value associated with a key. |
| 50 | 50 |
|
| 51 | 51 |
/// \bug Value shouldn't need to be default constructible. |
| 52 | 52 |
/// |
| 53 | 53 |
Value operator[](const Key &) const {return Value();}
|
| 54 | 54 |
|
| 55 | 55 |
template<typename _ReadMap> |
| 56 | 56 |
struct Constraints {
|
| 57 | 57 |
|
| 58 | 58 |
void constraints() {
|
| 59 | 59 |
Value val = m[key]; |
| 60 | 60 |
val = m[key]; |
| 61 | 61 |
typename _ReadMap::Value own_val = m[own_key]; |
| 62 | 62 |
own_val = m[own_key]; |
| 63 | 63 |
|
| 64 | 64 |
ignore_unused_variable_warning(val); |
| 65 | 65 |
ignore_unused_variable_warning(own_val); |
| 66 | 66 |
ignore_unused_variable_warning(key); |
| 67 | 67 |
} |
| 68 | 68 |
Key& key; |
| 69 | 69 |
typename _ReadMap::Key& own_key; |
| 70 | 70 |
_ReadMap& m; |
| 71 | 71 |
}; |
| 72 | 72 |
|
| 73 | 73 |
}; |
| 74 | 74 |
|
| 75 | 75 |
|
| 76 | 76 |
/// Writable map concept |
| 77 | 77 |
|
| 78 | 78 |
/// Writable map concept. |
| 79 | 79 |
/// |
| 80 | 80 |
template<typename K, typename T> |
| 81 | 81 |
class WriteMap |
| 82 | 82 |
{
|
| 83 | 83 |
public: |
| 84 | 84 |
/// The key type of the map. |
| 85 | 85 |
typedef K Key; |
| 86 | 86 |
/// The value type of the map. (The type of objects associated with the keys). |
| 87 | 87 |
typedef T Value; |
| 88 | 88 |
|
| 89 | 89 |
/// Sets the value associated with a key. |
| 90 | 90 |
void set(const Key &,const Value &) {}
|
| 91 | 91 |
|
| 92 | 92 |
///Default constructor |
| 93 | 93 |
WriteMap() {}
|
| 94 | 94 |
|
| 95 | 95 |
template <typename _WriteMap> |
| 96 | 96 |
struct Constraints {
|
| 97 | 97 |
void constraints() {
|
| 98 | 98 |
// No constraints for constructor. |
| 99 | 99 |
m.set(key, val); |
| 100 | 100 |
m.set(own_key, own_val); |
| 101 | 101 |
ignore_unused_variable_warning(key); |
| 102 | 102 |
ignore_unused_variable_warning(val); |
| 103 | 103 |
ignore_unused_variable_warning(own_key); |
| 104 | 104 |
ignore_unused_variable_warning(own_val); |
| 105 | 105 |
} |
| 106 | 106 |
|
| 107 | 107 |
Value& val; |
| 108 | 108 |
typename _WriteMap::Value own_val; |
| 109 | 109 |
Key& key; |
| 110 | 110 |
typename _WriteMap::Key& own_key; |
| 111 | 111 |
_WriteMap& m; |
| 112 | 112 |
|
| 113 | 113 |
}; |
| 114 | 114 |
}; |
| 115 | 115 |
|
| 116 | 116 |
/// Read/Writable map concept |
| 117 | 117 |
|
| 118 | 118 |
/// Read/writable map concept. |
| 119 | 119 |
/// |
| 120 | 120 |
template<typename K, typename T> |
| 121 | 121 |
class ReadWriteMap : public ReadMap<K,T>, |
| 122 | 122 |
public WriteMap<K,T> |
| 123 | 123 |
{
|
| 124 | 124 |
public: |
| 125 | 125 |
/// The key type of the map. |
| 126 | 126 |
typedef K Key; |
| 127 | 127 |
/// The value type of the map. (The type of objects associated with the keys). |
| 128 | 128 |
typedef T Value; |
| 129 | 129 |
|
| 130 | 130 |
/// Returns the value associated with a key. |
| 131 | 131 |
Value operator[](const Key &) const {return Value();}
|
| 132 | 132 |
/// Sets the value associated with a key. |
| 133 | 133 |
void set(const Key & ,const Value &) {}
|
| 134 | 134 |
|
| 135 | 135 |
template<typename _ReadWriteMap> |
| 136 | 136 |
struct Constraints {
|
| 137 | 137 |
void constraints() {
|
| 138 | 138 |
checkConcept<ReadMap<K, T>, _ReadWriteMap >(); |
| 139 | 139 |
checkConcept<WriteMap<K, T>, _ReadWriteMap >(); |
| 140 | 140 |
} |
| 141 | 141 |
}; |
| 142 | 142 |
}; |
| 143 | 143 |
|
| 144 | 144 |
|
| 145 | 145 |
/// Dereferable map concept |
| 146 | 146 |
|
| 147 | 147 |
/// Dereferable map concept. |
| 148 | 148 |
/// |
| 149 | 149 |
template<typename K, typename T, typename R, typename CR> |
| 150 | 150 |
class ReferenceMap : public ReadWriteMap<K,T> |
| 151 | 151 |
{
|
| 152 | 152 |
public: |
| 153 | 153 |
/// Tag for reference maps. |
| 154 | 154 |
typedef True ReferenceMapTag; |
| 155 | 155 |
/// The key type of the map. |
| 156 | 156 |
typedef K Key; |
| 157 | 157 |
/// The value type of the map. (The type of objects associated with the keys). |
| 158 | 158 |
typedef T Value; |
| 159 | 159 |
/// The reference type of the map. |
| 160 | 160 |
typedef R Reference; |
| 161 | 161 |
/// The const reference type of the map. |
| 162 | 162 |
typedef CR ConstReference; |
| 163 | 163 |
|
| 164 | 164 |
protected: |
| 165 | 165 |
Value tmp; |
| 166 | 166 |
public: |
| 167 | 167 |
|
| 168 | 168 |
///Returns a reference to the value associated to a key. |
| 169 | 169 |
Reference operator[](const Key &) { return tmp; }
|
| 170 | 170 |
///Returns a const reference to the value associated to a key. |
| 171 | 171 |
ConstReference operator[](const Key &) const { return tmp; }
|
| 172 | 172 |
/// Sets the value associated with a key. |
| 173 | 173 |
void set(const Key &k,const Value &t) { operator[](k)=t; }
|
| 174 | 174 |
|
| 175 | 175 |
/// \todo Rethink this concept. |
| 176 | 176 |
template<typename _ReferenceMap> |
| 177 | 177 |
struct ReferenceMapConcept {
|
| 178 | 178 |
|
| 179 | 179 |
void constraints() {
|
| 180 | 180 |
checkConcept<ReadWriteMap, _ReferenceMap >(); |
| 181 | 181 |
m[key] = val; |
| 182 | 182 |
val = m[key]; |
| 183 | 183 |
m[key] = ref; |
| 184 | 184 |
ref = m[key]; |
| 185 | 185 |
m[own_key] = own_val; |
| 186 | 186 |
own_val = m[own_key]; |
| 187 | 187 |
m[own_key] = own_ref; |
| 188 | 188 |
own_ref = m[own_key]; |
| 189 | 189 |
} |
| 190 | 190 |
|
| 191 | 191 |
typename _ReferenceMap::Key& own_key; |
| 192 | 192 |
typename _ReferenceMap::Value& own_val; |
| 193 | 193 |
typename _ReferenceMap::Reference& own_ref; |
| 194 | 194 |
Key& key; |
| 195 | 195 |
Value& val; |
| 196 | 196 |
Reference& ref; |
| 197 | 197 |
_ReferenceMap& m; |
| 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_DIM2_H |
| 20 | 20 |
#define LEMON_DIM2_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iostream> |
| 23 | 23 |
#include <lemon/bits/utility.h> |
| 24 | 24 |
|
| 25 | 25 |
///\ingroup misc |
| 26 | 26 |
///\file |
| 27 | 27 |
///\brief A simple two dimensional vector and a bounding box implementation |
| 28 | 28 |
/// |
| 29 | 29 |
/// The class \ref lemon::dim2::Point "dim2::Point" implements |
| 30 | 30 |
///a two dimensional vector with the usual |
| 31 | 31 |
/// operations. |
| 32 | 32 |
/// |
| 33 | 33 |
/// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox" |
| 34 | 34 |
/// can be used to determine |
| 35 | 35 |
/// the rectangular bounding box of a set of |
| 36 | 36 |
/// \ref lemon::dim2::Point "dim2::Point"'s. |
| 37 | 37 |
|
| 38 | 38 |
namespace lemon {
|
| 39 | 39 |
|
| 40 | 40 |
///Tools for handling two dimensional coordinates |
| 41 | 41 |
|
| 42 | 42 |
///This namespace is a storage of several |
| 43 | 43 |
///tools for handling two dimensional coordinates |
| 44 | 44 |
namespace dim2 {
|
| 45 | 45 |
|
| 46 | 46 |
/// \addtogroup misc |
| 47 | 47 |
/// @{
|
| 48 | 48 |
|
| 49 | 49 |
/// A simple two dimensional vector (plainvector) implementation |
| 50 | 50 |
|
| 51 | 51 |
/// A simple two dimensional vector (plainvector) implementation |
| 52 | 52 |
///with the usual vector |
| 53 | 53 |
/// operators. |
| 54 | 54 |
/// |
| 55 | 55 |
template<typename T> |
| 56 | 56 |
class Point {
|
| 57 | 57 |
|
| 58 | 58 |
public: |
| 59 | 59 |
|
| 60 | 60 |
typedef T Value; |
| 61 | 61 |
|
| 62 | 62 |
///First coordinate |
| 63 | 63 |
T x; |
| 64 | 64 |
///Second coordinate |
| 65 | 65 |
T y; |
| 66 | 66 |
|
| 67 | 67 |
///Default constructor |
| 68 | 68 |
Point() {}
|
| 69 | 69 |
|
| 70 | 70 |
///Construct an instance from coordinates |
| 71 | 71 |
Point(T a, T b) : x(a), y(b) { }
|
| 72 | 72 |
|
| 73 | 73 |
///The dimension of the vector. |
| 74 | 74 |
|
| 75 | 75 |
///The dimension of the vector. |
| 76 | 76 |
///This function always returns 2. |
| 77 | 77 |
int size() const { return 2; }
|
| 78 | 78 |
|
| 79 | 79 |
///Subscripting operator |
| 80 | 80 |
|
| 81 | 81 |
///\c p[0] is \c p.x and \c p[1] is \c p.y |
| 82 | 82 |
/// |
| 83 | 83 |
T& operator[](int idx) { return idx == 0 ? x : y; }
|
| 84 | 84 |
|
| 85 | 85 |
///Const subscripting operator |
| 86 | 86 |
|
| 87 | 87 |
///\c p[0] is \c p.x and \c p[1] is \c p.y |
| 88 | 88 |
/// |
| 89 | 89 |
const T& operator[](int idx) const { return idx == 0 ? x : y; }
|
| 90 | 90 |
|
| 91 | 91 |
///Conversion constructor |
| 92 | 92 |
template<class TT> Point(const Point<TT> &p) : x(p.x), y(p.y) {}
|
| 93 | 93 |
|
| 94 | 94 |
///Give back the square of the norm of the vector |
| 95 | 95 |
T normSquare() const {
|
| 96 | 96 |
return x*x+y*y; |
| 97 | 97 |
} |
| 98 | 98 |
|
| 99 | 99 |
///Increment the left hand side by u |
| 100 | 100 |
Point<T>& operator +=(const Point<T>& u) {
|
| 101 | 101 |
x += u.x; |
| 102 | 102 |
y += u.y; |
| 103 | 103 |
return *this; |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
///Decrement the left hand side by u |
| 107 | 107 |
Point<T>& operator -=(const Point<T>& u) {
|
| 108 | 108 |
x -= u.x; |
| 109 | 109 |
y -= u.y; |
| 110 | 110 |
return *this; |
| 111 | 111 |
} |
| 112 | 112 |
|
| 113 | 113 |
///Multiply the left hand side with a scalar |
| 114 | 114 |
Point<T>& operator *=(const T &u) {
|
| 115 | 115 |
x *= u; |
| 116 | 116 |
y *= u; |
| 117 | 117 |
return *this; |
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 | 120 |
///Divide the left hand side by a scalar |
| 121 | 121 |
Point<T>& operator /=(const T &u) {
|
| 122 | 122 |
x /= u; |
| 123 | 123 |
y /= u; |
| 124 | 124 |
return *this; |
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 | 127 |
///Return the scalar product of two vectors |
| 128 | 128 |
T operator *(const Point<T>& u) const {
|
| 129 | 129 |
return x*u.x+y*u.y; |
| 130 | 130 |
} |
| 131 | 131 |
|
| 132 | 132 |
///Return the sum of two vectors |
| 133 | 133 |
Point<T> operator+(const Point<T> &u) const {
|
| 134 | 134 |
Point<T> b=*this; |
| 135 | 135 |
return b+=u; |
| 136 | 136 |
} |
| 137 | 137 |
|
| 138 | 138 |
///Return the negative of the vector |
| 139 | 139 |
Point<T> operator-() const {
|
| 140 | 140 |
Point<T> b=*this; |
| 141 | 141 |
b.x=-b.x; b.y=-b.y; |
| 142 | 142 |
return b; |
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 | 145 |
///Return the difference of two vectors |
| 146 | 146 |
Point<T> operator-(const Point<T> &u) const {
|
| 147 | 147 |
Point<T> b=*this; |
| 148 | 148 |
return b-=u; |
| 149 | 149 |
} |
| 150 | 150 |
|
| 151 | 151 |
///Return a vector multiplied by a scalar |
| 152 | 152 |
Point<T> operator*(const T &u) const {
|
| 153 | 153 |
Point<T> b=*this; |
| 154 | 154 |
return b*=u; |
| 155 | 155 |
} |
| 156 | 156 |
|
| 157 | 157 |
///Return a vector divided by a scalar |
| 158 | 158 |
Point<T> operator/(const T &u) const {
|
| 159 | 159 |
Point<T> b=*this; |
| 160 | 160 |
return b/=u; |
| 161 | 161 |
} |
| 162 | 162 |
|
| 163 | 163 |
///Test equality |
| 164 | 164 |
bool operator==(const Point<T> &u) const {
|
| 165 | 165 |
return (x==u.x) && (y==u.y); |
| 166 | 166 |
} |
| 167 | 167 |
|
| 168 | 168 |
///Test inequality |
| 169 | 169 |
bool operator!=(Point u) const {
|
| 170 | 170 |
return (x!=u.x) || (y!=u.y); |
| 171 | 171 |
} |
| 172 | 172 |
|
| 173 | 173 |
}; |
| 174 | 174 |
|
| 175 | 175 |
///Return a Point |
| 176 | 176 |
|
| 177 | 177 |
///Return a Point. |
| 178 | 178 |
///\relates Point |
| 179 | 179 |
template <typename T> |
| 180 | 180 |
inline Point<T> makePoint(const T& x, const T& y) {
|
| 181 | 181 |
return Point<T>(x, y); |
| 182 | 182 |
} |
| 183 | 183 |
|
| 184 | 184 |
///Return a vector multiplied by a scalar |
| 185 | 185 |
|
| 186 | 186 |
///Return a vector multiplied by a scalar. |
| 187 | 187 |
///\relates Point |
| 188 | 188 |
template<typename T> Point<T> operator*(const T &u,const Point<T> &x) {
|
| 189 | 189 |
return x*u; |
| 190 | 190 |
} |
| 191 | 191 |
|
| 192 | 192 |
///Read a plainvector from a stream |
| 193 | 193 |
|
| 194 | 194 |
///Read a plainvector from a stream. |
| 195 | 195 |
///\relates Point |
| 196 | 196 |
/// |
| 197 | 197 |
template<typename T> |
| 1 |
/* -*- C++ -*- |
|
| 2 |
* |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
| 4 |
* |
|
| 5 |
* Copyright (C) 2003-2008 |
|
| 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
| 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
| 8 |
* |
|
| 9 |
* Permission to use, modify and distribute this software is granted |
|
| 10 |
* provided that this copyright notice appears in all copies. For |
|
| 11 |
* precise terms see the accompanying LICENSE file. |
|
| 12 |
* |
|
| 13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
| 14 |
* express or implied, and with no claim as to its suitability for any |
|
| 15 |
* purpose. |
|
| 16 |
* |
|
| 17 |
*/ |
|
| 18 |
| 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_MAPS_H |
| 20 | 20 |
#define LEMON_MAPS_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iterator> |
| 23 | 23 |
#include <functional> |
| 24 | 24 |
#include <vector> |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/bits/utility.h> |
| 27 | 27 |
// #include <lemon/bits/traits.h> |
| 28 | 28 |
|
| 29 | 29 |
///\file |
| 30 | 30 |
///\ingroup maps |
| 31 | 31 |
///\brief Miscellaneous property maps |
| 32 | 32 |
/// |
| 33 | 33 |
#include <map> |
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
/// \addtogroup maps |
| 38 | 38 |
/// @{
|
| 39 | 39 |
|
| 40 | 40 |
/// Base class of maps. |
| 41 | 41 |
|
| 42 | 42 |
/// Base class of maps. |
| 43 | 43 |
/// It provides the necessary <tt>typedef</tt>s required by the map concept. |
| 44 | 44 |
template<typename K, typename T> |
| 45 | 45 |
class MapBase {
|
| 46 | 46 |
public: |
| 47 | 47 |
/// The key type of the map. |
| 48 | 48 |
typedef K Key; |
| 49 | 49 |
/// The value type of the map. (The type of objects associated with the keys). |
| 50 | 50 |
typedef T Value; |
| 51 | 51 |
}; |
| 52 | 52 |
|
| 53 | 53 |
/// Null map. (a.k.a. DoNothingMap) |
| 54 | 54 |
|
| 55 | 55 |
/// This map can be used if you have to provide a map only for |
| 56 | 56 |
/// its type definitions, or if you have to provide a writable map, |
| 57 | 57 |
/// but data written to it is not required (i.e. it will be sent to |
| 58 | 58 |
/// <tt>/dev/null</tt>). |
| 59 | 59 |
template<typename K, typename T> |
| 60 | 60 |
class NullMap : public MapBase<K, T> {
|
| 61 | 61 |
public: |
| 62 | 62 |
typedef MapBase<K, T> Parent; |
| 63 | 63 |
typedef typename Parent::Key Key; |
| 64 | 64 |
typedef typename Parent::Value Value; |
| 65 | 65 |
|
| 66 | 66 |
/// Gives back a default constructed element. |
| 67 | 67 |
T operator[](const K&) const { return T(); }
|
| 68 | 68 |
/// Absorbs the value. |
| 69 | 69 |
void set(const K&, const T&) {}
|
| 70 | 70 |
}; |
| 71 | 71 |
|
| 72 | 72 |
///Returns a \c NullMap class |
| 73 | 73 |
|
| 74 | 74 |
///This function just returns a \c NullMap class. |
| 75 | 75 |
///\relates NullMap |
| 76 | 76 |
template <typename K, typename V> |
| 77 | 77 |
NullMap<K, V> nullMap() {
|
| 78 | 78 |
return NullMap<K, V>(); |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
|
| 82 | 82 |
/// Constant map. |
| 83 | 83 |
|
| 84 | 84 |
/// This is a readable map which assigns a specified value to each key. |
| 85 | 85 |
/// In other aspects it is equivalent to the \c NullMap. |
| 86 | 86 |
template<typename K, typename T> |
| 87 | 87 |
class ConstMap : public MapBase<K, T> {
|
| 88 | 88 |
private: |
| 89 | 89 |
T v; |
| 90 | 90 |
public: |
| 91 | 91 |
|
| 92 | 92 |
typedef MapBase<K, T> Parent; |
| 93 | 93 |
typedef typename Parent::Key Key; |
| 94 | 94 |
typedef typename Parent::Value Value; |
| 95 | 95 |
|
| 96 | 96 |
/// Default constructor |
| 97 | 97 |
|
| 98 | 98 |
/// Default constructor. |
| 99 | 99 |
/// The value of the map will be uninitialized. |
| 100 | 100 |
/// (More exactly it will be default constructed.) |
| 101 | 101 |
ConstMap() {}
|
| 102 | 102 |
|
| 103 | 103 |
/// Constructor with specified initial value |
| 104 | 104 |
|
| 105 | 105 |
/// Constructor with specified initial value. |
| 106 | 106 |
/// \param _v is the initial value of the map. |
| 107 | 107 |
ConstMap(const T &_v) : v(_v) {}
|
| 108 | 108 |
|
| 109 | 109 |
///\e |
| 110 | 110 |
T operator[](const K&) const { return v; }
|
| 111 | 111 |
|
| 112 | 112 |
///\e |
| 113 | 113 |
void setAll(const T &t) {
|
| 114 | 114 |
v = t; |
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 | 117 |
template<typename T1> |
| 118 | 118 |
struct rebind {
|
| 119 | 119 |
typedef ConstMap<K, T1> other; |
| 120 | 120 |
}; |
| 121 | 121 |
|
| 122 | 122 |
template<typename T1> |
| 123 | 123 |
ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
|
| 124 | 124 |
}; |
| 125 | 125 |
|
| 126 | 126 |
///Returns a \c ConstMap class |
| 127 | 127 |
|
| 128 | 128 |
///This function just returns a \c ConstMap class. |
| 129 | 129 |
///\relates ConstMap |
| 130 | 130 |
template<typename K, typename V> |
| 131 | 131 |
inline ConstMap<K, V> constMap(const V &v) {
|
| 132 | 132 |
return ConstMap<K, V>(v); |
| 133 | 133 |
} |
| 134 | 134 |
|
| 135 | 135 |
|
| 136 | 136 |
template<typename T, T v> |
| 137 | 137 |
struct Const { };
|
| 138 | 138 |
|
| 139 | 139 |
/// Constant map with inlined constant value. |
| 140 | 140 |
|
| 141 | 141 |
/// This is a readable map which assigns a specified value to each key. |
| 142 | 142 |
/// In other aspects it is equivalent to the \c NullMap. |
| 143 | 143 |
template<typename K, typename V, V v> |
| 144 | 144 |
class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
|
| 145 | 145 |
public: |
| 146 | 146 |
typedef MapBase<K, V> Parent; |
| 147 | 147 |
typedef typename Parent::Key Key; |
| 148 | 148 |
typedef typename Parent::Value Value; |
| 149 | 149 |
|
| 150 | 150 |
ConstMap() { }
|
| 151 | 151 |
///\e |
| 152 | 152 |
V operator[](const K&) const { return v; }
|
| 153 | 153 |
///\e |
| 154 | 154 |
void set(const K&, const V&) { }
|
| 155 | 155 |
}; |
| 156 | 156 |
|
| 157 | 157 |
///Returns a \c ConstMap class |
| 158 | 158 |
|
| 159 | 159 |
///This function just returns a \c ConstMap class with inlined value. |
| 160 | 160 |
///\relates ConstMap |
| 161 | 161 |
template<typename K, typename V, V v> |
| 162 | 162 |
inline ConstMap<K, Const<V, v> > constMap() {
|
| 163 | 163 |
return ConstMap<K, Const<V, v> >(); |
| 164 | 164 |
} |
| 165 | 165 |
|
| 166 | 166 |
///Map based on std::map |
| 167 | 167 |
|
| 168 | 168 |
///This is essentially a wrapper for \c std::map with addition that |
| 169 | 169 |
///you can specify a default value different from \c Value(). |
| 170 | 170 |
template <typename K, typename T, typename Compare = std::less<K> > |
| 171 | 171 |
class StdMap {
|
| 172 | 172 |
template <typename K1, typename T1, typename C1> |
| 173 | 173 |
friend class StdMap; |
| 174 | 174 |
public: |
| 175 | 175 |
|
| 176 | 176 |
typedef True ReferenceMapTag; |
| 177 | 177 |
///\e |
| 178 | 178 |
typedef K Key; |
| 179 | 179 |
///\e |
| 180 | 180 |
typedef T Value; |
| 181 | 181 |
///\e |
| 182 | 182 |
typedef T& Reference; |
| 183 | 183 |
///\e |
| 184 | 184 |
typedef const T& ConstReference; |
| 185 | 185 |
|
| 186 | 186 |
private: |
| 187 | 187 |
|
| 188 | 188 |
typedef std::map<K, T, Compare> Map; |
| 189 | 189 |
Value _value; |
| 190 | 190 |
Map _map; |
| 191 | 191 |
|
| 192 | 192 |
public: |
| 193 | 193 |
|
| 194 | 194 |
/// Constructor with specified default value |
| 195 | 195 |
StdMap(const T& value = T()) : _value(value) {}
|
| 196 | 196 |
/// \brief Constructs the map from an appropriate std::map, and explicitly |
| 197 | 197 |
/// specifies a default value. |
| 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 |
///\file |
| 20 | 20 |
///\brief Instantiation of the Random class. |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/random.h> |
| 23 | 23 |
|
| 24 | 24 |
namespace lemon {
|
| 25 | 25 |
/// \brief Global random number generator instance |
| 26 | 26 |
/// |
| 27 | 27 |
/// A global Mersenne Twister random number generator instance. |
| 28 | 28 |
Random rnd; |
| 29 | 29 |
} |
| 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 |
/* |
| 20 | 20 |
* This file contains the reimplemented version of the Mersenne Twister |
| 21 | 21 |
* Generator of Matsumoto and Nishimura. |
| 22 | 22 |
* |
| 23 | 23 |
* See the appropriate copyright notice below. |
| 24 | 24 |
* |
| 25 | 25 |
* Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, |
| 26 | 26 |
* All rights reserved. |
| 27 | 27 |
* |
| 28 | 28 |
* Redistribution and use in source and binary forms, with or without |
| 29 | 29 |
* modification, are permitted provided that the following conditions |
| 30 | 30 |
* are met: |
| 31 | 31 |
* |
| 32 | 32 |
* 1. Redistributions of source code must retain the above copyright |
| 33 | 33 |
* notice, this list of conditions and the following disclaimer. |
| 34 | 34 |
* |
| 35 | 35 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 36 | 36 |
* notice, this list of conditions and the following disclaimer in the |
| 37 | 37 |
* documentation and/or other materials provided with the distribution. |
| 38 | 38 |
* |
| 39 | 39 |
* 3. The names of its contributors may not be used to endorse or promote |
| 40 | 40 |
* products derived from this software without specific prior written |
| 41 | 41 |
* permission. |
| 42 | 42 |
* |
| 43 | 43 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 44 | 44 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 45 | 45 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 46 | 46 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 47 | 47 |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 48 | 48 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 49 | 49 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 50 | 50 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 51 | 51 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 52 | 52 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 53 | 53 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 54 | 54 |
* OF THE POSSIBILITY OF SUCH DAMAGE. |
| 55 | 55 |
* |
| 56 | 56 |
* |
| 57 | 57 |
* Any feedback is very welcome. |
| 58 | 58 |
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html |
| 59 | 59 |
* email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) |
| 60 | 60 |
*/ |
| 61 | 61 |
|
| 62 | 62 |
#ifndef LEMON_RANDOM_H |
| 63 | 63 |
#define LEMON_RANDOM_H |
| 64 | 64 |
|
| 65 | 65 |
#include <algorithm> |
| 66 | 66 |
#include <iterator> |
| 67 | 67 |
#include <vector> |
| 68 | 68 |
|
| 69 | 69 |
#include <ctime> |
| 70 | 70 |
#include <cmath> |
| 71 | 71 |
|
| 72 | 72 |
#include <lemon/dim2.h> |
| 73 | 73 |
///\ingroup misc |
| 74 | 74 |
///\file |
| 75 | 75 |
///\brief Mersenne Twister random number generator |
| 76 | 76 |
|
| 77 | 77 |
namespace lemon {
|
| 78 | 78 |
|
| 79 | 79 |
namespace _random_bits {
|
| 80 | 80 |
|
| 81 | 81 |
template <typename _Word, int _bits = std::numeric_limits<_Word>::digits> |
| 82 | 82 |
struct RandomTraits {};
|
| 83 | 83 |
|
| 84 | 84 |
template <typename _Word> |
| 85 | 85 |
struct RandomTraits<_Word, 32> {
|
| 86 | 86 |
|
| 87 | 87 |
typedef _Word Word; |
| 88 | 88 |
static const int bits = 32; |
| 89 | 89 |
|
| 90 | 90 |
static const int length = 624; |
| 91 | 91 |
static const int shift = 397; |
| 92 | 92 |
|
| 93 | 93 |
static const Word mul = 0x6c078965u; |
| 94 | 94 |
static const Word arrayInit = 0x012BD6AAu; |
| 95 | 95 |
static const Word arrayMul1 = 0x0019660Du; |
| 96 | 96 |
static const Word arrayMul2 = 0x5D588B65u; |
| 97 | 97 |
|
| 98 | 98 |
static const Word mask = 0x9908B0DFu; |
| 99 | 99 |
static const Word loMask = (1u << 31) - 1; |
| 100 | 100 |
static const Word hiMask = ~loMask; |
| 101 | 101 |
|
| 102 | 102 |
|
| 103 | 103 |
static Word tempering(Word rnd) {
|
| 104 | 104 |
rnd ^= (rnd >> 11); |
| 105 | 105 |
rnd ^= (rnd << 7) & 0x9D2C5680u; |
| 106 | 106 |
rnd ^= (rnd << 15) & 0xEFC60000u; |
| 107 | 107 |
rnd ^= (rnd >> 18); |
| 108 | 108 |
return rnd; |
| 109 | 109 |
} |
| 110 | 110 |
|
| 111 | 111 |
}; |
| 112 | 112 |
|
| 113 | 113 |
template <typename _Word> |
| 114 | 114 |
struct RandomTraits<_Word, 64> {
|
| 115 | 115 |
|
| 116 | 116 |
typedef _Word Word; |
| 117 | 117 |
static const int bits = 64; |
| 118 | 118 |
|
| 119 | 119 |
static const int length = 312; |
| 120 | 120 |
static const int shift = 156; |
| 121 | 121 |
|
| 122 | 122 |
static const Word mul = Word(0x5851F42Du) << 32 | Word(0x4C957F2Du); |
| 123 | 123 |
static const Word arrayInit = Word(0x00000000u) << 32 |Word(0x012BD6AAu); |
| 124 | 124 |
static const Word arrayMul1 = Word(0x369DEA0Fu) << 32 |Word(0x31A53F85u); |
| 125 | 125 |
static const Word arrayMul2 = Word(0x27BB2EE6u) << 32 |Word(0x87B0B0FDu); |
| 126 | 126 |
|
| 127 | 127 |
static const Word mask = Word(0xB5026F5Au) << 32 | Word(0xA96619E9u); |
| 128 | 128 |
static const Word loMask = (Word(1u) << 31) - 1; |
| 129 | 129 |
static const Word hiMask = ~loMask; |
| 130 | 130 |
|
| 131 | 131 |
static Word tempering(Word rnd) {
|
| 132 | 132 |
rnd ^= (rnd >> 29) & (Word(0x55555555u) << 32 | Word(0x55555555u)); |
| 133 | 133 |
rnd ^= (rnd << 17) & (Word(0x71D67FFFu) << 32 | Word(0xEDA60000u)); |
| 134 | 134 |
rnd ^= (rnd << 37) & (Word(0xFFF7EEE0u) << 32 | Word(0x00000000u)); |
| 135 | 135 |
rnd ^= (rnd >> 43); |
| 136 | 136 |
return rnd; |
| 137 | 137 |
} |
| 138 | 138 |
|
| 139 | 139 |
}; |
| 140 | 140 |
|
| 141 | 141 |
template <typename _Word> |
| 142 | 142 |
class RandomCore {
|
| 143 | 143 |
public: |
| 144 | 144 |
|
| 145 | 145 |
typedef _Word Word; |
| 146 | 146 |
|
| 147 | 147 |
private: |
| 148 | 148 |
|
| 149 | 149 |
static const int bits = RandomTraits<Word>::bits; |
| 150 | 150 |
|
| 151 | 151 |
static const int length = RandomTraits<Word>::length; |
| 152 | 152 |
static const int shift = RandomTraits<Word>::shift; |
| 153 | 153 |
|
| 154 | 154 |
public: |
| 155 | 155 |
|
| 156 | 156 |
void initState() {
|
| 157 | 157 |
static const Word seedArray[4] = {
|
| 158 | 158 |
0x12345u, 0x23456u, 0x34567u, 0x45678u |
| 159 | 159 |
}; |
| 160 | 160 |
|
| 161 | 161 |
initState(seedArray, seedArray + 4); |
| 162 | 162 |
} |
| 163 | 163 |
|
| 164 | 164 |
void initState(Word seed) {
|
| 165 | 165 |
|
| 166 | 166 |
static const Word mul = RandomTraits<Word>::mul; |
| 167 | 167 |
|
| 168 | 168 |
current = state; |
| 169 | 169 |
|
| 170 | 170 |
Word *curr = state + length - 1; |
| 171 | 171 |
curr[0] = seed; --curr; |
| 172 | 172 |
for (int i = 1; i < length; ++i) {
|
| 173 | 173 |
curr[0] = (mul * ( curr[1] ^ (curr[1] >> (bits - 2)) ) + i); |
| 174 | 174 |
--curr; |
| 175 | 175 |
} |
| 176 | 176 |
} |
| 177 | 177 |
|
| 178 | 178 |
template <typename Iterator> |
| 179 | 179 |
void initState(Iterator begin, Iterator end) {
|
| 180 | 180 |
|
| 181 | 181 |
static const Word init = RandomTraits<Word>::arrayInit; |
| 182 | 182 |
static const Word mul1 = RandomTraits<Word>::arrayMul1; |
| 183 | 183 |
static const Word mul2 = RandomTraits<Word>::arrayMul2; |
| 184 | 184 |
|
| 185 | 185 |
|
| 186 | 186 |
Word *curr = state + length - 1; --curr; |
| 187 | 187 |
Iterator it = begin; int cnt = 0; |
| 188 | 188 |
int num; |
| 189 | 189 |
|
| 190 | 190 |
initState(init); |
| 191 | 191 |
|
| 192 | 192 |
num = length > end - begin ? length : end - begin; |
| 193 | 193 |
while (num--) {
|
| 194 | 194 |
curr[0] = (curr[0] ^ ((curr[1] ^ (curr[1] >> (bits - 2))) * mul1)) |
| 195 | 195 |
+ *it + cnt; |
| 196 | 196 |
++it; ++cnt; |
| 197 | 197 |
if (it == end) {
|
| 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_TOLERANCE_H |
| 20 | 20 |
#define LEMON_TOLERANCE_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup misc |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief A basic tool to handle the anomalies of calculation with |
| 25 | 25 |
///floating point numbers. |
| 26 | 26 |
/// |
| 27 | 27 |
///\todo It should be in a module like "Basic tools" |
| 28 | 28 |
|
| 29 | 29 |
|
| 30 | 30 |
namespace lemon {
|
| 31 | 31 |
|
| 32 | 32 |
/// \addtogroup misc |
| 33 | 33 |
/// @{
|
| 34 | 34 |
|
| 35 | 35 |
///\brief A class to provide a basic way to |
| 36 | 36 |
///handle the comparison of numbers that are obtained |
| 37 | 37 |
///as a result of a probably inexact computation. |
| 38 | 38 |
/// |
| 39 | 39 |
///Tolerance is a class to provide a basic way to |
| 40 | 40 |
///handle the comparison of numbers that are obtained |
| 41 | 41 |
///as a result of a probably inexact computation. |
| 42 | 42 |
/// |
| 43 | 43 |
///This is an abstract class, it should be specialized for all numerical |
| 44 | 44 |
///data types. These specialized classes like \ref Tolerance\<double\> |
| 45 | 45 |
///may offer additional tuning parameters. |
| 46 | 46 |
/// |
| 47 | 47 |
///\sa Tolerance<float> |
| 48 | 48 |
///\sa Tolerance<double> |
| 49 | 49 |
///\sa Tolerance<long double> |
| 50 | 50 |
///\sa Tolerance<int> |
| 51 | 51 |
#if defined __GNUC__ && !defined __STRICT_ANSI__ |
| 52 | 52 |
///\sa Tolerance<long long int> |
| 53 | 53 |
#endif |
| 54 | 54 |
///\sa Tolerance<unsigned int> |
| 55 | 55 |
#if defined __GNUC__ && !defined __STRICT_ANSI__ |
| 56 | 56 |
///\sa Tolerance<unsigned long long int> |
| 57 | 57 |
#endif |
| 58 | 58 |
|
| 59 | 59 |
template<class T> |
| 60 | 60 |
class Tolerance |
| 61 | 61 |
{
|
| 62 | 62 |
public: |
| 63 | 63 |
typedef T Value; |
| 64 | 64 |
|
| 65 | 65 |
///\name Comparisons |
| 66 | 66 |
///The concept is that these bool functions return with \c true only if |
| 67 | 67 |
///the related comparisons hold even if some numerical error appeared |
| 68 | 68 |
///during the computations. |
| 69 | 69 |
|
| 70 | 70 |
///@{
|
| 71 | 71 |
|
| 72 | 72 |
///Returns \c true if \c a is \e surely strictly less than \c b |
| 73 | 73 |
static bool less(Value a,Value b) {return false;}
|
| 74 | 74 |
///Returns \c true if \c a is \e surely different from \c b |
| 75 | 75 |
static bool different(Value a,Value b) {return false;}
|
| 76 | 76 |
///Returns \c true if \c a is \e surely positive |
| 77 | 77 |
static bool positive(Value a) {return false;}
|
| 78 | 78 |
///Returns \c true if \c a is \e surely negative |
| 79 | 79 |
static bool negative(Value a) {return false;}
|
| 80 | 80 |
///Returns \c true if \c a is \e surely non-zero |
| 81 | 81 |
static bool nonZero(Value a) {return false;}
|
| 82 | 82 |
|
| 83 | 83 |
///@} |
| 84 | 84 |
|
| 85 | 85 |
///Returns the zero value. |
| 86 | 86 |
static Value zero() {return T();}
|
| 87 | 87 |
|
| 88 | 88 |
// static bool finite(Value a) {}
|
| 89 | 89 |
// static Value big() {}
|
| 90 | 90 |
// static Value negativeBig() {}
|
| 91 | 91 |
}; |
| 92 | 92 |
|
| 93 | 93 |
|
| 94 | 94 |
///Float specialization of \ref Tolerance. |
| 95 | 95 |
|
| 96 | 96 |
///Float specialization of \ref Tolerance. |
| 97 | 97 |
///\sa Tolerance |
| 98 | 98 |
///\relates Tolerance |
| 99 | 99 |
template<> |
| 100 | 100 |
class Tolerance<float> |
| 101 | 101 |
{
|
| 102 | 102 |
static float def_epsilon; |
| 103 | 103 |
float _epsilon; |
| 104 | 104 |
public: |
| 105 | 105 |
///\e |
| 106 | 106 |
typedef float Value; |
| 107 | 107 |
|
| 108 | 108 |
///Constructor setting the epsilon tolerance to the default value. |
| 109 | 109 |
Tolerance() : _epsilon(def_epsilon) {}
|
| 110 | 110 |
///Constructor setting the epsilon tolerance. |
| 111 | 111 |
Tolerance(float e) : _epsilon(e) {}
|
| 112 | 112 |
|
| 113 | 113 |
///Return the epsilon value. |
| 114 | 114 |
Value epsilon() const {return _epsilon;}
|
| 115 | 115 |
///Set the epsilon value. |
| 116 | 116 |
void epsilon(Value e) {_epsilon=e;}
|
| 117 | 117 |
|
| 118 | 118 |
///Return the default epsilon value. |
| 119 | 119 |
static Value defaultEpsilon() {return def_epsilon;}
|
| 120 | 120 |
///Set the default epsilon value. |
| 121 | 121 |
static void defaultEpsilon(Value e) {def_epsilon=e;}
|
| 122 | 122 |
|
| 123 | 123 |
///\name Comparisons |
| 124 | 124 |
///See class Tolerance for more details. |
| 125 | 125 |
|
| 126 | 126 |
///@{
|
| 127 | 127 |
|
| 128 | 128 |
///Returns \c true if \c a is \e surely strictly less than \c b |
| 129 | 129 |
bool less(Value a,Value b) const {return a+_epsilon<b;}
|
| 130 | 130 |
///Returns \c true if \c a is \e surely different from \c b |
| 131 | 131 |
bool different(Value a,Value b) const { return less(a,b)||less(b,a); }
|
| 132 | 132 |
///Returns \c true if \c a is \e surely positive |
| 133 | 133 |
bool positive(Value a) const { return _epsilon<a; }
|
| 134 | 134 |
///Returns \c true if \c a is \e surely negative |
| 135 | 135 |
bool negative(Value a) const { return -_epsilon>a; }
|
| 136 | 136 |
///Returns \c true if \c a is \e surely non-zero |
| 137 | 137 |
bool nonZero(Value a) const { return positive(a)||negative(a); }
|
| 138 | 138 |
|
| 139 | 139 |
///@} |
| 140 | 140 |
|
| 141 | 141 |
///Returns zero |
| 142 | 142 |
static Value zero() {return 0;}
|
| 143 | 143 |
}; |
| 144 | 144 |
|
| 145 | 145 |
///Double specialization of \ref Tolerance. |
| 146 | 146 |
|
| 147 | 147 |
///Double specialization of \ref Tolerance. |
| 148 | 148 |
///\sa Tolerance |
| 149 | 149 |
///\relates Tolerance |
| 150 | 150 |
template<> |
| 151 | 151 |
class Tolerance<double> |
| 152 | 152 |
{
|
| 153 | 153 |
static double def_epsilon; |
| 154 | 154 |
double _epsilon; |
| 155 | 155 |
public: |
| 156 | 156 |
///\e |
| 157 | 157 |
typedef double Value; |
| 158 | 158 |
|
| 159 | 159 |
///Constructor setting the epsilon tolerance to the default value. |
| 160 | 160 |
Tolerance() : _epsilon(def_epsilon) {}
|
| 161 | 161 |
///Constructor setting the epsilon tolerance. |
| 162 | 162 |
Tolerance(double e) : _epsilon(e) {}
|
| 163 | 163 |
|
| 164 | 164 |
///Return the epsilon value. |
| 165 | 165 |
Value epsilon() const {return _epsilon;}
|
| 166 | 166 |
///Set the epsilon value. |
| 167 | 167 |
void epsilon(Value e) {_epsilon=e;}
|
| 168 | 168 |
|
| 169 | 169 |
///Return the default epsilon value. |
| 170 | 170 |
static Value defaultEpsilon() {return def_epsilon;}
|
| 171 | 171 |
///Set the default epsilon value. |
| 172 | 172 |
static void defaultEpsilon(Value e) {def_epsilon=e;}
|
| 173 | 173 |
|
| 174 | 174 |
///\name Comparisons |
| 175 | 175 |
///See class Tolerance for more details. |
| 176 | 176 |
|
| 177 | 177 |
///@{
|
| 178 | 178 |
|
| 179 | 179 |
///Returns \c true if \c a is \e surely strictly less than \c b |
| 180 | 180 |
bool less(Value a,Value b) const {return a+_epsilon<b;}
|
| 181 | 181 |
///Returns \c true if \c a is \e surely different from \c b |
| 182 | 182 |
bool different(Value a,Value b) const { return less(a,b)||less(b,a); }
|
| 183 | 183 |
///Returns \c true if \c a is \e surely positive |
| 184 | 184 |
bool positive(Value a) const { return _epsilon<a; }
|
| 185 | 185 |
///Returns \c true if \c a is \e surely negative |
| 186 | 186 |
bool negative(Value a) const { return -_epsilon>a; }
|
| 187 | 187 |
///Returns \c true if \c a is \e surely non-zero |
| 188 | 188 |
bool nonZero(Value a) const { return positive(a)||negative(a); }
|
| 189 | 189 |
|
| 190 | 190 |
///@} |
| 191 | 191 |
|
| 192 | 192 |
///Returns zero |
| 193 | 193 |
static Value zero() {return 0;}
|
| 194 | 194 |
}; |
| 195 | 195 |
|
| 196 | 196 |
///Long double specialization of \ref Tolerance. |
| 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 |
#include <lemon/dim2.h> |
| 20 | 20 |
#include <iostream> |
| 21 | 21 |
#include "test_tools.h" |
| 22 | 22 |
|
| 23 | 23 |
using namespace std; |
| 24 | 24 |
using namespace lemon; |
| 25 | 25 |
|
| 26 | 26 |
int main() |
| 27 | 27 |
{
|
| 28 | 28 |
cout << "Testing classes 'dim2::Point' and 'dim2::BoundingBox'." << endl; |
| 29 | 29 |
|
| 30 | 30 |
typedef dim2::Point<int> Point; |
| 31 | 31 |
|
| 32 | 32 |
Point p; |
| 33 | 33 |
check(p.size()==2, "Wrong vector initialization."); |
| 34 | 34 |
|
| 35 | 35 |
Point a(1,2); |
| 36 | 36 |
Point b(3,4); |
| 37 | 37 |
check(a[0]==1 && a[1]==2, "Wrong vector initialization."); |
| 38 | 38 |
|
| 39 | 39 |
p = a+b; |
| 40 | 40 |
check(p.x==4 && p.y==6, "Wrong vector addition."); |
| 41 | 41 |
|
| 42 | 42 |
p = a-b; |
| 43 | 43 |
check(p.x==-2 && p.y==-2, "Wrong vector subtraction."); |
| 44 | 44 |
|
| 45 | 45 |
check(a.normSquare()==5,"Wrong vector norm calculation."); |
| 46 | 46 |
check(a*b==11, "Wrong vector scalar product."); |
| 47 | 47 |
|
| 48 | 48 |
int l=2; |
| 49 | 49 |
p = a*l; |
| 50 | 50 |
check(p.x==2 && p.y==4, "Wrong vector multiplication by a scalar."); |
| 51 | 51 |
|
| 52 | 52 |
p = b/l; |
| 53 | 53 |
check(p.x==1 && p.y==2, "Wrong vector division by a scalar."); |
| 54 | 54 |
|
| 55 | 55 |
typedef dim2::BoundingBox<int> BB; |
| 56 | 56 |
BB box1; |
| 57 | 57 |
check(box1.empty(), "It should be empty."); |
| 58 | 58 |
|
| 59 | 59 |
box1.add(a); |
| 60 | 60 |
check(!box1.empty(), "It should not be empty."); |
| 61 | 61 |
box1.add(b); |
| 62 | 62 |
|
| 63 | 63 |
check(box1.bottomLeft().x==1 && |
| 64 | 64 |
box1.bottomLeft().y==2 && |
| 65 | 65 |
box1.topRight().x==3 && |
| 66 | 66 |
box1.topRight().y==4, |
| 67 | 67 |
"Wrong addition of points to box."); |
| 68 | 68 |
|
| 69 | 69 |
p.x=2; p.y=3; |
| 70 | 70 |
check(box1.inside(p), "It should be inside."); |
| 71 | 71 |
|
| 72 | 72 |
p.x=1; p.y=3; |
| 73 | 73 |
check(box1.inside(p), "It should be inside."); |
| 74 | 74 |
|
| 75 | 75 |
p.x=0; p.y=3; |
| 76 | 76 |
check(!box1.inside(p), "It should not be inside."); |
| 77 | 77 |
|
| 78 | 78 |
BB box2(p); |
| 79 | 79 |
check(!box2.empty(), |
| 80 | 80 |
"It should not be empty. Constructed from 1 point."); |
| 81 | 81 |
|
| 82 | 82 |
box2.add(box1); |
| 83 | 83 |
check(box2.inside(p), |
| 84 | 84 |
"It should be inside. Incremented a box with another one."); |
| 85 | 85 |
|
| 86 | 86 |
return 0; |
| 87 | 87 |
} |
| 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 <deque> |
| 20 | 20 |
#include <set> |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/concept_check.h> |
| 23 | 23 |
#include <lemon/concepts/maps.h> |
| 24 | 24 |
#include <lemon/maps.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "test_tools.h" |
| 27 | 27 |
|
| 28 | 28 |
using namespace lemon; |
| 29 | 29 |
using namespace lemon::concepts; |
| 30 | 30 |
|
| 31 | 31 |
struct A {};
|
| 32 | 32 |
inline bool operator<(A, A) { return true; }
|
| 33 | 33 |
struct B {};
|
| 34 | 34 |
|
| 35 | 35 |
class F {
|
| 36 | 36 |
public: |
| 37 | 37 |
typedef A argument_type; |
| 38 | 38 |
typedef B result_type; |
| 39 | 39 |
|
| 40 | 40 |
B operator()(const A &) const {return B();}
|
| 41 | 41 |
}; |
| 42 | 42 |
|
| 43 | 43 |
int func(A) {return 3;}
|
| 44 | 44 |
|
| 45 | 45 |
int binc(int, B) {return 4;}
|
| 46 | 46 |
|
| 47 | 47 |
typedef ReadMap<A,double> DoubleMap; |
| 48 | 48 |
typedef ReadWriteMap<A, double> WriteDoubleMap; |
| 49 | 49 |
|
| 50 | 50 |
typedef ReadMap<A,bool> BoolMap; |
| 51 | 51 |
typedef ReadWriteMap<A, bool> BoolWriteMap; |
| 52 | 52 |
|
| 53 | 53 |
int main() |
| 54 | 54 |
{ // checking graph components
|
| 55 | 55 |
|
| 56 | 56 |
checkConcept<ReadMap<A,B>, ReadMap<A,B> >(); |
| 57 | 57 |
checkConcept<WriteMap<A,B>, WriteMap<A,B> >(); |
| 58 | 58 |
checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >(); |
| 59 | 59 |
checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >(); |
| 60 | 60 |
|
| 61 | 61 |
checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >(); |
| 62 | 62 |
checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >(); |
| 63 | 63 |
checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >(); |
| 64 | 64 |
checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >(); |
| 65 | 65 |
checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >(); |
| 66 | 66 |
checkConcept<ReadWriteMap<A,double>, NegWriteMap<WriteDoubleMap> >(); |
| 67 | 67 |
checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >(); |
| 68 | 68 |
checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >(); |
| 69 | 69 |
checkConcept<ReadWriteMap<A,double>, ShiftWriteMap<WriteDoubleMap> >(); |
| 70 | 70 |
checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >(); |
| 71 | 71 |
checkConcept<ReadWriteMap<A,double>, ScaleWriteMap<WriteDoubleMap> >(); |
| 72 | 72 |
checkConcept<ReadMap<A,double>, ForkMap<DoubleMap, DoubleMap> >(); |
| 73 | 73 |
checkConcept<ReadWriteMap<A,double>, |
| 74 | 74 |
ForkWriteMap<WriteDoubleMap, WriteDoubleMap> >(); |
| 75 | 75 |
|
| 76 | 76 |
checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >(); |
| 77 | 77 |
|
| 78 | 78 |
checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >(); |
| 79 | 79 |
|
| 80 | 80 |
checkConcept<ReadMap<A, bool>, NotMap<BoolMap> >(); |
| 81 | 81 |
checkConcept<ReadWriteMap<A, bool>, NotWriteMap<BoolWriteMap> >(); |
| 82 | 82 |
|
| 83 | 83 |
checkConcept<WriteMap<A, bool>, StoreBoolMap<A*> >(); |
| 84 | 84 |
checkConcept<WriteMap<A, bool>, BackInserterBoolMap<std::deque<A> > >(); |
| 85 | 85 |
checkConcept<WriteMap<A, bool>, FrontInserterBoolMap<std::deque<A> > >(); |
| 86 | 86 |
checkConcept<WriteMap<A, bool>, InserterBoolMap<std::set<A> > >(); |
| 87 | 87 |
checkConcept<WriteMap<A, bool>, FillBoolMap<WriteMap<A, B> > >(); |
| 88 | 88 |
checkConcept<WriteMap<A, bool>, SettingOrderBoolMap<WriteMap<A, int> > >(); |
| 89 | 89 |
|
| 90 | 90 |
int a; |
| 91 | 91 |
|
| 92 | 92 |
a=mapFunctor(constMap<A,int>(2))(A()); |
| 93 | 93 |
check(a==2,"Something is wrong with mapFunctor"); |
| 94 | 94 |
|
| 95 | 95 |
B b; |
| 96 | 96 |
b=functorMap(F())[A()]; |
| 97 | 97 |
|
| 98 | 98 |
a=functorMap(&func)[A()]; |
| 99 | 99 |
check(a==3,"Something is wrong with functorMap"); |
| 100 | 100 |
|
| 101 | 101 |
a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()]; |
| 102 | 102 |
check(a==4,"Something is wrong with combineMap"); |
| 103 | 103 |
|
| 104 | 104 |
|
| 105 | 105 |
std::cout << __FILE__ ": All tests passed.\n"; |
| 106 | 106 |
|
| 107 | 107 |
return 0; |
| 108 | 108 |
} |
| 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/random.h> |
| 20 | 20 |
#include "test_tools.h" |
| 21 | 21 |
|
| 22 | 22 |
///\file \brief Test cases for random.h |
| 23 | 23 |
/// |
| 24 | 24 |
///\todo To be extended |
| 25 | 25 |
/// |
| 26 | 26 |
|
| 27 | 27 |
int main() |
| 28 | 28 |
{
|
| 29 | 29 |
double a=lemon::rnd(); |
| 30 | 30 |
check(a<1.0&&a>0.0,"This should be in [0,1)"); |
| 31 | 31 |
a=lemon::rnd.gauss(); |
| 32 | 32 |
a=lemon::rnd.gamma(3.45,0); |
| 33 | 33 |
a=lemon::rnd.gamma(4); |
| 34 | 34 |
//Does gamma work with integer k? |
| 35 | 35 |
a=lemon::rnd.gamma(4.0,0); |
| 36 | 36 |
} |
| 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_TEST_TOOLS_H |
| 20 | 20 |
#define LEMON_TEST_TEST_TOOLS_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iostream> |
| 23 | 23 |
|
| 24 | 24 |
//! \ingroup misc |
| 25 | 25 |
//! \file |
| 26 | 26 |
//! \brief Some utilities to write test programs. |
| 27 | 27 |
|
| 28 | 28 |
|
| 29 | 29 |
///If \c rc is fail, writes an error message end exit. |
| 30 | 30 |
|
| 31 | 31 |
///If \c rc is fail, writes an error message end exit. |
| 32 | 32 |
///The error message contains the file name and the line number of the |
| 33 | 33 |
///source code in a standard from, which makes it possible to go there |
| 34 | 34 |
///using good source browsers like e.g. \c emacs. |
| 35 | 35 |
/// |
| 36 | 36 |
///For example |
| 37 | 37 |
///\code check(0==1,"This is obviously false.");\endcode will |
| 38 | 38 |
///print this (and then exits). |
| 39 | 39 |
///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim |
| 40 | 40 |
/// |
| 41 | 41 |
///\todo It should be in \c error.h |
| 42 | 42 |
#define check(rc, msg) \ |
| 43 | 43 |
if(!(rc)) { \
|
| 44 | 44 |
std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ |
| 45 | 45 |
abort(); \ |
| 46 | 46 |
} else { } \
|
| 47 | 47 |
|
| 48 | 48 |
#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 "test_tools.h" |
| 20 | 20 |
|
| 21 | 21 |
int main() |
| 22 | 22 |
{
|
| 23 | 23 |
check(false, "Don't panic. Failing is the right behaviour here."); |
| 24 | 24 |
return 0; |
| 25 | 25 |
} |
| 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 "test_tools.h" |
| 20 | 20 |
|
| 21 | 21 |
int main() |
| 22 | 22 |
{
|
| 23 | 23 |
check(true, "It should pass."); |
| 24 | 24 |
return 0; |
| 25 | 25 |
} |
0 comments (0 inline)