API Reference

Interface

DecisionFocusedLearningBenchmarks.Utils.DataSampleType
struct DataSample{I, F<:Union{Nothing, AbstractArray}, S<:Union{Nothing, AbstractArray}, C<:Union{Nothing, AbstractArray}}

Data sample data structure.

Fields

  • x::Union{Nothing, AbstractArray}: features

  • θ_true::Union{Nothing, AbstractArray}: target cost parameters (optional)

  • y_true::Union{Nothing, AbstractArray}: target solution (optional)

  • instance::Any: instance object (optional)

source
DecisionFocusedLearningBenchmarks.Utils.compute_gapFunction
compute_gap(
    bench::AbstractBenchmark,
    dataset::AbstractVector{<:DataSample},
    statistical_model,
    maximizer
) -> Any
compute_gap(
    bench::AbstractBenchmark,
    dataset::AbstractVector{<:DataSample},
    statistical_model,
    maximizer,
    op
) -> Any

Default behaviour of compute_gap for a benchmark problem where features, solutions and costs are all defined.

source
DecisionFocusedLearningBenchmarks.Utils.evaluate_policy!Function
evaluate_policy!(
    policy,
    envs::Vector{<:AbstractEnvironment};
    ...
) -> Tuple{Vector{Float64}, Any}
evaluate_policy!(
    policy,
    envs::Vector{<:AbstractEnvironment},
    episodes::Int64;
    kwargs...
) -> Tuple{Vector{Float64}, Any}

Run the policy on the environments and return the total rewards and a dataset of observations. By default, the environments are reset before running the policy.

source
DecisionFocusedLearningBenchmarks.Utils.evaluate_policy!Method
evaluate_policy!(
    policy,
    env::AbstractEnvironment,
    episodes::Int64;
    seed,
    kwargs...
) -> Tuple{Any, Any}

Evaluate the policy on the environment and return the total reward and a dataset of observations. By default, the environment is reset before running the policy.

source
DecisionFocusedLearningBenchmarks.Utils.evaluate_policy!Method
evaluate_policy!(
    policy,
    env::AbstractEnvironment;
    kwargs...
) -> Tuple{Any, Union{Vector{T} where T<:(DataSample{Nothing, F, S, Nothing} where {F<:Union{Nothing, AbstractArray}, S<:Union{Nothing, AbstractArray}}), Vector{T} where T<:(DataSample{I, F, S, Nothing} where {I<:DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPState, F<:Union{Nothing, AbstractArray}, S<:Union{Nothing, AbstractArray}})}}

Run the policy on the environment and return the total reward and a dataset of observations. By default, the environment is reset before running the policy.

source
DecisionFocusedLearningBenchmarks.Utils.generate_sampleFunction
generate_sample(::AbstractBenchmark, rng::AbstractRNG; kwargs...) -> DataSample

Generate a single DataSample for given benchmark. This is a low-level function that is used by generate_dataset to create a dataset of samples. It is not mandatory to implement this method, but it is recommended for benchmarks that have a well-defined way to generate individual samples. An alternative is to directly implement generate_dataset to create a dataset without generating individual samples.

source
DecisionFocusedLearningBenchmarks.Utils.grid_graphMethod
grid_graph(
    costs::AbstractArray{R, 2};
    acyclic
) -> SimpleWeightedGraphs.SimpleWeightedDiGraph{Int64}

Convert a grid of cell costs into a weighted directed graph from SimpleWeightedGraphs.jl, where the vertices correspond to the cells and the edges are weighted by the cost of the arrival cell.

  • If acyclic = false, a cell has edges to each one of its 8 neighbors.
  • If acyclic = true, a cell has edges to its south, east and southeast neighbors only (ensures an acyclic graph where topological sort will work)

This can be used to model the Warcraft shortest paths problem of

Differentiation of Blackbox Combinatorial Solvers, Vlastelica et al. (2019)

source
DecisionFocusedLearningBenchmarks.Utils.observeFunction
observe(env::AbstractEnvironment) --> Tuple

