diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -22,6 +22,7 @@ lemon/libemon.la lemon/stamp-h2 doc/Doxyfile +cmake/cmake.version .dirstamp .libs/* .deps/* diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,9 @@ INCLUDE(FindDoxygen) INCLUDE(FindGhostscript) +INCLUDE(CheckTypeSize) +CHECK_TYPE_SIZE("long long" LONG_LONG) + ENABLE_TESTING() ADD_SUBDIRECTORY(lemon) diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -24,6 +24,12 @@ dnl Do compilation tests using the C++ compiler. AC_LANG([C++]) +dnl Check the existence of long long type. +AC_CHECK_TYPE(long long, [long_long_found=yes], [long_long_found=no]) +if test x"$long_long_found" = x"yes"; then + AC_DEFINE([HAVE_LONG_LONG], [1], [Define to 1 if you have long long.]) +fi + dnl Checks for programs. AC_PROG_CXX AC_PROG_CXXCPP @@ -116,6 +122,8 @@ echo C++ compiler.................. : $CXX echo C++ compiles flags............ : $CXXFLAGS echo +echo Compiler supports long long... : $long_long_found +echo #echo GLPK support.................. : $lx_glpk_found #echo CPLEX support................. : $lx_cplex_found #echo SOPLEX support................ : $lx_soplex_found diff --git a/lemon/bits/default_map.h b/lemon/bits/default_map.h --- a/lemon/bits/default_map.h +++ b/lemon/bits/default_map.h @@ -96,7 +96,7 @@ }; -#if defined __GNUC__ && !defined __STRICT_ANSI__ +#if defined HAVE_LONG_LONG // long long template diff --git a/lemon/bits/windows.cc b/lemon/bits/windows.cc --- a/lemon/bits/windows.cc +++ b/lemon/bits/windows.cc @@ -28,7 +28,15 @@ #ifndef NOMINMAX #define NOMINMAX #endif +#ifdef UNICODE +#undef UNICODE +#endif #include +#ifdef LOCALE_INVARIANT +#define MY_LOCALE LOCALE_INVARIANT +#else +#define MY_LOCALE LOCALE_NEUTRAL +#endif #else #include #include @@ -87,27 +95,15 @@ #ifdef WIN32 SYSTEMTIME time; GetSystemTime(&time); -#if defined(_MSC_VER) && (_MSC_VER < 1500) - LPWSTR buf1, buf2, buf3; - if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - L"ddd MMM dd", buf1, 11) && - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, - L"HH':'mm':'ss", buf2, 9) && - GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - L"yyyy", buf3, 5)) { + char buf1[11], buf2[9], buf3[5]; + if (GetDateFormat(MY_LOCALE, 0, &time, + ("ddd MMM dd"), buf1, 11) && + GetTimeFormat(MY_LOCALE, 0, &time, + ("HH':'mm':'ss"), buf2, 9) && + GetDateFormat(MY_LOCALE, 0, &time, + ("yyyy"), buf3, 5)) { os << buf1 << ' ' << buf2 << ' ' << buf3; } -#else - char buf1[11], buf2[9], buf3[5]; - if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - "ddd MMM dd", buf1, 11) && - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, - "HH':'mm':'ss", buf2, 9) && - GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - "yyyy", buf3, 5)) { - os << buf1 << ' ' << buf2 << ' ' << buf3; - } -#endif else os << "unknown"; #else timeval tv; diff --git a/lemon/config.h.cmake b/lemon/config.h.cmake new file mode 100644 --- /dev/null +++ b/lemon/config.h.cmake @@ -0,0 +1,1 @@ +#cmakedefine HAVE_LONG_LONG 1 \ No newline at end of file diff --git a/lemon/config.h.in b/lemon/config.h.in --- a/lemon/config.h.in +++ b/lemon/config.h.in @@ -3,3 +3,6 @@ /* Define to 1 if you have GLPK. */ #undef HAVE_GLPK + +/* Define to 1 if you have long long */ +#undef HAVE_LONG_LONG diff --git a/lemon/lgf_reader.h b/lemon/lgf_reader.h --- a/lemon/lgf_reader.h +++ b/lemon/lgf_reader.h @@ -390,37 +390,13 @@ template class DigraphReader; - /// \brief Return a \ref DigraphReader class - /// - /// This function just returns a \ref DigraphReader class. - /// \relates DigraphReader template - DigraphReader digraphReader(Digraph& digraph, - std::istream& is = std::cin) { - DigraphReader tmp(digraph, is); - return tmp; - } - - /// \brief Return a \ref DigraphReader class - /// - /// This function just returns a \ref DigraphReader class. - /// \relates DigraphReader + DigraphReader digraphReader(Digraph& digraph, + std::istream& is = std::cin); template - DigraphReader digraphReader(Digraph& digraph, - const std::string& fn) { - DigraphReader tmp(digraph, fn); - return tmp; - } - - /// \brief Return a \ref DigraphReader class - /// - /// This function just returns a \ref DigraphReader class. - /// \relates DigraphReader + DigraphReader digraphReader(Digraph& digraph, const std::string& fn); template - DigraphReader digraphReader(Digraph& digraph, const char* fn) { - DigraphReader tmp(digraph, fn); - return tmp; - } + DigraphReader digraphReader(Digraph& digraph, const char *fn); /// \ingroup lemon_io /// @@ -584,12 +560,13 @@ private: - friend DigraphReader digraphReader<>(Digraph& digraph, - std::istream& is); - friend DigraphReader digraphReader<>(Digraph& digraph, - const std::string& fn); - friend DigraphReader digraphReader<>(Digraph& digraph, - const char *fn); + template + friend DigraphReader digraphReader(DGR& digraph, std::istream& is); + template + friend DigraphReader digraphReader(DGR& digraph, + const std::string& fn); + template + friend DigraphReader digraphReader(DGR& digraph, const char *fn); DigraphReader(DigraphReader& other) : _is(other._is), local_is(other.local_is), _digraph(other._digraph), @@ -1212,38 +1189,47 @@ }; + /// \brief Return a \ref DigraphReader class + /// + /// This function just returns a \ref DigraphReader class. + /// \relates DigraphReader + template + DigraphReader digraphReader(Digraph& digraph, std::istream& is) { + DigraphReader tmp(digraph, is); + return tmp; + } + + /// \brief Return a \ref DigraphReader class + /// + /// This function just returns a \ref DigraphReader class. + /// \relates DigraphReader + template + DigraphReader digraphReader(Digraph& digraph, + const std::string& fn) { + DigraphReader tmp(digraph, fn); + return tmp; + } + + /// \brief Return a \ref DigraphReader class + /// + /// This function just returns a \ref DigraphReader class. + /// \relates DigraphReader + template + DigraphReader digraphReader(Digraph& digraph, const char* fn) { + DigraphReader tmp(digraph, fn); + return tmp; + } + template class GraphReader; - - /// \brief Return a \ref GraphReader class - /// - /// This function just returns a \ref GraphReader class. - /// \relates GraphReader + template - GraphReader graphReader(Graph& graph, std::istream& is = std::cin) { - GraphReader tmp(graph, is); - return tmp; - } - - /// \brief Return a \ref GraphReader class - /// - /// This function just returns a \ref GraphReader class. - /// \relates GraphReader + GraphReader graphReader(Graph& graph, + std::istream& is = std::cin); template - GraphReader graphReader(Graph& graph, const std::string& fn) { - GraphReader tmp(graph, fn); - return tmp; - } - - /// \brief Return a \ref GraphReader class - /// - /// This function just returns a \ref GraphReader class. - /// \relates GraphReader + GraphReader graphReader(Graph& graph, const std::string& fn); template - GraphReader graphReader(Graph& graph, const char* fn) { - GraphReader tmp(graph, fn); - return tmp; - } + GraphReader graphReader(Graph& graph, const char *fn); /// \ingroup lemon_io /// @@ -1370,10 +1356,12 @@ } private: - friend GraphReader graphReader<>(Graph& graph, std::istream& is); - friend GraphReader graphReader<>(Graph& graph, - const std::string& fn); - friend GraphReader graphReader<>(Graph& graph, const char *fn); + template + friend GraphReader graphReader(GR& graph, std::istream& is); + template + friend GraphReader graphReader(GR& graph, const std::string& fn); + template + friend GraphReader graphReader(GR& graph, const char *fn); GraphReader(GraphReader& other) : _is(other._is), local_is(other.local_is), _graph(other._graph), @@ -2044,6 +2032,36 @@ }; + /// \brief Return a \ref GraphReader class + /// + /// This function just returns a \ref GraphReader class. + /// \relates GraphReader + template + GraphReader graphReader(Graph& graph, std::istream& is) { + GraphReader tmp(graph, is); + return tmp; + } + + /// \brief Return a \ref GraphReader class + /// + /// This function just returns a \ref GraphReader class. + /// \relates GraphReader + template + GraphReader graphReader(Graph& graph, const std::string& fn) { + GraphReader tmp(graph, fn); + return tmp; + } + + /// \brief Return a \ref GraphReader class + /// + /// This function just returns a \ref GraphReader class. + /// \relates GraphReader + template + GraphReader graphReader(Graph& graph, const char* fn) { + GraphReader tmp(graph, fn); + return tmp; + } + class SectionReader; SectionReader sectionReader(std::istream& is); diff --git a/lemon/lgf_writer.h b/lemon/lgf_writer.h --- a/lemon/lgf_writer.h +++ b/lemon/lgf_writer.h @@ -350,38 +350,17 @@ template class DigraphWriter; - /// \brief Return a \ref DigraphWriter class - /// - /// This function just returns a \ref DigraphWriter class. - /// \relates DigraphWriter template DigraphWriter digraphWriter(const Digraph& digraph, - std::ostream& os = std::cout) { - DigraphWriter tmp(digraph, os); - return tmp; - } - - /// \brief Return a \ref DigraphWriter class - /// - /// This function just returns a \ref DigraphWriter class. - /// \relates DigraphWriter + std::ostream& os = std::cout); template DigraphWriter digraphWriter(const Digraph& digraph, - const std::string& fn) { - DigraphWriter tmp(digraph, fn); - return tmp; - } + const std::string& fn); - /// \brief Return a \ref DigraphWriter class - /// - /// This function just returns a \ref DigraphWriter class. - /// \relates DigraphWriter template DigraphWriter digraphWriter(const Digraph& digraph, - const char* fn) { - DigraphWriter tmp(digraph, fn); - return tmp; - } + const char* fn); + /// \ingroup lemon_io /// @@ -526,12 +505,15 @@ private: - friend DigraphWriter digraphWriter<>(const Digraph& digraph, - std::ostream& os); - friend DigraphWriter digraphWriter<>(const Digraph& digraph, - const std::string& fn); - friend DigraphWriter digraphWriter<>(const Digraph& digraph, - const char *fn); + template + friend DigraphWriter digraphWriter(const DGR& digraph, + std::ostream& os); + template + friend DigraphWriter digraphWriter(const DGR& digraph, + const std::string& fn); + template + friend DigraphWriter digraphWriter(const DGR& digraph, + const char *fn); DigraphWriter(DigraphWriter& other) : _os(other._os), local_os(other.local_os), _digraph(other._digraph), @@ -933,39 +915,49 @@ /// @} }; + /// \brief Return a \ref DigraphWriter class + /// + /// This function just returns a \ref DigraphWriter class. + /// \relates DigraphWriter + template + DigraphWriter digraphWriter(const Digraph& digraph, + std::ostream& os) { + DigraphWriter tmp(digraph, os); + return tmp; + } + + /// \brief Return a \ref DigraphWriter class + /// + /// This function just returns a \ref DigraphWriter class. + /// \relates DigraphWriter + template + DigraphWriter digraphWriter(const Digraph& digraph, + const std::string& fn) { + DigraphWriter tmp(digraph, fn); + return tmp; + } + + /// \brief Return a \ref DigraphWriter class + /// + /// This function just returns a \ref DigraphWriter class. + /// \relates DigraphWriter + template + DigraphWriter digraphWriter(const Digraph& digraph, + const char* fn) { + DigraphWriter tmp(digraph, fn); + return tmp; + } + template class GraphWriter; - /// \brief Return a \ref GraphWriter class - /// - /// This function just returns a \ref GraphWriter class. - /// \relates GraphWriter template GraphWriter graphWriter(const Graph& graph, - std::ostream& os = std::cout) { - GraphWriter tmp(graph, os); - return tmp; - } - - /// \brief Return a \ref GraphWriter class - /// - /// This function just returns a \ref GraphWriter class. - /// \relates GraphWriter + std::ostream& os = std::cout); template - GraphWriter graphWriter(const Graph& graph, const std::string& fn) { - GraphWriter tmp(graph, fn); - return tmp; - } - - /// \brief Return a \ref GraphWriter class - /// - /// This function just returns a \ref GraphWriter class. - /// \relates GraphWriter + GraphWriter graphWriter(const Graph& graph, const std::string& fn); template - GraphWriter graphWriter(const Graph& graph, const char* fn) { - GraphWriter tmp(graph, fn); - return tmp; - } + GraphWriter graphWriter(const Graph& graph, const char* fn); /// \ingroup lemon_io /// @@ -1081,13 +1073,16 @@ private: - friend GraphWriter graphWriter<>(const Graph& graph, - std::ostream& os); - friend GraphWriter graphWriter<>(const Graph& graph, - const std::string& fn); - friend GraphWriter graphWriter<>(const Graph& graph, - const char *fn); - + template + friend GraphWriter graphWriter(const GR& graph, + std::ostream& os); + template + friend GraphWriter graphWriter(const GR& graph, + const std::string& fn); + template + friend GraphWriter graphWriter(const GR& graph, + const char *fn); + GraphWriter(GraphWriter& other) : _os(other._os), local_os(other.local_os), _graph(other._graph), _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { @@ -1534,6 +1529,37 @@ /// @} }; + /// \brief Return a \ref GraphWriter class + /// + /// This function just returns a \ref GraphWriter class. + /// \relates GraphWriter + template + GraphWriter graphWriter(const Graph& graph, + std::ostream& os) { + GraphWriter tmp(graph, os); + return tmp; + } + + /// \brief Return a \ref GraphWriter class + /// + /// This function just returns a \ref GraphWriter class. + /// \relates GraphWriter + template + GraphWriter graphWriter(const Graph& graph, const std::string& fn) { + GraphWriter tmp(graph, fn); + return tmp; + } + + /// \brief Return a \ref GraphWriter class + /// + /// This function just returns a \ref GraphWriter class. + /// \relates GraphWriter + template + GraphWriter graphWriter(const Graph& graph, const char* fn) { + GraphWriter tmp(graph, fn); + return tmp; + } + class SectionWriter; SectionWriter sectionWriter(std::istream& is); diff --git a/lemon/path.h b/lemon/path.h --- a/lemon/path.h +++ b/lemon/path.h @@ -929,9 +929,8 @@ }; template ::value, - bool revEnable = RevPathTagIndicator::value> - struct PathCopySelector { + bool buildEnable = BuildTagIndicator::value> + struct PathCopySelectorForward { static void copy(Target& target, const Source& source) { target.clear(); for (typename Source::ArcIt it(source); it != INVALID; ++it) { @@ -941,7 +940,16 @@ }; template - struct PathCopySelector { + struct PathCopySelectorForward { + static void copy(Target& target, const Source& source) { + target.clear(); + target.build(source); + } + }; + + template ::value> + struct PathCopySelectorBackward { static void copy(Target& target, const Source& source) { target.clear(); for (typename Source::RevArcIt it(source); it != INVALID; ++it) { @@ -951,21 +959,29 @@ }; template - struct PathCopySelector { - static void copy(Target& target, const Source& source) { - target.clear(); - target.build(source); - } - }; - - template - struct PathCopySelector { + struct PathCopySelectorBackward { static void copy(Target& target, const Source& source) { target.clear(); target.buildRev(source); } }; + + template ::value> + struct PathCopySelector { + static void copy(Target& target, const Source& source) { + PathCopySelectorForward::copy(target, source); + } + }; + + template + struct PathCopySelector { + static void copy(Target& target, const Source& source) { + PathCopySelectorBackward::copy(target, source); + } + }; + } diff --git a/lemon/random.h b/lemon/random.h --- a/lemon/random.h +++ b/lemon/random.h @@ -344,56 +344,46 @@ } }; - template = 0)> + template struct ShiftMultiplier { static const Result multiplier() { Result res = ShiftMultiplier::multiplier(); res *= res; - if ((exp & 1) == 1) res *= static_cast(2.0); - return res; - } - }; - - template - struct ShiftMultiplier { - static const Result multiplier() { - Result res = ShiftMultiplier::multiplier(); - res *= res; if ((exp & 1) == 1) res *= static_cast(0.5); return res; } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { return static_cast(1.0); } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { return static_cast(1.0/1048576.0); } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { - return static_cast(1.0/424967296.0); + return static_cast(1.0/4294967296.0); } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { return static_cast(1.0/9007199254740992.0); } }; template - struct ShiftMultiplier { + struct ShiftMultiplier { static const Result multiplier() { return static_cast(1.0/18446744073709551616.0); } @@ -413,7 +403,7 @@ static const int bits = std::numeric_limits::digits; static Result convert(RandomCore& rnd) { - return Shifting:: + return Shifting:: shift(static_cast(rnd() >> (bits - rest))); } }; @@ -423,7 +413,7 @@ static const int bits = std::numeric_limits::digits; static Result convert(RandomCore& rnd) { - return Shifting:: + return Shifting:: shift(static_cast(rnd())) + RealConversion:: convert(rnd); diff --git a/lemon/tolerance.h b/lemon/tolerance.h --- a/lemon/tolerance.h +++ b/lemon/tolerance.h @@ -38,17 +38,14 @@ ///handle the comparison of numbers that are obtained ///as a result of a probably inexact computation. /// - ///This is an abstract class, it should be specialized for all - ///numerical data types. These specialized classes like + ///The general implementation is suitable only if the data type is exact, + ///like the integer types, otherwise a specialized version must be + ///implemented. These specialized classes like ///Tolerance may offer additional tuning parameters. /// ///\sa Tolerance ///\sa Tolerance ///\sa Tolerance - ///\sa Tolerance - ///\sa Tolerance - ///\sa Tolerance - ///\sa Tolerance template class Tolerance @@ -64,20 +61,20 @@ ///@{ ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) {return false;} + static bool less(Value a,Value b) {return a(0) < a;} ///Returns \c true if \c a is \e surely negative - static bool negative(Value a) {return false;} + static bool negative(Value a) {return a < static_cast(0);} ///Returns \c true if \c a is \e surely non-zero - static bool nonZero(Value a) {return false;} + static bool nonZero(Value a) {return a != static_cast(0);} ///@} ///Returns the zero value. - static Value zero() {return T();} + static Value zero() {return static_cast(0);} // static bool finite(Value a) {} // static Value big() {} @@ -238,213 +235,6 @@ static Value zero() {return 0;} }; - ///Integer specialization of Tolerance. - - ///Integer specialization of Tolerance. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return aa; } - ///Returns \c true if \c a is \e surely non-zero - static bool nonZero(Value a) { return a!=0; } - - ///@} - - ///Returns zero - static Value zero() {return 0;} - }; - - ///Unsigned integer specialization of Tolerance. - - ///Unsigned integer specialization of Tolerance. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef unsigned int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return a - class Tolerance - { - public: - ///\e - typedef long int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return aa; } - ///Returns \c true if \c a is \e surely non-zero - static bool nonZero(Value a) { return a!=0;} - - ///@} - - ///Returns zero - static Value zero() {return 0;} - }; - - ///Unsigned long integer specialization of Tolerance. - - ///Unsigned long integer specialization of Tolerance. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef unsigned long int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return along long) - ///is not ansi compatible. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef long long int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return aa; } - ///Returns \c true if \c a is \e surely non-zero - static bool nonZero(Value a) { return a!=0;} - - ///@} - - ///Returns zero - static Value zero() {return 0;} - }; - - ///Unsigned long long integer specialization of Tolerance. - - ///Unsigned long long integer specialization of Tolerance. - ///\warning This class (more exactly, type unsigned long long) - ///is not ansi compatible. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef unsigned long long int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return a