Variables#

This section mainly relates to the quadratic models submitted to Leap service solvers such as the hybrid CQM solver.[1] For the variables in nonlinear models, see an introduction in the Model Construction (Nonlinear Models) section and the reference documentation under the dwave-optimization section.

The variables in supported models may be of the following types.

Table 104 Supported Variables#

Variable

Usage

Quadratic Model

Nonlinear Model

Binary.

\(v_i \in\{-1,+1\} \text{ or } \{0,1\}\).

Typically used for applications that optimize over decisions that could either be true (or yes) or false (no); for example,

  • Should the antenna transmit or no?

  • Did a network node experience failure?

BINARY and SPIN

BinaryVariable

Discrete.

For example, a variable that can be assigned one of the values of the set {red, green, blue, yellow}.

Typically used for applications that optimize over several distinct options; for example,

  • Which shift should employee X work?

  • Should the state be colored red, blue, green or yellow?

INTEGER

Integer.

Typically used for applications that optimize the number of something; for example,

  • How many widgets should be loaded onto the truck?

INTEGER

IntegerVariable

Real.

Typically used for applications that optimize over an uncountable set; for example,

  • Where should the sensor be built?

REAL

linprog()

Variable Representations and Labels#

Ocean software enables you to represent a variable with a quadratic model, as described in the Symbolic Math section. This makes it important to distinguish between such a variable’s representation and its label.

For example, in the code below, variables a, i, j are represented by QuadraticModel objects and the ten variables in array x by BinaryQuadraticModel objects:

>>> a = dimod.Real("a")
>>> i, j = dimod.Integers(["i", "j"])
>>> x = dimod.BinaryArray([f"x{i}" for i in range(10)])

Each such variable is represented by a quadratic model that has a single linear bias of 1,

>>> x[0]
BinaryQuadraticModel({'x0': 1.0}, {}, 0.0, 'BINARY')

with its single variable having a specified label; e.g., x0 for the first model in x.

The code below adds two variables to a ConstrainedQuadraticModel. The first, using the add_variable() method, adds a variable by specifying a label, "b", and the type of required variable, "REAL". The second, using the add_constraint_from_model() method, specifies the variable i instantiated above as a QuadraticModel object.

>>> cqm = dimod.ConstrainedQuadraticModel()
>>> cqm.add_variable("b", "REAL")
'b'
>>> cqm.add_constraint_from_model(i, ">=", 2, "Min i")
'Min i'
>>> cqm.variables
Variables(['b', 'i'])