didppy.IntVar

class didppy.IntVar

Integer variable.

If an arithmetic operator (+, -, *, //, %) with an IntExpr, IntVar, IntResourceVar, or int is applied, a new IntExpr is returned. For division (/) and power (**), a FloatExpr is returned. If an arithmetic operator with an FloatExpr, FloatVar, FloatResourceVar, or float is applied, a FloatExpr is returned. If abs() is applied, a new IntExpr is returned.

If a comparison operator (<, <=, ==, !=, >, >=) with an IntExpr, IntVar, IntResourceVar, FloatExpr, FloatVar, FloatResourceVar, int, or float 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()
>>> var = model.add_int_var(target=3)
>>> state = model.target_state
>>> state[var]
3
>>> (-var).eval(state, model)
-3
>>> (var + 1).eval(state, model)
4
>>> (var + 1.5).eval(state, model)
4.5
>>> (var - 1).eval(state, model)
2
>>> (var * 2).eval(state, model)
6
>>> (var / 2).eval(state, model)
1.5
>>> (var // 2).eval(state, model)
1
>>> (var % 2).eval(state, model)
1
>>> abs(var).eval(state, model)
3
>>> (var ** 2).eval(state, model)
9.0
>>> pow(var, 2).eval(state, model)
9.0
>>> (2 ** var).eval(state, model)
8.0
>>> pow(2, var).eval(state, model)
8.0
>>> (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