Poly

class Poly

The polynomial class used for representing objective functions and constraints.

Methods

__init__

__init__

as_dict

Return the dictionary representation of the polynomial.

as_variable

Return the variable representation of the polynomial.

asdict

alias of as_dict()

decode

Equivalent to evaluate().

degree

Return the degree of the polynomial.

evaluate

Evaluate the polynomial by substituting variables using the given values.

is_linear

Return True if the polynomial is linear.

is_number

Return True if the polynomial is a constant polynomial.

is_quadratic

Return True if the polynomial is quadratic.

is_variable

Return True if the polynomial represents a single variable.

substitute

Assign numbers or other polynomials to variables in the polynomial.

Attributes

id

Variable ID.

lower_bound

Lower bound of the variable.

name

Variable name.

type

Variable type.

upper_bound

Upper bound of the variable.

variables

List of all variables in the polynomial.

class Iterator
__init__(*args, **kwargs)
__iter__(self) Iterator

__iter__

戻り値の型:

Iterator

__next__(self) tuple[tuple[Poly, ...], float]

__next__

戻り値の型:

tuple[tuple[Poly, ...], float]

__add__(self, arg: Poly | float, /) Poly
__add__(self, arg: ndarray[], /) PolyArray[Dim]
__add__(self, arg: Constraint | ConstraintList, /) Model

__add__

Overload 1.

