-
Notifications
You must be signed in to change notification settings - Fork 8
Various fixes to KirlikSayin #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ function optimize_multiobjective!(algorithm::KirlikSayin, model::Optimizer) | |
model.ideal_point .*= -1 | ||
return status, solutions | ||
end | ||
@assert sense == MOI.MIN_SENSE | ||
solutions = SolutionPoint[] | ||
# Problem with p objectives. | ||
# Set k = 1, meaning the nondominated points will get projected | ||
|
@@ -99,68 +100,62 @@ function optimize_multiobjective!(algorithm::KirlikSayin, model::Optimizer) | |
variables = MOI.get(model.inner, MOI.ListOfVariableIndices()) | ||
n = MOI.output_dimension(model.f) | ||
yI, yN = zeros(n), zeros(n) | ||
δ = sense == MOI.MIN_SENSE ? -1 : 1 | ||
# This tolerance is really important! | ||
δ = 1.0 | ||
scalars = MOI.Utilities.scalarize(model.f) | ||
# Ideal and Nadir point estimation | ||
for (i, f_i) in enumerate(scalars) | ||
# Ideal point | ||
MOI.set(model.inner, MOI.ObjectiveFunction{typeof(f_i)}(), f_i) | ||
MOI.set(model.inner, MOI.ObjectiveSense(), sense) | ||
MOI.optimize!(model.inner) | ||
status = MOI.get(model.inner, MOI.TerminationStatus()) | ||
if !_is_scalar_status_optimal(status) | ||
return status, nothing | ||
end | ||
_, Y = _compute_point(model, variables, f_i) | ||
yI[i] = Y + 1 | ||
model.ideal_point[i] = Y | ||
MOI.set( | ||
model.inner, | ||
MOI.ObjectiveSense(), | ||
sense == MOI.MIN_SENSE ? MOI.MAX_SENSE : MOI.MIN_SENSE, | ||
) | ||
model.ideal_point[i] = yI[i] = Y | ||
# Nadir point | ||
MOI.set(model.inner, MOI.ObjectiveSense(), MOI.MAX_SENSE) | ||
MOI.optimize!(model.inner) | ||
status = MOI.get(model.inner, MOI.TerminationStatus()) | ||
if !_is_scalar_status_optimal(status) | ||
_warn_on_nonfinite_anti_ideal(algorithm, sense, i) | ||
# Repair ObjectiveSense before exiting | ||
MOI.set(model.inner, MOI.ObjectiveSense(), MOI.MIN_SENSE) | ||
_warn_on_nonfinite_anti_ideal(algorithm, MOI.MIN_SENSE, i) | ||
return status, nothing | ||
end | ||
_, Y = _compute_point(model, variables, f_i) | ||
yN[i] = Y | ||
yN[i] = Y + δ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a +1 here because the \delta was for e-constraints. Having +1 makes it consistent with KS and DR. Original algorithm uses some big M. |
||
MOI.set(model.inner, MOI.ObjectiveSense(), MOI.MIN_SENSE) | ||
end | ||
# Reset the sense after modifying it. | ||
MOI.set(model.inner, MOI.ObjectiveSense(), sense) | ||
L = [_Rectangle(_project(yI, k), _project(yN, k))] | ||
SetType = ifelse( | ||
sense == MOI.MIN_SENSE, | ||
MOI.LessThan{Float64}, | ||
MOI.GreaterThan{Float64}, | ||
) | ||
status = MOI.OPTIMAL | ||
while !isempty(L) | ||
if _time_limit_exceeded(model, start_time) | ||
status = MOI.TIME_LIMIT | ||
break | ||
return MOI.TIME_LIMIT, solutions | ||
end | ||
Rᵢ = L[argmax([_volume(Rᵢ, _project(yI, k)) for Rᵢ in L])] | ||
lᵢ, uᵢ = Rᵢ.l, Rᵢ.u | ||
max_volume_index = argmax([_volume(Rᵢ, _project(yI, k)) for Rᵢ in L]) | ||
uᵢ = L[max_volume_index].u | ||
# Solving the first stage model: P_k(ε) | ||
# Set ε := uᵢ | ||
ε = insert!(copy(uᵢ), k, 0.0) | ||
ε_constraints = Any[] | ||
# minimize: f_1(x) | ||
# s.t.: f_i(x) <= u_i - δ | ||
@assert k == 1 | ||
MOI.set( | ||
model.inner, | ||
MOI.ObjectiveFunction{typeof(scalars[k])}(), | ||
scalars[k], | ||
) | ||
ε_constraints = Any[] | ||
for (i, f_i) in enumerate(scalars) | ||
if i != k | ||
ci = MOI.Utilities.normalize_and_add_constraint( | ||
model.inner, | ||
f_i, | ||
SetType(ε[i] + δ), | ||
) | ||
push!(ε_constraints, ci) | ||
if i == k | ||
continue | ||
end | ||
ci = MOI.Utilities.normalize_and_add_constraint( | ||
model.inner, | ||
f_i, | ||
MOI.LessThan{Float64}(uᵢ[i-1] - δ), | ||
) | ||
push!(ε_constraints, ci) | ||
end | ||
MOI.optimize!(model.inner) | ||
if !_is_scalar_status_optimal(model) | ||
|
@@ -171,7 +166,7 @@ function optimize_multiobjective!(algorithm::KirlikSayin, model::Optimizer) | |
zₖ = MOI.get(model.inner, MOI.ObjectiveValue()) | ||
# Solving the second stage model: Q_k(ε, zₖ) | ||
# Set objective sum(model.f) | ||
sum_f = sum(1.0 * s for s in scalars) | ||
sum_f = MOI.Utilities.operate(+, Float64, scalars...) | ||
MOI.set(model.inner, MOI.ObjectiveFunction{typeof(sum_f)}(), sum_f) | ||
# Constraint to eliminate weak dominance | ||
zₖ_constraint = MOI.Utilities.normalize_and_add_constraint( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this tolerance arbitrary? Why
1.0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these algorithms target integer programs, the e-constraints enforces f_i(x) < u_i and the bound are integer as well.