Skip to content

Commit

Permalink
fix best-worst on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytecode committed Nov 10, 2024
1 parent a3e389b commit b2d5ebd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/bestworst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using ..JuMP, ..Ipopt
struct BestWorstResult
ε::Float64
weights::Vector
is_solved_and_feasible::Bool
end


Expand Down Expand Up @@ -90,18 +91,23 @@ function bestworst(pref_to_best::Vector{Int}, pref_to_worst::Vector{Int})::BestW
worstindices = indices[indices.!=worst_index]

for i in bestindices
@NLconstraint(model, abs(w[best_index] / w[i] - pref_to_best[i]) <= ε)
# abs(w[best_index] / w[i] - pref_to_best[i]) <= ε
@constraint(model, (w[best_index] / w[i] - pref_to_best[i]) <= ε)
@constraint(model, -ε <= (w[best_index] / w[i] - pref_to_best[i]))
end

for i in worstindices
@NLconstraint(model, abs(w[i] / w[worst_index] - pref_to_worst[i]) <= ε)
# abs(w[i] / w[worst_index] - pref_to_worst[i]) <= ε
@constraint(model, (w[i] / w[worst_index] - pref_to_worst[i]) <= ε)
@constraint(model, -ε <= (w[i] / w[worst_index] - pref_to_worst[i]))
end

@constraint(model, sum(w) == 1)

optimize!(model)

result = BestWorstResult(value(ε), value.(w))
status = JuMP.is_solved_and_feasible(model)
result = BestWorstResult(value(ε), value.(w), status)

return result
end
Expand Down
3 changes: 3 additions & 0 deletions test/mcdm/testbestworst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

result = bestworst(pref_to_best, pref_to_worst)

# Test for the result is solved and feasible
@test result.is_solved_and_feasible

@test isapprox(result.ε, 0.26, atol = eps)

@test isapprox(result.weights, [0.071, 0.338, 0.589], atol = eps)
Expand Down

0 comments on commit b2d5ebd

Please sign in to comment.