NO FRAMES

Class IloSolution

Definition file: ilconcert/ilosolution.h
Instances of this class store solutions to problems.

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:

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 numeric 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 the classes IloStoreSolution and IloRestoreSolution in the ILOG Solver Reference Manual.

See Also:

Constructor Summary
public IloSolution()
public IloSolution(IloSolutionI * impl)
public IloSolution(const IloSolution & solution)
public IloSolution(IloEnv mem, const char * name=0)
Method Summary
public voidadd(IloAnySetVarArray a) const
public voidadd(IloAnySetVar var) const
public voidadd(IloAnyVarArray a) const
public voidadd(IloAnyVar var) const
public voidadd(IloNumVarArray a) const
public voidadd(IloNumVar var) const
public voidadd(IloObjective objective) const
public IloBoolcontains(IloExtractable extr) const
public voidcopy(IloExtractable extr, IloSolution solution) const
public voidcopy(IloSolution solution) const
public voidend()
public IloEnvgetEnv() const
public IloSolutionI *getImpl() const
public IloNumgetMax(IloNumVar var) const
public IloNumgetMin(IloNumVar var) const
public const char *getName() const
public IloAnygetObject() const
public IloObjectivegetObjective() const
public IloNumgetObjectiveValue() const
public IloNumVargetObjectiveVar() const
public IloAnySetgetPossibleSet(IloAnySetVar var) const
public IloAnySetgetRequiredSet(IloAnySetVar var) const
public IloAnygetValue(IloAnyVar var) const
public IloNumgetValue(IloNumVar var) const
public IloNumgetValue(IloObjective obj) const
public IloBoolisBetterThan(IloSolution solution) const
public IloBoolisBound(IloAnySetVar var) const
public IloBoolisBound(IloNumVar var) const
public IloBoolisEquivalent(IloExtractable extr, IloSolution solution) const
public IloBoolisEquivalent(IloSolution solution) const
public IloBoolisFixed(IloIntVar var) const
public IloBoolisObjectiveSet() const
public IloBoolisRestorable(IloExtractable extr) const
public IloBoolisWorseThan(IloSolution solution) const
public IloSolutionmakeClone(IloEnv env) const
public voidoperator=(const IloSolution & solution)
public voidremove(IloExtractableArray extr) const
public voidremove(IloExtractable extr) const
public voidrestore(IloExtractable extr, IloAlgorithm algorithm) const
public voidrestore(IloAlgorithm algorithm) const
public voidsetFalse(IloBoolVar var) const
public voidsetMax(IloNumVar var, IloNum max) const
public voidsetMin(IloNumVar var, IloNum min) const
public voidsetName(const char * name) const
public voidsetNonRestorable(IloExtractableArray array) const
public voidsetNonRestorable(IloExtractable extr) const
public voidsetObject(IloAny obj) const
public voidsetObjective(IloObjective objective) const
public voidsetPossibleSet(IloAnySetVar var, IloAnySet possible) const
public voidsetRequiredSet(IloAnySetVar var, IloAnySet required) const
public voidsetRestorable(IloExtractableArray array) const
public voidsetRestorable(IloExtractable ex) const
public voidsetTrue(IloBoolVar var) const
public voidsetValue(IloAnyVar var, IloAny value) const
public voidsetValue(IloNumVar var, IloNum value) const
public voidsetValue(IloObjective objective, IloNum value) const
public voidstore(IloExtractable extr, IloAlgorithm algorithm) const
public voidstore(IloAlgorithm algorithm) const
public voidunsetObjective() const
Inner Class
IloSolution::Iterator It allows you to traverse the variables in a solution.
Constructor Detail

IloSolution

public IloSolution()

This constructor creates a solution whose implementation pointer is 0 (zero). The handle must be assigned before its methods can be used.


IloSolution

public IloSolution(IloSolutionI * impl)

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).


IloSolution

public IloSolution(const IloSolution & solution)

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.


IloSolution

public IloSolution(IloEnv mem, const char * name=0)

This constructor creates an instance of the IloSolution class. The optional argument name, if supplied, becomes the name of the created object.


Method Detail

add

public void add(IloAnySetVarArray a) const

This member function adds each element of array to the invoking solution.


add

public void add(IloAnySetVar var) const

This member function adds the set variable var to the invoking solution.


add

public void add(IloAnyVarArray a) const

This member function adds each element of array to the invoking solution.


add

public void add(IloAnyVar var) const

This member function adds the variable var to the invoking solution.


add

public void add(IloNumVarArray a) const

This member function adds each element of array to the invoking solution.


add

public void add(IloNumVar var) const

This member function adds the variable var to the invoking solution.


add

public void add(IloObjective objective) const

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.


contains

public IloBool contains(IloExtractable extr) const

This member function returns IloTrue if extr is present in the invoking object. Otherwise, it returns IloFalse.


copy

public void copy(IloExtractable extr, IloSolution solution) const

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.


copy

public void copy(IloSolution solution) const

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.


end

public void end()

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.


getEnv

public IloEnv getEnv() const

This member function returns the environment specified when the invoking object was constructed.


getImpl

public IloSolutionI * getImpl() const