Get the current observation from the environment. This function should return a tuple of two elements: 1. An array of features representing the current state of the environment. 2. An internal state of the environment, which can be used for further processing (return nothing if not needed).

source
DecisionFocusedLearningBenchmarks.Utils.reset!Function
reset!(env::AbstractEnvironment; reset_rng::Bool, seed=get_seed(env)) --> Nothing

Reset the environment to its initial state. If reset_rng is true, the random number generator is reset to the given seed.

source
DecisionFocusedLearningBenchmarks.Utils.step!Function
step!(env::AbstractEnvironment, action) --> Float64

Perform a step in the environment with the given action. Returns the reward received after taking the action. This function may also update the internal state of the environment. If the environment is terminated, it should raise an error.

source
StatsAPI.fitMethod
fit(
    transform_type,
    dataset::AbstractVector{<:DataSample};
    kwargs...
) -> Distributions.Cauchy

Fit the given transform type (ZScoreTransform or UnitRangeTransform) on the dataset.

source
StatsBase.reconstruct!Method
reconstruct!(t, dataset::AbstractVector{<:DataSample})

Reconstruct the features in the dataset in place.

source
StatsBase.reconstructMethod
reconstruct(t, dataset::AbstractVector{<:DataSample}) -> Any

Reconstruct the features in the dataset.

source
StatsBase.transform!Method
transform!(t, dataset::AbstractVector{<:DataSample})

Transform the features in the dataset in place.

source
StatsBase.transformMethod
transform(t, dataset::AbstractVector{<:DataSample}) -> Any

Transform the features in the dataset.

source

Argmax2D

Argmax

DecisionFocusedLearningBenchmarks.Argmax.ArgmaxBenchmarkType
struct ArgmaxBenchmark{E} <: AbstractBenchmark

Basic benchmark problem with an argmax as the CO algorithm.

Fields

  • instance_dim::Int64: instances dimension, total number of classes

  • nb_features::Int64: number of features

  • encoder::Any: true mapping between features and costs

source
DecisionFocusedLearningBenchmarks.Utils.generate_sampleMethod
generate_sample(
    bench::ArgmaxBenchmark,
    rng::Random.AbstractRNG;
    noise_std
) -> DataSample{Nothing, Matrix{Float32}}

Generate a data sample for the argmax benchmark. This function generates a random feature matrix, computes the costs using the encoder, and adds noise to the costs before computing a target solution.

source

Dynamic Vehicle Scheduling

DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DynamicVehicleSchedulingBenchmarkType
struct DynamicVehicleSchedulingBenchmark <: AbstractDynamicBenchmark{true}

Abstract type for dynamic vehicle scheduling benchmarks.

Fields

  • max_requests_per_epoch::Int64: maximum number of customers entering the system per epoch

  • Δ_dispatch::Float64: time between decision and dispatch of a vehicle

  • epoch_duration::Float64: duration of an epoch

  • two_dimensional_features::Bool: whether to use two-dimensional features

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPEnvMethod
DVSPEnv(
    instance::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.Instance;
    seed
) -> DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPEnv{DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPState{DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.StaticInstance{Float64}}, Random.MersenneTwister, Nothing}

Constructor for DVSPEnv.

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.StaticInstanceType
struct StaticInstance{T}

Instance data structure for the (deterministic and static) Vehicle Scheduling Problem.

Fields

  • coordinate::Array{DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.Point{T}, 1} where T: coordinates of the locations. The first one is always the depot.

  • service_time::Vector: service time at each location

  • start_time::Vector: start time at each location

  • duration::Matrix: duration matrix between locations

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.VSPSolutionType
struct VSPSolution

Solution for the static Vehicle Scheduling Problem.

Fields

  • routes::Vector{Vector{Int64}}: list of routes, each route being a list of request indices in corresponding instance (excluding the depot).

  • edge_matrix::BitMatrix: size (nblocations, nblocations). edge_matrix[i, j] is equal to 1 if a route takes edge (i, j).

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.animate_epochsMethod
animate_epochs(
    data_samples::Vector{<:DataSample};
    filename,
    fps,
    figsize,
    margin,
    legend_margin_factor,
    titlefontsize,
    guidefontsize,
    legendfontsize,
    tickfontsize,
    show_axis_labels,
    kwargs...
) -> Plots.Animation

