didppy.FloatVar

class didppy.FloatVar

Continuous variable.

If an arithmetic operator (+, -, *, /, //, %, **) with an IntExpr, IntVar, IntResourceVar, FloatExpr, FloatVar, FloatResourceVar, int, or float is applied, a new FloatExpr is returned. If abs() is applied, a new FloatExpr is returned. round(), trunc(), floor(), and ceil() return an IntExpr.

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_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