didppy.ElementExpr

class didppy.ElementExpr(value)

Element expression.

If an arithmetic operator (+, -, *, /, //, %) with an ElementExpr, ElementVar, ElementResourceVar, or int is applied, a new ElementExpr is returned.

If a comparison operator (<, <=, ==, !=, >, >=) with an ElementExpr, ElementVar, ElementResourceVar, or int is applied, a Condition is returned.

Note that didppy.max() and didppy.min() should be used instead of max() and min() as comparison operators are overloaded.

Parameters:

value (int) – A non-negative value from which a constant expression is created.

Raises:

OverflowError – If the value is negative.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> state = model.target_state
>>> expr = dp.ElementExpr(3)
>>> expr.eval(state, model)
3
>>> (expr + 1).eval(state, model)
4
>>> (expr - 1).eval(state, model)
2
>>> (expr * 2).eval(state, model)
6
>>> (expr / 2).eval(state, model)
1
>>> (expr // 2).eval(state, model)
1
>>> (expr % 2).eval(state, model)
1
>>> (expr < 3).eval(state, model)
False
>>> (expr <= 3).eval(state, model)
True
>>> (expr == 3).eval(state, model)
True
>>> (expr != 3).eval(state, model)
False
>>> (expr > 3).eval(state, model)
False
>>> (expr >= 3).eval(state, model)
True

Methods

eval(state, model)

Evaluates the expression.

eval(state, model)

Evaluates the expression.

Parameters:
  • state (State) – State.

  • model (Model) – DyPDL Model.

Returns:

Value of the expression.

Return type:

int

Raises:

PanicException – If the expression is not valid.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_element_var(object_type=obj, target=0)
>>> expr = var + 1
>>> state = model.target_state
>>> expr.eval(state, model)
1