Skip to content

Commit

Permalink
less constraints in p-median problem
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytecode committed May 22, 2024
1 parent 9d4f8d8 commit 1e16279
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/pmedian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ function pmedian_with_distances(distancematrix::Matrix, ncenters::Int)::PMedianR

distances = distancematrix

M = 100000.0 * n


model = Model(HiGHS.Optimizer)
MOI.set(model, MOI.Silent(), true)
Expand All @@ -127,9 +129,7 @@ function pmedian_with_distances(distancematrix::Matrix, ncenters::Int)::PMedianR
@constraint(model, sum(y) == ncenters)

for i = 1:n
for j = 1:n
@constraint(model, z[i, j] .<= y[j])
end
@constraint(model, sum(z[:, i]) <= M * y[i])
end

for i = 1:n
Expand Down
3 changes: 2 additions & 1 deletion test/testpmedian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
result2 = pmedian_with_distances(distance_matrix, 3)
result3 = pmedian_with_distances(distance_matrix, 4)

@test sort(result1.centers) == [3, 4]

@test (sort(result1.centers) == [3, 4]) || (sort(result1.centers) == [1, 2])
@test result1.objective == 22.0

@test sort(result2.centers) == [3, 4, 5]
Expand Down

0 comments on commit 1e16279

Please sign in to comment.