grid.Var
- class grid.Var(id, var_type, initial_value, preference=None)[source]
Bases:
ExprDecision variable of the model.
Returned by the variable-creation methods of
RoutingModelandVehicleType(add_integer_var,add_float_var,add_nodes_set_var). Subclass ofExprso that variables can be combined with other expressions through operator overloading.Instances are typically obtained via
RoutingModel.add_integer_var(),RoutingModel.add_float_var(), or the equivalent methods onVehicleType, not constructed directly..- Parameters:
id (
int) – Unique identifier of the variable within the model.var_type (
Literal['integer','float','boolean']) – Numeric type of the variable’s value.initial_value (int, float, or bool) – Value of the variable at the start of the route.
preference (
Literal['low','high',None]) – Solver hint indicating preferred direction during search.
Examples
>>> import grid >>> model = grid.RoutingModel() >>> vehicle = model.add_vehicle_type(id=0, count=1, capacity=10) >>> load = vehicle.add_integer_var(initial_value=10) >>> load Var_0 >>> load - 3 Expr(-, Var_0, Const_3, integer) >>> load >= 0 Expr(>=, Var_0, Const_0, boolean)
Methods
__init__(id, var_type, initial_value[, ...])same(other)Return whether this variable refers to the same id as
other.- same(other)[source]
Return whether this variable refers to the same id as
other.Distinct from
__eq__, which is overloaded to build a booleanExprfor use in constraints.Examples
>>> import grid >>> model = grid.RoutingModel() >>> vehicle = model.add_vehicle_type(id=0, count=1, capacity=10) >>> load = vehicle.add_integer_var(initial_value=10) >>> battery = vehicle.add_float_var(initial_value=100.0) >>> load.same(load) True >>> load.same(battery) False