Parameter

Parameter#

class Parameter#

A symbolic numerical input to a fixed-structure optimization problem.

The caller supplies a value when materializing a ParametricInstance; the solver does not choose it. Parameters can represent coefficients or constants in objectives and constraints. Their IDs share the decision-variable ID space and must be distinct from all decision-variable IDs and other parameter IDs in the same family. Changing a parameter value does not create or remove model components.

name, subscripts, parameters, and description are modeling labels. In particular, the string-valued parameters metadata is separate from the numerical assignment passed to with_parameters().

Arithmetic operators build expressions just as for decision variables. The comparisons ==, <=, and >= construct constraints; == does not compare two Parameter objects for equality. Compare their IDs when checking identity.

Examples#

>>> from ommx import DecisionVariable, Linear, Parameter
>>> p = Parameter(1, name="offset")
>>> x = DecisionVariable.integer(2)
>>> expression = x + p
>>> assert isinstance(expression, Linear)
>>> assert expression.evaluate({x.id: 2, p.id: 3}) == 5.0

See from_components() for a complete model using parameterized profits, weights, and capacity, then with_parameters() to create an Instance.

__add__(rhs: ScalarLike | LinearLike | Parameter) → Linear#
__add__(rhs: Quadratic) → Quadratic
__add__(rhs: Polynomial) → Polynomial
__add__(rhs: Function) → Function
__copy__() → Parameter#
__deepcopy__(_memo: Any) → Parameter#
__eq__(other: builtins.int | builtins.float | numpy.integer | numpy.floating | DecisionVariable | AttachedDecisionVariable | Parameter | Linear | Quadratic | Polynomial | Function) → Constraint#

Create an equality constraint: self == other → Constraint with EqualToZero

__ge__(other: builtins.int | builtins.float | numpy.integer | numpy.floating | DecisionVariable | AttachedDecisionVariable | Parameter | Linear | Quadratic | Polynomial | Function) → Constraint#

Create a greater-than-or-equal constraint: self >= other → Constraint

__le__(other: builtins.int | builtins.float | numpy.integer | numpy.floating | DecisionVariable | AttachedDecisionVariable | Parameter | Linear | Quadratic | Polynomial | Function) → Constraint#

Create a less-than-or-equal constraint: self <= other → Constraint

__mul__(rhs: ScalarLike) → Linear#
__mul__(rhs: LinearLike | Parameter) → Quadratic
__mul__(rhs: Quadratic | Polynomial) → Polynomial
__mul__(rhs: Function) → Function
__neg__() → Linear#

Negation operator: -p → Linear(-1 * p)

__new__(id: int, name: Optional[str] = None, subscripts: Sequence[int] = [], parameters: Mapping[str, str] = {}, description: Optional[str] = None) → Parameter#

Create a new Parameter.

Args:

  • id: Unique identifier for the parameter (must be unique within the instance including decision variables)

  • name: Optional name for the parameter

  • subscripts: Optional subscripts for indexing

  • parameters: Optional metadata key-value pairs

  • description: Optional human-readable description

__radd__(lhs: ScalarLike | LinearLike | Parameter) → Linear#
__radd__(lhs: Quadratic) → Quadratic
__radd__(lhs: Polynomial) → Polynomial
__radd__(lhs: Function) → Function
__repr__() → str#
__rmul__(lhs: ScalarLike) → Linear#
__rmul__(lhs: LinearLike | Parameter) → Quadratic
__rmul__(lhs: Quadratic | Polynomial) → Polynomial
__rmul__(lhs: Function) → Function
__rsub__(lhs: ScalarLike | LinearLike | Parameter) → Linear#
__rsub__(lhs: Quadratic) → Quadratic
__rsub__(lhs: Polynomial) → Polynomial
__rsub__(lhs: Function) → Function
__sub__(rhs: ScalarLike | LinearLike | Parameter) → Linear#
__sub__(rhs: Quadratic) → Quadratic
__sub__(rhs: Polynomial) → Polynomial
__sub__(rhs: Function) → Function
property description: str#

Read-only property.

property id: int#

Read-only property.

property name: str#

Read-only property.

property parameters: dict[str, str]#

Read-only property.

property subscripts: list[int]#

Read-only property.