bpp-core  2.2.0
bpp::IntervalConstraint Class Reference

An interval, either bounded or not, which can also have infinite bounds. More...

#include <Bpp/Numeric/Constraints.h>

+ Inheritance diagram for bpp::IntervalConstraint:
+ Collaboration diagram for bpp::IntervalConstraint:

Public Member Functions

 IntervalConstraint ()
 
 IntervalConstraint (double lowerBound, double upperBound, bool inclLower, bool inclUpper, double precision=NumConstants::TINY())
 
 IntervalConstraint (bool isPositive, double bound, bool incl, double precision=NumConstants::TINY())
 Create an interval with an infinite lower/upper bound. More...
 
 IntervalConstraint (std::string &desc)
 Create an interval from a string description, using readDescription method. More...
 
virtual ~IntervalConstraint ()
 
IntervalConstraintclone () const
 Create a copy of this object and send a pointer to it. More...
 
void setLowerBound (double lowerBound, bool strict)
 
void setUpperBound (double upperBound, bool strict)
 
double getLowerBound () const
 
double getUpperBound () const
 
bool strictLowerBound () const
 
bool strictUpperBound () const
 
bool finiteLowerBound () const
 
bool finiteUpperBound () const
 
bool includes (double min, double max) const
 Tell if all the values in a given interval are correct. More...
 
virtual bool isCorrect (double value) const
 Tell if a given value is correct. More...
 
bool operator< (double value) const
 
bool operator> (double value) const
 
bool operator<= (double value) const
 
bool operator>= (double value) const
 
double getLimit (double value) const
 Give the nearest limit for a bad value. More...
 
double getAcceptedLimit (double value) const
 Give the nearest accepted limit for a bad value. More...
 
double getPrecision () const
 
std::string getDescription () const
 Give a short description on the type of constraint. More...
 
void readDescription (std::string &desc)
 Sets the bounds of the interval from a string. More...
 
Constraintoperator & (const Constraint &c) const
 Intersect this IntervalConstraint with another one. More...
 
IntervalConstraintoperator &= (const Constraint &c)
 Intersect this IntervalConstraint with another constraint. More...
 
bool operator== (const IntervalConstraint &i) const
 Tells if this interval equals another one. More...
 
bool operator!= (const IntervalConstraint &i) const
 Tells if this interval is different from another one. More...
 
bool operator<= (const IntervalConstraint &i) const
 Tells if this interval is included or equal in another one. More...
 
bool isEmpty () const
 Tells if this interval is empty. More...
 

Protected Attributes

double lowerBound_
 The boundaries of the interval. More...
 
double upperBound_
 
bool inclLowerBound_
 Boolean flags are true if the boundaries are included. More...
 
bool inclUpperBound_
 
double precision_
 the accepted precision on the boundary (default: 1e-12) More...
 

Detailed Description

An interval, either bounded or not, which can also have infinite bounds.

The upper and lower bound can be included or not (strict bound), finite or infinite (in that case, equal to a very large value). Despite the mathematical non-sense, and infinite bound can be either excluded or included.

Definition at line 135 of file Constraints.h.

Constructor & Destructor Documentation

◆ IntervalConstraint() [1/4]

bpp::IntervalConstraint::IntervalConstraint ( )
inline

Definition at line 158 of file Constraints.h.

Referenced by clone(), and operator &().

◆ IntervalConstraint() [2/4]

bpp::IntervalConstraint::IntervalConstraint ( double  lowerBound,
double  upperBound,
bool  inclLower,
bool  inclUpper,
double  precision = NumConstants::TINY() 
)
inline

Definition at line 164 of file Constraints.h.

◆ IntervalConstraint() [3/4]

bpp::IntervalConstraint::IntervalConstraint ( bool  isPositive,
double  bound,
bool  incl,
double  precision = NumConstants::TINY() 
)
inline

Create an interval with an infinite lower/upper bound.

The infinite bound will not be included, following mathematical conventions.

Parameters
isPositiveTell if the infinite bound is positive or negative.
boundThe finite bound.
inclTell if the finite bound is included or not.
precisionParameter precision.

