didppy.IntExpr
- class didppy.IntExpr(value)
Integer expression.
If an arithmetic operator (
+,-,*,//,%) with anIntExpr,IntVar,IntResourceVar, orintis applied, a newIntExpris returned. For division (/) and power (**), aFloatExpris returned. If an arithmetic operator with anFloatExpr,FloatVar,FloatResourceVar, orfloatis applied, aFloatExpris returned. Ifabs()is applied, a newIntExpris returned.If a comparison operator (
<,<=,==,!=,>,>=) with anIntExpr,IntVar,IntResourceVar,FloatExpr,FloatVar,FloatResourceVar,int, orfloatis applied, aConditionis returned.Note that
didppy.max()anddidppy.min()should be used instead ofmax()andmin()as comparison operators are overloaded.- Parameters:
value (int) – A value from which a constant expression is created.
Examples
>>> import didppy as dp >>> model = dp.Model() >>> state = model.target_state >>> expr = dp.IntExpr(3) >>> expr.eval(state, model) 3 >>> (-expr).eval(state, model) -3 >>> (expr + 1).eval(state, model) 4 >>> (expr + 1.5).eval(state, model) 4.5 >>> (expr - 1).eval(state, model) 2 >>> (expr * 2).eval(state, model) 6 >>> (expr / 2).eval(state, model) 1.5 >>> (expr // 2).eval(state, model) 1 >>> (expr % 2).eval(state, model) 1 >>> abs(expr).eval(state, model) 3 >>> (expr ** 2).eval(state, model) 9.0 >>> pow(expr, 2).eval(state, model) 9.0 >>> (2 ** expr).eval(state, model) 8.0 >>> pow(2, expr).eval(state, model) 8.0 >>> (expr < 3).eval(state, model) False >>> (expr <= 3).eval(state, model) True >>> (expr == 3).eval(state, model) True >>> (expr != 3).eval(state, model) False >>> (expr > 3).eval(state, model) False >>> (expr >= 3).eval(state, model) True
Methods
eval(state, model)Evaluates the expression.
eval_cost(cost, state, model)Evaluates the cost expression.
Returns the cost of the transitioned state, which can be used in a cost expression.
- eval(state, model)
Evaluates the expression.
- Parameters:
- Returns:
Value of the expression.
- Return type:
int
- Raises:
PanicException – If the expression is not valid.
Examples
>>> import didppy as dp >>> model = dp.Model() >>> var = model.add_int_var(target=0) >>> expr = var + 1 >>> state = model.target_state >>> expr.eval(state, model) 1
- eval_cost(cost, state, model)
Evaluates the cost expression.
- Parameters:
- Returns:
Value of the expression.
- Return type:
int
- Raises:
PanicException – If the expression is not valid.
Examples
>>> import didppy as dp >>> model = dp.Model() >>> var = model.add_int_var(target=0) >>> expr = var + dp.IntExpr.state_cost() >>> state = model.target_state >>> expr.eval_cost(1, state, model) 1
- static state_cost()
Returns the cost of the transitioned state, which can be used in a cost expression.
- Returns:
The cost of the transitioned state.
- Return type:
Examples
>>> import didppy as dp >>> model = dp.Model() >>> state = model.target_state >>> cost = dp.IntExpr.state_cost() + 1 >>> cost.eval_cost(1, state, model) 2