Skip to content

Commit

Permalink
Add VRP test case
Browse files Browse the repository at this point in the history
  • Loading branch information
iagoleal committed Dec 18, 2024
1 parent 84e307d commit 21a7084
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/cases/vrp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using LinearAlgebra

function vrp_simple()
A = Float64[
1 0 0 1 1 1 0 1 1 1 1
0 1 0 1 0 1 1 0 1 1 1
0 0 1 0 1 0 1 1 1 1 1
]
b = Float64[1, 1, 1]
c = Float64[2, 4, 4, 4, 4, 4, 5, 4, 5, 6, 5];

ϵ = 1
ρ = sum(abs, c) + ϵ
Q = diagm(c) + ρ * (A'A - 2 * diagm(A'b))
β = ρ * b'b

return Q, β
end

@testset "Vehicle Routing Problem (VRP)" begin
# See https://secquoia.github.io/QUBOBook/QUBO%20and%20Ising%20Models.html
Q, beta = vrp_simple()

E, psi = solve(Q, nothing, beta)
x = TenSolver.sample(psi)

# Known Solution
@test E 5.0 atol=1e-4

@test [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0] in psi
@test [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] in psi
@test x in ( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
, [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
)
end
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ end
include(filepath("qubo.jl"))
# JuMP interface
include(filepath("jump.jl"))

# Cases from papers
include(filepath("cases/vrp.jl"))

0 comments on commit 21a7084

Please sign in to comment.