Definition at line 182 of file Constraints.h.

◆ IntervalConstraint() [4/4]

bpp::IntervalConstraint::IntervalConstraint ( std::string &  desc)
inline

Create an interval from a string description, using readDescription method.

Definition at line 195 of file Constraints.h.

References readDescription().

◆ ~IntervalConstraint()

virtual bpp::IntervalConstraint::~IntervalConstraint ( )
inlinevirtual

Definition at line 205 of file Constraints.h.

Member Function Documentation

◆ clone()

IntervalConstraint* bpp::IntervalConstraint::clone ( ) const
inlinevirtual

Create a copy of this object and send a pointer to it.

Returns
A pointer toward the copy object.

Implements bpp::Constraint.

Definition at line 207 of file Constraints.h.

References IntervalConstraint().

Referenced by bpp::ConstantDistribution::restrictToConstraint(), bpp::TruncatedExponentialDiscreteDistribution::restrictToConstraint(), and bpp::SimpleDiscreteDistribution::restrictToConstraint().

◆ finiteLowerBound()

bool bpp::IntervalConstraint::finiteLowerBound ( ) const
inline

◆ finiteUpperBound()

bool bpp::IntervalConstraint::finiteUpperBound ( ) const
inline

◆ getAcceptedLimit()

double bpp::IntervalConstraint::getAcceptedLimit ( double  value) const
inlinevirtual

Give the nearest accepted limit for a bad value.

The difference with getLimit() is when the Constraint is open at the limit, in which case the retruned value is the limit +- 1e-12.

Parameters
valueThe bad value.
Returns
The nearer limit.

Implements bpp::Constraint.

Definition at line 260 of file Constraints.h.

References isCorrect(), lowerBound_, precision_, strictLowerBound(), strictUpperBound(), and upperBound_.

◆ getDescription()

std::string bpp::IntervalConstraint::getDescription ( ) const
inlinevirtual

Give a short description on the type of constraint.

Returns
A string which describes the constraint.

Implements bpp::Constraint.

Definition at line 273 of file Constraints.h.

References finiteLowerBound(), finiteUpperBound(), inclLowerBound_, inclUpperBound_, lowerBound_, bpp::TextTools::toString(), and upperBound_.

◆ getLimit()

double bpp::IntervalConstraint::getLimit ( double  value) const
inlinevirtual

Give the nearest limit for a bad value.

Parameters
valueThe bad value.
Returns
The nearer limit.

Implements bpp::Constraint.

Definition at line 254 of file Constraints.h.

References isCorrect(), lowerBound_, and upperBound_.

◆ getLowerBound()

◆ getPrecision()

double bpp::IntervalConstraint::getPrecision ( ) const
inline

Definition at line 268 of file Constraints.h.

References precision_.

Referenced by operator &(), and operator &=().

◆ getUpperBound()

◆ includes()

bool bpp::IntervalConstraint::includes ( double  min,
double  max 
) const
inlinevirtual

Tell if all the values in a given interval are correct.

Parameters
min,maxThe bounds of the interval.
Returns
True is the value is correct.

Implements bpp::Constraint.

Definition at line 222 of file Constraints.h.

References getLowerBound(), getUpperBound(), inclLowerBound_, and inclUpperBound_.

◆ isCorrect()

◆ isEmpty()

bool bpp::IntervalConstraint::isEmpty ( ) const
inlinevirtual

Tells if this interval is empty.

Implements bpp::Constraint.

Definition at line 425 of file Constraints.h.

References inclLowerBound_, inclUpperBound_, lowerBound_, and upperBound_.

◆ operator &()

Constraint* bpp::IntervalConstraint::operator& ( const Constraint c) const
inlinevirtual

Intersect this IntervalConstraint with another one.

Parameters
cthe intersected IntervalConstraint
Returns
the intersection, or NULL if c is not an IntervalConstraint. The resulting precision is the maximum of both precisions.

Implements bpp::Constraint.

Definition at line 318 of file Constraints.h.

