FRAMES NO FRAMES

Class IlcFloatVar

Definition file: ilsolver/fltexp.h
Include file: <ilsolver/ilosolver.h>

The class IlcFloatVar is a subclass of IlcFloatExp. A constrained floating-point variable (an instance of IlcFloatVar) is a constrained floating-point expression that stores its domain (instead of computing the domain from the domains of its subexpressions). The domain of a constrained floating-point variable contains values of type IlcFloat.

Most member functions in this class contain assert statements. For an explanation of the macro NDEBUG (a way to turn on or turn off these assert statements), see the concept Assert and NDEBUG.

Continuous and Discrete Enumerated Floating-Point Variables

Solver offers two different kinds of constrained floating-point variables: continuous and discrete or enumerated. Both kinds of variables assume values of type IlcFloat. They differ in the way their domains are represented, however.

A continuous floating-point variable is any instance of IlcFloatExp or IlcFloatVar not created by IlcFloatVar For continuous floating-point variables, the number of elements in the domain is very high (typically millions). Consequently, Solver associates an interval with the variable to represent its domain. Because it is not practical to count the elements in the domain of a continuous floating-point variable, there are no iterators for traversing the domain of continuous floating-point variables.

For users of Solver prior to version 5, these continuous variables defined on intervals were the only constrained floating-point variables available. Continuous floating-point variables are still available in Solver version 5; in addition, there are now also discrete or enumerated floating-point variables.

In contrast to continuous floating-point variables, discrete floating-point variables can be enumerated. That is, their domain can be counted explicitly. Consequently, Solver associates an enumerated set with the variable to represent its domain. To create a discrete floating-point variable, use the constructor

IlcFloatVar

With that constructor, you explicitly enumerate the values that the discrete variable may assume. This constructor offers the only way to create a discrete floating-point variable with an enumerated domain.

Failure

If the boundaries of the domain are identical and equal to minus infinity or plus infinity, then failure is triggered since no finite solution is then possible. That situation can happen with the following declaration, for example:

 IloSolver s;
 IlcFloatVar x(s,0,10);
 IlcFloatVar y=IlcLog(x);
 s.add( x == 0);

Those lines cause failure since the minimal and maximal boundaries of y are equal to minus infinity.

Domain-Delta And Propagation

When a propagation event is triggered for a constrained variable, the variable is pushed into the propagation queue if it was not already in the queue. Moreover, the modifications of the domain of the constrained variable are stored in a special set called the domain-delta. This domain-delta can be accessed during the propagation of the constraints posted on that variable. When all the constraints posted on that variable have been processed, then the domain-delta is cleared. If the variable is modified again, then the whole process begins again. The state of the domain-delta is reversible.

For discrete floating-point variables (that is, instances of IlcFloatVar created by the constructor IlcFloatVar) to traverse their domain-delta, Solver offers iterators of the class IlcFloatVarDeltaIterator.

Backtracking and Reversibility

All the member functions and operators defined for this class and capable of modifying constrained variables are reversible. In particular, the changes made by constraint-posting functions are made with reversible assignments. Thus, the value, the domain, and the constraints posted on any constrained variable are restored when Solver backtracks.

See Also:

Constructor Summary
public IlcFloatVar()
public IlcFloatVar(IloSolver solver, IlcFloat min, IlcFloat max, const char * name=0)
public IlcFloatVar(IloSolver solver, IlcFloat min, IlcFloat max, IlcFloat precision, const char * name=0)
public IlcFloatVar(IloSolver solver, const IlcFloatArray array, const char * name=0)
public IlcFloatVar(IlcFloatVarI * impl)
public IlcFloatVar(IlcIntVar var)
public IlcFloatVar(const IlcFloatExp exp)
Method Summary
public IlcFloatgetMax() const
public IlcFloatgetMaxDelta() const
public IlcFloatgetMin() const
public IlcFloatgetMinDelta() const
public IlcFloatgetOldMax() const
public IlcFloatgetOldMin() const
public IlcBoolisInDelta(IlcFloat value) const
public IlcBoolisInProcess() const
public voidoperator=(const IlcFloatVar & exp)
public voidoperator=(const IlcFloatExp & exp)
Inherited Methods from IlcFloatExp
display, getCopy, getImpl, getMax, getMin, getName, getNextHigher, getNextLower, getObject, getPrecision, getSize, getSolver, getSolverI, isBound, isInDomain, operator=, removeDomain, removeDomain, removeRange, removeValue, setDomain, setDomain, setDomain, setMax, setMin, setName, setObject, setPrecision, setRange, whenDomain, whenRange, whenValue
Constructor Detail

IlcFloatVar

public IlcFloatVar()