Create an animated GIF showing the evolution of states and routes over epochs. Each frame shows the state and routes for one epoch.

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.anticipative_solverFunction
anticipative_solver(
    env::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPEnv;
    ...
) -> Tuple{Union{Float64, Vector{Float64}}, Vector}
anticipative_solver(
    env::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPEnv,
    scenario;
    model_builder,
    two_dimensional_features,
    reset_env,
    nb_epochs,
    seed,
    verbose
) -> Tuple{Union{Float64, Vector{Float64}}, Vector}

Solve the anticipative VSP problem for environment env. For this, it uses the current environment history, so make sure that the environment is terminated before calling this method.

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.costMethod
cost(
    routes::Vector{Vector{Int64}},
    duration::AbstractMatrix
) -> Any

Compute the total cost of a set of routes given a distance matrix, i.e. the sum of the distances between each location in the route. Note that the first location is implicitly assumed to be the depot, and should not appear in the route.

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.is_feasibleMethod
is_feasible(
    state::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPState,
    routes::Vector{Vector{Int64}};
    verbose
) -> Bool

Check if the given routes are feasible. Routes should be given with global indexation. Use env_routes_from_state_routes if needed to convert the indices beforehand.

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.plot_epochsMethod
plot_epochs(
    data_samples::Vector{<:DataSample};
    plot_routes_flag,
    cols,
    figsize,
    margin,
    legend_margin_factor,
    titlefontsize,
    guidefontsize,
    legendfontsize,
    tickfontsize,
    show_axis_labels,
    show_colorbar,
    kwargs...
) -> Any

Plot multiple epochs side by side from a vector of DataSample objects. Each DataSample should contain an instance (DVSPState) and optionally y_true (routes). All subplots will use the same xlims and ylims to show the dynamics clearly.

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.plot_routesMethod
plot_routes(
    state::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPState,
    routes::BitMatrix;
    kwargs...
) -> Plots.Plot

Plot a given DVSPState with routes overlaid. This version accepts routes as a BitMatrix where entry (i,j) = true indicates an edge from location i to location j.

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.plot_routesMethod
plot_routes(
    state::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPState,
    routes::Vector{Vector{Int64}};
    route_colors,
    route_linewidth,
    route_alpha,
    show_route_labels,
    kwargs...
) -> Plots.Plot

Plot a given DVSPState with routes overlaid, showing depot, requests, and vehicle routes. Routes should be provided as a vector of vectors, where each inner vector contains the indices of locations visited by that route (excluding the depot).

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.plot_stateMethod
plot_state(
    state::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPState;
    customer_markersize,
    depot_markersize,
    alpha_depot,
    depot_color,
    must_dispatch_color,
    postponable_color,
    show_axis_labels,
    markerstrokewidth,
    kwargs...
) -> Plots.Plot

Plot a given DVSPState showing depot, must-dispatch requests, and postponable requests.

source
DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.read_vsp_instanceMethod
read_vsp_instance(
    filepath::String;
    rounded,
    normalization
) -> DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.StaticInstance

Create a VSPInstance from file filepath containing a VRPTW instance. It uses time window values to compute task times as the middle of the interval.

Round all values to Int if rounded=true. Normalize all time values by the normalization parameter.

source
DecisionFocusedLearningBenchmarks.Utils.observeMethod
observe(
    env::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPEnv
) -> Tuple{Any, DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPState}

Get the current state of the environment.

source
DecisionFocusedLearningBenchmarks.Utils.reset!Method
reset!(
    env::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPEnv;
    seed,
    reset_rng
)

Reset the environment to its initial state. Also reset the rng to seed if reset_rng is set to true.

source
DecisionFocusedLearningBenchmarks.Utils.step!Function
step!(
    env::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPEnv,
    routes
) -> Any
step!(
    env::DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling.DVSPEnv,
    routes,
    scenario
) -> Any

Remove dispatched customers, advance time, and add new requests to the environment.

source

