Overview | Group | Tree | Graph | Index | Concepts |
Instances of this class store solutions to problems. The fundamental property of
IloSolution
is its ability to transfer stored values from or to the
active objects associated with it. In particular, the member function
IloSolution::store
stores the values from algorithm variables while
the member function IloSolution::restore
instantiates the actual
variables with stored values. Variables in the solution may be selectively restored.
This class also offers member functions to copy and to compare solutions.
Information about these classes of variables can be stored in an instance of
IloSolution
:
IloAnySet:
the required and possible sets are stored; when the
variable is bound, the required and possible sets are equivalent.IloAnyVar
: the value of the variable is stored.IloBoolVar
: the value (true or false) of the variable is stored. Some
of the member functions for IloBoolVar
are covered by the member function
for IloNumVar
, as IloBoolVar
is a subclass of
IloNumVar
. For example, there is no explicit member function to add
objects of type IloBoolVar
.IloIntSetVar
: the required and possible sets are stored; when the
variable is bound, the required and possible sets are equivalent.IloNumVar
: the lower and upper bounds are stored; when the variable
is bound, the current lower and upper bound are equivalent.IloObjective
: the value of the objective is stored. Objectives are
never restored; operations such as setRestorable
cannot change this. More
than one instance of IloObjective
can be added to a solution,. In such
cases, there is the notion of an active objective, which is returned by
IloSolution::getObjective
. The active objective typically specifies the
optimization criterion for the problem to which the solution object is a solution. For
example, the ILOG Solver class IloImprove
uses the notion of an active
objective.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.
Objects of type IloSolution
have a scope, comprising the set of
variables that have their values stored in the solution. The scope is given
before the basic operations of storing and restoring are performed, via
add
and remove
methods. For example,
IloNumVar var(env); IloSolution soln(env); solution.add(var);
creates a numerical variable and a solution and adds the variable to the solution. Arrays of variables can also be added to the solution. For example,
IloNumVarArray arr(env, 10, 0, 1); soln.add(arr);
adds 10 variables with range [0...1]. When an array of variables is added to the
solution, the array object itself is not present in the scope of the solution; only
the elements are present. If the solution is then stored by means of
soln.store(algorithm)
, the values of variable var
and
arr[0]
to arr[9]
are saved. Any attempt to add a variable
that is already present in a solution throws an exception, an instance of
IloException
.
Accessors allow access to the stored values of the variables, regardless of the state (or existence) of the algorithm they were stored from. For example,
cout << "arr[3] = " << soln.getValue(arr[3]) << endl;
Any attempt to access a variable that is not present in the solution throws an
instance of IloException
.
A variable or an array of variables can be removed from a solution. For example,
soln.remove(var);
removes var
from the scope of the solution; and
soln.remove(arr);
removes arr[0]
to arr[9]
from the solution.
Any attempt to remove a variable that is not present in the solution throws an
instance of IloException
.
See Also:
IloAnySetVar, IloAnyVar, IloNumVar, IloIntSetVar, IloObjective, IloRestoreSolution documented in the ILOG Solver Reference Manual , IloStoreSolution documented in the ILOG Solver Reference Manual
Constructor Summary | |
---|---|
public | IloSolution() |
public | IloSolution(IloSolutionI *) |
public | IloSolution(const IloSolution &) |
public | IloSolution(IloEnv, const char *) |
Inner Class |
---|
IloSolution::Iterator |
Constructor Detail |
---|
This constructor creates a solution whose implementation pointer is 0 (zero). The handle must be assigned before its methods can be used.
This constructor creates a handle object (an instance of the class
IloSolution
) from a pointer to an implementation object (an instance of
the class IloSolutionI
).
This constructor creates a handle object from a reference to a solution. After
execution, both the newly constructed handle and solution
point to the
same implementation object.
This constructor creates an instance of the IloSolution
class. The
optional argument name
, if supplied, becomes the name of the created
object.
Method Detail |
---|
This member function adds each element of array
to the invoking
solution.
This member function adds the set variable var
to the invoking
solution.
This member function adds each element of array
to the invoking
solution.
This member function adds the variable var
to the invoking
solution.
This member function adds each element of array
to the invoking
solution.
This member function adds the variable var
to the invoking solution.
This member function adds objective
to the invoking solution. If the
solution has no active objective, then objective
becomes the active
objective. Otherwise, the active objective remains unchanged.
This member function returns IloTrue
if extr
is present
in the invoking object. Otherwise, it returns IloFalse
.
This member function copies the saved value of extr
from
solution
to the invoking solution. If extr
does not exist in
either solution
or the invoking object, this member function throws an
instance of IloException
. The restorable status of extr
is
not copied.
For each variable that has been added to solution
, this member
function copies its saved data to the invoking solution. If a particular extractable
does not already exist in the invoking solution, it is automatically added first. If
variables were added to the invoking solution, their restorable status is the same as
in solution
. Otherwise, their status remains unchanged in the invoking
solution.
This member function deallocates the memory used to store the solution. If you no longer need a solution, calling this member function can reduce memory consumption.
This member function returns the environment specified when the invoking object was constructed.
This member function returns a pointer to the implementation object corresponding to the invoking solution.
This member function returns the maximal value of the variable var
in
the invoking solution.
This member function returns the minimal value of the variable var
in
the invoking solution.
This member function returns a character string indicating the name of the invoking object (if there is one).
This member function returns the object associated with the invoking object (if there is one). Normally, an associated object contains user data pertinent to the invoking object.
This member function returns the active objective as set via a previous
call to IloSolution::add
or
setObjective(IloObjective)
. If there is no active objective, an empty
handle is returned.
This member function returns the saved value of the current active objective. It
can be seen as performing the action getValue(getObjective())
.
If the active objective corresponds to a simple IloNumVar
, this member
function returns that variable. If there is no active objective or if the objective is
not a simple variable, an empty handle is returned.
This member function returns the set of possible values for the variable
var
, as stored in the invoking solution.
This member function returns the set of required values for the variable
var
, as stored in the invoking solution.
This member function returns the value of the variable var
in the
invoking solution.
This member function returns the value of the variable var
in the
invoking solution. If the saved minimum and maximum of the variable are not equal,
this member function throws an instance of IloException
.
This member function returns the saved value of objective objective
in
the invoking solution.
This member function returns IloTrue
if the invoking solution and
solution
have the same objective and if the invoking solution has a
strictly higher quality objective value (according to the sense of the objective). In
all other situations, it returns IloFalse
.
This member function returns IloTrue
if the stored required and
possible sets for the set variable var
are equal in the invoking solution.
Otherwise, it returns IloFalse
.
This member function returns IloTrue
if var
takes a
single value in the invoking solution. Otherwise, it returns IloFalse
.
This member function returns IloTrue
if the saved value of
extr
is the same in the invoking solution and solution
.
Otherwise, it returns IloFalse
. If extr
does not exist in
either solution
or the invoking object, the member function throws an
instance of IloException
.
This member function returns IloTrue
if the invoking object and
solution
contain the same variables with the same saved values. Otherwise,
it returns IloFalse
.
This member function returns IloTrue
if the invoking solution has an
active objective. Otherwise, it returns IloFalse
.
This member function returns IloFalse
if
setNonRestorable(extr)
was called more recently than
setRestorable(extr)
. Otherwise, it returns IloTrue
. This
member function always returns IloFalse
when it is passed an
IloObjective
object.
This member function returns IloTrue
if the invoking solution and
solution
have the same objective and if the invoking solution has a
strictly lower quality objective value (according to the sense of the objective). In
all other situations, it returns IloFalse
.
This member function allocates a new solution on env
and adds to it
all variables that were added to the invoking object. The “restorable”
status of all variables in the clone is the same as that in the invoking solution.
Likewise, the active objective in the clone is the same as that in the invoking
solution. The newly created solution is returned.
This operator assigns an address to the handle pointer of the invoking solution.
That address is the location of the implementation object of solution
.
After the execution of this operator, the invoking solution and solution
both point to the same implementation object.
This member function removes each element of array
from the invoking
solution. If the invoking solution does not contain all elements of array
,
the member function throws an instance of IloException
.
This member function removes extractable extr
from the invoking
solution. If the invoking solution does not contain extr
, the member
function throws an instance of IloException
.
This member function restores the value of the extractable corresponding to
extr
by reference to algorithm
. The use of this member
function depends on the state of algorithm
. If algorithm
is
an instance of the ILOG Solver class IloSolver
, this member function can
only be used during search. If extr
does not exist in the invoking
solution, the member function throws an instance of IloException
.
This member function uses algorithm
to instantiate the variables in
the invoking solution with their saved values. The value of any objective added to the
solution is not restored. The use of this member function depends on the state of
algorithm
. If algorithm
is an instance of the ILOG Solver
class IloSolver
, this member function can only be used during search.
This member function sets the stored value of var
to
IloFalse
in the invoking solution.
This member function sets the maximal value of the variable var
in the
invoking solution to max
.
This member function sets the minimal value of the variable var
in the
invoking solution to min
.
This member function assigns name
to the invoking object.
This member function indicates to the invoking solution that when the solution is
restored by means of restore(IloAlgorithm)
or
restore(IloExtractable, IloAlgorithm)
, no elements of array
will be restored. When an array of variables is added to a solution, each variable is
added in a “restorable” state.
This member function indicates to the invoking solution that when the solution is
restored by means of restore(IloAlgorithm)
or
restore(IloExtractable, IloAlgorithm)
, extr
will not be
restored. When a variable is added to a solution, it is added in a
“restorable” state.
This member function associates obj
with the
invoking object. The member function getObject
accesses
this associated object afterwards. Normally, obj
contains
user data pertinent to the invoking object.
This member function adds objective
to the invoking solution, if it is
not already present, and sets the active objective to objective
.
This member function sets the stored possible values for var
as
possible
in the invoking solution.
This member function sets the stored required values for var
as
required
in the invoking solution.
This member function indicates to the invoking solution that when the solution is
restored by means of restore(IloAlgorithm)
or
restore(IloExtractable, IloAlgorithm)
, the appropriate element(s) of
array
will be restored. When an array of variables is added to a solution,
each variable is added in a “restorable” state. This call has no effect on
objects of type IloObjective
; objects of this type are never restored.
This member function indicates to the invoking solution that when the solution is
restored by means of restore(IloAlgorithm)
or
restore(IloExtractable, IloAlgorithm)
, extr
will be restored.
When a variable is added to a solution, it is added in a “restorable”
state. This call has no effect on objects of type IloObjective
; objects
of this type are never restored.
This member function sets the stored value of var
to
IloTrue
in the invoking solution.
This member function sets the value of the variable var
to
value
in the invoking solution.
This member function sets the value (both minimum and maximum) of the variable
var
to value
in the invoking solution.
This member function sets the value of objective
as stored in the
invoking solution to value
. This member function should be used with care
and only when the objective value of the solution is known exactly.
This member function stores the value of the extractable corresponding to
extr
by reference to algorithm
. If extr
does
not exist in the invoking solution, the member function throws an instance of
IloException
.
This member function stores the values of the objects added to the solution by
reference to algorithm
.
This member function asserts that there should be no active objective in the
invoking solution, although the previous active object is still present. A new active
objective can be set via IloSolution::add
or
IloSolution::setObjective
.