41 #ifndef BPP_NUMERIC_CONSTRAINTS_H
42 #define BPP_NUMERIC_CONSTRAINTS_H
52 #include "../Clonable.h"
53 #include "../Text/TextTools.h"
54 #include "../Exceptions.h"
88 virtual bool includes(
double min,
double max)
const = 0;
96 virtual double getLimit(
double value)
const = 0;
294 size_t pdp = desc.find(
";");
295 size_t dc = desc.find_first_of(
"[]", 1);
297 if (dc == std::string::npos || pdp == std::string::npos ||
298 (desc[0] !=
']' && desc[0] !=
'[') || (pdp >= dc))
299 throw Exception(
"Constraints::readDescription. Wrong description:" + desc);
301 std::string deb = desc.substr(1, pdp - 1);
302 std::string fin = desc.substr(pdp + 1, dc - pdp - 1);
320 double lowerBound, upperBound;
321 bool inclLowerBound, inclUpperBound;
381 catch (std::bad_cast&) {}
The Clonable interface (allow an object to be cloned).
The constraint interface.
virtual double getLimit(double value) const =0
Give the nearest limit for a bad value.
virtual std::string getDescription() const =0
Give a short description on the type of constraint.
virtual double getAcceptedLimit(double value) const =0
Give the nearest accepted limit for a bad value.
virtual bool isCorrect(double value) const =0
Tell if a given value is correct.
virtual bool includes(double min, double max) const =0
Tell if all the values in a given interval are correct.
virtual bool isEmpty() const =0
Tells if this constraints defines an empty set.
Constraint * clone() const =0
Create a copy of this object and send a pointer to it.
virtual Constraint * operator&(const Constraint &c) const =0
Intersect this Constraint with another one.
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
An interval, either bounded or not, which can also have infinite bounds.
std::string getDescription() const
Give a short description on the type of constraint.
bool operator<=(double value) const
bool operator!=(const IntervalConstraint &i) const
Tells if this interval is different from another one.
virtual bool isCorrect(double value) const
Tell if a given value is correct.
IntervalConstraint(std::string &desc)
Create an interval from a string description, using readDescription method.
double precision_
the accepted precision on the boundary (default: 1e-12)
bool isEmpty() const
Tells if this interval is empty.
double getAcceptedLimit(double value) const
Give the nearest accepted limit for a bad value.
IntervalConstraint(double lowerBound, double upperBound, bool inclLower, bool inclUpper, double precision=NumConstants::TINY())
bool includes(double min, double max) const
Tell if all the values in a given interval are correct.
double getLowerBound() const
bool strictLowerBound() const
virtual ~IntervalConstraint()
void setLowerBound(double lowerBound, bool strict)
double getLimit(double value) const
Give the nearest limit for a bad value.
bool operator<=(const IntervalConstraint &i) const
Tells if this interval is included or equal in another one.
bool inclLowerBound_
Boolean flags are true if the boundaries are included.
Constraint * operator&(const Constraint &c) const
Intersect this IntervalConstraint with another one.
bool operator<(double value) const
IntervalConstraint(bool isPositive, double bound, bool incl, double precision=NumConstants::TINY())
Create an interval with an infinite lower/upper bound.
bool operator==(const IntervalConstraint &i) const
Tells if this interval equals another one.
IntervalConstraint & operator&=(const Constraint &c)
Intersect this IntervalConstraint with another constraint.
bool finiteLowerBound() const
bool strictUpperBound() const
double lowerBound_
The boundaries of the interval.
bool operator>(double value) const
bool operator>=(double value) const
bool finiteUpperBound() const
IntervalConstraint * clone() const
Create a copy of this object and send a pointer to it.
double getPrecision() const
double getUpperBound() const
void readDescription(std::string &desc)
Sets the bounds of the interval from a string.
void setUpperBound(double upperBound, bool strict)
this static class contains several useful constant values.
double toDouble(const std::string &s, char dec, char scientificNotation)
Convert from string to double.
std::string toString(T t)
General template method to convert to a string.