Dynamic Assortment

DecisionFocusedLearningBenchmarks.DynamicAssortment.DynamicAssortmentBenchmarkType
struct DynamicAssortmentBenchmark{exogenous, M} <: AbstractDynamicBenchmark{exogenous}

Benchmark for the dynamic assortment problem.

Fields

  • customer_choice_model::Any: customer choice model (price, hype, saturation, and features)

  • N::Int64: number of items

  • d::Int64: dimension of feature vectors (in addition to hype, satisfaction, and price)

  • K::Int64: assortment size constraint

  • max_steps::Int64: number of steps per episode

Reference: https://arxiv.org/abs/2505.19053

source
DecisionFocusedLearningBenchmarks.DynamicAssortment.EnvironmentType
mutable struct Environment{I<:DecisionFocusedLearningBenchmarks.DynamicAssortment.Instance, R<:Random.AbstractRNG, S<:Union{Nothing, Int64}} <: AbstractEnvironment

Environment for the dynamic assortment problem.

Fields

  • instance::DecisionFocusedLearningBenchmarks.DynamicAssortment.Instance: associated instance

  • step::Int64: current step

  • purchase_history::Vector{Int64}: purchase history (used to update hype feature)

  • rng::Random.AbstractRNG: rng

  • seed::Union{Nothing, Int64}: seed for RNG

  • utility::Vector{Float64}: customer utility for each item

  • features::Matrix{Float64}: current full features

  • d_features::Matrix{Float64}: satisfaction + hype feature change from the last step

source
DecisionFocusedLearningBenchmarks.DynamicAssortment.InstanceType
struct Instance{B<:DynamicAssortmentBenchmark}

Instance of the dynamic assortment problem.

Fields

  • config::DynamicAssortmentBenchmark: associated benchmark

  • prices::Vector{Float64}: item prices (including no purchase action)

  • features::Matrix{Float64}: static features, size (d, N)

  • starting_hype_and_saturation::Matrix{Float64}: starting hype and saturation features, size (2, N)

source
DecisionFocusedLearningBenchmarks.DynamicAssortment.InstanceMethod
Instance(
    b::DynamicAssortmentBenchmark,
    rng::Random.AbstractRNG
) -> DecisionFocusedLearningBenchmarks.DynamicAssortment.Instance

Generates a random instance:

  • random prices uniformly in [1, 10]
  • random features uniformly in [1, 10]
  • random starting hype and saturation uniformly in [1, 10]
source
DecisionFocusedLearningBenchmarks.DynamicAssortment.hype_updateMethod
hype_update(
    env::DecisionFocusedLearningBenchmarks.DynamicAssortment.Environment
) -> Vector{Float64}

Compute an hype multiplier vector based on the purchase history. The hype multiplier (equal to 1 by default) for each item is updated as follows:

  • If the item was purchased in the last step, its hype multiplier increases by 0.02.
  • If the item was purchased in the last 2 to 5 steps, its hype multiplier decreases by 0.005.
source
DecisionFocusedLearningBenchmarks.Utils.generate_environmentMethod
generate_environment(
    ::DynamicAssortmentBenchmark,
    instance::DecisionFocusedLearningBenchmarks.DynamicAssortment.Instance,
    rng::Random.AbstractRNG;
    kwargs...
) -> DecisionFocusedLearningBenchmarks.DynamicAssortment.Environment{I, Random.MersenneTwister, Int64} where I<:DecisionFocusedLearningBenchmarks.DynamicAssortment.Instance

Creates an Environment from an Instance of the dynamic assortment benchmark. The seed of the environment is randomly generated using the provided random number generator.

source
DecisionFocusedLearningBenchmarks.Utils.generate_policiesMethod
generate_policies(
    _::DynamicAssortmentBenchmark
) -> Tuple{Policy{typeof(DecisionFocusedLearningBenchmarks.DynamicAssortment.expert_policy)}, Policy{typeof(DecisionFocusedLearningBenchmarks.DynamicAssortment.greedy_policy)}}

