didppy.IntVar
- class didppy.IntVar
Integer variable.
If an arithmetic operator (
+
,-
,*
,//
,%
) with anIntExpr
,IntVar
,IntResourceVar
, orint
is applied, a newIntExpr
is returned. For division (/) and power (**), aFloatExpr
is returned. If an arithmetic operator with anFloatExpr
,FloatVar
,FloatResourceVar
, orfloat
is applied, aFloatExpr
is returned. Ifabs()
is applied, a newIntExpr
is returned.If a comparison operator (
<
,<=
,==
,!=
,>
,>=
) with anIntExpr
,IntVar
,IntResourceVar
,FloatExpr
,FloatVar
,FloatResourceVar
,int
, orfloat
is applied, aCondition
is returned.Note that
didppy.max()
anddidppy.min()
should be used instead ofmax()
andmin()
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