VariableGenerator

class VariableGenerator

Provides functionality to generate a decision variable or an array of decision variables.

Methods

__init__

__init__

array

Generate an array of variables.

matrix

Generate a quadratic polynomial in coefficient-matrix form.

scalar

Generate a scalar variable.

Attributes

variables

List of all variables created.

__init__(self) None

__init__

array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
shape: tuple[()],
bounds: tuple[float | None, ...] = (None, None),
name: str = '',
) PolyArray[Dim0]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
shape: tuple[int] | int,
bounds: tuple[float | None, ...] = (None, None),
name: str = '',
) PolyArray[Dim1]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
shape: tuple[int, int],
bounds: tuple[float | None, ...] = (None, None),
name: str = '',
) PolyArray[Dim2]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
shape: tuple[int, int, int],
bounds: tuple[float | None, ...] = (None, None),
name: str = '',
) PolyArray[Dim3]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
shape: tuple[int, int, int, int],
bounds: tuple[float | None, ...] = (None, None),
name: str = '',
) PolyArray[Dim4]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
arg0: int,
) PolyArray[Dim1]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
arg0: int,
arg1: int,
) PolyArray[Dim2]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
arg0: int,
arg1: int,
arg2: int,
) PolyArray[Dim3]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
arg0: int,
arg1: int,
arg2: int,
arg3: int,
) PolyArray[Dim4]
array(self, type: typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType, shape: tuple[int, int, int, int, int, *tuple[int, ...]], bounds: tuple[float | None, ...] = (None, None), name: str = '') PolyArray[Dim]
array(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
*shape: int,
) PolyArray[Dim]

Generate an array of variables. array array array array array array array array array array

Variables are generated in an n-dimensional array. Each variable has the same type and bounds (if any).

Overload 1.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • shape (tuple[()]): The NumPy-like shape of the variable array.

    For example, (3, 4) generates a two-dimensional variable array with 3 rows and 4 columns.

  • bounds (tuple[float | None, ...]): The lower and upper bounds of the variables.
    If either of the bounds is not specified, it will be unbounded in that direction.

    Defaults to (None, None).

  • name (str): The name of the variable array.
    Each variable is automatically assigned a name consisting of this string and a specific index.

    Defaults to ''.

Returns:

amplify.PolyArray[Dim0]: Generated variable array.

Overload 2.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • shape (tuple[int] | int): The NumPy-like shape of the variable array.

    For example, (3, 4) generates a two-dimensional variable array with 3 rows and 4 columns.

  • bounds (tuple[float | None, ...]): The lower and upper bounds of the variables.
    If either of the bounds is not specified, it will be unbounded in that direction.

    Defaults to (None, None).

  • name (str): The name of the variable array.
    Each variable is automatically assigned a name consisting of this string and a specific index.

    Defaults to ''.

Returns:

amplify.PolyArray[Dim1]: Generated variable array.

Overload 3.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • shape (tuple[int, int]): The NumPy-like shape of the variable array.

    For example, (3, 4) generates a two-dimensional variable array with 3 rows and 4 columns.

  • bounds (tuple[float | None, ...]): The lower and upper bounds of the variables.
    If either of the bounds is not specified, it will be unbounded in that direction.

    Defaults to (None, None).

  • name (str): The name of the variable array.
    Each variable is automatically assigned a name consisting of this string and a specific index.

    Defaults to ''.

Returns:

amplify.PolyArray[Dim2]: Generated variable array.

Overload 4.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • shape (tuple[int, int, int]): The NumPy-like shape of the variable array.

    For example, (3, 4) generates a two-dimensional variable array with 3 rows and 4 columns.

  • bounds (tuple[float | None, ...]): The lower and upper bounds of the variables.
    If either of the bounds is not specified, it will be unbounded in that direction.

    Defaults to (None, None).

  • name (str): The name of the variable array.
    Each variable is automatically assigned a name consisting of this string and a specific index.

    Defaults to ''.

Returns:

amplify.PolyArray[Dim3]: Generated variable array.

Overload 5.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • shape (tuple[int, int, int, int]): The NumPy-like shape of the variable array.

    For example, (3, 4) generates a two-dimensional variable array with 3 rows and 4 columns.

  • bounds (tuple[float | None, ...]): The lower and upper bounds of the variables.
    If either of the bounds is not specified, it will be unbounded in that direction.

    Defaults to (None, None).

  • name (str): The name of the variable array.
    Each variable is automatically assigned a name consisting of this string and a specific index.

    Defaults to ''.

