Skip to content

Commit

Permalink
Don't optimize at all if model has results and fix return value
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelma committed Nov 14, 2024
1 parent e1be8b0 commit 9591f2e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/run_spineopt_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ function solve_model!(
else
(save_outputs=false, output_suffix=output_suffix)
end
_do_solve_model!(m_mp; log_level, update_names, log_prefix, extra_kwargs...) || break
_do_solve_model!(m_mp; log_level, update_names, log_prefix, extra_kwargs...) || return false
@timelog log_level 2 "Processing $(_model_name(m_mp)) solution" process_master_problem_solution(m_mp, m)
_do_solve_multi_stage_model!(
m;
Expand All @@ -428,7 +428,7 @@ function solve_model!(
calculate_duals=true,
log_prefix="$(log_prefix)Benders iteration $j $(_current_solution_string(m_mp)) - ",
extra_kwargs...,
) || break
) || return false
@timelog log_level 2 "Computing benders gap..." save_mp_objective_bounds_and_gap!(m_mp, m)
@log log_level 1 "Benders iteration $j complete"
@log log_level 1 "Objective lower bound: $(_lb_str(m_mp))"
Expand Down Expand Up @@ -463,7 +463,7 @@ function solve_model!(
unfix_history!(m)
global current_bi = add_benders_iteration(j + 1)
end
m
true
end
end

Expand Down Expand Up @@ -525,16 +525,18 @@ function _do_solve_model!(
for k in Iterators.countfrom(k0)
@log log_level 1 "\n$full_model_name - window $k of $(window_count(m)): $(current_window(m))"
_call_event_handlers(m, :window_about_to_solve, k)
if optimize_model!(
m; log_level, output_suffix, calculate_duals, save_outputs, print_conflict=!skip_failed_windows
)
_call_event_handlers(m, :window_solved, k)
elseif skip_failed_windows
@error "$full_model_name - window $k failed to solve! - you might see a gap in the results"
_call_event_handlers(m, :window_failed, k)
unfix_history!(m)
else
return false
if !m.ext[:spineopt].has_results[]
if optimize_model!(
m; log_level, output_suffix, calculate_duals, save_outputs, print_conflict=!skip_failed_windows
)
_call_event_handlers(m, :window_solved, k)
elseif skip_failed_windows
@error "$full_model_name - window $k failed to solve! - you might see a gap in the results"
_call_event_handlers(m, :window_failed, k)
unfix_history!(m)
else
return false
end
end
_save_window_state(m, k; write_as_roll, resume_file_path)
if @timelog log_level 2 "$model_name - Rolling temporal structure...\n" !roll_temporal_structure!(m, k)
Expand Down Expand Up @@ -614,7 +616,6 @@ function optimize_model!(
write_mps_file(model=m.ext[:spineopt].instance) == :write_mps_always && write_to_file(m, "model_diagnostics.mps")
# NOTE: The above results in a lot of Warning: Variable connection_flow[...] is mentioned in BOUNDS,
# but is not mentioned in the COLUMNS section.
m.ext[:spineopt].has_results[] && return true
model_name = _model_name(m)
@timelog log_level 0 "Optimizing $model_name..." optimize!(m)
termination_st = termination_status(m)
Expand Down

0 comments on commit 9591f2e

Please sign in to comment.