OMMX Python SDK 1.5.0#
This notebook describes the new features. Please refer the GitHub release note for the detailed information.
Evaluation and Partial Evaluation#
From the first release of OMMX, ommx.v1.Instance supports evaluate method to produce Solution message
from ommx.v1 import Instance, DecisionVariable
# Create an instance of the OMMX API
x = DecisionVariable.binary(1)
y = DecisionVariable.binary(2)
instance = Instance.from_components(
decision_variables=[x, y],
objective=x + y,
constraints=[x + y <= 1],
sense=Instance.MINIMIZE
)
solution = instance.evaluate({1: 1, 2: 0})
solution.decision_variables
From Python SDK 1.5.0, Function and its base classes, Linear, Quadratic, and Polynomial also support evaluate method:
f = 2*x + 3*y
value, used_ids = f.evaluate({1: 1, 2: 0})
print(f"{value=}, {used_ids=}")
This returns evaluated value of the function and used decision variable IDs. If some decision variables are lacking, the evaluate method raises an exception:
try:
f.evaluate({3: 1})
except RuntimeError as e:
print(e)
In addition, there is partial_evaluate method
f2, used_ids = f.partial_evaluate({1: 1})
print(f"{f2=}, {used_ids=}")
This creates a new function by substituting x = 1. partial_evaluate is also added to ommx.v1.Instance class:
new_instance = instance.partial_evaluate({1: 1})
new_instance.objective
This method will be useful for creating a problem with fixing specific decision variables.