diff --git a/docs/src/tutorials/warcraft_tutorial.jl b/docs/src/tutorials/warcraft_tutorial.jl index b3a2368e..ddc490ed 100644 --- a/docs/src/tutorials/warcraft_tutorial.jl +++ b/docs/src/tutorials/warcraft_tutorial.jl @@ -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) diff --git a/src/DynamicVehicleScheduling/anticipative_solver.jl b/src/DynamicVehicleScheduling/anticipative_solver.jl index b44f0e86..dcea3dfc 100644 --- a/src/DynamicVehicleScheduling/anticipative_solver.jl +++ b/src/DynamicVehicleScheduling/anticipative_solver.jl @@ -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 ) ) @@ -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] @@ -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! diff --git a/src/DynamicVehicleScheduling/maximizer.jl b/src/DynamicVehicleScheduling/maximizer.jl index 8c7e2726..ba0be2be 100644 --- a/src/DynamicVehicleScheduling/maximizer.jl +++ b/src/DynamicVehicleScheduling/maximizer.jl @@ -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] .= θ @@ -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...) diff --git a/src/StochasticVehicleScheduling/instance/instance.jl b/src/StochasticVehicleScheduling/instance/instance.jl index 919cef0d..fe420596 100644 --- a/src/StochasticVehicleScheduling/instance/instance.jl +++ b/src/StochasticVehicleScheduling/instance/instance.jl @@ -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 diff --git a/src/StochasticVehicleScheduling/maximizer.jl b/src/StochasticVehicleScheduling/maximizer.jl index 66e9eb32..515d9892 100644 --- a/src/StochasticVehicleScheduling/maximizer.jl +++ b/src/StochasticVehicleScheduling/maximizer.jl @@ -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, diff --git a/src/StochasticVehicleScheduling/solution/algorithms/local_search.jl b/src/StochasticVehicleScheduling/solution/algorithms/local_search.jl index 49ae00c0..87fe47b5 100644 --- a/src/StochasticVehicleScheduling/solution/algorithms/local_search.jl +++ b/src/StochasticVehicleScheduling/solution/algorithms/local_search.jl @@ -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() @@ -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, diff --git a/src/Utils/data_sample.jl b/src/Utils/data_sample.jl index 1a7002de..c63230a3 100644 --- a/src/Utils/data_sample.jl +++ b/src/Utils/data_sample.jl @@ -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 @@ -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 diff --git a/test/Project.toml b/test/Project.toml index c50fef39..aba6b3c5 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -22,5 +22,5 @@ DecisionFocusedLearningBenchmarks = {path = ".."} [compat] Aqua = "0.8.14" -JuliaFormatter = "1" +JuliaFormatter = "2" Test = "1" diff --git a/test/contextual_stochastic_argmax.jl b/test/contextual_stochastic_argmax.jl index 79533ccf..04a7d9ad 100644 --- a/test/contextual_stochastic_argmax.jl +++ b/test/contextual_stochastic_argmax.jl @@ -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