didppy.FloatVar
- class didppy.FloatVar
Continuous variable.
If an arithmetic operator (
+
,-
,*
,/
,//
,%
,**
) with anIntExpr
,IntVar
,IntResourceVar
,FloatExpr
,FloatVar
,FloatResourceVar
,int
, orfloat
is applied, a newFloatExpr
is returned. Ifabs()
is applied, a newFloatExpr
is returned.round()
,trunc()
,floor()
, andceil()
return anIntExpr
.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_float_var(target=3.5) >>> state = model.target_state >>> state[var] 3.5 >>> (-var).eval(state, model) -3.5 >>> (var + 1.5).eval(state, model) 5.0 >>> (var + 1).eval(state, model) 4.5 >>> (var - 1.5).eval(state, model) 2.0 >>> (var * 2.5).eval(state, model) 8.75 >>> (var / 2.5).eval(state, model) 1.4 >>> (var // 2.5).eval(state, model) 1.0 >>> (var % 2.5).eval(state, model) 1.0 >>> abs(var).eval(state, model) 3.5 >>> (var ** 2.0).eval(state, model) 12.25 >>> pow(var, 2.0).eval(state, model) 12.25 >>> (1.0 ** var).eval(state, model) 1.0 >>> pow(1.0, var).eval(state, model) 1.0 >>> round(var).eval(state, model) 4 >>> import math >>> math.trunc(var).eval(state, model) 3 >>> math.floor(var).eval(state, model) 3 >>> math.ceil(var).eval(state, model) 4 >>> (var < 3.0).eval(state, model) False >>> (var > 3.0).eval(state, model) True
Methods