Skip to main content

Class: Solution

Solution of a Model. When a model is solved, the solution is stored in this object. The solution contains values of all variables in the model (including optional variables) and the value of the objective (if the model specified one).

Evaluation version of OptalCP

Note that in evaluation version of OptalCP the values of variables in the solution are masked and replaced by value absent (null in JavaScript).

Constructors

constructor

new Solution()

Creates an empty solution. That is, all variables are absent and the objective value is undefined.

Use this function to create a an external solution that can be passed to the solver before the solve starts as a warmStart (see solve, Solver) or during the solve using sendSolution.

Methods

getEnd

getEnd(variable): null | number

Returns end of the given interval variable in the solution. If the variable is absent in the solution then it returns null.

In evaluation version of OptalCP this function always returns null because real values of variables are masked and replaced by value absent.

Parameters

NameType
variableIntervalVar

Returns

null | number


getObjective

getObjective(): ObjectiveValue

Returns objective value of the solution. If the model did not specify an objective returns undefined. If the objective value is absent (see optional IntExpr) then it returns null.

The correct value is reported even in case of evaluation version of OptalCP.

Returns

ObjectiveValue


getStart

getStart(variable): null | number

Returns start of the given interval variable in the solution. If the variable is absent in the solution then it returns null.

In evaluation version of OptalCP this function always returns null because real values of variables are masked and replaced by value absent.

Parameters

NameType
variableIntervalVar

Returns

null | number


isAbsent

isAbsent(variable): boolean

Returns true if the given variable is absent in the solution, i.e. if its value is absent. See optional IntervalVar.

In evaluation version of OptalCP this function always returns true because real values of variables are masked and replaced by value absent.

Parameters

NameType
variableIntervalVar

Returns

boolean


isPresent

isPresent(variable): boolean

Returns true if the given variable is present in the solution, i.e. if its value is not absent. See optional IntervalVar.

In evaluation version of OptalCP this function always returns false because real values of variables are masked and replaced by value absent.

Parameters

NameType
variableIntervalVar

Returns

boolean


setAbsent

setAbsent(intervalVar): void

Sets the given variable to be absent in the solution.

Normally, solution is completely constructed by the solver. This function can be used for construction of an external solution that can be passed to the solver (see solve, Solver and sendSolution).

Parameters

NameType
intervalVarIntervalVar

Returns

void


setObjective

setObjective(value): void

Sets objective value of the solution.

Normally, solution is completely constructed by the solver. This function can be used for construction of an external solution that can be passed to the solver (see solve, Solver and sendSolution).

Parameters

NameType
valueObjectiveValue

Returns

void


setValue

setValue(intervalVar, start, end): void

Sets start and end of the given interval variable in the solution. I.e. the interval variable will be present in the solution.

Normally, solution is completely constructed by the solver. This function can be used for construction of an external solution that can be passed to the solver (see solve, Solver and sendSolution).

Parameters

NameType
intervalVarIntervalVar
startnumber
endnumber

Returns

void