Args:
  • arg (amplify.Poly | float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

Overload 3.

Args:
  • arg (amplify.Constraint | amplify.ConstraintList)

Returns:

amplify.Model:

__and__(self, arg: Poly | bool, /) Poly
__and__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

Logical AND of two polynomials. This is meaningful only for polynomials that take values 0 or 1. __and__

q_0 & q_1 is equivalent to q_0 * q_1.

Overload 1.

Args:
  • arg (amplify.Poly | bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__bool__(self) bool

Cast a polynomial to a boolean value. Only valid for constant polynomials that take values 0 or 1.

戻り値の型:

bool

__eq__(self, arg: object, /) bool

__eq__

パラメータ:

arg (object)

戻り値の型:

bool

__float__(self) float

Cast a polynomial to a float value. Only valid for constant polynomials.

戻り値の型:

float

__iadd__(self, arg: Poly | float, /) Poly

__iadd__

パラメータ:

arg (Poly | float)

戻り値の型:

Poly

__iand__(self, arg: Poly | bool, /) Poly

__iand__

パラメータ:

arg (Poly | bool)

戻り値の型:

Poly

__imul__(self, arg: Poly | float, /) Poly

__imul__

パラメータ:

arg (Poly | float)

戻り値の型:

Poly

__index__(self) int

Cast a polynomial to an integer. Only valid for constant polynomials.

戻り値の型:

int

__init__(self) None
__init__(self, arg: float, /) None
__init__(self, arg: Variable, /) None

__init__

Overload 2.

Args:
  • arg (float)

Overload 3.

Args:
  • arg (amplify.Variable)

__int__(self) int

Cast a polynomial to an integer. Only valid for constant polynomials.

戻り値の型:

int

__invert__(self) Poly

Logical NOT of a polynomial. This is meaningful only for polynomials that take values 0 or 1.

~q_0 is equivalent to 1 - q_0.

戻り値の型:

Poly

__ior__(self, arg: Poly | bool, /) Poly

__ior__

パラメータ:

arg (Poly | bool)

戻り値の型:

Poly

__ipow__(self, arg: int, /) Poly

__ipow__

パラメータ:

arg (int)

戻り値の型:

Poly

__isub__(self, arg: Poly | float, /) Poly

__isub__

パラメータ:

arg (Poly | float)

戻り値の型:

Poly

__iter__(self) Iterator

Iterate over the terms in the polynomial.

Each term is represented as a tuple of a tuple of variables and a coefficient. For example, the polynomial 3 * x_0 * x_1 - 2 * x_0 + 5 is iterated as ((Poly(x_0), Poly(x_1)), 3.0), ((Poly(x_0),), -2.0), and ((), 5.0).

戻り値の型:

Iterator

__itruediv__(self, arg: float, /) Poly

__itruediv__

パラメータ:

arg (float)

戻り値の型:

Poly

__ixor__(self, arg: Poly | bool, /) Poly

__ixor__

パラメータ:

arg (Poly | bool)

戻り値の型:

Poly

__len__(self) int

Return the number of terms in the polynomial.

戻り値の型:

int

__mul__(self, arg: Poly | float, /) Poly
__mul__(self, arg: ndarray[], /) PolyArray[Dim]

__mul__

Overload 1.

Args:
  • arg (amplify.Poly | float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__ne__(self, arg: object, /) bool

__ne__

パラメータ:

arg (object)

戻り値の型:

bool

__neg__(self) Poly

__neg__

戻り値の型:

Poly

__or__(self, arg: Poly | bool, /) Poly
__or__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

Logical OR of two polynomials. This is meaningful only for polynomials that take values 0 or 1. __or__

q_0 | q_1 is equivalent to -q_0 * q_1 + q_0 + q_1.

Overload 1.

Args:
  • arg (amplify.Poly | bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__pos__(self) Poly

__pos__

戻り値の型:

Poly

__pow__(self, arg: int, /) Poly

__pow__

パラメータ:

arg (int)

戻り値の型:

Poly

__radd__(self, arg: float, /) Poly
__radd__(self, arg: ndarray[], /) PolyArray[Dim]
__radd__(self, arg: Constraint | ConstraintList, /) Model

__radd__

Overload 1.

Args:
  • arg (float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

Overload 3.

Args:
  • arg (amplify.Constraint | amplify.ConstraintList)

Returns:

amplify.Model:

__rand__(self, arg: bool, /) Poly
__rand__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

__rand__

Overload 1.

Args:
  • arg (bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__repr__(self) str

__repr__

戻り値の型:

str

__rmul__(self, arg: float, /) Poly
__rmul__(self, arg: ndarray[], /) PolyArray[Dim]

__rmul__

Overload 1.

Args:
  • arg (float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__ror__(self, arg: bool, /) Poly
__ror__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

__ror__

Overload 1.

Args:
  • arg (bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__rsub__(self, arg: float, /) Poly
__rsub__(self, arg: ndarray[], /) PolyArray[Dim]

__rsub__

Overload 1.

Args:
  • arg (float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__rxor__(self, arg: bool, /) Poly
__rxor__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

__rxor__

Overload 1.

Args:
  • arg (bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__str__(self) str

__str__

戻り値の型:

str

__sub__(self, arg: Poly | float, /) Poly
__sub__(self, arg: ndarray[], /) PolyArray[Dim]

__sub__

Overload 1.

Args:
  • arg (amplify.Poly | float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__truediv__(self, arg: float, /) Poly
__truediv__(self, arg: ndarray[], /) PolyArray[Dim]

__truediv__

Overload 1.

Args:
  • arg (float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__xor__(self, arg: Poly | bool, /) Poly
__xor__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

Logical XOR of two polynomials. This is meaningful only for polynomials that take values 0 or 1. __xor__

q_0 ^ q_1 is equivalent to -2 * q_0 * q_1 + q_0 + q_1.

Overload 1.

Args:
  • arg (amplify.Poly | bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

as_dict(self) dict[tuple[int, ...], float]

Return the dictionary representation of the polynomial.

The polynomial is represented as a dictionary where keys are tuples of variable indices and values are coefficients. For example, the polynomial 3 * x_0 - 2 * x_0 * x_1 + 5 will be represented as {(): 5, (0,): 3, (0, 1): -2}.

戻り値の型:

dict[tuple[int, ...], float]

as_variable(self) Variable

Return the variable representation of the polynomial. Only valid for polynomials that represent a single variable.

戻り値の型:

Variable

asdict(self) dict[tuple[int, ...], float]

alias of as_dict()

戻り値の型:

dict[tuple[int, ...], float]

decode(self, values: Values) float
decode(self, values: Values, default: float) float
decode(self, values: Values, default: None) Poly

Equivalent to evaluate(). decode decode

This method is deprecated since Amplify v1.0.0 and will be removed in a future version. Please see the migration guide for details: https://amplify.fixstars.com/docs/amplify/v1/migration.html

Overload 1.

Args:
  • values (amplify.Values)

Returns:

float:

Overload 2.

Args:
  • values (amplify.Values)

  • default (float)

Returns:

float:

Overload 3.

Args:
  • values (amplify.Values)

  • default (None)

Returns:

amplify.Poly:

degree(self) int

Return the degree of the polynomial.

戻り値の型:

int

evaluate(self, values: Values) float
evaluate(self, values: Values, default: float) float
evaluate(self, values: Values, default: None) Poly

Evaluate the polynomial by substituting variables using the given values. evaluate evaluate

This method is usually used to obtain optimization results in array form.

If the keyword argument default is not specified, variables that are not specified in values will be substituted by a reasonable default value.

If the keyword argument default is specified with a float value, variables that are not specified in values will be substituted by that value.

If the keyword argument default is specified with None, variables that are not specified in values will remain as symbolic variables without substitution.

Overload 1.

Args:
  • values (amplify.Values): Values obtained from optimization results, e.g. result.best.values.

Returns:

float:

Overload 2.

Args:
  • values (amplify.Values): Values that can be obtained from optimization results, e.g. result.best.values.

  • default (float): The default value for variables not specified in values.

Returns:

float:

Overload 3.

Args:
  • values (amplify.Values): Values obtained from optimization results, e.g. result.best.values.

  • default (None): Set to None to keep variables not specified in values symbolic.

Returns:

amplify.Poly:

is_linear(self) bool

Return True if the polynomial is linear.

戻り値の型:

bool

is_number(self) bool

Return True if the polynomial is a constant polynomial.

戻り値の型:

bool

is_quadratic(self) bool

Return True if the polynomial is quadratic.

戻り値の型:

bool

is_variable(self) bool

Return True if the polynomial represents a single variable.

戻り値の型:

bool

substitute(
self,
mapping: Mapping[Poly, Poly | float | int] | Mapping[Variable, Poly | float | int],
) Poly

Assign numbers or other polynomials to variables in the polynomial.

パラメータ:

mapping (Mapping[Poly, Poly | float | int] | Mapping[Variable, Poly | float | int]) -- Key-value pairs of variables and replacement values. Each value can be a number or another polynomial.

戻り値の型:

Poly

property id

Variable ID. Only valid for polynomials that represent a single variable.

戻り値の型:

int

property lower_bound

Lower bound of the variable. Only valid for polynomials that represent a single variable.

戻り値の型:

float | None

property name

Variable name. Only valid for polynomials that represent a single variable.

戻り値の型:

str

property type

Variable type. Only valid for polynomials that represent a single variable.

戻り値の型:

VariableType

property upper_bound

Upper bound of the variable. Only valid for polynomials that represent a single variable.

戻り値の型:

float | None

property variables

List of all variables in the polynomial.

戻り値の型:

list[Variable]