didppy.Condition

class didppy.Condition

Condition.

The negation of a condition can be crated by ~x. The conjunction of two conditions can be crated by x & y. The disjunction of two conditions can be crated by x | y.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> var = model.add_int_var(target=4)
>>> state = model.target_state
>>> condition = var >= 4
>>> condition.eval(state, model)
True
>>> (~condition).eval(state, model)
False
>>> (condition & (var <= 5)).eval(state, model)
True
>>> (condition | (var <= 5)).eval(state, model)
True

Methods

eval(state, model)

Evaluates the condition.

if_then_else(x, y)

Returns an 'if-then-else' expression, which returns the first expression if the condition holds and the second one otherwise.

eval(state, model)

Evaluates the condition.

Parameters:
  • state (State) – State.

  • model (Model) – DyPDL Model.

Returns:

Value of the condition.

Return type:

bool

Raises:

PanicException – If the condition is not valid.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> var = model.add_int_var(target=0)
>>> condition = var >= 0
>>> state = model.target_state
>>> condition.eval(state, model)
True
if_then_else(x, y)

Returns an ‘if-then-else’ expression, which returns the first expression if the condition holds and the second one otherwise.

Parameters:
Returns:

The ‘if-then-else’ expression. The type of the return value is determined according to the types of x and y.

Return type:

ElementExpr, SetExpr, IntExpr, or FloatExpr

Raises:

TypeError – If the types of x and y mismatch.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> var = model.add_int_var(target=4)
>>> expr = (var >= 0).if_then_else(2, 3)
>>> expr.eval(model.target_state, model)
2