Returns two policies for the dynamic assortment benchmark:

  • Greedy: selects the assortment containing items with the highest prices
  • Expert: selects the assortment with the highest expected revenue (through brute-force enumeration)
source
DecisionFocusedLearningBenchmarks.Utils.generate_sampleFunction
generate_sample(
    b::DynamicAssortmentBenchmark
) -> DataSample{I, Nothing, Nothing, Nothing} where I<:DecisionFocusedLearningBenchmarks.DynamicAssortment.Instance
generate_sample(
    b::DynamicAssortmentBenchmark,
    rng::Random.AbstractRNG
) -> DataSample{I, Nothing, Nothing, Nothing} where I<:DecisionFocusedLearningBenchmarks.DynamicAssortment.Instance

Outputs a data sample containing an Instance.

source
DecisionFocusedLearningBenchmarks.Utils.generate_statistical_modelMethod
generate_statistical_model(
    b::DynamicAssortmentBenchmark;
    seed
) -> Flux.Chain{T} where T<:Tuple{Flux.Dense{typeof(identity), Matrix{Float32}}, Flux.Dense{typeof(identity), Matrix{Float32}}, typeof(vec)}

Generates a statistical model for the dynamic assortment benchmark. The model is a small neural network with one hidden layer of size 5 and no activation function.

source
DecisionFocusedLearningBenchmarks.Utils.observeMethod
observe(
    env::DecisionFocusedLearningBenchmarks.DynamicAssortment.Environment
) -> Tuple{Matrix{Float64}, Nothing}

Features observed by the agent at current step, as a concatenation of:

  • current full features (including prices, hype, saturation, and static features)
  • change in hype and saturation features from the last step
  • change in hype and saturation features from the starting state
  • normalized current step (divided by max steps and multiplied by 10)

All features are normalized by dividing by 10.

source
DecisionFocusedLearningBenchmarks.Utils.reset!Method
reset!(
    env::DecisionFocusedLearningBenchmarks.DynamicAssortment.Environment;
    reset_rng,
    seed
)

Resets the environment to the initial state:

  • reset the rng if reset_rng is true
  • reset the step to 1
  • reset the features to the initial features
  • reset the change in features to zero
  • reset the utility to the initial utility
  • clear the purchase history
source
DecisionFocusedLearningBenchmarks.Utils.step!Method
step!(
    env::DecisionFocusedLearningBenchmarks.DynamicAssortment.Environment,
    assortment::BitVector
) -> Float64

Performs one step in the environment given an assortment. Draw an item according to the customer choice model and updates the environment state.

source

Fixed-size shortest path

DecisionFocusedLearningBenchmarks.FixedSizeShortestPath.FixedSizeShortestPathBenchmarkType
struct FixedSizeShortestPathBenchmark <: AbstractBenchmark

Benchmark problem for the shortest path problem. In this benchmark, all graphs are acyclic directed grids, all of the same size grid_size. Features are given at instance level (one dimensional vector of length p for each graph).

Data is generated using the process described in: https://arxiv.org/abs/2307.13565.

Fields

  • graph::Graphs.SimpleGraphs.SimpleDiGraph{Int64}: grid graph instance

  • grid_size::Tuple{Int64, Int64}: grid size of graphs

  • p::Int64: size of feature vectors

  • deg::Int64: degree of formula between features and true weights

  • ν::Float32: multiplicative noise for true weights sampled between [1-ν, 1+ν], should be between 0 and 1

source
DecisionFocusedLearningBenchmarks.Utils.generate_maximizerMethod
generate_maximizer(
    bench::FixedSizeShortestPathBenchmark;
    use_dijkstra
) -> DecisionFocusedLearningBenchmarks.FixedSizeShortestPath.var"#shortest_path_maximizer#8"{DecisionFocusedLearningBenchmarks.FixedSizeShortestPath.var"#shortest_path_maximizer#5#9"{typeof(Graphs.dijkstra_shortest_paths), Vector{Int64}, Vector{Int64}, Int64, Int64, Graphs.SimpleGraphs.SimpleDiGraph{Int64}}}

Outputs a function that computes the longest path on the grid graph, given edge weights θ as input.

