NO FRAMES

Class IloSolution

Definition file: ilconcert/ilosolution.h

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 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:

Constructor Summary
public IloSolution()
public IloSolution(IloSolutionI *)
public IloSolution(const IloSolution &)
public IloSolution(IloEnv, const char *)
Method Summary
public voidadd(IloAnySetVarArray)
public voidadd(IloAnySetVar)
public voidadd(IloAnyVarArray)
public voidadd(IloAnyVar)
public voidadd(IloNumVarArray)
public voidadd(IloNumVar)
public voidadd(IloObjective)
public IloBoolcontains(IloExtractable)
public voidcopy(IloExtractable, IloSolution)
public voidcopy(IloSolution)
public voidend()
public IloEnvgetEnv()
public IloSolutionI *getImpl()
public IloNumgetMax(IloNumVar)
public IloNumgetMin(IloNumVar)
public const char *getName()
public IloAnygetObject()
public IloObjectivegetObjective()
public IloNumgetObjectiveValue()
public IloNumVargetObjectiveVar()
public IloAnySetgetPossibleSet(IloAnySetVar)
public IloAnySetgetRequiredSet(IloAnySetVar)
public IloAnygetValue(IloAnyVar)
public IloNumgetValue(IloNumVar)
public IloNumgetValue(IloObjective)
public IloBoolisBetterThan(IloSolution)
public IloBoolisBound(IloAnySetVar)
public IloBoolisBound(IloNumVar)
public IloBoolisEquivalent(IloExtractable, IloSolution)
public IloBoolisEquivalent(IloSolution)
public IloBoolisObjectiveSet()
public IloBoolisRestorable(IloExtractable)
public IloBoolisWorseThan(IloSolution)
public IloSolutionmakeClone(IloEnv)
public voidoperator=(const IloSolution &)
public voidremove(IloExtractableArray)
public voidremove(IloExtractable)
public voidrestore(IloExtractable, IloAlgorithm)
public voidrestore(IloAlgorithm)
public voidsetFalse(IloBoolVar)
public voidsetMax(IloNumVar, IloNum)
public voidsetMin(IloNumVar, IloNum)
public voidsetName(const char *)
public voidsetNonRestorable(IloExtractableArray)
public voidsetNonRestorable(IloExtractable)
public voidsetObject(IloAny)
public voidsetObjective(IloObjective)
public voidsetPossibleSet(IloAnySetVar, IloAnySet)
public voidsetRequiredSet(IloAnySetVar, IloAnySet)
public voidsetRestorable(IloExtractableArray)
public voidsetRestorable(IloExtractable)
public voidsetTrue(IloBoolVar)
public voidsetValue(IloAnyVar, IloAny)
public voidsetValue(IloNumVar, IloNum)
public voidsetValue(IloObjective, IloNum)
public voidstore(IloExtractable, IloAlgorithm)
public voidstore(IloAlgorithm)
public voidunsetObjective()
Inner Class
IloSolution::Iterator
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 env, const char * name)

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)

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


add

public void add(IloAnySetVar var)

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


add

public void add(IloAnyVarArray a)

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


add

public void add(IloAnyVar var)

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


add

public void add(IloNumVarArray a)

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


add

public void add(IloNumVar var)

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


add

public void add(IloObjective objective)

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)

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)

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)

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

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


getImpl

public IloSolutionI * getImpl()

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


getMax

public IloNum getMax(IloNumVar var)

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


getMin

public IloNum getMin(IloNumVar var)

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


getName

public const char * getName()

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


getObject

public IloAny getObject()

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

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

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

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)

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)

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)

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


getValue

public IloNum getValue(IloNumVar var)

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)

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


isBetterThan

public IloBool isBetterThan(IloSolution 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.


isBound

public IloBool isBound(IloAnySetVar var)

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.


isBound

public IloBool isBound(IloNumVar var)

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


isEquivalent

public IloBool isEquivalent(IloExtractable extr, IloSolution solution)

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)

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


isObjectiveSet

public IloBool isObjectiveSet()

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


isRestorable

public IloBool isRestorable(IloExtractable extr)

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)

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)

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)

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)

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)

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)

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)

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


setMax

public void setMax(IloNumVar var, IloNum max)

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)

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


setName

public void setName(const char * name)

This member function assigns name to the invoking object.


setNonRestorable

public void setNonRestorable(IloExtractableArray array)

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.


setNonRestorable

public void setNonRestorable(IloExtractable extr)

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.


setObject

public void setObject(IloAny object)

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.


setObjective

public void setObjective(IloObjective objective)

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)

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


setRequiredSet

public void setRequiredSet(IloAnySetVar var, IloAnySet required)

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


setRestorable

public void setRestorable(IloExtractableArray array)

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.


setRestorable

public void setRestorable(IloExtractable ex)

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.


setTrue

public void setTrue(IloBoolVar var)

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


setValue

public void setValue(IloAnyVar var, IloAny value)

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


setValue

public void setValue(IloNumVar var, IloNum value)

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)

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)

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)

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


unsetObjective

public void unsetObjective()

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.