-
Notifications
You must be signed in to change notification settings - Fork 0
/
NonDominatedSet.h
258 lines (223 loc) · 8.39 KB
/
NonDominatedSet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*! \file NonDominatedSet.h
* \brief The definition of the NonDominatedSet<T> class template.
* \author Christos Nitsas
* \date 2012
*/
#ifndef NON_DOMINATED_SET_H
#define NON_DOMINATED_SET_H
#include <set>
#include "Point.h"
#include "PointAndSolution.h"
/*!
* \weakgroup ParetoApproximator Everything needed for the Pareto set approximation algorithms.
* @{
*/
//! The namespace containing everything needed for the Pareto set approximation algorithms.
namespace pareto_approximator {
//! A container that only keeps non-dominated points. (plus solutions)
/*!
* The NonDominatedSet<T> is a type of container/filter. It stores unique
* T instances. T must represent some kind of a point. It must have at
* least the following methods:
* - bool dominates(const T & s, double eps):
* Returns true if the current instance eps-covers s; false otherwise.
* We say that a point p \f$ \epsilon \f$-covers another point q
* (\f$\epsilon \ge 0 \f$) iff \f$ p_{i} \le (1 + \epsilon) q_{i} \f$,
* for all i. Both p and q must be of the same dimension.
* (see Point or PointAndSolution for more info and examples)
* - bool operator==(const T & s):
* Returns true if the current instance is equal to s; false otherwise.
* - bool operator<(const T & s):
* Returns true if the current instance is less-than s; false otherwise.
* (only needed for the sort method)
*
* The key difference from a std::set<T> container is the fact that
* NonDominatedSet<T> acts as a filter that only keeps those T instances
* that form a Pareto frontier - that is, a frontier of Pareto-efficient
* points (points not dominated by each other or by any point we have
* inserted so far).
*
* Another difference is that we have not exposed all methods of the
* std::set that lies underneath. The NonDominatedSet class is meant for
* a very specific purpose and not as a general container. However, if
* some new functionality is required it shouldn't be hard to add new
* methods that delegate to the underlying set's methods.
*
* \sa PointAndSolution
*/
template <class T>
class NonDominatedSet
{
public:
//! Bidirectional iterator to the set's contents.
typedef typename std::set<T>::iterator iterator;
//! Constant bidirectional iterator to the set's contents.
typedef typename std::set<T>::const_iterator const_iterator;
//! Unsigned integral type (usually same as size_t).
typedef typename std::set<T>::size_type size_type;
//! Default constructor. Makes an empty set.
NonDominatedSet();
//! Iteration constructor.
/*!
* \param first Input iterator to the initial position in a sequence
* of T instances.
* \param last Input iterator to the past-the-end position in a
* sequence of T instances.
*
* Reminder: T instances represent some kind of point. (e.g. the Point
* or PointAndSolution<T> classes)
*
* Iterates between first and last, filtering and inserting the
* elements of the sequence into the container object. The range used
* is [first, last), which includes all the elements between first and
* last, including the element pointed by first but not the element
* pointed by last.
*
* Elements will be filtered during the insertion process so that
* only non-dominated T instances are kept.
*
* The function template type can be any type of input iterator
* that points to T instances.
*
* \sa NonDominatedSet
*/
template <class InputIterator>
NonDominatedSet(InputIterator first, InputIterator last);
//! Destructor. (all the contained elements' destructors will be called)
~NonDominatedSet();
//! Return iterator to beginning.
/*!
* \return An iterator referring to the first T element in the
* container.
*
* \sa NonDominatedSet
*/
iterator begin();
//! Return const_iterator to beginning.
/*!
* \return A const_iterator referring to the first T element in the
* container.
*
* \sa NonDominatedSet
*/
const_iterator begin() const;
//! Return iterator to end.
/*!
* \return An iterator pointing to the past-the-end T element in the
* container.
*
* \sa NonDominatedSet
*/
iterator end();
//! Return const_iterator to end.
/*!
* \return A const_iterator pointing to the past-the-end T element
* in the container.
*
* \sa NonDominatedSet
*/
const_iterator end() const;
//! Test whether container is empty.
/*!
* \return true if the container is empty; false otherwise.
*
* \sa NonDominatedSet
*/
bool empty() const;
//! Returns the number of elements in the container.
/*!
* \return The number of elements that form the set's content.
*
* Member type size_type is (usually) an unsigned integral type.
*
* \sa NonDominatedSet
*/
size_type size() const;
//! Insert element.
/*!
* \param t The T instance to insert.
* \return true if the element was actually inserted (was not
* dominated); false otherwise.
*
* Reminder: T instances represent some kind of point. (e.g. the Point
* or PointAndSolution<T> classes)
*
* The container is extended by inserting a single new element iff the
* new element is not already dominated.
*
* The element will be inserted if and only if it is not dominated by
* any other element in the set. Any elements dominated by the newly
* inserted element will be deleted.
*
* \sa NonDominatedSet
*/
bool insert(const T & t);
//! Insert elements.
/*!
* \param first Input iterator to the initial position in a sequence
* of T instances.
* \param last Input iterator to the past-the-end position in a
* sequence of T instances.
* \return true if at least one element was actually inserted (not
* dominated); false otherwise.
*
* Reminder: T instances represent some kind of point. (e.g. the Point
* or PointAndSolution<T> classes)
*
* Iterates between first and last, filtering and inserting the
* elements of the sequence into the container object. The range used
* is [first, last), which includes all the elements between first and
* last, including the element pointed by first but not the element
* pointed by last.
*
* Elements will be filtered during the insertion process so that
* only non-dominated T instances are kept.
*
* The function template type can be any type of input iterator
* that points to T instances.
*
* \sa NonDominatedSet
*/
template <class InputIterator>
bool insert(InputIterator first, InputIterator last);
//! Check if some element in the set dominates the given instance.
/*!
* \param t A T instance.
* \return true if some element in the set dominates t; false otherwise.
*
* For every element (T instance) in the set, check if it dominates t.
* Return true if some does; false otherwise.
*
* \sa NonDominatedSet
*/
bool dominates(const T & t) const;
//! Clear content.
/*!
* All the elements' destructors are called and then they are removed
* from the container, leaving it with a size of 0.
*
* \sa NonDominatedSet
*/
void clear();
//! Get iterator to element.
/*!
* \param t A T instance.
* \return An iterator to the T element which is equal to t if one
* exists; an iterator to the past-the-end element otherwise.
*
* Searches the container for a T instance that is equal to the given
* instance (t) and returns an iterator to it if it exists, otherwise
* it returns an iterator to NonDominatedSet::end().
*
* \sa NonDominatedSet and NonDominatedSet::end()
*/
iterator find(const T & t) const;
private:
std::set<T> contents_;
};
} // namespace pareto_approximator
/* @} */
// We've got to #include the implementation here because we are describing
// a class template, not a simple class.
#include "NonDominatedSet.cpp"
#endif // NON_DOMINATED_SET_H