-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Description
None error here, but in the case of a lexicographic optimization, the access to results is not fully intuitive.
To illustrate it (see below), for a problem with e.g. 3 objectives, to get the result for e.g. the objective 1, the iterator value must be 3, objective 2 with value 1, objective 3 with value 2:
using Random
function generate_MO01UKP(n = 10, o = 2, max_ci = 100, max_wi = 30)
Random.seed!(123)
p = rand(1:max_ci,o,n)
w = rand(1:max_wi,n)
c = round(Int64, sum(w)/2)
return p, w, c
end
p,w,c = generate_MO01UKP(10,3)
d,n = size(p)
The code and result in optimizing function independently:
using JuMP, GLPK
model = Model()
@variable(model, x[1:n], Bin)
@expression(model, z[k=1:d], sum(p[k,j] * x[j] for j in 1:n))
@constraint(model, sum(w[i] * x[i] for i in 1:n) ≤ c)
set_optimizer(model,GLPK.Optimizer)
@objective(model, Max, z[1])
optimize!(model)
z_opt = objective_value(model)
println("z1_opt=", z_opt)
@objective(model, Max, z[2])
optimize!(model)
z_opt = objective_value(model)
println("z2_opt=", z_opt)
@objective(model, Max, z[3])
optimize!(model)
z_opt = objective_value(model)
println("z3_opt=", z_opt)
we obtain:
z1_opt=322.0
z2_opt=429.0
z3_opt=361.0
The code and results using MOA:
using JuMP, GLPK
import MultiObjectiveAlgorithms as MOA
model = Model()
@variable(model, x[1:n], Bin)
@expression(model, z[k=1:d], sum(p[k,j] * x[j] for j in 1:n))
@objective(model, Max, [z[k] for k=1:d])
@constraint(model, sum(w[i] * x[i] for i in 1:n) ≤ c)
set_optimizer(model,()->MOA.Optimizer(GLPK.Optimizer))
set_attribute(model, MOA.Algorithm(), MOA.Lexicographic())
optimize!(model)
z1_opt = objective_value(model; result=1)
z2_opt = objective_value(model; result=2)
z3_opt = objective_value(model; result=3)
z_ideal = objective_bound(model)
println("zᴵ = ",z_ideal,"\n")
println("z¹_lex = ", z1_opt, "\nz²_lex = ", z2_opt, "\nz³_lex = ", z3_opt)
we obtain:
zᴵ = [322.0, 429.0, 361.0]
z¹_lex = [232.0, 429.0, 317.0]
z²_lex = [288.0, 404.0, 361.0]
z³_lex = [322.0, 371.0, 333.0]
In looking print(model)
, the order of objective is 1-2-3 but result=1
is the solution for objective 2.
It is a source of misuse of the results for an inattentive user (who would associate the result corresponding to objective
Metadata
Metadata
Assignees
Labels
No labels