Returns:

amplify.PolyArray[Dim4]: Generated variable array.

Overload 6.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • arg0 (int): First element of the NumPy-like shape of the array.

Returns:

amplify.PolyArray[Dim1]: Generated variable array.

Overload 7.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • arg0 (int): First element of the NumPy-like shape of the array.

  • arg1 (int): Second element of the NumPy-like shape of the array.

Returns:

amplify.PolyArray[Dim2]: Generated variable array.

Overload 8.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • arg0 (int): First element of the NumPy-like shape of the array.

  • arg1 (int): Second element of the NumPy-like shape of the array.

  • arg2 (int): Third element of the NumPy-like shape of the array.

Returns:

amplify.PolyArray[Dim3]: Generated variable array.

Overload 9.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • arg0 (int): First element of the NumPy-like shape of the array.

  • arg1 (int): Second element of the NumPy-like shape of the array.

  • arg2 (int): Third element of the NumPy-like shape of the array.

  • arg3 (int): Fourth element of the NumPy-like shape of the array.

Returns:

amplify.PolyArray[Dim4]: Generated variable array.

Overload 10.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • shape (tuple[int, int, int, int, int, *tuple[int, ...]]): The NumPy-like shape of the variable array.

    For example, (3, 4) generates a two-dimensional variable array with 3 rows and 4 columns.

  • bounds (tuple[float | None, ...]): The lower and upper bounds of the variables.
    If either of the bounds is not specified, it will be unbounded in that direction.

    Defaults to (None, None).

  • name (str): The name of the variable array.
    Each variable is automatically assigned a name consisting of this string and a specific index.

    Defaults to ''.

Returns:

amplify.PolyArray[Dim]: Generated variable array.

Overload 11.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • *shape (int): The NumPy-like shape of the variable array.

    For example, (3, 4) generates a two-dimensional variable array with 3 rows and 4 columns.

Returns:

amplify.PolyArray[Dim]: Generated variable array.

matrix(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
shape: int | tuple[int, ...],
bounds: tuple[float | None, ...] = (None, None),
name: str = '',
) Matrix
matrix(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
*shape: int,
) Matrix

Generate a quadratic polynomial in coefficient-matrix form. matrix

A variable array of the specified shape is generated together with the coefficient matrix. The polynomial represented by the coefficient matrix is defined as \((x^T) Q x + (p^T) x + c\), where Q is the quadratic coefficient matrix, p is the linear coefficient array, c is the constant term, and x is the variable array.

Overload 1.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • shape (int | tuple[int, ...]): The shape of the array. It can be specified in two ways:
    • A single integer, e.g., 5, which will generate a one-dimensional variable array with 5 elements.

    • A NumPy-like shape, e.g., (3, 4), which will generate a two-dimensional variable array with 3 rows and 4 columns.

  • bounds (tuple[float | None, ...]): The lower and upper bounds of the variables.

    If either bound is omitted, the variable is unbounded in that direction. Defaults to (None, None).

  • name (str): The name of the variable array.

    Each variable is automatically assigned a name consisting of this string and a specific index. Defaults to ''.

Returns:

amplify.Matrix: Coefficient matrix and generated variable array.

Overload 2.

Args:
  • type (typing.Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType): The type of variables.

  • *shape (int): The shape of the array.

    This overload is provided for backward compatibility.

Returns:

amplify.Matrix: Coefficient matrix and generated variable array.

scalar(
self,
type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
bounds: tuple[float | None, ...] = (None, None),
name: str = '',
) Poly

Generate a scalar variable.

The variable will have the specified type and bounds (if any).

パラメータ:
  • type (Literal['Binary', 'Ising', 'Integer', 'Real'] | amplify.VariableType) -- The type of the variable.

  • bounds (tuple[float | None, ...]) -- The lower and upper bounds of the variable. Defaults to (None, None).

  • name (str) -- The name of the variable. Defaults to ''.

戻り値:

Generated variable.

戻り値の型:

Poly

property variables

List of all variables created.

戻り値の型:

list[Variable]