Skip to content

Commit d9c3fd9

Browse files
committed
try to fix tests in CI
1 parent a66f67e commit d9c3fd9

23 files changed

Lines changed: 131 additions & 101 deletions

Project.toml

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ uuid = "2fbe496a-299b-4c81-bab5-c44dfc55cf20"
33
authors = ["Members of JuliaDecisionFocusedLearning"]
44
version = "0.3.0"
55

6+
[workspace]
7+
projects = ["docs", "test"]
8+
69
[deps]
710
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
811
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
@@ -65,22 +68,3 @@ SparseArrays = "1"
6568
Statistics = "1"
6669
StatsBase = "0.34.4"
6770
julia = "1.10"
68-
69-
[extras]
70-
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
71-
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
72-
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
73-
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
74-
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
75-
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
76-
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
77-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
78-
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
79-
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
80-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
81-
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
82-
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
83-
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
84-
85-
[targets]
86-
test = ["Aqua", "Documenter", "Flux", "Graphs", "JET", "JuliaFormatter", "Random", "ProgressMeter", "StableRNGs", "Statistics", "Test", "TestItemRunner", "UnicodePlots", "Zygote"]

src/DynamicVehicleScheduling/anticipative_solver.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ function retrieve_routes_anticipative(
2121
current_task = task
2222
while current_task != 1 # < nb_tasks
2323
push!(route, current_task)
24-
local next_task
24+
next_task = -1
2525
for i in 1:nb_tasks
2626
if isapprox(y[current_task, i, t], 1; atol=0.1)
2727
next_task = i
2828
break
2929
end
3030
end
31+
@assert next_task != -1 "No next task found from task $current_task at epoch $t"
3132
current_task = next_task
3233
end
3334
push!(routes[i], route)
@@ -92,14 +93,14 @@ function anticipative_solver(
9293
job_indices = 2:nb_nodes
9394
epoch_indices = T
9495

95-
@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)
9697

9798
@objective(
9899
model,
99100
Max,
100101
sum(
101-
-duration[i, j] * y[i, j, t] for
102-
i in 1:nb_nodes, j in 1:nb_nodes, t in epoch_indices
102+
-duration[i, j] * y[i, j, t] for i in 1:nb_nodes, j in 1:nb_nodes,
103+
t in epoch_indices
103104
)
104105
)
105106

@@ -171,12 +172,14 @@ function anticipative_solver(
171172
routes = epoch_routes[i]
172173
epoch_customers = epoch_indices[i]
173174

174-
y_true = VSPSolution(
175-
Vector{Int}[
176-
map(idx -> findfirst(==(idx), epoch_customers), route) for route in routes
177-
];
178-
max_index=length(epoch_customers),
179-
).edge_matrix
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
180183

181184
location_indices = customer_index[epoch_customers]
182185
new_coordinates = env.instance.static_instance.coordinate[location_indices]
@@ -200,8 +203,7 @@ function anticipative_solver(
200203
is_must_dispatch[2:end] .= true
201204
else
202205
is_must_dispatch[2:end] .=
203-
planning_start_time .+ epoch_duration .+ @view(new_duration[1, 2:end]) .>
204-
new_start_time[2:end]
206+
planning_start_time .+ epoch_duration .+ @view(new_duration[1, 2:end]) .> new_start_time[2:end]
205207
end
206208
is_postponable[2:end] .= .!is_must_dispatch[2:end]
207209
# TODO: avoid code duplication with add_new_customers!

src/DynamicVehicleScheduling/maximizer.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ function retrieve_routes(y::AbstractArray, graph::AbstractGraph)
6262
current_task = task
6363
while current_task != 1 # < nb_tasks
6464
push!(route, current_task)
65-
local next_task
65+
next_task = -1
6666
for i in outneighbors(graph, current_task)
6767
if isapprox(y[current_task, i], 1; atol=0.1)
6868
next_task = i
6969
break
7070
end
7171
end
72+
@assert next_task != -1 "No next task found from task $current_task"
7273
current_task = next_task
7374
end
7475
push!(routes, route)
@@ -93,7 +94,7 @@ function prize_collecting_vsp(
9394
nb_nodes = nv(graph)
9495
job_indices = 2:(nb_nodes)
9596

96-
@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)
9798

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

130131
function oracle(θ; instance::DVSPState, kwargs...)
131132
routes = prize_collecting_vsp(θ; instance=instance, kwargs...)
132-
return VSPSolution(routes; max_index=location_count(instance.state_instance)).edge_matrix
133+
return VSPSolution(
134+
routes; max_index=location_count(instance.state_instance)
135+
).edge_matrix
133136
end
134137

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

src/DynamicVehicleScheduling/static_vsp/parsing.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Normalize all time values by the `normalization` parameter.
1010
function read_vsp_instance(filepath::String; normalization=3600.0, digits=2)
1111
type = Float64 #rounded ? Int : Float64
1212
mode = ""
13-
local edge_weight_type
14-
local edge_weight_format
13+
edge_weight_type = ""
14+
edge_weight_format = ""
1515
duration_matrix = Vector{type}[]
1616
nb_locations = 0
17-
local demand
18-
local service_time
19-
local coordinates
20-
local start_time
17+
demand = type[]
18+
service_time = type[]
19+
coordinates = Matrix{type}(undef, 0, 2)
20+
start_time = type[]
2121

2222
file = open(filepath, "r")
2323
for line in eachline(file)

src/StochasticVehicleScheduling/instance/instance.jl

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

4141
travel_times = [
42-
distance(task1.end_point, task2.start_point) for
43-
task1 in city.tasks, task2 in city.tasks
42+
distance(task1.end_point, task2.start_point) for task1 in city.tasks,
43+
task2 in city.tasks
4444
]
4545

4646
# 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
15-
task1 in city.tasks, task2 in city.tasks
14+
distance(task1.end_point, task2.start_point) for task1 in city.tasks,
15+
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/policy.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ function evaluate_policy!(
3838
reset!(env; reset_rng=true, seed=seed)
3939
end
4040
total_reward = 0.0
41-
local labeled_dataset
41+
labeled_dataset = DataSample[]
4242
while !is_terminated(env)
4343
y = policy(env; kwargs...)
4444
features, state = observe(env)
4545
state_copy = deepcopy(state) # To avoid mutation issues
4646
reward = step!(env, y)
4747
sample = DataSample(; x=features, y=y, state=state_copy, reward=reward)
48-
if @isdefined labeled_dataset
49-
push!(labeled_dataset, sample)
48+
if isempty(labeled_dataset)
49+
labeled_dataset = typeof(sample)[sample]
5050
else
51-
labeled_dataset = [sample]
51+
push!(labeled_dataset, sample)
5252
end
5353
total_reward += reward
5454
end

test/Project.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[deps]
2+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3+
DecisionFocusedLearningBenchmarks = "2fbe496a-299b-4c81-bab5-c44dfc55cf20"
4+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
5+
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
6+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
7+
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
8+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
9+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
10+
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
11+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
12+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
13+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
14+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
15+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
16+
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
17+
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
18+
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
19+
20+
[sources]
21+
DecisionFocusedLearningBenchmarks = {path = ".."}
22+
23+
[compat]
24+
Aqua = "0.8.14"
25+
Test = "1"

test/argmax.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testitem "Argmax" begin
1+
@testset "Argmax" begin
22
using DecisionFocusedLearningBenchmarks
33

44
instance_dim = 10

0 commit comments

Comments
 (0)