maximizer = generate_maximizer(bench)
maximizer(θ)
source
DecisionFocusedLearningBenchmarks.Utils.generate_sampleMethod
generate_sample(
    bench::FixedSizeShortestPathBenchmark,
    rng::Random.AbstractRNG;
    type
) -> Union{DataSample{Nothing, Vector{Float32}, BitVector, Vector{Float32}}, DataSample{Nothing, Vector{Float32}, BitVector, Vector{Float64}}}

Generate a labeled sample for the fixed size shortest path benchmark.

source

Portfolio Optimization

DecisionFocusedLearningBenchmarks.PortfolioOptimization.PortfolioOptimizationBenchmarkType
struct PortfolioOptimizationBenchmark <: AbstractBenchmark

Benchmark problem for the portfolio optimization problem.

Data is generated using the process described in: https://arxiv.org/abs/2307.13565.

Fields

  • d::Int64: number of assets

  • p::Int64: size of feature vectors

  • deg::Int64: hypermarameter for data generation

  • ν::Float32: another hyperparameter, should be positive

  • Σ::Matrix{Float32}: covariance matrix

  • γ::Float32: maximum variance of portfolio

  • L::Matrix{Float32}: useful for dataset generation

  • f::Vector{Float32}: useful for dataset generation

source
DecisionFocusedLearningBenchmarks.Utils.generate_maximizerMethod
generate_maximizer(
    bench::PortfolioOptimizationBenchmark
) -> DecisionFocusedLearningBenchmarks.PortfolioOptimization.var"#portfolio_maximizer#3"{Float32, Matrix{Float32}, Int64}

Create a function solving the MIQP formulation of the portfolio optimization problem.

source

Ranking

DecisionFocusedLearningBenchmarks.Ranking.RankingBenchmarkType
struct RankingBenchmark{E} <: AbstractBenchmark

Basic benchmark problem with ranking as the CO algorithm.

Fields

  • instance_dim::Int64: instances dimension, total number of classes

  • nb_features::Int64: number of features

  • encoder::Any: true mapping between features and costs

source

Subset selection

Stochastic Vehicle Scheduling

DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.compact_linearized_mipMethod
compact_linearized_mip(
    instance::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Instance;
    scenario_range,
    model_builder,
    silent
) -> Any

Returns the optimal solution of the Stochastic VSP instance, by solving the associated compact MIP. Quadratic constraints are linearized using Mc Cormick linearization. Note: If you have Gurobi, use grb_model as model_builder instead of highs_model.

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.compact_mipMethod
compact_mip(
    instance::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Instance;
    scenario_range,
    model_builder,
    silent
) -> Any

Returns the optimal solution of the Stochastic VSP instance, by solving the associated compact quadratic MIP. Note: If you have Gurobi, use grb_model as model_builder instead of highs_model.

Warning

You need to use a solver that supports quadratic constraints to use this method.

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.CityType
struct City

Data structure for a city in the vehicle scheduling problem. Contains all the relevant information to build an instance of the problem.

Fields

  • width::Int64: city width (in minutes)

  • vehicle_cost::Float64: cost of a vehicle in the objective function

  • delay_cost::Float64: cost of one minute delay in the objective function

  • nb_tasks::Int64: number of tasks to fulfill

  • tasks::Vector{DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Task}: tasks list (see Task), that should be ordered by start time

  • district_width::Int64: idth (in minutes) of each district

  • districts::Matrix{DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.District}: districts matrix (see District), indices corresponding to their relative positions

  • random_inter_area_factor::Distributions.LogNormal{Float64}: a log-normal distribution modeling delay between districts

  • scenario_inter_area_factor::Matrix{Float64}: size (nb_scenarios, 24), each row correspond to one scenario, each column to one hour of the day

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.DistrictType
struct District

Data structure for a district in the vehicle scheduling problem.

Fields

  • random_delay::Distributions.LogNormal{Float64}: log-normal distribution modeling the district delay

  • scenario_delay::Matrix{Float64}: size (nb_scenarios, 24), observed delays for each scenario and hour of the day

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.InstanceType
struct Instance{CC, G<:Graphs.AbstractGraph, M1<:(AbstractMatrix), M2<:(AbstractMatrix), F, C}