This constructor creates a constrained floating-point variable which is empty, that is, whose handle pointer is null. This object must then be assigned before it can be used, exactly as when you, as a developer, declare a pointer. To check whether a floating-point variable is empty, use the member function IlcFloatExp::getImpl.


IlcFloatVar

public IlcFloatVar(IloSolver solver, IlcFloat min, IlcFloat max, const char * name=0)

This constructor creates a continuous constrained floating-point variable with a domain containing all the floating-point values between min and max, inclusive. If min is greater than max, the function IlcFail is called. The optional argument name, if provided, becomes the name of the constrained floating-point variable. The precision associated with the constrained floating-point variable will be the default precision of Solver.


IlcFloatVar

public IlcFloatVar(IloSolver solver, IlcFloat min, IlcFloat max, IlcFloat precision, const char * name=0)

This constructor creates a continuous constrained floating-point variable with a domain containing all the floating-point values between min and max, inclusive. If min is greater than max, the function IlcFail is called. The argument precision becomes the precision associated with the constrained floating-point variable. If the optional argument name is provided, it becomes the name of the constrained floating-point variable.

For example, here's how to create a constrained floating-point variable with a minimum of 0, a maximum of 10, and a name.

 IlcFloatVar x (s, 0, 10, "x");

Here's how to create a constrained floating-point variable with an associated precision of 10-4.

 IlcFloatVar x (s, 0, 100, 1e-4);

You can specify both the name and the precision at the same time, like this:

 IlcFloatVar x (s, -100, 100, 1e-4, "x");

IlcFloatVar

public IlcFloatVar(IloSolver solver, const IlcFloatArray array, const char * name=0)

This constructor creates a discrete constrained floating-point variable. Its domain is enumerated by the array array.


IlcFloatVar

public IlcFloatVar(IlcFloatVarI * impl)

This constructor creates a handle object (an instance of the class IlcFloatVar from a pointer to an object (an instance of the class IlcFloatVarI.


IlcFloatVar

public IlcFloatVar(IlcIntVar var)

This constructor creates an instance of the class IlcFloatVar. This instance is constrained to be equal to the argument var.


IlcFloatVar

public IlcFloatVar(const IlcFloatExp exp)

This constructor associates a domain with the continuous constrained floating-point expression exp. Moreover, the newly created floating-point variable points to the same implementation object as exp. In other words, this constructor transforms a constrained floating-point expression (which computes its domain from its subexpressions) into a constrained floating-point variable (which stores its domain).


Method Detail

getMax

public IlcFloat getMax() const

This member function returns the maximum of the domain of the invoking object.


getMaxDelta

public IlcFloat getMaxDelta() const

This member function returns the difference between the maximum of the domain of the invoking constrained variable and the maximum of its domain-delta. This member function can be applied only to the variable currently in process.


getMin

public IlcFloat getMin() const

This member function returns the minimum of the domain of the invoking object.


getMinDelta

public IlcFloat getMinDelta() const

This member function returns the difference between the minimum of the domain of the invoking constrained variable and the minimum of its domain-delta. This member function can be applied only to the variable currently in process.

For example, to know whether the minimum of a constrained floating-point variable x has been modified since the last time the constraints posted on x were processed, it is sufficient to test the value of x.getMinDelta(). If that test returns 0, then the minimum of x has not been modified.


getOldMax

public IlcFloat getOldMax() const

This member function returns the maximum of the domain-delta of the invoking constrained variable. This member function can be applied only to the variable currently in process.


getOldMin

public IlcFloat getOldMin() const

This member function returns the minimum of the domain-delta of the invoking constrained variable. This member function can be applied only to the variable currently in process.


isInDelta

public IlcBool isInDelta(IlcFloat value) const

This member function returns IlcTrue if the argument value belongs to the domain-delta of the invoking constrained variable. This member function can be applied only to the variable currently in process.


isInProcess

public IlcBool isInProcess() const

This member function returns IlcTrue if the invoking constrained variable is currently being processed by the constraint propagation algorithm. Only one variable can be in process at a time.


operator=

public void operator=(const IlcFloatVar & exp)

This operator assigns an address to the handle pointer of the invoking object. That address is the location of the implementation object of the argument exp. After the execution of this operator, the invoking object and the exp object both point to the same implementation object. This assignment operator has no effect on its argument.


operator=

public void operator=(const IlcFloatExp & exp)

This operator assigns an address to the handle pointer of the invoking object. That address is the location of the implementation object of the argument exp. After the execution of this operator, the invoking object and exp both point to the same implementation object. Moreover, this assignment operator associates a domain with the constrained floating-point expression exp, which is thus transformed into a constrained floating-point variable.