-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointAndSolution.cpp
More file actions
229 lines (192 loc) · 6.33 KB
/
PointAndSolution.cpp
File metadata and controls
229 lines (192 loc) · 6.33 KB
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
/*! \file PointAndSolution.cpp
* \brief The definition of the PointAndSolution<S> class template.
* \author Christos Nitsas
* \date 2012
*
* Won't `include` PointAndSolution.h. In fact, PointAndSolution.h
* will `include` PointAndSolution.cpp because it describes a class
* template (which doesn't allow us to split declaration from definition).
*/
/*!
* \weakgroup ParetoApproximator Everything needed for the Pareto set approximation algorithms.
* @{
*/
//! The namespace containing everything needed for the Pareto set approximation algorithms.
namespace pareto_approximator {
template <class S>
//! The empty constructor. Creates a null PointAndSolution<S> instance.
PointAndSolution<S>::PointAndSolution() : _isNull(true) { }
//! A constructor initializing all attributes except weightsUsed.
template <class S>
PointAndSolution<S>::PointAndSolution(const Point & p, const S & s) :
point(p), solution(s), _isNull(false) { }
//! A constructor initializing PointAndSolution's attributes.
/*!
* \param p A Point object.
* \param s An S object. A problem solution.
* \param first Iterator to the initial position in a std::vector<double>
* containing the weights used to obtain p and s.
* \param last Iterator to the final (past-the-end) position in a
* std::vector<double> containing the weights used to
* obtain p and s.
*/
template <class S>
PointAndSolution<S>::PointAndSolution(const Point & p, const S & s,
std::vector<double>::const_iterator first,
std::vector<double>::const_iterator last) :
point(p), solution(s), _isNull(false)
{
weightsUsed.assign(first, last);
}
//! PointAndSolution's default destructor. (empty)
template <class S>
PointAndSolution<S>::~PointAndSolution() { }
//! \brief Sets the object's "point" attribute. (also makes it non-null)
template <class S>
void
PointAndSolution<S>::setPoint(const Point & p)
{
point = p;
_isNull = false;
}
//! \brief Sets the object's attributes. (also makes it non-null)
template <class S>
void
PointAndSolution<S>::setAttributes(const Point & p, const S & s)
{
point = p;
solution = s;
_isNull = false;
}
//! Is the instance null?
/*!
* \return true if the instance is a null instance; false otherwise.
*
* \sa PointAndSolution and Point
*/
template <class S>
bool
PointAndSolution<S>::isNull() const
{
return _isNull;
}
/*!
* \brief Check if the contained Point instance is strictly positive
* (i.e. all coordinates strictly greater than zero).
*
* Possible exceptions:
* - May throw a NullObjectException exception if either this or the
* contained Point instance is null.
*
* \sa Point
*/
template <class S>
bool
PointAndSolution<S>::isStrictlyPositive() const
{
if (isNull())
throw exception_classes::NullObjectException();
return point.isStrictlyPositive();
}
//! PointAndSolution equality operator.
/*!
* \param pas A PointAndSolution instance to compare with the current
* instance.
* \return true if the point in pas is the same as the one in the
* current instance; false otherwise.
*
* Compare the points in the two PointAndSolutionInstances.
*
* \sa PointAndSolution
*/
template <class S>
bool
PointAndSolution<S>::operator== (const PointAndSolution & pas) const
{
if (isNull() and pas.isNull())
return true;
else if (isNull() or pas.isNull())
return false;
// else
return (this->point == pas.point);
}
//! The PointAndSolution less-than operator.
/*!
* Let's call L the instance on the left of the operator and R the one
* on the right. Returns true if L.point is less than R.point using
* Point::operator<().
*
* Compare the two PointAndSolution instances according to the Point
* instances they contain.
*
* Possible exceptions:
* - May throw a NullObjectException exception if either
* PointAndSolution instance (or either of the contained Point
* instances) is null.
* - May throw a DifferentDimensionsException exception if the two Points
* are of different dimensions (can't be compared).
*
* \sa PointAndSolution and Point::operator<()
*/
template <class S>
bool
PointAndSolution<S>::operator< (const PointAndSolution<S> & pas) const
{
if (isNull() or pas.isNull())
throw exception_classes::NullObjectException();
// else
return (this->point < pas.point);
}
//! Check if this instance's point eps-covers the given instance's point.
/*!
* \param pas A PointAndSolution<S> instance whose point (q) has
* \f$ q_{i} \ge 0 \f$ for all i.
* \param eps An approximation factor.
* \return true if this instance's point (p) eps-covers the given
* instance's point (q); false otherwise.
*
* This method is just a pass-through to Point::dominates().
*
* Possible exceptions:
* - May throw a NullObjectException exception if either
* PointAndSolution instance (or either of the contained Point
* instances) is null.
* - May throw a NotPositivePointException (or
* NotStrictlyPositivePointException if Point::dominates() is using the
* multiplicative error measure) exception if either p or q is not
* positive (strictly positive, respectively), i.e. some coordinate is
* less than 0.0 (less than or equal to 0.0, respectively).
* - May throw a NegativeApproximationRatioException if \f$ eps < 0 \f$.
* - May throw a DifferentDimensionsException if p and q are of
* different dimensions.
*
* \sa PointAndSolution and Point::dominates()
*/
template <class S>
bool
PointAndSolution<S>::dominates(const PointAndSolution<S> & pas,
double eps) const
{
if (isNull() or pas.isNull())
throw exception_classes::NullObjectException();
return this->point.dominates(pas.point, eps);
}
//! The dimension of the space that the contained point lives in.
/*!
* Just a shortcut for point.dimension().
*
* Possible exceptions:
* - May throw a NullObjectException exception if the instance is null.
*
* \sa PointAndSolution
*/
template <class S>
unsigned int
PointAndSolution<S>::dimension() const
{
if (isNull())
throw exception_classes::NullObjectException();
return point.dimension();
}
} // namespace pareto_approximator
/*! @} */