Instance of the stochastic VSP problem.

Fields

  • graph::Graphs.AbstractGraph: graph computed from city with the create_VSP_graph(city::City) method

  • features::Matrix: features matrix computed from city

  • slacks::AbstractMatrix: slack matrix

  • intrinsic_delays::AbstractMatrix: intrinsic delays scenario matrix

  • vehicle_cost::Any: cost of a vehicle

  • delay_cost::Any: cost of one minute delay

  • city::Any: associated city

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.TaskType
struct Task

Data structure for a task in the vehicle scheduling problem.

Fields

  • type::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.TaskType: type of the task (depot start, job, or depot end)

  • start_point::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Point: starting location of the task

  • end_point::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Point: end location of the task

  • start_time::Float64: start time (in minutes) of the task

  • end_time::Float64: end time (in minutes) of the task

  • random_delay::Distributions.LogNormal{Float64}: lognormal distribution modeling the task start delay

  • scenario_start_time::Vector{Float64}: size (nb_scenarios), observed delayed start times for each scenario

  • scenario_end_time::Vector{Float64}: size (nb_scenarios), observed delayed end times for each scenario

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling._local_searchMethod
_local_search(
    solution::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Solution,
    instance::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Instance;
    nb_it
) -> Tuple{DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Solution, Any, Vector{Int64}, Vector}

Very simple local search heuristic, using the neighborhood defined by move_one_random_task

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.compute_featuresMethod
compute_features(
    city::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.City
) -> Matrix{Float32}

Returns a matrix of features of size (20, nb_edges). For each edge, compute the following features (in the same order):

  • travel time
  • vehicle_cost if edge is connected to source, else 0
  • 9 deciles of the slack
  • cumulative probability distribution of the slack evaluated in [-100, -50, -20, -10, 0, 10, 50, 200, 500]
source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.create_VSP_graphMethod
create_VSP_graph(
    city::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.City
) -> Graphs.SimpleGraphs.SimpleDiGraph{Int64}

Return the acyclic directed graph corresponding to city. Each vertex represents a task. Vertices are ordered by start time of corresponding task. There is an edge from task u to task v the (end time of u + tie distance between u and v <= start time of v).

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.create_random_cityMethod
create_random_city(
;
    αᵥ_low,
    αᵥ_high,
    first_begin_time,
    last_begin_time,
    district_μ,
    district_σ,
    task_μ,
    task_σ,
    seed,
    rng,
    city_kwargs...
) -> DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.City
  • Creates a city from city_kwargs
  • Depot location at city center
  • Randomize tasks, and add two dummy tasks : one source task at time=0 from the depot, and one destination task ending at time=end at depot
  • Roll every scenario.
source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.solve_deterministic_VSPMethod
solve_deterministic_VSP(
    instance::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Instance;
    include_delays,
    model_builder,
    verbose
) -> Tuple{Union{Float64, Vector{Float64}}, Any}

Return the optimal solution of the deterministic VSP problem associated to instance. The objective function is vehicle_cost * nb_vehicles + include_delays * delay_cost * sum_of_travel_times Note: If you have Gurobi, use grb_model as model_builder instead od highs_model.

source
DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.to_arrayMethod
to_array(
    solution::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Solution,
    instance::DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling.Instance
) -> Any

Returns a BitMatrix, with value true at each index (i, j) if corresponding edge of graph is selected in the solution

source
DecisionFocusedLearningBenchmarks.Utils.generate_sampleMethod
generate_sample(
    benchmark::StochasticVehicleSchedulingBenchmark,
    rng::Random.AbstractRNG;
    store_city,
    compute_solutions,
    algorithm,
    kwargs...
) -> DataSample{I, Matrix{Float32}, S, Nothing} where {I, S<:Union{Nothing, AbstractArray}}

