Table of Contents

Class Solution

Namespace
OptalCP
Assembly
OptalCP.dll

Access to variable values after solving.

public class Solution
Inheritance
Solution
Inherited Members

Remarks

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

Preview version of OptalCP

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

Constructors

Solution()

Creates an empty solution.

public Solution()

Remarks

Creates a solution where all variables are absent, and the objective value is None/undefined.

Use this constructor to create an external solution that can be passed to the solver as a warm start (see Model.Solve) or sent during solving using Solver.SendSolution.

var model = new Model();
var x = model.IntervalVar(length: 10, name: "x");
model.Minimize(x.End());

// Create an external solution
var solution = new Solution();
solution.SetValue(x, 0, 10);  // x starts at 0, ends at 10
solution.SetObjective(10);    // objective value = x.End() = 10

// Use it as a warm start
var result = model.Solve(new Parameters { timeLimit = 60 }, solution);

Methods

GetEnd(IntervalVar)

Gets an interval variable's end time from the solution.

public int? GetEnd(IntervalVar variable)

Parameters

variable IntervalVar

The interval variable to query

Returns

int?

The end value, or None if absent

Remarks

If the variable is absent in the solution, it returns null.

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

GetLength(IntervalVar)

Gets an interval variable's length from the solution.

public int? GetLength(IntervalVar variable)

Parameters

variable IntervalVar

The interval variable to query

Returns

int?

The length value, or None if absent

Remarks

If the variable is absent in the solution, it returns null.

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

GetObjective()

Returns the objective value of the solution.

public long? GetObjective()

Returns

long?

The objective value

Remarks

Returns null if no objective was specified or if the objective expression is absent (see optional IntExpr).

The correct value is reported even in the preview version of OptalCP.

GetStart(IntervalVar)

Gets an interval variable's start time from the solution.

public int? GetStart(IntervalVar variable)

Parameters

variable IntervalVar

The interval variable to query

Returns

int?

The start value, or None if absent

Remarks

If the variable is absent in the solution, it returns null.

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

GetValue(BoolVar)

Gets a boolean variable's value from the solution.

public bool? GetValue(BoolVar variable)

Parameters

variable BoolVar

The boolean variable to get the value of.

Returns

bool?

The value, or null if the variable is absent.

Remarks

Returns the value assigned to the given boolean variable in this solution, or null if the variable is absent.

See also:

GetValue(IntVar)

Gets an integer variable's value from the solution.

public int? GetValue(IntVar variable)

Parameters

variable IntVar

The integer variable to get the value of.

Returns

int?

The value, or null if the variable is absent.

Remarks

Returns the value assigned to the given integer variable in this solution, or null if the variable is absent.

See also:

GetValue(IntervalVar)

Gets an interval variable's start and end from the solution.

public (int Start, int End)? GetValue(IntervalVar interval)

Parameters

interval IntervalVar

The interval variable to get the value of.

Returns

(int Start, int End)?

A (Start, End) tuple, or null if the interval is absent.

Remarks

Returns the start and end assigned to the given interval variable in this solution, or null if the variable is absent.

See also:

IsAbsent(BoolVar)

Returns true if the given variable is absent in the solution.

public bool IsAbsent(BoolVar variable)

Parameters

variable BoolVar

The variable to check

Returns

bool

True if the variable is absent

Remarks

In the preview version of OptalCP, this method always returns true because real values of variables are masked and replaced by value absent.

IsAbsent(IntVar)

Returns true if the given variable is absent in the solution.

public bool IsAbsent(IntVar variable)

Parameters

variable IntVar

The variable to check

Returns

bool

True if the variable is absent

Remarks

In the preview version of OptalCP, this method always returns true because real values of variables are masked and replaced by value absent.

IsAbsent(IntervalVar)

Returns true if the given variable is absent in the solution.

public bool IsAbsent(IntervalVar interval)

Parameters

interval IntervalVar

Returns

bool

True if the variable is absent

Remarks

In the preview version of OptalCP, this method always returns true because real values of variables are masked and replaced by value absent.

IsPresent(BoolVar)

Returns true if the given variable is present in the solution.

public bool IsPresent(BoolVar variable)

Parameters

variable BoolVar

The variable to check

Returns

bool

True if the variable is present

Remarks

In the preview version of OptalCP, this method always returns false because real values of variables are masked and replaced by value absent.

IsPresent(IntVar)

Returns true if the given variable is present in the solution.

public bool IsPresent(IntVar variable)

Parameters

variable IntVar

The variable to check

Returns

bool

True if the variable is present

Remarks

In the preview version of OptalCP, this method always returns false because real values of variables are masked and replaced by value absent.

IsPresent(IntervalVar)

Returns true if the given variable is present in the solution.

public bool IsPresent(IntervalVar interval)

Parameters

interval IntervalVar

Returns

bool

True if the variable is present

Remarks

In the preview version of OptalCP, this method always returns false because real values of variables are masked and replaced by value absent.

SetAbsent(BoolVar)

Sets the given variable to be absent in the solution.

public void SetAbsent(BoolVar variable)

Parameters

variable BoolVar

The variable to set as absent

Remarks

This function can be used for construction of an external solution that can be passed to the solver (see Model.Solve and Solver.SendSolution).

SetAbsent(IntVar)

Sets the given variable to be absent in the solution.

public void SetAbsent(IntVar variable)

Parameters

variable IntVar

The variable to set as absent

Remarks

This function can be used for construction of an external solution that can be passed to the solver (see Model.Solve and Solver.SendSolution).

SetAbsent(IntervalVar)

Sets the given variable to be absent in the solution.

public void SetAbsent(IntervalVar interval)

Parameters

interval IntervalVar

Remarks

This function can be used for construction of an external solution that can be passed to the solver (see Model.Solve and Solver.SendSolution).

SetObjective(long?)

Sets objective value of the solution.

public void SetObjective(long? value)

Parameters

value long?

The objective value to set

Remarks

This function can be used for construction of an external solution that can be passed to the solver (see Model.Solve, Solver and Solver.SendSolution).

SetValue(BoolVar, bool)

Sets the value of the given boolean variable in the solution.

public void SetValue(BoolVar variable, bool value)

Parameters

variable BoolVar

The boolean variable.

value bool

The value to set.

Remarks

The variable will be present in the solution with the given value.

See also:

SetValue(IntVar, int)

Sets the value of the given integer variable in the solution.

public void SetValue(IntVar variable, int value)

Parameters

variable IntVar

The integer variable.

value int

The value to set.

Remarks

The variable will be present in the solution with the given value.

See also:

SetValue(IntervalVar, int, int)

Sets the start and end of the given interval variable in the solution.

public void SetValue(IntervalVar variable, int start, int end)

Parameters

variable IntervalVar

The interval variable.

start int

The start time.

end int

The end time.

Remarks

The interval variable will be present in the solution with the given start and end.

See also:

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.