Skip to content

Commit 761b08c

Browse files
authored
style: bump JuliaFormatter to v2 (#72)
1 parent 612d0d6 commit 761b08c

9 files changed

Lines changed: 24 additions & 27 deletions

File tree

docs/src/tutorials/warcraft_tutorial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ opt_state = Flux.setup(Adam(1e-3), model)
7272
loss_history = Float64[]
7373
for epoch in 1:50
7474
val, grads = Flux.withgradient(model) do m
75-
sum(loss(m(x), y) for (; x, y) in train_dataset) / length(train_dataset)
75+
return sum(loss(m(x), y) for (; x, y) in train_dataset) / length(train_dataset)
7676
end
7777
Flux.update!(opt_state, model, grads[1])
7878
push!(loss_history, val)

src/DynamicVehicleScheduling/anticipative_solver.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ function anticipative_solver(
9393
job_indices = 2:nb_nodes
9494
epoch_indices = T
9595

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

9898
@objective(
9999
model,
100100
Max,
101101
sum(
102-
-duration[i, j] * y[i, j, t] for i in 1:nb_nodes, j in 1:nb_nodes,
103-
t in epoch_indices
102+
-duration[i, j] * y[i, j, t] for
103+
i in 1:nb_nodes, j in 1:nb_nodes, t in epoch_indices
104104
)
105105
)
106106

@@ -172,14 +172,12 @@ function anticipative_solver(
172172
routes = epoch_routes[i]
173173
epoch_customers = epoch_indices[i]
174174

175-
y_true =
176-
VSPSolution(
177-
Vector{Int}[
178-
map(idx -> findfirst(==(idx), epoch_customers), route) for
179-
route in routes
180-
];
181-
max_index=length(epoch_customers),
182-
).edge_matrix
175+
y_true = VSPSolution(
176+
Vector{Int}[
177+
map(idx -> findfirst(==(idx), epoch_customers), route) for route in routes
178+
];
179+
max_index=length(epoch_customers),
180+
).edge_matrix
183181

184182
location_indices = customer_index[epoch_customers]
185183
new_coordinates = env.instance.static_instance.coordinate[location_indices]
@@ -203,7 +201,8 @@ function anticipative_solver(
203201
is_must_dispatch[2:end] .= true
204202
else
205203
is_must_dispatch[2:end] .=
206-
planning_start_time .+ epoch_duration .+ @view(new_duration[1, 2:end]) .> new_start_time[2:end]
204+
planning_start_time .+ epoch_duration .+ @view(new_duration[1, 2:end]) .>
205+
new_start_time[2:end]
207206
end
208207
is_postponable[2:end] .= .!is_must_dispatch[2:end]
209208
# TODO: avoid code duplication with add_new_customers!

src/DynamicVehicleScheduling/maximizer.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function prize_collecting_vsp(
9494
nb_nodes = nv(graph)
9595
job_indices = 2:(nb_nodes)
9696

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

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

131131
function oracle(θ; instance::DVSPState, kwargs...)
132132
routes = prize_collecting_vsp(θ; instance=instance, kwargs...)
133-
return VSPSolution(
134-
routes; max_index=location_count(instance.state_instance)
135-
).edge_matrix
133+
return VSPSolution(routes; max_index=location_count(instance.state_instance)).edge_matrix
136134
end
137135

138136
function g(y; instance, kwargs...)

src/StochasticVehicleScheduling/instance/instance.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ function create_VSP_graph(city::City)
5151
job_tasks = 2:(city.nb_tasks + 1)
5252

5353
travel_times = [
54-
distance(task1.end_point, task2.start_point) for task1 in city.tasks,
55-
task2 in city.tasks
54+
distance(task1.end_point, task2.start_point) for
55+
task1 in city.tasks, task2 in city.tasks
5656
]
5757

5858
# Create existing edges

src/StochasticVehicleScheduling/maximizer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function vsp_maximizer(
1414
nb_nodes = nv(graph)
1515
job_indices = 2:(nb_nodes - 1)
1616

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

1919
@objective(
2020
model,

src/StochasticVehicleScheduling/solution/algorithms/local_search.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function solve_deterministic_VSP(
1111
(; city, graph) = instance
1212

1313
travel_times = [
14-
distance(task1.end_point, task2.start_point) for task1 in city.tasks,
15-
task2 in city.tasks
14+
distance(task1.end_point, task2.start_point) for
15+
task1 in city.tasks, task2 in city.tasks
1616
]
1717

1818
model = model_builder()
@@ -21,7 +21,7 @@ function solve_deterministic_VSP(
2121
nb_nodes = nv(graph)
2222
job_indices = 2:(nb_nodes - 1)
2323

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

2626
@objective(
2727
model,

src/Utils/data_sample.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Transform the features in the dataset.
184184
function StatsBase.transform(t, dataset::AbstractVector{<:DataSample})
185185
return map(dataset) do d
186186
(; context, extra, x, θ, y) = d
187-
DataSample(; x=StatsBase.transform(t, x), θ, y, context..., extra)
187+
return DataSample(; x=StatsBase.transform(t, x), θ, y, context..., extra)
188188
end
189189
end
190190

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

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ DecisionFocusedLearningBenchmarks = {path = ".."}
2222

2323
[compat]
2424
Aqua = "0.8.14"
25-
JuliaFormatter = "1"
25+
JuliaFormatter = "2"
2626
Test = "1"

test/contextual_stochastic_argmax.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ end
9494
maximizer = generate_maximizer(saa)
9595
labeled = map(dataset) do s
9696
y_saa = maximizer(mean(s.scenarios))
97-
DataSample(; s.context..., x=s.x, y=y_saa, extra=s.extra)
97+
return DataSample(; s.context..., x=s.x, y=y_saa, extra=s.extra)
9898
end
9999
@test sum(first(labeled).y) 1.0
100100

0 commit comments

Comments
 (0)