Generate a sample for the given StochasticVehicleSchedulingBenchmark. If you want to not add label solutions in the sample, set compute_solutions=false. By default, they will be computed using column generation. Note that computing solutions can be time-consuming, especially for large instances. You can also use instead compact_mip or compact_linearized_mip as the algorithm to compute solutions. If you want to provide a custom algorithm to compute solutions, you can pass it as the algorithm keyword argument. If algorithm takes keyword arguments, you can pass them as well directly in kwargs.... If store_city=false, the coordinates and unnecessary information about instances will not be stored in the sample.

source

Warcraft

DecisionFocusedLearningBenchmarks.Utils.generate_datasetFunction
generate_dataset(::WarcraftBenchmark) -> Vector
generate_dataset(
    ::WarcraftBenchmark,
    dataset_size::Int64
) -> Vector

Downloads and decompresses the Warcraft dataset the first time it is called.

Warning

dataset_size is capped at 10000, i.e. the number of available samples in the dataset files.

source
DecisionFocusedLearningBenchmarks.Utils.generate_maximizerMethod
generate_maximizer(
    ::WarcraftBenchmark;
    dijkstra
) -> typeof(DecisionFocusedLearningBenchmarks.Warcraft.dijkstra_maximizer)

Returns an optimization algorithm that computes a longest path on the grid graph with given weights. Uses a shortest path algorithm on opposite weights to get the longest path.

source
DecisionFocusedLearningBenchmarks.Utils.generate_statistical_modelMethod
generate_statistical_model(
    ::WarcraftBenchmark;
    seed
) -> Flux.Chain{T} where T<:Tuple{Any, Any, Any, Any, Flux.AdaptiveMaxPool{4, 2}, typeof(DecisionFocusedLearningBenchmarks.Utils.average_tensor), typeof(DecisionFocusedLearningBenchmarks.Utils.neg_tensor), typeof(DecisionFocusedLearningBenchmarks.Utils.squeeze_last_dims)}

Create and return a Flux.Chain embedding for the Warcraft terrains, inspired by differentiation of blackbox combinatorial solvers.

The embedding is made as follows:

  1. The first 5 layers of ResNet18 (convolution, batch normalization, relu, maxpooling and first resnet block).
  2. An adaptive maxpooling layer to get a (12x12x64) tensor per input image.
  3. An average over the third axis (of size 64) to get a (12x12x1) tensor per input image.
  4. The element-wize neg_tensor function to get cell weights of proper sign to apply shortest path algorithms.
  5. A squeeze function to forget the two last dimensions.
source
DecisionFocusedLearningBenchmarks.Utils.plot_dataMethod
plot_data(
    ::WarcraftBenchmark,
    sample::DataSample;
    θ_true,
    θ_title,
    y_title,
    kwargs...
) -> Any

Plot the content of input DataSample as images. x as the initial image, θ as the weights, and y as the path.

The keyword argument θ_true is used to set the color range of the weights plot.

source
DecisionFocusedLearningBenchmarks.Warcraft.create_datasetMethod
create_dataset(
    decompressed_path::String,
    nb_samples::Int64
) -> Vector

Create the dataset corresponding to the data located at decompressed_path, possibly sub-sampling nb_samples points. The dataset is made of images of Warcraft terrains, cell cost labels and shortest path labels. It is a Vector of tuples, each Tuple being a dataset point.

source
DecisionFocusedLearningBenchmarks.Warcraft.dijkstra_maximizerMethod
dijkstra_maximizer(
    θ::AbstractMatrix;
    kwargs...
) -> Matrix{Int64}

Computes the longest path in given grid graph weights by computing the shortest path in the graph with opposite weights. Using the Dijkstra algorithm.

Warning

Only works on graph with positive weights, i.e. if θ only contains negative values.

source
DecisionFocusedLearningBenchmarks.Warcraft.read_datasetFunction
read_dataset(
    decompressed_path::String
) -> Tuple{Any, Any, Any}
read_dataset(
    decompressed_path::String,
    dtype::String
) -> Tuple{Any, Any, Any}

Read the dataset of type dtype at the decompressed_path location. The dataset is made of images of Warcraft terrains, cell cost labels and shortest path labels. They are returned separately, with proper axis permutation and image scaling to be consistent with Flux embeddings.

source