VariableGenerator¶
- class VariableGenerator¶
Provides functionality to generate a decision variable or an array of decision variables.
Methods
__init__
Generate an array of variables.
Generate a quadratic polynomial in coefficient-matrix form.
Generate a scalar variable.
Attributes
List of all variables created.
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- shape: tuple[()],
- bounds: tuple[float | None, ...] = (None, None),
- name: str = '',
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- shape: tuple[int] | int,
- bounds: tuple[float | None, ...] = (None, None),
- name: str = '',
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- shape: tuple[int, int],
- bounds: tuple[float | None, ...] = (None, None),
- name: str = '',
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- shape: tuple[int, int, int],
- bounds: tuple[float | None, ...] = (None, None),
- name: str = '',
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- shape: tuple[int, int, int, int],
- bounds: tuple[float | None, ...] = (None, None),
- name: str = '',
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- arg0: int,
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- arg0: int,
- arg1: int,
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- arg0: int,
- arg1: int,
- arg2: int,
- array(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- arg0: int,
- arg1: int,
- arg2: int,
- arg3: int,
- 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,
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(
- self,
- type: Literal['Binary', 'Ising', 'Integer', 'Real'] | VariableType,
- *shape: int,
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.