grid.VehicleType
- class grid.VehicleType(id, count=1, capacity=None, start_node=None, end_node=None)[source]
Bases:
objectDefinition of a homogeneous group of vehicles sharing the same parameters.
A model may contain several vehicle types, each with its own count, capacity, permitted depots, and user-defined variables.
- Parameters:
id (
int) – Unique identifier of the vehicle type.count (
int) – Number of vehicles of this type available.capacity (
dict[str,float] |int|float) – Vehicle capacity. Scalar for single-commodity, dict mapping commodity name to per-commodity capacity for multi-commodity problems.start_node (
int) – Id of the node where vehicles of this type start.end_node (
int) – Id of the node where vehicles of this type must end.
- variables
Decision variables registered on this vehicle type via
add_integer_var(),add_float_var(),add_nodes_set_var().
Examples
>>> import grid >>> model = grid.RoutingModel() >>> vehicle = model.add_vehicle_type(id=0, count=2, capacity=10) >>> vehicle.count 2 >>> load = vehicle.add_integer_var(initial_value=10) >>> load Var_0
Methods
__init__(id[, count, capacity, start_node, ...])add_float_var(initial_value[, preference])Create a float decision variable bound to this vehicle type.
add_integer_var(initial_value[, preference])Create an integer decision variable bound to this vehicle type.
add_nodes_set_var(initial_value)Create a set decision variable bound to this vehicle type.
- add_float_var(initial_value, preference=None)[source]
Create a float decision variable bound to this vehicle type.
- Parameters:
- Returns:
The newly created variable.
- Return type:
Examples
>>> import grid >>> model = grid.RoutingModel() >>> vehicle = model.add_vehicle_type(id=0, count=1, capacity=10) >>> battery = vehicle.add_float_var(initial_value=100.0, preference="high") >>> battery.preference 'high' >>> battery.type 'float'
- add_integer_var(initial_value, preference=None)[source]
Create an integer decision variable bound to this vehicle type.
- Parameters:
- Returns:
The newly created variable.
- Return type:
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.initial_value 10 >>> load.type 'integer'
- add_nodes_set_var(initial_value)[source]
Create a set decision variable bound to this vehicle type.
Used to track sets of node ids over the route (e.g. unvisited or visited nodes).
- Parameters:
initial_value (
set|list) – Initial contents of the set at the start of the route.- Returns:
The newly created set variable.
- Return type:
Examples
>>> import grid >>> model = grid.RoutingModel() >>> vehicle = model.add_vehicle_type(id=0, count=1, capacity=10) >>> stations = vehicle.add_nodes_set_var(initial_value={3, 4}) >>> sorted(stations.initial_value) [3, 4]