References getPrecision(), inclLowerBound_, inclUpperBound_, IntervalConstraint(), lowerBound_, precision_, and upperBound_.

◆ operator &=()

IntervalConstraint& bpp::IntervalConstraint::operator&= ( const Constraint c)
inline

Intersect this IntervalConstraint with another constraint.

Parameters
cthe intersected constraint
Returns
this IntervalConstraint modified, or not modified if c is not an IntervalConstraint. The precision is set to the maximum of bith precisions.

Definition at line 361 of file Constraints.h.

References getPrecision(), inclLowerBound_, inclUpperBound_, lowerBound_, precision_, and upperBound_.

◆ operator!=()

bool bpp::IntervalConstraint::operator!= ( const IntervalConstraint i) const
inline

Tells if this interval is different from another one.

Parameters
ithe compared IntervalConstraint

Definition at line 402 of file Constraints.h.

References inclLowerBound_, inclUpperBound_, lowerBound_, and upperBound_.

◆ operator<()

bool bpp::IntervalConstraint::operator< ( double  value) const
inline

Definition at line 234 of file Constraints.h.

References inclUpperBound_, and upperBound_.

◆ operator<=() [1/2]

bool bpp::IntervalConstraint::operator<= ( double  value) const
inline

Definition at line 244 of file Constraints.h.

References upperBound_.

◆ operator<=() [2/2]

bool bpp::IntervalConstraint::operator<= ( const IntervalConstraint i) const
inline

Tells if this interval is included or equal in another one.

Parameters
ithe compared IntervalConstraint

Definition at line 415 of file Constraints.h.

References lowerBound_, and upperBound_.

◆ operator==()

bool bpp::IntervalConstraint::operator== ( const IntervalConstraint i) const
inline

Tells if this interval equals another one.

Parameters
ithe compared IntervalConstraint

Definition at line 389 of file Constraints.h.

References inclLowerBound_, inclUpperBound_, lowerBound_, and upperBound_.

◆ operator>()

bool bpp::IntervalConstraint::operator> ( double  value) const
inline

Definition at line 239 of file Constraints.h.

References inclLowerBound_, and lowerBound_.

◆ operator>=()

bool bpp::IntervalConstraint::operator>= ( double  value) const
inline

Definition at line 249 of file Constraints.h.

References lowerBound_.

◆ readDescription()

void bpp::IntervalConstraint::readDescription ( std::string &  desc)
inline

Sets the bounds of the interval from a string.

Parameters
descthe description in interval-like syntax, with signs "[", ";", "]" as well as floats and "-inf" and "inf".

Definition at line 291 of file Constraints.h.

References inclLowerBound_, inclUpperBound_, lowerBound_, bpp::NumConstants::MINF(), bpp::NumConstants::PINF(), bpp::TextTools::toDouble(), and upperBound_.

Referenced by IntervalConstraint().

◆ setLowerBound()

◆ setUpperBound()

◆ strictLowerBound()

bool bpp::IntervalConstraint::strictLowerBound ( ) const
inline

◆ strictUpperBound()

bool bpp::IntervalConstraint::strictUpperBound ( ) const
inline

Member Data Documentation

◆ inclLowerBound_

bool bpp::IntervalConstraint::inclLowerBound_
protected

Boolean flags are true if the boundaries are included.

Definition at line 148 of file Constraints.h.

Referenced by getDescription(), includes(), isCorrect(), isEmpty(), operator &(), operator &=(), operator!=(), operator==(), operator>(), readDescription(), setLowerBound(), and strictLowerBound().

◆ inclUpperBound_

bool bpp::IntervalConstraint::inclUpperBound_
protected

◆ lowerBound_

double bpp::IntervalConstraint::lowerBound_
protected

◆ precision_

double bpp::IntervalConstraint::precision_
protected

the accepted precision on the boundary (default: 1e-12)

Definition at line 154 of file Constraints.h.

Referenced by getAcceptedLimit(), getPrecision(), operator &(), and operator &=().

◆ upperBound_


The documentation for this class was generated from the following file: