diff --git a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp index 6189a2b85..5a7df49a0 100644 --- a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp +++ b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp @@ -287,6 +287,13 @@ void BendersByBatch::GetSubproblemCut( worker->solve(subproblem_data.lpstatus, Options().OUTPUTROOT, Options().LAST_MASTER_MPS + MPS_SUFFIX, _writer); // worker->get_solution(subproblem_data.solution); + // TODO not supported yet + // if (Options().EXTERNAL_LOOP_OPTIONS.DO_OUTER_LOOP) { + // std::vector solution; + // worker->get_solution(solution); + // subproblem_data.outer_loop_criterions = + // ComputeOuterLoopCriterion(name, solution); + // } worker->get_value(subproblem_data.subproblem_cost); // solution phi(x,s) worker->get_subgradient( subproblem_data.var_name_and_subgradient); // dual pi_s diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index cb8eeac71..266d32ce1 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -397,7 +397,12 @@ void BendersBase::GetSubproblemCut(SubProblemDataMap &subproblem_data_map) { worker->solve(subproblem_data.lpstatus, _options.OUTPUTROOT, _options.LAST_MASTER_MPS + MPS_SUFFIX, _writer); worker->get_value(subproblem_data.subproblem_cost); - worker->get_solution(subproblem_data.solution); + if (_options.EXTERNAL_LOOP_OPTIONS.DO_OUTER_LOOP) { + std::vector solution; + worker->get_solution(solution); + subproblem_data.outer_loop_criterions = + ComputeOuterLoopCriterion(name, solution); + } worker->get_subgradient(subproblem_data.var_name_and_subgradient); worker->get_splex_num_of_ite_last(subproblem_data.simplex_iter); subproblem_data.subproblem_timer = subproblem_timer.elapsed(); @@ -427,9 +432,7 @@ void BendersBase::compute_cut(const SubProblemDataMap &subproblem_data_map) { subproblem_data.var_name_and_subgradient, _data.x_cut, subproblem_data.subproblem_cost); relevantIterationData_.last._cut_trace[subproblem_name] = subproblem_data; - // ComputeOuterLoopCriterion(subproblem_name, subproblem_data); } - // outer_loop_criterion_.push_back(current_outer_loop_criterion_); } void compute_cut_val(const Point &var_name_subgradient, const Point &x_cut, @@ -1022,8 +1025,7 @@ std::vector BendersBase::GetOuterLoopCriterionAtBestBenders() const { std::vector BendersBase::ComputeOuterLoopCriterion( const std::string &subproblem_name, - const PlainData::SubProblemData &sub_problem_data) { - + const std::vector &sub_problem_solution) { auto outer_loop_input_size = var_indices_.size(); // num of patterns std::vector outer_loop_criterion_per_sub_problem(outer_loop_input_size, {}); @@ -1037,8 +1039,7 @@ std::vector BendersBase::ComputeOuterLoopCriterion( ++pattern_index) { auto pattern_variables_indices = var_indices_[pattern_index]; for (auto variables_index : pattern_variables_indices) { - - if (auto solution = sub_problem_data.solution[variables_index]; + if (auto solution = sub_problem_solution[variables_index]; solution > criterion_count_threshold) // 1h of no supplied energy outer_loop_criterion_per_sub_problem[pattern_index] += diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index fb4c2819a..3ccb9d2bc 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -237,7 +237,7 @@ class BendersBase { // outer loop criterion per pattern std::vector ComputeOuterLoopCriterion( const std::string &subproblem_name, - const PlainData::SubProblemData &sub_problem_data); + const std::vector &sub_problem_solution); void UpdateOuterLoopMaxCriterionArea(); void UpdateOuterLoopSolution(); diff --git a/src/cpp/benders/benders_core/include/SubproblemCut.h b/src/cpp/benders/benders_core/include/SubproblemCut.h index 69c0f392c..6c070750d 100644 --- a/src/cpp/benders/benders_core/include/SubproblemCut.h +++ b/src/cpp/benders/benders_core/include/SubproblemCut.h @@ -9,7 +9,7 @@ namespace PlainData { struct SubProblemData { double subproblem_cost; Point var_name_and_subgradient; - std::vector solution; + std::vector outer_loop_criterions; double single_subpb_costs_under_approx; double subproblem_timer; int simplex_iter; @@ -19,7 +19,7 @@ struct SubProblemData { void serialize(Archive &ar, const unsigned int version) { ar & subproblem_cost; ar & var_name_and_subgradient; - ar & solution; + ar & outer_loop_criterions; ar & single_subpb_costs_under_approx; ar & subproblem_timer; ar & simplex_iter; diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index a808cbf6e..45a8c7868 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -168,15 +168,16 @@ BendersMpi::ComputeSubproblemsContributionToOuterLoopCriterion( var_indices_.size(), {}); std::vector outer_loop_criterion_sub_problems_map_result( var_indices_.size(), {}); + for (const auto &[subproblem_name, subproblem_data] : subproblem_data_map) { AddVectors( outer_loop_criterion_per_sub_problem_per_pattern, - ComputeOuterLoopCriterion(subproblem_name, subproblem_data)); + subproblem_data.outer_loop_criterions); } + Reduce(outer_loop_criterion_per_sub_problem_per_pattern, outer_loop_criterion_sub_problems_map_result, std::plus(), rank_0); - // outer_loop_criterion_sub_problems_map_result/=nbyears; return outer_loop_criterion_sub_problems_map_result; }