Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/tutorials/warcraft_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ opt_state = Flux.setup(Adam(1e-3), model)
loss_history = Float64[]
for epoch in 1:50
val, grads = Flux.withgradient(model) do m
sum(loss(m(x), y) for (; x, y) in train_dataset) / length(train_dataset)
return sum(loss(m(x), y) for (; x, y) in train_dataset) / length(train_dataset)
end
Flux.update!(opt_state, model, grads[1])
push!(loss_history, val)
Expand Down
23 changes: 11 additions & 12 deletions src/DynamicVehicleScheduling/anticipative_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ function anticipative_solver(
job_indices = 2:nb_nodes
epoch_indices = T

@variable(model, y[i=1:nb_nodes, j=1:nb_nodes, t=epoch_indices]; binary=true)
@variable(model, y[i = 1:nb_nodes, j = 1:nb_nodes, t = epoch_indices]; binary=true)

@objective(
model,
Max,
sum(
-duration[i, j] * y[i, j, t] for i in 1:nb_nodes, j in 1:nb_nodes,
t in epoch_indices
-duration[i, j] * y[i, j, t] for
i in 1:nb_nodes, j in 1:nb_nodes, t in epoch_indices
)
)

Expand Down Expand Up @@ -172,14 +172,12 @@ function anticipative_solver(
routes = epoch_routes[i]
epoch_customers = epoch_indices[i]

y_true =
VSPSolution(
Vector{Int}[
map(idx -> findfirst(==(idx), epoch_customers), route) for
route in routes
];
max_index=length(epoch_customers),
).edge_matrix
y_true = VSPSolution(
Vector{Int}[
map(idx -> findfirst(==(idx), epoch_customers), route) for route in routes
];
max_index=length(epoch_customers),
).edge_matrix

location_indices = customer_index[epoch_customers]
new_coordinates = env.instance.static_instance.coordinate[location_indices]
Expand All @@ -203,7 +201,8 @@ function anticipative_solver(
is_must_dispatch[2:end] .= true
else
is_must_dispatch[2:end] .=
planning_start_time .+ epoch_duration .+ @view(new_duration[1, 2:end]) .> new_start_time[2:end]
planning_start_time .+ epoch_duration .+ @view(new_duration[1, 2:end]) .>
new_start_time[2:end]
end
is_postponable[2:end] .= .!is_must_dispatch[2:end]
# TODO: avoid code duplication with add_new_customers!
Expand Down
6 changes: 2 additions & 4 deletions src/DynamicVehicleScheduling/maximizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function prize_collecting_vsp(
nb_nodes = nv(graph)
job_indices = 2:(nb_nodes)

@variable(model, y[i=1:nb_nodes, j=1:nb_nodes; has_edge(graph, i, j)] >= 0)
@variable(model, y[i = 1:nb_nodes, j = 1:nb_nodes; has_edge(graph, i, j)] >= 0)

θ_ext = fill(0.0, location_count(instance)) # no prize for must dispatch requests, only hard constraints
θ_ext[instance.is_postponable] .= θ
Expand Down Expand Up @@ -130,9 +130,7 @@ end

function oracle(θ; instance::DVSPState, kwargs...)
routes = prize_collecting_vsp(θ; instance=instance, kwargs...)
return VSPSolution(
routes; max_index=location_count(instance.state_instance)
).edge_matrix
return VSPSolution(routes; max_index=location_count(instance.state_instance)).edge_matrix
end

function g(y; instance, kwargs...)
Expand Down
4 changes: 2 additions & 2 deletions src/StochasticVehicleScheduling/instance/instance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function create_VSP_graph(city::City)
job_tasks = 2:(city.nb_tasks + 1)

travel_times = [
distance(task1.end_point, task2.start_point) for task1 in city.tasks,
task2 in city.tasks
distance(task1.end_point, task2.start_point) for
task1 in city.tasks, task2 in city.tasks
]

# Create existing edges
Expand Down
2 changes: 1 addition & 1 deletion src/StochasticVehicleScheduling/maximizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function vsp_maximizer(
nb_nodes = nv(graph)
job_indices = 2:(nb_nodes - 1)

@variable(model, y[i=1:nb_nodes, j=1:nb_nodes; has_edge(graph, i, j)], Bin)
@variable(model, y[i = 1:nb_nodes, j = 1:nb_nodes; has_edge(graph, i, j)], Bin)

@objective(
model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function solve_deterministic_VSP(
(; city, graph) = instance

travel_times = [
distance(task1.end_point, task2.start_point) for task1 in city.tasks,
task2 in city.tasks
distance(task1.end_point, task2.start_point) for
task1 in city.tasks, task2 in city.tasks
]

model = model_builder()
Expand All @@ -21,7 +21,7 @@ function solve_deterministic_VSP(
nb_nodes = nv(graph)
job_indices = 2:(nb_nodes - 1)

@variable(model, x[i=1:nb_nodes, j=1:nb_nodes; has_edge(graph, i, j)], Bin)
@variable(model, x[i = 1:nb_nodes, j = 1:nb_nodes; has_edge(graph, i, j)], Bin)

@objective(
model,
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/data_sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Transform the features in the dataset.
function StatsBase.transform(t, dataset::AbstractVector{<:DataSample})
return map(dataset) do d
(; context, extra, x, θ, y) = d
DataSample(; x=StatsBase.transform(t, x), θ, y, context..., extra)
return DataSample(; x=StatsBase.transform(t, x), θ, y, context..., extra)
end
end

Expand All @@ -207,7 +207,7 @@ Reconstruct the features in the dataset.
function StatsBase.reconstruct(t, dataset::AbstractVector{<:DataSample})
return map(dataset) do d
(; context, extra, x, θ, y) = d
DataSample(StatsBase.reconstruct(t, x), θ, y, context, extra)
return DataSample(StatsBase.reconstruct(t, x), θ, y, context, extra)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ DecisionFocusedLearningBenchmarks = {path = ".."}

[compat]
Aqua = "0.8.14"
JuliaFormatter = "1"
JuliaFormatter = "2"
Test = "1"
2 changes: 1 addition & 1 deletion test/contextual_stochastic_argmax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end
maximizer = generate_maximizer(saa)
labeled = map(dataset) do s
y_saa = maximizer(mean(s.scenarios))
DataSample(; s.context..., x=s.x, y=y_saa, extra=s.extra)
return DataSample(; s.context..., x=s.x, y=y_saa, extra=s.extra)
end
@test sum(first(labeled).y) ≈ 1.0

Expand Down