@@ -18,6 +18,25 @@ using Random: Random, AbstractRNG, MersenneTwister, seed!, randperm
1818using Requires: @require
1919using Statistics: mean, quantile
2020
21+ """
22+ $TYPEDEF
23+
24+ Abstract type for dynamic vehicle scheduling benchmarks.
25+
26+ # Fields
27+ $TYPEDFIELDS
28+ """
29+ @kwdef struct DynamicVehicleSchedulingBenchmark <: AbstractDynamicBenchmark{true}
30+ " maximum number of customers entering the system per epoch"
31+ max_requests_per_epoch:: Int = 10
32+ " time between decision and dispatch of a vehicle"
33+ Δ_dispatch:: Float64 = 1.0
34+ " duration of an epoch"
35+ epoch_duration:: Float64 = 1.0
36+ " whether to use two-dimensional features"
37+ two_dimensional_features:: Bool = false
38+ end
39+
2140include (" utils.jl" )
2241
2342# static vsp stuff
@@ -38,46 +57,35 @@ include("anticipative_solver.jl")
3857include (" features.jl" )
3958include (" policy.jl" )
4059
41- """
42- $TYPEDEF
43-
44- Abstract type for dynamic vehicle scheduling benchmarks.
45-
46- # Fields
47- $TYPEDFIELDS
48- """
49- @kwdef struct DynamicVehicleSchedulingBenchmark <: AbstractDynamicBenchmark{true}
50- " maximum number of customers entering the system per epoch"
51- max_requests_per_epoch:: Int = 10
52- " time between decision and dispatch of a vehicle"
53- Δ_dispatch:: Float64 = 1.0
54- " duration of an epoch"
55- epoch_duration:: Float64 = 1.0
56- " whether to use two-dimensional features"
57- two_dimensional_features:: Bool = false
58- end
59-
6060"""
6161$TYPEDSIGNATURES
6262
63- Generate a dataset for the dynamic vehicle scheduling benchmark.
64- Returns a vector of [`DataSample`](@ref) objects, each containing an [`Instance`](@ref).
65- The dataset is generated from pre-existing DVRPTW files.
63+ Generate environments for the dynamic vehicle scheduling benchmark.
64+ Reads from pre-existing DVRPTW files and creates [`DVSPEnv`](@ref) environments.
6665"""
67- function Utils. generate_dataset (b:: DynamicVehicleSchedulingBenchmark , dataset_size:: Int = 1 )
66+ function Utils. generate_environments (
67+ b:: DynamicVehicleSchedulingBenchmark ,
68+ n:: Int ;
69+ seed= nothing ,
70+ rng= MersenneTwister (seed),
71+ kwargs... ,
72+ )
6873 (; max_requests_per_epoch, Δ_dispatch, epoch_duration, two_dimensional_features) = b
6974 files = readdir (datadep " dvrptw" ; join= true )
70- dataset_size = min (dataset_size , length (files))
75+ n = min (n , length (files))
7176 return [
72- DataSample (;
73- instance= Instance (
77+ generate_environment (
78+ b,
79+ Instance (
7480 read_vsp_instance (files[i]);
7581 max_requests_per_epoch,
7682 Δ_dispatch,
7783 epoch_duration,
7884 two_dimensional_features,
7985 ),
80- ) for i in 1 : dataset_size
86+ rng;
87+ kwargs... ,
88+ ) for i in 1 : n
8189 ]
8290end
8391
@@ -87,7 +95,7 @@ $TYPEDSIGNATURES
8795Creates an environment from an [`Instance`](@ref) of the dynamic vehicle scheduling benchmark.
8896The seed of the environment is randomly generated using the provided random number generator.
8997"""
90- function Utils . generate_environment (
98+ function generate_environment (
9199 :: DynamicVehicleSchedulingBenchmark , instance:: Instance , rng:: AbstractRNG ; kwargs...
92100)
93101 seed = rand (rng, 1 : typemax (Int))
107115"""
108116$TYPEDSIGNATURES
109117
110- Generate a scenario for the dynamic vehicle scheduling benchmark.
111- This is a wrapper around the generic scenario generation function.
112- """
113- function Utils. generate_scenario (b:: DynamicVehicleSchedulingBenchmark , args... ; kwargs... )
114- return Utils. generate_scenario (args... ; kwargs... )
115- end
116-
117- """
118- $TYPEDSIGNATURES
119-
120118Generate an anticipative solution for the dynamic vehicle scheduling benchmark.
121119The solution is computed using the anticipative solver with the benchmark's feature configuration.
122120"""
131129"""
132130$TYPEDSIGNATURES
133131
132+ Return the anticipative solver for the dynamic vehicle scheduling benchmark.
133+ The callable takes a scenario and solver kwargs (including `instance`) and returns a
134+ training trajectory as a `Vector{DataSample}`.
135+ """
136+ function Utils. generate_anticipative_solver (:: DynamicVehicleSchedulingBenchmark )
137+ return (scenario; instance, kwargs... ) -> begin
138+ env = DVSPEnv (instance, scenario)
139+ _, trajectory = anticipative_solver (env; reset_env= false , kwargs... )
140+ return trajectory
141+ end
142+ end
143+
144+ """
145+ $TYPEDSIGNATURES
146+
134147Generate baseline policies for the dynamic vehicle scheduling benchmark.
135148Returns a tuple containing:
136149- `lazy`: A policy that dispatches vehicles only when they are ready
0 commit comments