COIN-OR::LEMON - Graph Library

Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • lemon/assert.h

    r108 r118  
    2727
    2828namespace lemon {
    29 
    30   /// @{
    31 
    32   ///\e
    33   class AssertionFailedError : public LogicError {
    34   protected:
    35     const char *_assertion;
    36     const char *_file;
    37     int _line;
    38     const char *_function;
    39     const char *_message;
    40 
    41     mutable ExceptionMember<std::string> _message_holder;
    42   public:
    43     ///\e
    44     AssertionFailedError(const char *file, int line, const char *function,
    45                          const char *msg, const char *assertion = 0) :
    46       _assertion(assertion), _file(file), _line(line),
    47       _function(function), _message(msg) {}
    48 
    49     ///\e
    50     const char* assertion() const { return _assertion; }
    51     ///\e
    52     const char* message() const { return _message; }
    53     ///\e
    54     const char* file() const { return _file; }
    55     ///\e
    56     const char* function() const { return _function; }
    57     ///\e
    58     int line() const { return _line; }
    59 
    60 
    61     virtual const char* what() const throw() {
    62       try {
    63         std::ostringstream ostr;
    64         ostr << _file << ":" << _line << ": ";
    65         if (_function)
    66           ostr << _function << ": ";
    67         ostr << _message;
    68         if (_assertion)
    69            ostr << " (assertion '" << _assertion << "' failed)";
    70         _message_holder.set(ostr.str());
    71         return ostr.str().c_str();
    72       }
    73       catch(...) {}
    74       if( _message_holder.valid() ) return _message_holder.get().c_str();
    75       return "lemon::AssertionFailedError";
    76     }
    77     virtual ~AssertionFailedError() throw() {}
    78   };
    79 
    80 
    81   inline void assert_fail_log(const char *file, int line,
    82                               const char *function,
    83                               const std::exception& exception,
    84                               const char *assertion)
    85   {
    86     std::cerr << file << ":" << line << ": ";
    87     if (function)
    88       std::cerr << function << ": ";
    89     std::cerr << exception.what();
    90     if (assertion)
    91       std::cerr << " (assertion '" << assertion << "' failed)";
    92     std::cerr << std::endl;
    93   }
    9429
    9530  inline void assert_fail_log(const char *file, int line, const char *function,
     
    10540  }
    10641
    107   inline void assert_fail_log(const char *file, int line, const char *function,
    108                               const std::string& message, const char *assertion)
    109   {
    110     assert_fail_log(file, line, function, message.c_str(), assertion);
    111   }
    112 
    113   inline void assert_fail_abort(const char *file, int line,
    114                                 const char *function,
    115                                 const std::exception& exception,
    116                                 const char *assertion)
    117   {
    118     std::cerr << file << ":" << line << ": ";
    119     if (function)
    120       std::cerr << function << ": ";
    121     std::cerr << exception.what();
    122     if (assertion)
    123       std::cerr << " (assertion '" << assertion << "' failed)";
    124     std::cerr << std::endl;
    125     std::abort();
    126   }
    127 
    12842  inline void assert_fail_abort(const char *file, int line,
    12943                                const char *function, const char* message,
    13044                                const char *assertion)
    13145  {
    132     std::cerr << file << ":" << line << ": ";
    133     if (function)
    134       std::cerr << function << ": ";
    135     std::cerr << message;
    136     if (assertion)
    137       std::cerr << " (assertion '" << assertion << "' failed)";
    138     std::cerr << std::endl;
     46    assert_fail_log(file, line, function, message, assertion);
    13947    std::abort();
    14048  }
    14149
    142   inline void assert_fail_abort(const char *file, int line,
    143                                 const char *function,
    144                                 const std::string& message,
    145                                 const char *assertion)
    146   {
    147     assert_fail_abort(file, line, function, message.c_str(), assertion);
     50  namespace _assert_bits {
     51   
     52   
     53    inline const char* cstringify(const std::string& str) {
     54      return str.c_str();
     55    }
     56
     57    inline const char* cstringify(const char* str) {
     58      return str;
     59    }   
    14860  }
    149 
    150   inline void assert_fail_error(const char *file, int line,
    151                                   const char *function,
    152                                   const std::exception& exception,
    153                                   const char *assertion)
    154   {
    155     throw AssertionFailedError(file, line, function,
    156                                exception.what(), assertion);
    157   }
    158 
    159   inline void assert_fail_error(const char *file, int line,
    160                                   const char *function, const char *message,
    161                                   const char *assertion)
    162   {
    163     throw AssertionFailedError(file, line, function, message, assertion);
    164   }
    165 
    166   inline void assert_fail_error(const char *file, int line,
    167                                   const char *function,
    168                                   const std::string& message,
    169                                   const char *assertion)
    170   {
    171     assert_fail_error(file, line, function, message.c_str(), assertion);
    172   }
    173 
    174   template <typename Exception>
    175   inline void assert_fail_exception(const char *, int, const char *,
    176                                     const Exception& exception,
    177                                     const char *, const std::exception* =
    178                                     static_cast<const Exception*>(0))
    179   {
    180     throw exception;
    181   }
    182 
    183   inline void assert_fail_exception(const char *file, int line,
    184                                     const char *function, const char *message,
    185                                     const char *assertion)
    186   {
    187     throw AssertionFailedError(file, line, function, message, assertion);
    188   }
    189 
    190   inline void assert_fail_exception(const char *file, int line,
    191                                     const char *function,
    192                                     const std::string& message,
    193                                     const char *assertion)
    194   {
    195     assert_fail_exception(file, line, function, message.c_str(), assertion);
    196   }
    197 
    198 /// @}
    199 
    20061}
     62
    20163#endif // LEMON_ASSERT_H
    20264
    20365#undef LEMON_ASSERT
    20466#undef LEMON_FIXME
     67#undef LEMON_DEBUG
    20568
    20669#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) +               \
    20770  (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +               \
    208   (defined(LEMON_ASSERT_ERROR) ? 1 : 0) +               \
    209   (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) +           \
    21071  (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
    211 #error "Lemon assertion system is not set properly"
     72#error "LEMON assertion system is not set properly"
    21273#endif
    21374
    21475#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) +              \
    21576     (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +            \
    216      (defined(LEMON_ASSERT_ERROR) ? 1 : 0) +            \
    217      (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) +        \
    21877     (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||     \
    219      defined(LEMON_ENABLE_ASSERT)) &&                   \
    220   defined(LEMON_DISABLE_ASSERTS)
    221 #error "Lemon assertion system is not set properly"
     78     defined(LEMON_ENABLE_ASSERTS)) &&                  \
     79  (defined(LEMON_DISABLE_ASSERTS) ||                    \
     80   defined(NDEBUG))
     81#error "LEMON assertion system is not set properly"
    22282#endif
    22383
     
    22989#  undef LEMON_ASSERT_HANDLER
    23090#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
    231 #elif defined LEMON_ASSERT_ERROR
    232 #  undef LEMON_ASSERT_HANDLER
    233 #  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_error
    234 #elif defined LEMON_ASSERT_EXCEPTION
    235 #  undef LEMON_ASSERT_HANDLER
    236 #  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception
    23791#elif defined LEMON_ASSERT_CUSTOM
    23892#  undef LEMON_ASSERT_HANDLER
     
    24195#  endif
    24296#  define LEMON_ASSERT_HANDLER LEMON_CUSTOM_ASSERT_HANDLER
    243 #elif defined LEMON_ENABLE_ASSERTS
    244 #  undef LEMON_ASSERT_HANDLER
     97#elif defined LEMON_DISABLE_ASSERTS
     98#  undef LEMON_ASSERT_HANDLER
     99#elif defined NDEBUG
     100#  undef LEMON_ASSERT_HANDLER
     101#else
    245102#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
    246 #else
    247 #  undef LEMON_ASSERT_HANDLER
    248 #endif
    249 
     103#endif
    250104
    251105#ifndef LEMON_FUNCTION_NAME
     
    257111/// \ingroup exceptions
    258112///
    259 /// \brief Macro for assertions with customizable message
    260 ///
    261 /// Macro for assertions with customizable message. 
    262 /// \param exp An expression convertible to bool. If the expression is
     113/// \brief Macro for assertion with customizable message
     114///
     115/// Macro for assertion with customizable message.  \param exp An
     116/// expression that must be convertible to \c bool.  If it is \c
    263117/// false, then an assertion is raised. The concrete behaviour depends
    264 /// on the settings of the assertion system.
    265 /// \param msg A \e const \e char*, a \e const std::string& or a \e
    266 /// const \e std::exception& parameter. The variable can be used to
    267 /// provide information about the circumstances of failed assertion.
    268 ///
    269 /// The assertions are disabled in the default behaviour. You can
    270 /// enable the assertions with the following code:
    271 /// \code
    272 /// #define LEMON_ENABLE_ASSERTS
     118/// on the settings of the assertion system.  \param msg A <tt>const
     119/// char*</tt> parameter, which can be used to provide information
     120/// about the circumstances of the failed assertion.
     121///
     122/// The assertions are enabled in the default behaviour.
     123/// You can disable them with the following code:
     124/// \code
     125/// #define LEMON_DISABLE_ASSERTS
    273126/// \endcode
    274127/// or with compilation parameters:
    275128/// \code
    276 /// g++ -DLEMON_ENABLE_ASSERTS
    277 /// make CXXFLAGS='-DLEMON_ENABLE_ASSERTS'
    278 /// \endcode
     129/// g++ -DLEMON_DISABLE_ASSERTS
     130/// make CXXFLAGS='-DLEMON_DISABLE_ASSERTS'
     131/// \endcode
     132/// The checking is also disabled when the standard macro \c NDEBUG is defined.
    279133///
    280 /// The %lemon assertion system has a wide range of customization
    281 /// properties. As default behaviour the failed assertion prints a
    282 /// short log message to the standard ouput and aborts the execution.
     134/// The LEMON assertion system has a wide range of customization
     135/// properties. As a default behaviour the failed assertion prints a
     136/// short log message to the standard error and aborts the execution.
    283137///
    284138/// The following modes can be used in the assertion system:
    285139///
    286 /// - \e LEMON_ASSERT_LOG The failed assert print a short convenient
    287 ///   error message to the standard error and continues the
    288 ///   execution.
    289 /// - \e LEMON_ASSERT_ABORT This mode is similar to the \e
     140/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log
     141///   message to the standard error and continues the execution.
     142/// - \c LEMON_ASSERT_ABORT This mode is similar to the \c
    290143///   LEMON_ASSERT_LOG, but it aborts the program. It is the default
    291 ///   operation mode when the asserts are enabled with \e
    292 ///   LEMON_ENABLE_ASSERTS.
    293 /// - \e LEMON_ASSERT_ERROR The assert throws an \ref
    294 ///   lemon::AssertionFailedError "AssertionFailedError". If the \c
    295 ///   msg parameter is an exception, then the result of the \ref
    296 ///   lemon::Exception::what() "what()" member function is passed as
    297 ///   error message.
    298 /// - \e LEMON_ASSERT_EXCEPTION If the specified \c msg is an
    299 ///   exception then it raised directly (solving that the exception
    300 ///   can not be thrown polymorphically), otherwise an \ref
    301 ///   lemon::AssertionFailedError "AssertionFailedError" is thrown with
    302 ///   the given parameter.
    303 /// - \e LEMON_ASSERT_CUSTOM The user can define an own assertion
    304 ///   handler functions. Three overloaded functions should be defined
    305 ///   with the following parameter lists:
     144///   behaviour.
     145/// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler
     146///   function.
    306147///   \code
    307 ///     void custom_assert_handler(const char* file, int line,
    308 ///                                const char* function, const char* message, const char* expression);
    309 ///     void custom_assert_handler(const char* file, int line,
    310 ///                                const char* function, const std::string& message, const char* expression);
    311 ///     void custom_assert_handler(const char* file, int line,
    312 ///                                const char* function, const std::exception& message, const char* expression);
     148///     void custom_assert_handler(const char* file, int line, const char* function,
     149///                                const char* message, const char* assertion);
    313150///   \endcode
    314 ///   The name of the functions should be defined as the \c
     151///   The name of the function should be defined as the \c
    315152///   LEMON_CUSTOM_ASSERT_HANDLER macro name.
    316153///   \code
    317154///     #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler
    318155///   \endcode
    319 ///   Whenever an assertion is occured, one of the custom assertion
     156///   Whenever an assertion is occured, the custom assertion
    320157///   handler is called with appropiate parameters.
    321158///
    322 /// The assertion mode can be changed within one compilation unit, if
    323 /// the macros are redefined with other settings and the
    324 /// lemon/assert.h file is reincluded then the behaviour is changed
    325 /// appropiately to the new settings.
     159/// The assertion mode can also be changed within one compilation unit.
     160/// If the macros are redefined with other settings and the
     161/// \ref lemon/assert.h "assert.h" file is reincluded, then the
     162/// behaviour is changed appropiately to the new settings.
    326163#  define LEMON_ASSERT(exp, msg)                                        \
    327164  (static_cast<void> (!!(exp) ? 0 : (                                   \
    328165    LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                            \
    329166                         LEMON_FUNCTION_NAME,                           \
    330                          msg, #exp), 0)))
    331 
     167                         ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
    332168
    333169/// \ingroup exceptions
     
    340176///   LEMON_ASSERT(false, msg);
    341177/// \endcode
     178///
     179/// \see LEMON_ASSERT
    342180#  define LEMON_FIXME(msg)                                              \
     181  (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,        \
     182                        ::lemon::_assert_bits::cstringify(msg),         \
     183                        static_cast<const char*>(0)))
     184
     185/// \ingroup exceptions
     186///
     187/// \brief Macro for internal assertions
     188///
     189/// Macro for internal assertions, it is used in the library to check
     190/// the consistency of results of algorithms, several pre- and
     191/// postconditions and invariants. The checking is disabled by
     192/// default, but it can be turned on with the macro \c
     193/// LEMON_ENABLE_DEBUG.
     194/// \code
     195/// #define LEMON_ENABLE_DEBUG
     196/// \endcode
     197/// or with compilation parameters:
     198/// \code
     199/// g++ -DLEMON_ENABLE_DEBUG
     200/// make CXXFLAGS='-DLEMON_ENABLE_DEBUG'
     201/// \endcode
     202///
     203/// This macro works like the \c LEMON_ASSERT macro, therefore the
     204/// current behaviour depends on the settings of \c LEMON_ASSERT
     205/// macro.
     206///
     207/// \see LEMON_ASSERT
     208#  define LEMON_DEBUG(exp, msg)                                         \
     209  (static_cast<void> (!!(exp) ? 0 : (                                   \
     210    LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                            \
     211                         LEMON_FUNCTION_NAME,                           \
     212                         ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
     213
     214#else
     215
     216#  ifndef LEMON_ASSERT_HANDLER
     217#    define LEMON_ASSERT(exp, msg)  (static_cast<void>(0))
     218#    define LEMON_FIXME(msg) (static_cast<void>(0))
     219#    define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
     220#  else
     221#    define LEMON_ASSERT(exp, msg)                                      \
     222       (static_cast<void> (!!(exp) ? 0 : (                              \
     223        LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                        \
     224                             LEMON_FUNCTION_NAME,                       \
     225                             ::lemon::_assert_bits::cstringify(msg),    \
     226                             #exp), 0)))
     227#    define LEMON_FIXME(msg)                                            \
    343228       (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,   \
    344                              "FIXME: " msg, static_cast<const char*>(0)))
     229                             ::lemon::_assert_bits::cstringify(msg),    \
     230                             static_cast<const char*>(0)))
     231
     232#    if LEMON_ENABLE_DEBUG
     233#      define LEMON_DEBUG(exp, msg)
     234         (static_cast<void> (!!(exp) ? 0 : (         \
     235           LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
     236                                LEMON_FUNCTION_NAME, \
     237                                ::lemon::_assert_bits::cstringify(msg), \
     238                                #exp), 0)))
     239#    else
     240#      define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
     241#    endif
     242#  endif
     243
     244#endif
     245
     246#ifdef DOXYGEN
     247
    345248
    346249#else
    347250
    348 #  ifndef LEMON_ASSERT_HANDLER
    349 #    define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
    350 #    define LEMON_FIXME(msg) (static_cast<void>(0))
    351 #  else
    352 #    define LEMON_ASSERT(exp, msg)                 \
    353        (static_cast<void> (!!(exp) ? 0 : (         \
    354          LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
    355                               LEMON_FUNCTION_NAME, \
    356                               msg, #exp), 0)))
    357 #    define LEMON_FIXME(msg) \
    358        (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,   \
    359                              "FIXME: " msg,  static_cast<const char*>(0)))
    360 #  endif
    361 
    362 #endif
    363 
    364 
     251
     252#endif
     253
     254
  • lemon/bits/utility.h

    r39 r117  
    2222// Boost enable_if library
    2323
    24 // Copyright 2003 © The Trustees of Indiana University.
     24// Copyright 2003 (c) The Trustees of Indiana University.
    2525
    2626// Use, modification, and distribution is subject to the Boost Software
     
    2828// http://www.boost.org/LICENSE_1_0.txt)
    2929
    30 //    Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
     30//    Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
    3131//             Jeremiah Willcock (jewillco at osl.iu.edu)
    3232//             Andrew Lumsdaine (lums at osl.iu.edu)
  • lemon/concepts/heap.h

    r100 r113  
    1919///\ingroup concept
    2020///\file
    21 ///\brief Classes for representing heaps.
    22 ///
     21///\brief The concept of heaps.
    2322
    2423#ifndef LEMON_CONCEPT_HEAP_H
     
    2827
    2928namespace lemon {
     29
    3030  namespace concepts {
     31
    3132    /// \addtogroup concept
    3233    /// @{
    3334
    34 
    35     /// \brief A concept structure describes the main interface of heaps.
     35    /// \brief The heap concept.
    3636    ///
    37     /// A concept structure describes the main interface of heaps.
    38     ///
    39     template <typename Prio, typename ItemIntMap>
     37    /// Concept class describing the main interface of heaps.
     38    template <typename Priority, typename ItemIntMap>
    4039    class Heap {
    4140    public:
    4241
    43       ///\brief Type of the items stored in the heap.
    44       typedef typename ItemIntMap::Key  Item;
    45  
    46 
    47       /// \brief Type to represent the items states.
    48       ///
    49       /// Each Item element have a state associated to it. It may be "in heap",
    50       /// "pre heap" or "post heap". The later two are indifferent from the
    51       /// heap's point of view, but may be useful to the user.
    52       ///
    53       /// The ItemIntMap _should_ be initialized in such way, that it maps
    54       /// PRE_HEAP (-1) to any element to be put in the heap...
     42      /// Type of the items stored in the heap.
     43      typedef typename ItemIntMap::Key Item;
     44
     45      /// Type of the priorities.
     46      typedef Priority Prio;
     47
     48      /// \brief Type to represent the states of the items.
     49      ///
     50      /// Each item has a state associated to it. It can be "in heap",
     51      /// "pre heap" or "post heap". The later two are indifferent
     52      /// from the point of view of the heap, but may be useful for
     53      /// the user.
     54      ///
     55      /// The \c ItemIntMap must be initialized in such a way, that it
     56      /// assigns \c PRE_HEAP (<tt>-1</tt>) to every item.
    5557      enum State {
    5658        IN_HEAP = 0,
     
    6264      ///
    6365      /// The constructor.
    64       /// \param _iim should be given to the constructor, since it is used
    65       /// internally to handle the cross references. The value of the map
    66       /// should be PRE_HEAP (-1) for each element.
    67       explicit Heap(ItemIntMap &_iim) {}
     66      /// \param map A map that assigns \c int values to keys of type
     67      /// \c Item. It is used internally by the heap implementations to
     68      /// handle the cross references. The assigned value must be
     69      /// \c PRE_HEAP (<tt>-1</tt>) for every item.
     70      explicit Heap(ItemIntMap &map) {}
    6871
    6972      /// \brief The number of items stored in the heap.
     
    7275      int size() const { return 0; }
    7376
    74       /// \brief Checks if the heap stores no items.
    75       ///
    76       /// Returns \c true if and only if the heap stores no items.
     77      /// \brief Checks if the heap is empty.
     78      ///
     79      /// Returns \c true if the heap is empty.
    7780      bool empty() const { return false; }
    7881
    79       /// \brief Makes empty this heap.
    80       ///
    81       /// Makes this heap empty.
     82      /// \brief Makes the heap empty.
     83      ///
     84      /// Makes the heap empty.
    8285      void clear();
    8386
    84       /// \brief Insert an item into the heap with the given heap.
     87      /// \brief Inserts an item into the heap with the given priority.
    8588      ///   
    86       /// Adds \c i to the heap with priority \c p.
     89      /// Inserts the given item into the heap with the given priority.
    8790      /// \param i The item to insert.
    8891      /// \param p The priority of the item.
    8992      void push(const Item &i, const Prio &p) {}
    9093
    91       /// \brief Returns the item with minimum priority.
    92       ///
    93       /// This method returns the item with minimum priority. 
    94       /// \pre The heap must be nonempty. 
     94      /// \brief Returns the item having minimum priority.
     95      ///
     96      /// Returns the item having minimum priority.
     97      /// \pre The heap must be non-empty.
    9598      Item top() const {}
    9699
    97       /// \brief Returns the minimum priority.
    98       ///
    99       /// It returns the minimum priority.
    100       /// \pre The heap must be nonempty.
     100      /// \brief The minimum priority.
     101      ///
     102      /// Returns the minimum priority.
     103      /// \pre The heap must be non-empty.
    101104      Prio prio() const {}
    102105
    103       /// \brief Deletes the item with minimum priority.
    104       ///
    105       /// This method deletes the item with minimum priority.
    106       /// \pre The heap must be non-empty. 
     106      /// \brief Removes the item having minimum priority.
     107      ///
     108      /// Removes the item having minimum priority.
     109      /// \pre The heap must be non-empty.
    107110      void pop() {}
    108111
    109       /// \brief Deletes \c i from the heap.
    110       ///
    111       /// This method deletes item \c i from the heap, if \c i was
     112      /// \brief Removes an item from the heap.
     113      ///
     114      /// Removes the given item from the heap if it is already stored.
     115      /// \param i The item to delete.
     116      void erase(const Item &i) {}
     117
     118      /// \brief The priority of an item.
     119      ///
     120      /// Returns the priority of the given item. 
     121      /// \pre \c i must be in the heap.
     122      /// \param i The item.
     123      Prio operator[](const Item &i) const {}
     124
     125      /// \brief Sets the priority of an item or inserts it, if it is
     126      /// not stored in the heap.
     127      ///
     128      /// This method sets the priority of the given item if it is
    112129      /// already stored in the heap.
    113       /// \param i The item to erase.
    114       void erase(const Item &i) {}
    115 
    116       /// \brief Returns the priority of \c i.
    117       ///
    118       /// This function returns the priority of item \c i. 
    119       /// \pre \c i must be in the heap.
    120       /// \param i The item.
    121       Prio operator[](const Item &i) const {}
    122 
    123       /// \brief \c i gets to the heap with priority \c p independently
    124       /// if \c i was already there.
    125       ///
    126       /// This method calls \ref push(\c i, \c p) if \c i is not stored
    127       /// in the heap and sets the priority of \c i to \c p otherwise.
    128       /// It may throw an \e UnderFlowPriorityException.
     130      /// Otherwise it inserts the given item with the given priority.
     131      ///
     132      /// It may throw an \ref UnderflowPriorityException.
    129133      /// \param i The item.
    130134      /// \param p The priority.
    131135      void set(const Item &i, const Prio &p) {}
    132136     
    133       /// \brief Decreases the priority of \c i to \c p.
    134       ///
    135       /// This method decreases the priority of item \c i to \c p.
     137      /// \brief Decreases the priority of an item to the given value.
     138      ///
     139      /// Decreases the priority of an item to the given value.
    136140      /// \pre \c i must be stored in the heap with priority at least \c p.
    137141      /// \param i The item.
     
    139143      void decrease(const Item &i, const Prio &p) {}
    140144
    141       /// \brief Increases the priority of \c i to \c p.
    142       ///
    143       /// This method sets the priority of item \c i to \c p.
    144       /// \pre \c i must be stored in the heap with priority at most \c
    145       /// p relative to \c Compare.
     145      /// \brief Increases the priority of an item to the given value.
     146      ///
     147      /// Increases the priority of an item to the given value.
     148      /// \pre \c i must be stored in the heap with priority at most \c p.
    146149      /// \param i The item.
    147150      /// \param p The priority.
    148151      void increase(const Item &i, const Prio &p) {}
    149152
    150       /// \brief Returns if \c item is in, has already been in, or has
     153      /// \brief Returns if an item is in, has already been in, or has
    151154      /// never been in the heap.
    152155      ///
    153       /// This method returns PRE_HEAP if \c item has never been in the
    154       /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
    155       /// otherwise. In the latter case it is possible that \c item will
    156       /// get back to the heap again.
     156      /// This method returns \c PRE_HEAP if the given item has never
     157      /// been in the heap, \c IN_HEAP if it is in the heap at the moment,
     158      /// and \c POST_HEAP otherwise.
     159      /// In the latter case it is possible that the item will get back
     160      /// to the heap again.
    157161      /// \param i The item.
    158162      State state(const Item &i) const {}
    159163
    160       /// \brief Sets the state of the \c item in the heap.
    161       ///
    162       /// Sets the state of the \c item in the heap. It can be used to
    163       /// manually clear the heap when it is important to achive the
     164      /// \brief Sets the state of an item in the heap.
     165      ///
     166      /// Sets the state of the given item in the heap. It can be used
     167      /// to manually clear the heap when it is important to achive the
    164168      /// better time complexity.
    165169      /// \param i The item.
    166       /// \param st The state. It should not be \c IN_HEAP. 
     170      /// \param st The state. It should not be \c IN_HEAP.
    167171      void state(const Item& i, State st) {}
    168172
     
    171175      struct Constraints {
    172176      public:
    173    
    174177        void constraints() {
     178          typedef typename _Heap::Item OwnItem;
     179          typedef typename _Heap::Prio OwnPrio;
     180          typedef typename _Heap::State OwnState;
     181
    175182          Item item;
    176183          Prio prio;
    177 
     184          State state;
    178185          item=Item();
    179186          prio=Prio();
    180 
    181187          ignore_unused_variable_warning(item);
    182188          ignore_unused_variable_warning(prio);
    183 
    184           typedef typename _Heap::State State;
    185           State state;
    186 
    187189          ignore_unused_variable_warning(state);
    188      
    189           _Heap heap1 = _Heap(map);
    190 
     190
     191          OwnItem own_item;
     192          OwnPrio own_prio;
     193          OwnState own_state;
     194          own_item=Item();
     195          own_prio=Prio();
     196          ignore_unused_variable_warning(own_item);
     197          ignore_unused_variable_warning(own_prio);
     198          ignore_unused_variable_warning(own_state);
     199
     200          _Heap heap1(map);
     201          _Heap heap2 = heap1;
    191202          ignore_unused_variable_warning(heap1);
    192      
    193           heap.push(item, prio);
     203          ignore_unused_variable_warning(heap2);
     204         
     205          int s = heap.size();
     206          bool e = heap.empty();
    194207
    195208          prio = heap.prio();
    196209          item = heap.top();
    197 
     210          prio = heap[item];
     211          own_prio = heap.prio();
     212          own_item = heap.top();
     213          own_prio = heap[own_item];
     214
     215          heap.push(item, prio);
     216          heap.push(own_item, own_prio);
    198217          heap.pop();
    199218
     
    201220          heap.decrease(item, prio);
    202221          heap.increase(item, prio);
    203           prio = heap[item];
     222          heap.set(own_item, own_prio);
     223          heap.decrease(own_item, own_prio);
     224          heap.increase(own_item, own_prio);
    204225
    205226          heap.erase(item);
     227          heap.erase(own_item);
     228          heap.clear();
    206229
    207230          state = heap.state(item);
     231          heap.state(item, state);
     232          state = heap.state(own_item);
     233          heap.state(own_item, own_state);
    208234
    209235          state = _Heap::PRE_HEAP;
    210236          state = _Heap::IN_HEAP;
    211237          state = _Heap::POST_HEAP;
    212 
    213           heap.clear();
     238          own_state = _Heap::PRE_HEAP;
     239          own_state = _Heap::IN_HEAP;
     240          own_state = _Heap::POST_HEAP;
    214241        }
    215    
     242
    216243        _Heap& heap;
    217244        ItemIntMap& map;
    218 
    219         Constraints() : heap(0), map(0) {}
    220245      };
    221246    };
  • lemon/concepts/maps.h

    r94 r114  
    2525///\ingroup concept
    2626///\file
    27 ///\brief Map concepts checking classes for testing and documenting.
     27///\brief The concept of maps.
    2828
    2929namespace lemon {
     
    106106        const Value& val;
    107107        const typename _WriteMap::Key& own_key;
    108         const typename _WriteMap::Value own_val;
     108        const typename _WriteMap::Value& own_val;
    109109        _WriteMap& m;
    110110      };
  • lemon/random.h

    r110 r116  
    796796          }
    797797      } while(nu>std::pow(xi,delta-1.0)*std::exp(-xi));
    798       return theta*(xi-gamma(int(std::floor(k))));
     798      return theta*(xi+gamma(int(std::floor(k))));
    799799    }
    800800   
     
    820820    double pareto(double k,double x_min)
    821821    {
    822       return exponential(gamma(k,1.0/x_min));
     822      return exponential(gamma(k,1.0/x_min))+x_min;
    823823    } 
    824824     
  • test/error_test.cc

    r108 r118  
    4040}
    4141
    42 void no_assertion_exception_disable() {
    43   LEMON_ASSERT(true, Exception());
    44 }
    45 
    4642void assertion_text_disable() {
    4743  LEMON_ASSERT(false, "This is a fault message");
    48 }
    49 
    50 void assertion_exception_disable() {
    51   LEMON_ASSERT(false, Exception());
    5244}
    5345
     
    5850void check_assertion_disable() {
    5951  no_assertion_text_disable();
    60   no_assertion_exception_disable();
    61   assertion_exception_disable();
    6252  assertion_text_disable();
    6353  fixme_disable();
    6454}
    6555#undef LEMON_DISABLE_ASSERTS
    66 
    67 
    68 #define LEMON_ASSERT_ERROR
    69 #include <lemon/assert.h>
    70 
    71 void no_assertion_text_error() {
    72   LEMON_ASSERT(true, "This is a fault message");
    73 }
    74 
    75 void no_assertion_exception_error() {
    76   LEMON_ASSERT(true, Exception());
    77 }
    78 
    79 void assertion_text_error() {
    80   LEMON_ASSERT(false, "This is a fault message");
    81 }
    82 
    83 void assertion_exception_error() {
    84   LEMON_ASSERT(false, Exception());
    85 }
    86 
    87 void fixme_error() {
    88   LEMON_FIXME("fixme_error() is fixme!");
    89 }
    90 
    91 void check_assertion_error() {
    92   no_assertion_text_error();
    93   no_assertion_exception_error();
    94   try {
    95     assertion_exception_error();
    96     check(false, "Assertion error");
    97   } catch (const AssertionFailedError& e) {
    98   }
    99 
    100   try {
    101     assertion_text_error();
    102     check(false, "Assertion error");
    103   } catch (const AssertionFailedError& e) {
    104   }
    105 
    106   try {
    107     fixme_error();
    108     check(false, "Assertion error");
    109   } catch (const AssertionFailedError& e) {
    110   }
    111 }
    112 #undef LEMON_ASSERT_ERROR
    113 
    114 #define LEMON_ASSERT_EXCEPTION
    115 #include <lemon/assert.h>
    116 
    117 void no_assertion_text_exception() {
    118   LEMON_ASSERT(true, "This is a fault message");
    119 }
    120 
    121 void no_assertion_exception_exception() {
    122   LEMON_ASSERT(true, Exception());
    123 }
    124 
    125 void assertion_text_exception() {
    126   LEMON_ASSERT(false, "This is a fault message");
    127 }
    128 
    129 void assertion_exception_exception() {
    130   LEMON_ASSERT(false, Exception());
    131 }
    132 
    133 void fixme_exception() {
    134   LEMON_FIXME("fixme_exception() is fixme!");
    135 }
    136 
    137 void check_assertion_exception() {
    138   no_assertion_text_exception();
    139   no_assertion_exception_exception();
    140   try {
    141     assertion_exception_exception();
    142     check(false, "Assertion error");
    143   } catch (const Exception& e) {
    144   }
    145 
    146   try {
    147     assertion_text_exception();
    148     check(false, "Assertion error");
    149   } catch (const AssertionFailedError& e) {
    150   }
    151 
    152   try {
    153     assertion_text_exception();
    154     check(false, "Assertion error");
    155   } catch (const AssertionFailedError& e) {
    156   }
    157 
    158   try {
    159     fixme_exception();
    160     check(false, "Assertion error");
    161   } catch (const AssertionFailedError& e) {
    162   }
    163 }
    164 #undef LEMON_ASSERT_EXCEPTION
    165 
    166 #define LEMON_ASSERT_LOG
    167 
    168 #include <lemon/assert.h>
    169 
    170 void no_assertion_text_log() {
    171   LEMON_ASSERT(true, "This is a fault message");
    172 }
    173 
    174 void no_assertion_exception_log() {
    175   LEMON_ASSERT(true, Exception());
    176 }
    177 
    178 void assertion_text_log() {
    179   LEMON_ASSERT(false, "This is a fault message");
    180 }
    181 
    182 void assertion_exception_log() {
    183   LEMON_ASSERT(false, Exception());
    184 }
    185 
    186 void fixme_log() {
    187   LEMON_FIXME("fixme_log() is fixme!");
    188 }
    189 
    190 void check_assertion_log() {
    191   no_assertion_text_log();
    192   no_assertion_exception_log();
    193   std::cerr << "The next 3 failure messages are expected: " << std::endl;
    194   assertion_exception_log();
    195   assertion_text_log();
    196   fixme_log();
    197   std::cerr << "End of expected error messages" << std::endl;
    198 }
    199 #undef LEMON_ASSERT_LOG
    20056
    20157#define LEMON_ASSERT_CUSTOM
     
    20763}
    20864
    209 void my_assert_handler(const char*, int, const char*,
    210                        const std::exception&, const char*) {
    211   ++cnt;
    212 }
    213 
    214 void my_assert_handler(const char*, int, const char*,
    215                        const std::string&, const char*) {
    216   ++cnt;
    217 }
    218 
    219 
    22065#define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler
    22166#include <lemon/assert.h>
     
    22570}
    22671
    227 void no_assertion_exception_custom() {
    228   LEMON_ASSERT(true, Exception());
    229 }
    230 
    23172void assertion_text_custom() {
    23273  LEMON_ASSERT(false, "This is a fault message");
    233 }
    234 
    235 void assertion_exception_custom() {
    236   LEMON_ASSERT(false, Exception());
    23774}
    23875
     
    24380void check_assertion_custom() {
    24481  no_assertion_text_custom();
    245   no_assertion_exception_custom();
    246   assertion_exception_custom();
    24782  assertion_text_custom();
    24883  fixme_custom();
    249   check(cnt == 3, "The custom assert handler does not work");
     84  check(cnt == 2, "The custom assert handler does not work");
    25085}
    25186
     
    25590int main() {
    25691  check_assertion_disable();
    257   check_assertion_error();
    258   check_assertion_exception();
    259   check_assertion_log();
    26092  check_assertion_custom();
    26193
Note: See TracChangeset for help on using the changeset viewer.