PolyΒΆ
- class PolyΒΆ
The polynomial class used for representing objective functions and constraints.
Methods
__init__
Return the dictionary representation of the polynomial.
Return the variable representation of the polynomial.
alias of
as_dict()Equivalent to
evaluate().Return the degree of the polynomial.
Evaluate the polynomial by substituting variables using the given values.
Return
Trueif the polynomial is linear.Return
Trueif the polynomial is a constant polynomial.Return
Trueif the polynomial is quadratic.Return
Trueif the polynomial represents a single variable.Assign numbers or other polynomials to variables in the polynomial.
Attributes
Variable ID.
Lower bound of the variable.
Variable name.
Variable type.
Upper bound of the variable.
List of all variables in the polynomial.
- __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_1is equivalent toq_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.
- Return type:
- __float__(self) floatΒΆ
Cast a polynomial to a float value. Only valid for constant polynomials.
- Return type:
- __index__(self) intΒΆ
Cast a polynomial to an integer. Only valid for constant polynomials.
- Return type:
- __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.
- Return type:
- __invert__(self) PolyΒΆ
Logical NOT of a polynomial. This is meaningful only for polynomials that take values 0 or 1.
~q_0is equivalent to1 - q_0.- Return type:
- __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 + 5is iterated as((Poly(x_0), Poly(x_1)), 3.0),((Poly(x_0),), -2.0), and((), 5.0).- Return type:
- __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]:
- __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_1is 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]:
- __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]:
- __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]:
- __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_1is 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 + 5will be represented as{(): 5, (0,): 3, (0, 1): -2}.
- as_variable(self) VariableΒΆ
Return the variable representation of the polynomial. Only valid for polynomials that represent a single variable.
- Return type:
- decode(self, values: Values) floatΒΆ
- decode(self, values: Values, default: float) float
- decode(self, values: Values, default: None) Poly
Equivalent to
evaluate(). decode decodeThis 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:
- 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
defaultis not specified, variables that are not specified invalueswill be substituted by a reasonable default value.If the keyword argument
defaultis specified with a float value, variables that are not specified invalueswill be substituted by that value.If the keyword argument
defaultis specified withNone, variables that are not specified invalueswill 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
Noneto keep variables not specified invaluessymbolic.
- Returns:
amplify.Poly:
- property idΒΆ
Variable ID. Only valid for polynomials that represent a single variable.
- Return type:
- property lower_boundΒΆ
Lower bound of the variable. Only valid for polynomials that represent a single variable.
- Return type:
float | None
- property nameΒΆ
Variable name. Only valid for polynomials that represent a single variable.
- Return type:
- property typeΒΆ
Variable type. Only valid for polynomials that represent a single variable.
- Return type: