Input file for coloring.
2 * lemon/concept/heap.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
19 ///\brief Classes for representing heaps.
22 #ifndef LEMON_CONCEPT_HEAP_H
23 #define LEMON_CONCEPT_HEAP_H
25 #include <lemon/invalid.h>
29 /// \addtogroup concept
33 /// \brief A concept structure describes the main interface of heaps.
35 /// A concept structure describes the main interface of heaps.
37 template <typename Item, typename Prio, typename ItemIntMap>
42 /// \brief Type to represent the items states.
44 /// Each Item element have a state associated to it. It may be "in heap",
45 /// "pre heap" or "post heap". The later two are indifferent from the
46 /// heap's point of view, but may be useful to the user.
48 /// The ItemIntMap _should_ be initialized in such way, that it maps
49 /// PRE_HEAP (-1) to any element to be put in the heap...
56 /// \brief The constructor.
59 /// \param _iim should be given to the constructor, since it is used
60 /// internally to handle the cross references. The value of the map
61 /// should be PRE_HEAP (-1) for each element.
62 explicit Heap(ItemIntMap &_iim) {}
64 /// The number of items stored in the heap.
66 /// \brief Returns the number of items stored in the heap.
67 int size() const { return 0; }
68 /// \brief Checks if the heap stores no items.
70 /// Returns \c true if and only if the heap stores no items.
71 bool empty() const { return false; }
73 /// \brief Insert an item into the heap with the given heap.
75 /// Adds \c i to the heap with priority \c p.
76 /// \param i The item to insert.
77 /// \param p The priority of the item.
78 void push(const Item &i, const Prio &p) {}
80 /// \brief Returns the item with minimum priority.
82 /// This method returns the item with minimum priority.
83 /// \pre The heap must be nonempty.
86 /// \brief Returns the minimum priority.
88 /// It returns the minimum priority.
89 /// \pre The heap must be nonempty.
92 /// \brief Deletes the item with minimum priority.
94 /// This method deletes the item with minimum priority.
95 /// \pre The heap must be non-empty.
98 /// \brief Deletes \c i from the heap.
100 /// This method deletes item \c i from the heap, if \c i was
101 /// already stored in the heap.
102 /// \param i The item to erase.
103 void erase(const Item &i) {}
105 /// \brief Returns the priority of \c i.
107 /// This function returns the priority of item \c i.
108 /// \pre \c i must be in the heap.
109 /// \param i The item.
110 Prio operator[](const Item &i) const {}
112 /// \brief \c i gets to the heap with priority \c p independently
113 /// if \c i was already there.
115 /// This method calls \ref push(\c i, \c p) if \c i is not stored
116 /// in the heap and sets the priority of \c i to \c p otherwise.
117 /// It may throw an \e UnderFlowPriorityException.
118 /// \param i The item.
119 /// \param p The priority.
120 void set(const Item &i, const Prio &p) {}
122 /// \brief Decreases the priority of \c i to \c p.
124 /// This method decreases the priority of item \c i to \c p.
125 /// \pre \c i must be stored in the heap with priority at least \c p.
126 /// \param i The item.
127 /// \param p The priority.
128 void decrease(const Item &i, const Prio &p) {}
130 /// \brief Increases the priority of \c i to \c p.
132 /// This method sets the priority of item \c i to \c p.
133 /// \pre \c i must be stored in the heap with priority at most \c
134 /// p relative to \c Compare.
135 /// \param i The item.
136 /// \param p The priority.
137 void increase(const Item &i, const Prio &p) {}
139 /// \brief Returns if \c item is in, has already been in, or has
140 /// never been in the heap.
142 /// This method returns PRE_HEAP if \c item has never been in the
143 /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
144 /// otherwise. In the latter case it is possible that \c item will
145 /// get back to the heap again.
146 /// \param i The item.
147 state_enum state(const Item &i) const {}
150 template <typename _Heap>
161 ignore_unused_variable_warning(item);
162 ignore_unused_variable_warning(prio);
164 typedef typename _Heap::state_enum state_enum;
167 ignore_unused_variable_warning(state);
169 _Heap heap1 = _Heap(map);
171 ignore_unused_variable_warning(heap1);
173 heap.push(item, prio);
180 heap.set(item, prio);
181 heap.decrease(item, prio);
182 heap.increase(item, prio);
187 state = heap.state(item);
189 state = _Heap::PRE_HEAP;
190 state = _Heap::IN_HEAP;
191 state = _Heap::POST_HEAP;
197 Constraints() : heap(0), map(0) {}
204 #endif // LEMON_CONCEPT_PATH_H