Table of Contents

Class IntVar

Namespace
OptalCP
Assembly
OptalCP.dll

Integer decision variable with a domain.

public class IntVar : IntExpr
Inheritance
IntVar
Inherited Members

Remarks

Integer variable represents an unknown (integer) value that solver has to find.

The value of the integer variable can be constrained using arithmetic operators (+, -, *, /) and comparison operators (<, <=, ==, !=, >, >=).

OptalCP solver focuses on scheduling problems and concentrates on IntervalVar variables. Therefore, interval variables should be the primary choice for modeling in OptalCP. However, integer variables can be used for other purposes, such as counting or indexing. In particular, integer variables can be helpful for cumulative expressions with variable heights; see Model.Pulse, Model.StepAtStart, Model.StepAtEnd, and Model.StepAt.

The integer variable can be optional. In this case, the solver can make the variable absent, which is usually interpreted as the fact that the solver does not use the variable at all. Functions Model.Presence and IntExpr.Presence can constrain the presence of the variable.

Integer variables can be created using the function Model.IntVar.

Example:

In the following example we create three integer variables x, y and z. Variables x and y are present, but variable z is optional. Each variable has a different range of possible values.
var model = new Model();
var x = model.IntVar(min: 1, max: 3, name: "x");
var y = model.IntVar(min: 0, max: 100, name: "y");
var z = model.IntVar(min: 10, max: 20, optional: true, name: "z");

Properties

Max

The maximum value of the integer variable's domain.

public int Max { get; set; }

Property Value

int

Remarks

Gets or sets the maximum value of the integer variable's domain.

The initial value is set during construction by Model.IntVar.

Note: This property reflects the variable's domain in the model (before the solve), not in the solution.

The value must be in the range Model.IntVarMin to Model.IntVarMax.

Example:

var model = new Model();
var x = model.IntVar(min: 5, max: 10, name: "x");

Console.WriteLine(x.Max); // 10

x.Max = 8; Console.WriteLine(x.Max); // 8

See also:

Min

The minimum value of the integer variable's domain.

public int Min { get; set; }

Property Value

int

Remarks

Gets or sets the minimum value of the integer variable's domain.

The initial value is set during construction by Model.IntVar.

Note: This property reflects the variable's domain in the model (before the solve), not in the solution.

The value must be in the range Model.IntVarMin to Model.IntVarMax.

Example:

var model = new Model();
var x = model.IntVar(min: 5, max: 10, name: "x");

Console.WriteLine(x.Min); // 5

x.Min = 7; Console.WriteLine(x.Min); // 7

See also:

Optional

Whether the integer variable is optional.

public bool Optional { get; set; }

Property Value

bool

Remarks

Gets or sets whether the integer variable is optional:

  • True / true: The variable is optional - the solver decides whether it is present or absent in the solution.
  • False / false: The variable is present - it must have a value in the solution.

To force a variable to be absent, make it optional and constrain its presence to be false: model.enforce(~model.presence(x)) (Python), model.enforce(model.presence(x).not()) (TypeScript), or model.Enforce(!model.Presence(x)) (C#).

Note: This property reflects the presence status in the model (before the solve), not in the solution.

Example:

var model = new Model();
var x = model.IntVar(min: 0, max: 10, name: "x");
var y = model.IntVar(min: 0, max: 10, optional: true, name: "y");

Console.WriteLine(x.Optional); // False (present by default) Console.WriteLine(y.Optional); // True (optional)

// Make x optional x.Optional = true; Console.WriteLine(x.Optional); // True

See also: