ml4co_kit.task.routing.vrp.cvrptw
Capacitated Vehicle Routing Problem with Time Windows (CVRPTW).
CVRPTW extends CVRP by requiring every vehicle route to satisfy customer time windows and service times. Early arrivals can wait, while late arrivals are infeasible.
Note: We set the speed of each vehicle to 1.0 for simplicity. In this case, the travel time is equal to the distance.
Classes
|
- class ml4co_kit.task.routing.vrp.cvrptw.CVRPTWTask(cvrp_open: bool = False, distance_type: ~ml4co_kit.task.routing.base.DISTANCE_TYPE = DISTANCE_TYPE.EUC_2D, round_type: ~ml4co_kit.task.routing.base.ROUND_TYPE = ROUND_TYPE.NO, precision: ~numpy.float32 | ~numpy.float64 = <class 'numpy.float32'>, threshold: float = 0.0001)[source]
Bases:
CVRPTask- from_data(depots: ndarray = None, points: ndarray = None, demands: ndarray = None, capacity: float = None, tw: ndarray = None, service: ndarray = None, sol: ndarray = None, ref: bool = False, normalize: bool = False, name: str = None)[source]
Populate the task from numpy arrays.
Parameters
- depotsnp.ndarray, optional
Depot coordinates, shape
(2,)or(3,).- pointsnp.ndarray, optional
Customer coordinates, shape
(V, 2)or(V, 3).- demandsnp.ndarray, optional
Customer demands, shape
(V,).- capacityfloat, optional
Vehicle capacity.
- solnp.ndarray, optional
Tour encoding with
0depot delimiters.- refbool, optional
If
True, storesolinref_solinstead ofsol.- normalizebool, optional
Scale coordinates to
[0, 1](EUC_2Donly).- namestr, optional
Instance name override.
- render(save_path: Path, with_sol: bool = True, figsize: tuple = (5, 5), node_color: str = 'darkblue', edge_color: str = 'darkblue', node_size: int = 50)[source]
Save a matplotlib figure of the instance (and optional solution).
Parameters
- save_pathpathlib.Path
Output image path (
.png, etc.).- with_solbool, optional
Draw
self.solroutes whenTrue; instance only whenFalse.- figsizetuple, optional
Figure size in inches.
- node_color, edge_colorstr, optional
Plot colors (used when applicable).
- node_sizeint, optional
Scatter marker size for customers.