This member function returns a pointer to the implementation object corresponding to the invoking solution.


getMax

public IloNum getMax(IloNumVar var) const

This member function returns the maximal value of the variable var in the invoking solution.


getMin

public IloNum getMin(IloNumVar var) const

This member function returns the minimal value of the variable var in the invoking solution.


getName

public const char * getName() const

This member function returns a character string specifying the name of the invoking object (if there is one).


getObject

public IloAny getObject() const

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.


getObjective

public IloObjective getObjective() const

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.


getObjectiveValue

public IloNum getObjectiveValue() const

This member function returns the saved value of the current active objective. It can be seen as performing the action getValue(getObjective()).


getObjectiveVar

public IloNumVar getObjectiveVar() const

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.


getPossibleSet

public IloAnySet getPossibleSet(IloAnySetVar var) const

This member function returns the set of possible values for the variable var, as stored in the invoking solution.


getRequiredSet

public IloAnySet getRequiredSet(IloAnySetVar var) const

This member function returns the set of required values for the variable var, as stored in the invoking solution.


getValue

public IloAny getValue(IloAnyVar var) const

This member function returns the value of the variable var in the invoking solution.


getValue

public IloNum getValue(IloNumVar var) const

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.


getValue

public IloNum getValue(IloObjective obj) const

This member function returns the saved value of objective objective in the invoking solution.


isBetterThan

public IloBool isBetterThan(IloSolution solution) const

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.


isBound

public IloBool isBound(IloAnySetVar var) const

The method isBound has been deprecated. Consider the method isFixed instead.

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.

See Also:


isBound

public IloBool isBound(IloNumVar var) const

The method isBound has been deprecated. Consider the method isFixed instead.

This member function returns IloTrue if var takes a single value in the invoking solution. Otherwise, it returns IloFalse.

See Also:


isEquivalent

public IloBool isEquivalent(IloExtractable extr, IloSolution solution) const

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.


isEquivalent

public IloBool isEquivalent(IloSolution solution) const

This member function returns IloTrue if the invoking object and solution contain the same variables with the same saved values. Otherwise, it returns IloFalse.


isFixed

public IloBool isFixed(IloIntVar var) const

This member function returns IloTrue if var takes a single value in the invoking solution. Otherwise, it returns IloFalse.


isObjectiveSet

public IloBool isObjectiveSet() const

This member function returns IloTrue if the invoking solution has an active objective. Otherwise, it returns IloFalse.


isRestorable

public IloBool isRestorable(IloExtractable extr) const

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.


isWorseThan

public IloBool isWorseThan(IloSolution solution) const

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.


makeClone

public IloSolution makeClone(IloEnv env) const

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.


operator=

public void operator=(const IloSolution & solution)

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.


remove

public void remove(IloExtractableArray extr) const

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.


remove

public void remove(IloExtractable extr) const

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.


restore

public void restore(IloExtractable extr, IloAlgorithm algorithm) const

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.


restore

public void restore(IloAlgorithm algorithm) const

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.


setFalse

public void setFalse(IloBoolVar var) const

This member function sets the stored value of var to IloFalse in the invoking solution.


setMax

public void setMax(IloNumVar var, IloNum max) const

This member function sets the maximal value of the variable var in the invoking solution to max.


setMin

public void setMin(IloNumVar var, IloNum min) const

This member function sets the minimal value of the variable var in the invoking solution to min.


setName

public void setName(const char * name) const

This member function assigns name to the invoking object.


setNonRestorable

public void setNonRestorable(IloExtractableArray array) const

This member function specifies 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.


setNonRestorable

public void setNonRestorable(IloExtractable extr) const

This member function specifies 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.


setObject

public void setObject(IloAny obj) const

This member function associates obj with the invoking object. The member function getObject accesses this associated object afterward. Normally, obj contains user data pertinent to the invoking object.


setObjective

public void setObjective(IloObjective objective) const

This member function adds objective to the invoking solution, if it is not already present, and sets the active objective to objective.


setPossibleSet

public void setPossibleSet(IloAnySetVar var, IloAnySet possible) const

This member function sets the stored possible values for var as possible in the invoking solution.


setRequiredSet

public void setRequiredSet(IloAnySetVar var, IloAnySet required) const

This member function sets the stored required values for var as required in the invoking solution.


setRestorable

public void setRestorable(IloExtractableArray array) const

This member function specifies 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.


setRestorable

public void setRestorable(IloExtractable ex) const

This member function specifies 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 that type are never restored.


setTrue

public void setTrue(IloBoolVar var) const

This member function sets the stored value of var to IloTrue in the invoking solution.


setValue

public void setValue(IloAnyVar var, IloAny value) const

This member function sets the value of the variable var to value in the invoking solution.


setValue

public void setValue(IloNumVar var, IloNum value) const

This member function sets the value (both minimum and maximum) of the variable var to value in the invoking solution.


setValue

public void setValue(IloObjective objective, IloNum value) const

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.


store

public void store(IloExtractable extr, IloAlgorithm algorithm) const

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.


store

public void store(IloAlgorithm algorithm) const

This member function stores the values of the objects added to the solution by reference to algorithm.


unsetObjective

public void unsetObjective() const

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.