Correct optimize!, add stochastic test case

This commit is contained in:
2023-03-16 12:03:40 -05:00
parent 20939dc4b7
commit 414128cc0b
4 changed files with 131 additions and 86 deletions

View File

@@ -10,46 +10,73 @@ function optimize!(model::JuMP.Model, method::XavQiuWanThi2019.Method)::Nothing
JuMP.set_optimizer_attribute(model, "MIPGap", gap)
@info @sprintf("MIP gap tolerance set to %f", gap)
end
initial_time = time()
large_gap = false
has_transmission = false
for sc in model[:instance].scenarios
large_gap = false
has_transmission = (length(sc.isf) > 0)
if length(sc.isf) > 0
has_transmission = true
end
if has_transmission && method.two_phase_gap
set_gap(1e-2)
large_gap = true
end
end
while true
time_elapsed = time() - initial_time
time_remaining = method.time_limit - time_elapsed
if time_remaining < 0
@info "Time limit exceeded"
break
end
@info @sprintf(
"Setting MILP time limit to %.2f seconds",
time_remaining
)
JuMP.set_time_limit_sec(model, time_remaining)
@info "Solving MILP..."
JuMP.optimize!(model)
while true
initial_time = time()
time_elapsed = time() - initial_time
time_remaining = method.time_limit - time_elapsed
if time_remaining < 0
@info "Time limit exceeded"
break
has_transmission || break
@info "Verifying transmission limits..."
time_screening = @elapsed begin
violations = []
for sc in model[:instance].scenarios
push!(
violations,
_find_violations(
model,
sc,
max_per_line = method.max_violations_per_line,
max_per_period = method.max_violations_per_period,
),
)
end
@info @sprintf(
"Setting MILP time limit to %.2f seconds",
time_remaining
)
JuMP.set_time_limit_sec(model, time_remaining)
@info "Solving MILP..."
JuMP.optimize!(model)
has_transmission || break
violations = _find_violations(
model,
sc,
max_per_line = method.max_violations_per_line,
max_per_period = method.max_violations_per_period,
)
if isempty(violations)
@info "No violations found"
if large_gap
large_gap = false
set_gap(method.gap_limit)
else
break
end
end
@info @sprintf(
"Verified transmission limits in %.2f seconds",
time_screening
)
violations_found = false
for v in violations
if !isempty(v)
violations_found = true
end
end
if violations_found
for (i, v) in enumerate(violations)
_enforce_transmission(model, v, model[:instance].scenarios[i])
end
else
@info "No violations found"
if large_gap
large_gap = false
set_gap(method.gap_limit)
else
_enforce_transmission(model, violations, sc)
break
end
end
end