Skip to content

Commit 29434e7

Browse files
committed
cleanup and fix fixed size shortest path
1 parent fdbc713 commit 29434e7

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

src/FixedSizeShortestPath/FixedSizeShortestPath.jl

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ function Utils.generate_dataset(
125125
[rand(rng, Uniform{type}(1 - ν, 1 + ν), E) for _ in 1:dataset_size]
126126
end
127127
costs = [
128-
(1 .+ (3 .+ B * zᵢ ./ type(sqrt(p))) .^ deg) .* ξᵢ for (ξᵢ, zᵢ) in zip(ξ, features)
128+
-(1 .+ (3 .+ B * zᵢ ./ type(sqrt(p))) .^ deg) .* ξᵢ for (ξᵢ, zᵢ) in zip(ξ, features)
129129
]
130130

131131
shortest_path_maximizer = Utils.generate_maximizer(bench)
132132

133133
# Label solutions
134-
solutions = shortest_path_maximizer.(.-costs)
134+
solutions = shortest_path_maximizer.(costs)
135135
return [DataSample(; x=x, θ=θ, y=y) for (x, θ, y) in zip(features, costs, solutions)]
136136
end
137137

@@ -145,23 +145,6 @@ function Utils.generate_statistical_model(bench::FixedSizeShortestPathBenchmark)
145145
return Chain(Dense(p, ne(graph)))
146146
end
147147

148-
function objective_value(::FixedSizeShortestPathBenchmark, θ, y)
149-
return dot(θ, y)
150-
end
151-
152-
function Utils.compute_gap(
153-
bench::FixedSizeShortestPathBenchmark, model, features, costs, solutions, maximizer
154-
)
155-
res = 0.0
156-
for (x, ȳ, θ̄) in zip(features, solutions, costs)
157-
θ = model(x)
158-
y = maximizer(θ)
159-
val = objective_value(bench, θ̄, ȳ)
160-
res += (objective_value(bench, θ̄, y) - val) / val
161-
end
162-
return res / length(features)
163-
end
164-
165148
export FixedSizeShortestPathBenchmark
166149

167150
end

test/fixed_size_shortest_path.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
model = generate_statistical_model(b)
1515
maximizer = generate_maximizer(b)
1616

17+
gap = compute_gap(b, dataset, model, maximizer)
18+
@test gap >= 0
19+
1720
for sample in dataset
1821
x = sample.x
1922
θ_true = sample.θ
2023
y_true = sample.y
24+
@test all(θ_true .< 0)
2125
@test size(x) == (p,)
2226
@test length(θ_true) == A
2327
@test length(y_true) == A
2428
@test isnothing(sample.instance)
25-
@test all(y_true .== maximizer(-θ_true))
29+
@test all(y_true .== maximizer(θ_true))
2630
θ = model(x)
2731
@test length(θ) == length(θ_true)
2832
y = maximizer(θ)

0 commit comments

Comments
 (0)