didppy.ElementResourceVar

class didppy.ElementResourceVar

Element resource variable.

Intuitively, with less_is_better=True/less_is_better=False, if everything else is the same, a state having a smaller/greater value is better. Formally, if the values of non-resource variables are the same, a state having equal or better resource variable values must lead to an equal or better solution that has equal or fewer transitions than the other.

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.

Examples

>>> import didppy as dp
>>> model = dp.Model()
>>> obj = model.add_object_type(number=4)
>>> var = model.add_element_resource_var(object_type=obj, target=3, less_is_better=True)
>>> state = model.target_state
>>> state[var]
3
>>> (var + 1).eval(state, model)
4
>>> (var - 1).eval(state, model)
2
>>> (var * 2).eval(state, model)
6
>>> (var / 2).eval(state, model)
1
>>> (var // 2).eval(state, model)
1
>>> (var % 2).eval(state, model)
1
>>> (var < 3).eval(state, model)
False
>>> (var <= 3).eval(state, model)
True
>>> (var == 3).eval(state, model)
True
>>> (var != 3).eval(state, model)
False
>>> (var > 3).eval(state, model)
False
>>> (var >= 3).eval(state, model)
True

Methods