-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDynamicVehicleScheduling.jl
More file actions
123 lines (104 loc) · 3.27 KB
/
DynamicVehicleScheduling.jl
File metadata and controls
123 lines (104 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module DynamicVehicleScheduling
using ..Utils
using Base: @kwdef
using DataDeps: @datadep_str
using DocStringExtensions: TYPEDEF, TYPEDFIELDS, TYPEDSIGNATURES
using Flux: Chain, Dense
using Graphs
using HiGHS
using InferOpt: LinearMaximizer
using IterTools: partition
using JSON
using JuMP
using Plots: plot, plot!, scatter!, @animate, Plots, gif
using Printf: @printf, @sprintf
using Random: Random, AbstractRNG, MersenneTwister, seed!, randperm
using Requires: @require
using Statistics: mean, quantile
include("utils.jl")
# static vsp stuff
include("static_vsp/instance.jl")
include("static_vsp/parsing.jl")
include("static_vsp/solution.jl")
include("static_vsp/plot.jl")
include("instance.jl")
include("state.jl")
include("scenario.jl")
include("environment.jl")
include("plot.jl")
include("maximizer.jl")
include("anticipative_solver.jl")
include("features.jl")
include("policy.jl")
"""
$TYPEDEF
Abstract type for dynamic vehicle scheduling benchmarks.
# Fields
$TYPEDFIELDS
"""
@kwdef struct DynamicVehicleSchedulingBenchmark <: AbstractDynamicBenchmark{true}
"maximum number of customers entering the system per epoch"
max_requests_per_epoch::Int = 10
"time between decision and dispatch of a vehicle"
Δ_dispatch::Float64 = 1.0
"duration of an epoch"
epoch_duration::Float64 = 1.0
"whether to use two-dimensional features"
two_dimensional_features::Bool = false
end
function Utils.generate_dataset(b::DynamicVehicleSchedulingBenchmark, dataset_size::Int=1)
(; max_requests_per_epoch, Δ_dispatch, epoch_duration, two_dimensional_features) = b
files = readdir(datadep"dvrptw"; join=true)
dataset_size = min(dataset_size, length(files))
return [
DataSample(;
instance=Instance(
read_vsp_instance(files[i]);
max_requests_per_epoch,
Δ_dispatch,
epoch_duration,
two_dimensional_features,
),
) for i in 1:dataset_size
]
end
function Utils.generate_environment(
::DynamicVehicleSchedulingBenchmark, instance::Instance, rng::AbstractRNG; kwargs...
)
seed = rand(rng, 1:typemax(Int))
return DVSPEnv(instance; seed)
end
function Utils.generate_maximizer(::DynamicVehicleSchedulingBenchmark)
return LinearMaximizer(oracle; g, h)
end
function Utils.generate_scenario(b::DynamicVehicleSchedulingBenchmark, args...; kwargs...)
return Utils.generate_scenario(args...; kwargs...)
end
function Utils.generate_anticipative_solution(
b::DynamicVehicleSchedulingBenchmark, args...; kwargs...
)
return anticipative_solver(
args...; kwargs..., two_dimensional_features=b.two_dimensional_features
)
end
function Utils.generate_policies(b::DynamicVehicleSchedulingBenchmark)
lazy = Policy(
"Lazy",
"Lazy policy that dispatches vehicles only when they are ready.",
lazy_policy,
)
greedy = Policy(
"Greedy",
"Greedy policy that dispatches vehicles to the nearest customer.",
greedy_policy,
)
return (lazy, greedy)
end
function Utils.generate_statistical_model(
b::DynamicVehicleSchedulingBenchmark; seed=nothing
)
Random.seed!(seed)
return Chain(Dense((b.two_dimensional_features ? 2 : 14) => 1), vec)
end
export DynamicVehicleSchedulingBenchmark
end