Skip to content

Commit

Permalink
Don't save outputs for benders master problem
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelma committed Aug 7, 2023
1 parent 50bbb2e commit 8478314
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/data_structure/preprocess_data_structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ Generate a default `report` object, only if no report objects exist.
"""
function generate_report()
isempty(report()) || return
add_objects!(report, [Object(:default_report)])
add_objects!(report, [Object(:default_report, :report)])
end

"""
Expand All @@ -757,14 +757,16 @@ end
Add outputs that are required for calculating other outputs.
"""
function add_required_outputs()
required_outputs = Dict(
required_output_names = Dict(
:connection_avg_throughflow => :connection_flow,
:connection_avg_intact_throughflow => :connection_intact_flow,
)
for r in report()
new_outs = (get(required_outputs, out, nothing) for out in report__output(report=r))
new_rels = [(r, out) for out in new_outs if out !== nothing]
isempty(new_rels) || add_relationships!(report__output, new_rels)
new_output_names = (get(required_output_names, out.name, nothing) for out in report__output(report=r))
new_output_names = [n for n in new_output_names if n !== nothing]
isempty(new_output_names) && continue
add_objects!(output, [Object(n, :output) for n in new_output_names])
add_relationships!(report__output, [(r, output(n)) for n in new_output_names])
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/run_spineopt_benders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function rerun_spineopt_benders!(
j = 1
while optimize
@log log_level 0 "\nStarting Benders iteration $j"
optimize_model!(m_mp; log_level=log_level) || break
optimize_model!(m_mp; log_level=log_level, save_outputs=false) || break
@timelog log_level 2 "Processing master problem solution" process_master_problem_solution!(m_mp)
k = 1
subproblem_solved = nothing
Expand Down
10 changes: 6 additions & 4 deletions src/run_spineopt_standard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ end
Optimize the given model.
If an optimal solution is found, save results and return `true`, otherwise return `false`.
"""
function optimize_model!(m::Model; log_level=3, calculate_duals=false, iterations=nothing)
function optimize_model!(m::Model; log_level=3, calculate_duals=false, save_outputs=true, iterations=nothing)
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.
Expand All @@ -359,7 +359,10 @@ function optimize_model!(m::Model; log_level=3, calculate_duals=false, iteration
m; iterations=iterations
)
calculate_duals && _calculate_duals(m; log_level=log_level)
@timelog log_level 2 "Saving outputs..." _save_outputs!(m; iterations=iterations)
if save_outputs
@timelog log_level 2 "Saving outputs..." _save_outputs!(m; iterations=iterations)
@timelog log_level 2 "Postprocessing results..." postprocess_results!(m)
end
else
m.ext[:spineopt].has_results[] = false
@warn "no solution available for window $(current_window(m)) - moving on..."
Expand Down Expand Up @@ -391,7 +394,6 @@ Save a model results: first postprocess results, then save variables and objecti
function _save_model_results!(m; iterations=nothing)
_save_variable_values!(m)
_save_objective_values!(m)
postprocess_results!(m)
end

"""
Expand Down Expand Up @@ -555,7 +557,7 @@ function _save_output!(m, out, value_or_param, crop_to_window; iterations=nothin
by_entity_non_aggr = _value_by_entity_non_aggregated(m, value_or_param, crop_to_window)
for (entity, by_analysis_time_non_aggr) in by_entity_non_aggr
if !isnothing(iterations)
# FIXME: Needs to be done, befooooore we execute solve, as we need to set objective for this solve
# FIXME: Needs to be done before we solve, as we need to set objective for this solve
new_mga_name = Symbol(string("mga_it_", iterations))
if mga_iteration(new_mga_name) == nothing
new_mga_i = Object(new_mga_name)
Expand Down

0 comments on commit 8478314

Please sign in to comment.