From 6451f90a2df2a7e9fac7e04828c160653f077b69 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 19 Mar 2024 10:58:22 +0100 Subject: [PATCH 01/15] start migrating code --- src/cpp/benders/benders_core/BendersBase.cpp | 17 +++++++++++++++++ .../benders/benders_core/SimulationOptions.cpp | 7 ++++++- .../benders/benders_core/include/BendersBase.h | 6 ++++++ src/cpp/benders/benders_core/include/common.h | 14 ++++++++------ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index b0c94599c..8b0b62d3d 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -944,3 +944,20 @@ void BendersBase::InitExternalValues() { CurrentIterationData BendersBase::GetCurrentIterationData() const { return _data; } + +void BendersBase::ComputeOuterLoopCriterion() { + double sum_loss_ = 0; + for (const auto &[sub_problem_name, sub_problem_data] : + relevantIterationData_.best._cut_trace) { + for (auto i(0); i < sub_problem_data.variables.names.size(); ++i) { + auto var_name = sub_problem_data.variables.names[i]; + auto solution = sub_problem_data.variables.values[i]; + if (std::regex_search(var_name, rgx_) && + solution > _options.EXTERNAL_LOOP_OPTIONS + .EXT_LOOP_CRITERION_COUNT_THRESHOLD) { + // 1h of unsupplied energy + sum_loss_ += 1; + } + } + } +} diff --git a/src/cpp/benders/benders_core/SimulationOptions.cpp b/src/cpp/benders/benders_core/SimulationOptions.cpp index 13cbe07b5..464d98639 100644 --- a/src/cpp/benders/benders_core/SimulationOptions.cpp +++ b/src/cpp/benders/benders_core/SimulationOptions.cpp @@ -168,7 +168,12 @@ BendersBaseOptions SimulationOptions::get_benders_options() const { result.LAST_MASTER_MPS = LAST_MASTER_MPS; result.LAST_MASTER_BASIS = LAST_MASTER_BASIS; result.BATCH_SIZE = BATCH_SIZE; - + result.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_VALUE = + EXT_LOOP_CRITERION_VALUE; + result.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_TOLERANCE = + EXT_LOOP_CRITERION_TOLERANCE; + result.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_COUNT_THRESHOLD = + EXT_LOOP_CRITERION_COUNT_THRESHOLD; return result; } diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index 3054d3712..a3792de25 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -2,6 +2,7 @@ #include #include +#include #include "BendersMathLogger.h" #include "BendersStructsDatas.h" @@ -192,6 +193,8 @@ class BendersBase { SolverLogManager solver_log_manager_; + void ComputeOuterLoopCriterion(); + private: void print_master_and_cut(std::ostream &file, int ite, WorkerMasterData &trace, Point const &xopt); @@ -227,6 +230,9 @@ class BendersBase { int iterations_before_resume = 0; int cumulative_number_of_subproblem_resolved_before_resume = 0; Timer benders_timer; + const std::string positive_unsupplied_vars_prefix_ = + "^PositiveUnsuppliedEnergy::"; + const std::regex rgx_ = std::regex(positive_unsupplied_vars_prefix_); public: Logger _logger; diff --git a/src/cpp/benders/benders_core/include/common.h b/src/cpp/benders/benders_core/include/common.h index 3cfb2d115..7cd3f5d14 100644 --- a/src/cpp/benders/benders_core/include/common.h +++ b/src/cpp/benders/benders_core/include/common.h @@ -141,6 +141,13 @@ struct BaseOptions { Str2Dbl weights; }; typedef BaseOptions MergeMPSOptions; + +struct ExternalLoopOptions { + double EXT_LOOP_CRITERION_VALUE = 1.0; + double EXT_LOOP_CRITERION_TOLERANCE = 1e-1; + double EXT_LOOP_CRITERION_COUNT_THRESHOLD = 1e-1; +}; + struct BendersBaseOptions : public BaseOptions { explicit BendersBaseOptions(const BaseOptions &base_to_copy) : BaseOptions(base_to_copy) {} @@ -164,12 +171,7 @@ struct BendersBaseOptions : public BaseOptions { std::string LAST_MASTER_BASIS; size_t BATCH_SIZE; -}; - -struct ExternalLoopOptions { - double EXT_LOOP_CRITERION_VALUE = 1.0; - double EXT_LOOP_CRITERION_TOLERANCE = 1e-1; - double EXT_LOOP_CRITERION_COUNT_THRESHOLD = 1e-1; + ExternalLoopOptions EXTERNAL_LOOP_OPTIONS; }; void usage(int argc); From 77668c82f360dc7df97940506f3a5954b2788dc4 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 19 Mar 2024 11:34:31 +0100 Subject: [PATCH 02/15] compute outer loop criterion --- src/cpp/benders/benders_core/BendersBase.cpp | 27 ++++++++++--------- .../benders_core/include/BendersBase.h | 6 ++++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index 8b0b62d3d..923ff07ad 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -401,6 +401,7 @@ void BendersBase::GetSubproblemCut(SubProblemDataMap &subproblem_data_map) { * */ void BendersBase::compute_cut(const SubProblemDataMap &subproblem_data_map) { + current_outer_loop_criterion_ = 0.0; for (auto const &[subproblem_name, subproblem_data] : subproblem_data_map) { _data.ub += subproblem_data.subproblem_cost; @@ -408,7 +409,9 @@ 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, @@ -945,19 +948,17 @@ CurrentIterationData BendersBase::GetCurrentIterationData() const { return _data; } -void BendersBase::ComputeOuterLoopCriterion() { - double sum_loss_ = 0; - for (const auto &[sub_problem_name, sub_problem_data] : - relevantIterationData_.best._cut_trace) { - for (auto i(0); i < sub_problem_data.variables.names.size(); ++i) { - auto var_name = sub_problem_data.variables.names[i]; - auto solution = sub_problem_data.variables.values[i]; - if (std::regex_search(var_name, rgx_) && - solution > _options.EXTERNAL_LOOP_OPTIONS - .EXT_LOOP_CRITERION_COUNT_THRESHOLD) { - // 1h of unsupplied energy - sum_loss_ += 1; - } +void BendersBase::ComputeOuterLoopCriterion( + const std::string &subproblem_name, + const PlainData::SubProblemData &sub_problem_data) { + for (auto i(0); i < sub_problem_data.variables.names.size(); ++i) { + auto var_name = sub_problem_data.variables.names[i]; + auto solution = sub_problem_data.variables.values[i]; + if (std::regex_search(var_name, rgx_) && + solution > + _options.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_COUNT_THRESHOLD) { + // 1h of unsupplied energy + current_outer_loop_criterion_ += 1; } } } diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index a3792de25..30723bc0f 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -193,7 +193,9 @@ class BendersBase { SolverLogManager solver_log_manager_; - void ComputeOuterLoopCriterion(); + void ComputeOuterLoopCriterion( + const std::string &subproblem_name, + const PlainData::SubProblemData &sub_problem_data); private: void print_master_and_cut(std::ostream &file, int ite, @@ -233,6 +235,8 @@ class BendersBase { const std::string positive_unsupplied_vars_prefix_ = "^PositiveUnsuppliedEnergy::"; const std::regex rgx_ = std::regex(positive_unsupplied_vars_prefix_); + double current_outer_loop_criterion_ = 0; + std::vector outer_loop_criterion_; public: Logger _logger; From 7f6e7906712dd1e5837498ac23fb68d4a64030a1 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 19 Mar 2024 12:29:16 +0100 Subject: [PATCH 03/15] multiprocess outerloop criterion --- src/cpp/benders/benders_core/BendersBase.cpp | 14 ++++++++------ .../benders/benders_core/include/BendersBase.h | 11 +++++------ src/cpp/benders/benders_mpi/BendersMPI.cpp | 15 +++++++++++++++ src/cpp/benders/benders_mpi/include/BendersMPI.h | 2 ++ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index 923ff07ad..34bb7b3c0 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -401,7 +401,7 @@ void BendersBase::GetSubproblemCut(SubProblemDataMap &subproblem_data_map) { * */ void BendersBase::compute_cut(const SubProblemDataMap &subproblem_data_map) { - current_outer_loop_criterion_ = 0.0; + // current_outer_loop_criterion_ = 0.0; for (auto const &[subproblem_name, subproblem_data] : subproblem_data_map) { _data.ub += subproblem_data.subproblem_cost; @@ -409,9 +409,9 @@ 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); + // ComputeOuterLoopCriterion(subproblem_name, subproblem_data); } - outer_loop_criterion_.push_back(current_outer_loop_criterion_); + // outer_loop_criterion_.push_back(current_outer_loop_criterion_); } void compute_cut_val(const Point &var_name_subgradient, const Point &x_cut, @@ -940,7 +940,7 @@ void BendersBase::ResetData(double criterion) { } void BendersBase::InitExternalValues() { - _data.external_loop_criterion = 0; + // _data.external_loop_criterion = 0; _data.benders_num_run = 0; } @@ -948,9 +948,10 @@ CurrentIterationData BendersBase::GetCurrentIterationData() const { return _data; } -void BendersBase::ComputeOuterLoopCriterion( +double BendersBase::ComputeOuterLoopCriterion( const std::string &subproblem_name, const PlainData::SubProblemData &sub_problem_data) { + double outer_loop_criterion_per_sub_problem = 0.0; for (auto i(0); i < sub_problem_data.variables.names.size(); ++i) { auto var_name = sub_problem_data.variables.names[i]; auto solution = sub_problem_data.variables.values[i]; @@ -958,7 +959,8 @@ void BendersBase::ComputeOuterLoopCriterion( solution > _options.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_COUNT_THRESHOLD) { // 1h of unsupplied energy - current_outer_loop_criterion_ += 1; + outer_loop_criterion_per_sub_problem += 1; } } + return outer_loop_criterion_per_sub_problem; } diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index 30723bc0f..03ff633b2 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -97,6 +97,10 @@ class BendersBase { bool init_data_ = true; bool init_problems_ = true; bool free_problems_ = true; + const std::string positive_unsupplied_vars_prefix_ = + "^PositiveUnsuppliedEnergy::"; + const std::regex rgx_ = std::regex(positive_unsupplied_vars_prefix_); + std::vector outer_loop_criterion_; protected: virtual void Run() = 0; @@ -193,7 +197,7 @@ class BendersBase { SolverLogManager solver_log_manager_; - void ComputeOuterLoopCriterion( + double ComputeOuterLoopCriterion( const std::string &subproblem_name, const PlainData::SubProblemData &sub_problem_data); @@ -232,11 +236,6 @@ class BendersBase { int iterations_before_resume = 0; int cumulative_number_of_subproblem_resolved_before_resume = 0; Timer benders_timer; - const std::string positive_unsupplied_vars_prefix_ = - "^PositiveUnsuppliedEnergy::"; - const std::regex rgx_ = std::regex(positive_unsupplied_vars_prefix_); - double current_outer_loop_criterion_ = 0; - std::vector outer_loop_criterion_; public: Logger _logger; diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index bf2859bc7..a66e6ed4a 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -139,11 +139,26 @@ void BendersMpi::gather_subproblems_cut_package_and_build_cuts( Reduce(GetSubproblemsCpuTime(), cumulative_subproblems_timer_per_iter, std::plus(), rank_0); SetSubproblemsCumulativeCpuTime(cumulative_subproblems_timer_per_iter); + ComputeSubproblemsContributionToOuterLoopCriterion(subproblem_data_map); + if (_world.rank() == rank_0) { + outer_loop_criterion_.push_back(_data.external_loop_criterion); + } // only rank_0 receive non-emtpy gathered_subproblem_map master_build_cuts(gathered_subproblem_map); } } +void BendersMpi::ComputeSubproblemsContributionToOuterLoopCriterion( + const SubProblemDataMap &subproblem_data_map) { + double outer_loop_criterion_sub_problems_map = 0.0; + for (const auto &[subproblem_name, subproblem_data] : subproblem_data_map) { + outer_loop_criterion_sub_problems_map += + ComputeOuterLoopCriterion(subproblem_name, subproblem_data); + } + Reduce(_data.external_loop_criterion, outer_loop_criterion_sub_problems_map, + std::plus(), rank_0); +} + SubProblemDataMap BendersMpi::get_subproblem_cut_package() { SubProblemDataMap subproblem_data_map; GetSubproblemCut(subproblem_data_map); diff --git a/src/cpp/benders/benders_mpi/include/BendersMPI.h b/src/cpp/benders/benders_mpi/include/BendersMPI.h index fd3bedaa5..12be60cb9 100644 --- a/src/cpp/benders/benders_mpi/include/BendersMPI.h +++ b/src/cpp/benders/benders_mpi/include/BendersMPI.h @@ -85,4 +85,6 @@ class BendersMpi : public BendersBase { void AllReduce(const T &in_value, T &out_value, Op op) const { mpi::all_reduce(_world, in_value, out_value, op); } + virtual void ComputeSubproblemsContributionToOuterLoopCriterion( + const SubProblemDataMap &subproblem_data_map); }; From c37f2d26d8e8ff7b83b7b5e043c976e319b84024 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 19 Mar 2024 18:05:05 +0100 Subject: [PATCH 04/15] update BBBATCH --- src/cpp/benders/benders_by_batch/BendersByBatch.cpp | 11 ++++++++--- .../benders_by_batch/include/BendersByBatch.h | 4 ++-- src/cpp/benders/benders_mpi/BendersMPI.cpp | 13 +++++++++---- src/cpp/benders/benders_mpi/include/BendersMPI.h | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp index 1f5653ed7..5b6a05b81 100644 --- a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp +++ b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp @@ -195,8 +195,10 @@ void BendersByBatch::SolveBatches() { const auto &batch_sub_problems = batch.sub_problem_names; double batch_subproblems_costs_contribution_in_gap_per_proc = 0; double batch_subproblems_costs_contribution_in_gap = 0; + double external_loop_criterion_current_batch = 0; BuildCut(batch_sub_problems, - &batch_subproblems_costs_contribution_in_gap_per_proc); + &batch_subproblems_costs_contribution_in_gap_per_proc, + external_loop_criterion_current_batch); Reduce(batch_subproblems_costs_contribution_in_gap_per_proc, batch_subproblems_costs_contribution_in_gap, std::plus(), rank_0); @@ -206,6 +208,7 @@ void BendersByBatch::SolveBatches() { _data.number_of_subproblem_solved += batch_sub_problems.size(); _data.cumulative_number_of_subproblem_solved += batch_sub_problems.size(); remaining_epsilon_ -= batch_subproblems_costs_contribution_in_gap; + _data.external_loop_criterion += external_loop_criterion_current_batch; } BroadCast(remaining_epsilon_, rank_0); @@ -222,7 +225,8 @@ void BendersByBatch::SolveBatches() { */ void BendersByBatch::BuildCut( const std::vector &batch_sub_problems, - double *batch_subproblems_costs_contribution_in_gap_per_proc) { + double *batch_subproblems_costs_contribution_in_gap_per_proc, + double &external_loop_criterion_current_batch) { SubProblemDataMap subproblem_data_map; Timer subproblems_timer_per_proc; GetSubproblemCut(subproblem_data_map, batch_sub_problems, @@ -235,7 +239,8 @@ void BendersByBatch::BuildCut( misprice_ = global_misprice; Gather(subproblem_data_map, gathered_subproblem_map, rank_0); SetSubproblemsWalltime(subproblems_timer_per_proc.elapsed()); - + external_loop_criterion_current_batch = + ComputeSubproblemsContributionToOuterLoopCriterion(subproblem_data_map); for (const auto &subproblem_map : gathered_subproblem_map) { for (auto &&[sub_problem_name, subproblem_data] : subproblem_map) { SetSubproblemCost(GetSubproblemCost() + subproblem_data.subproblem_cost); diff --git a/src/cpp/benders/benders_by_batch/include/BendersByBatch.h b/src/cpp/benders/benders_by_batch/include/BendersByBatch.h index 06af08e98..41c6a13c8 100644 --- a/src/cpp/benders/benders_by_batch/include/BendersByBatch.h +++ b/src/cpp/benders/benders_by_batch/include/BendersByBatch.h @@ -13,8 +13,8 @@ class BendersByBatch : public BendersMpi { std::shared_ptr mathLoggerDriver); ~BendersByBatch() override = default; void Run() override; - void BuildCut(const std::vector &batch_sub_problems, - double *sum); + void BuildCut(const std::vector &batch_sub_problems, double *sum, + double &external_loop_criterion_current_batch); std::string BendersName() const override { return "Benders By Batch mpi"; } protected: diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index a66e6ed4a..2de79de96 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -139,7 +139,8 @@ void BendersMpi::gather_subproblems_cut_package_and_build_cuts( Reduce(GetSubproblemsCpuTime(), cumulative_subproblems_timer_per_iter, std::plus(), rank_0); SetSubproblemsCumulativeCpuTime(cumulative_subproblems_timer_per_iter); - ComputeSubproblemsContributionToOuterLoopCriterion(subproblem_data_map); + _data.external_loop_criterion = + ComputeSubproblemsContributionToOuterLoopCriterion(subproblem_data_map); if (_world.rank() == rank_0) { outer_loop_criterion_.push_back(_data.external_loop_criterion); } @@ -148,15 +149,19 @@ void BendersMpi::gather_subproblems_cut_package_and_build_cuts( } } -void BendersMpi::ComputeSubproblemsContributionToOuterLoopCriterion( +double BendersMpi::ComputeSubproblemsContributionToOuterLoopCriterion( const SubProblemDataMap &subproblem_data_map) { double outer_loop_criterion_sub_problems_map = 0.0; + double outer_loop_criterion_sub_problems_map_result = 0.0; for (const auto &[subproblem_name, subproblem_data] : subproblem_data_map) { outer_loop_criterion_sub_problems_map += ComputeOuterLoopCriterion(subproblem_name, subproblem_data); } - Reduce(_data.external_loop_criterion, outer_loop_criterion_sub_problems_map, - std::plus(), rank_0); + Reduce(outer_loop_criterion_sub_problems_map, + outer_loop_criterion_sub_problems_map_result, std::plus(), + rank_0); + + return outer_loop_criterion_sub_problems_map; } SubProblemDataMap BendersMpi::get_subproblem_cut_package() { diff --git a/src/cpp/benders/benders_mpi/include/BendersMPI.h b/src/cpp/benders/benders_mpi/include/BendersMPI.h index 12be60cb9..b54eb2bde 100644 --- a/src/cpp/benders/benders_mpi/include/BendersMPI.h +++ b/src/cpp/benders/benders_mpi/include/BendersMPI.h @@ -85,6 +85,6 @@ class BendersMpi : public BendersBase { void AllReduce(const T &in_value, T &out_value, Op op) const { mpi::all_reduce(_world, in_value, out_value, op); } - virtual void ComputeSubproblemsContributionToOuterLoopCriterion( + virtual double ComputeSubproblemsContributionToOuterLoopCriterion( const SubProblemDataMap &subproblem_data_map); }; From 1ce0c1f7cbe07d32f33e96deb9f49e8fe9cd8cd7 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Tue, 19 Mar 2024 18:08:01 +0100 Subject: [PATCH 05/15] update outer loop crit vect --- src/cpp/benders/benders_by_batch/BendersByBatch.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp index 5b6a05b81..7ec91945a 100644 --- a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp +++ b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp @@ -151,6 +151,7 @@ void BendersByBatch::SeparationLoop() { SolveBatches(); if (Rank() == rank_0) { + outer_loop_criterion_.push_back(_data.external_loop_criterion); UpdateTrace(); SaveCurrentBendersData(); } From 40c69a418588218bcbe86ed605c0cf258decb447 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 20 Mar 2024 16:25:21 +0100 Subject: [PATCH 06/15] use lambda_{max, min} as stopping criterion --- .../external_loop/MasterUpdateBase.cpp | 56 +++++++++++-------- src/cpp/benders/external_loop/OuterLoop.cpp | 6 +- .../external_loop/include/MasterUpdate.h | 16 ++++-- src/cpp/benders/factories/BendersFactory.cpp | 3 +- tests/cpp/ext_loop/ext_loop_test.cpp | 9 ++- 5 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/cpp/benders/external_loop/MasterUpdateBase.cpp b/src/cpp/benders/external_loop/MasterUpdateBase.cpp index 2217dc88a..98aea7cde 100644 --- a/src/cpp/benders/external_loop/MasterUpdateBase.cpp +++ b/src/cpp/benders/external_loop/MasterUpdateBase.cpp @@ -1,29 +1,37 @@ #include "MasterUpdate.h" -MasterUpdateBase::MasterUpdateBase(pBendersBase benders, double tau) - : benders_(std::move(benders)), lambda_(0), lambda_min_(0) { +MasterUpdateBase::MasterUpdateBase(pBendersBase benders, double tau, + double epsilon_lambda) + : benders_(std::move(benders)), + lambda_(0), + lambda_min_(0), + epsilon_lambda_(epsilon_lambda) { CheckTau(tau); } MasterUpdateBase::MasterUpdateBase(pBendersBase benders, double tau, - const std::string &name) - : MasterUpdateBase(benders, tau) { + const std::string &name, + double epsilon_lambda) + : MasterUpdateBase(benders, tau, epsilon_lambda) { min_invest_constraint_name_ = name; } MasterUpdateBase::MasterUpdateBase(pBendersBase benders, double lambda, double lambda_min, double lambda_max, - double tau) + double tau, double epsilon_lambda) : benders_(std::move(benders)), lambda_(lambda), lambda_min_(lambda_min), - lambda_max_(lambda_max) { + lambda_max_(lambda_max), + epsilon_lambda_(epsilon_lambda) { CheckTau(tau); } MasterUpdateBase::MasterUpdateBase(pBendersBase benders, double lambda, double lambda_min, double lambda_max, - double tau, const std::string &name) - : MasterUpdateBase(benders, lambda, lambda_min, lambda_max, tau) { + double tau, const std::string &name, + double epsilon_lambda) + : MasterUpdateBase(benders, lambda, lambda_min, lambda_max, tau, + epsilon_lambda) { min_invest_constraint_name_ = name; } @@ -50,22 +58,26 @@ void MasterUpdateBase::SetLambdaMaxToMaxInvestmentCosts() { lambda_max_ += obj[var_id] * max_invest.at(var_name); } } -void MasterUpdateBase::Update(const CRITERION &criterion) { - switch (criterion) { - case CRITERION::LOW: - lambda_max_ = - std::min(lambda_max_, benders_->GetBestIterationData().invest_cost); - break; - case CRITERION::HIGH: - lambda_min_ = lambda_; - break; +bool MasterUpdateBase::Update(const CRITERION &criterion) { + switch (criterion) { + case CRITERION::LOW: + lambda_max_ = + std::min(lambda_max_, benders_->GetBestIterationData().invest_cost); + break; + case CRITERION::HIGH: + lambda_min_ = lambda_; + break; - default: - return; + default: + return true; + } + stop_update_ = std::abs(lambda_max_ - lambda_min_) < epsilon_lambda_; + if (!stop_update_) { + lambda_ = dichotomy_weight_coeff_ * lambda_max_ + + (1 - dichotomy_weight_coeff_) * lambda_min_; + UpdateConstraints(); } - lambda_ = dichotomy_weight_coeff_ * lambda_max_ + - (1 - dichotomy_weight_coeff_) * lambda_min_; - UpdateConstraints(); + return stop_update_; } void MasterUpdateBase::UpdateConstraints() { diff --git a/src/cpp/benders/external_loop/OuterLoop.cpp b/src/cpp/benders/external_loop/OuterLoop.cpp index f86ca3d92..8f12a7f8d 100644 --- a/src/cpp/benders/external_loop/OuterLoop.cpp +++ b/src/cpp/benders/external_loop/OuterLoop.cpp @@ -52,15 +52,15 @@ void OuterLoop::Run() { } mpi::broadcast(world_, criterion, 0); - - while (criterion != CRITERION::IS_MET) { + bool stop_update_master = false; + while (!stop_update_master) { benders_->ResetData(criterion_->CriterionValue()); PrintLog(); benders_->launch(); if (world_.rank() == 0) { criterion = criterion_->IsCriterionSatisfied( benders_->BestIterationWorkerMaster()); - master_updater_->Update(criterion); + stop_update_master = master_updater_->Update(criterion); } mpi::broadcast(world_, criterion, 0); diff --git a/src/cpp/benders/external_loop/include/MasterUpdate.h b/src/cpp/benders/external_loop/include/MasterUpdate.h index 51f3a746b..538690a18 100644 --- a/src/cpp/benders/external_loop/include/MasterUpdate.h +++ b/src/cpp/benders/external_loop/include/MasterUpdate.h @@ -3,21 +3,23 @@ class IMasterUpdate { public: - virtual void Update(const CRITERION &criterion) = 0; + virtual bool Update(const CRITERION &criterion) = 0; virtual void Init() = 0; }; class MasterUpdateBase : public IMasterUpdate { public: explicit MasterUpdateBase(pBendersBase benders, double lambda, - double lambda_min, double lambda_max, double tau); + double lambda_min, double lambda_max, double tau, + double epsilon_lambda); explicit MasterUpdateBase(pBendersBase benders, double lambda, double lambda_min, double lambda_max, double tau, - const std::string &name); + const std::string &name, double epsilon_lambda); + explicit MasterUpdateBase(pBendersBase benders, double tau, + const std::string &name, double epsilon_lambda); explicit MasterUpdateBase(pBendersBase benders, double tau, - const std::string &name); - explicit MasterUpdateBase(pBendersBase benders, double tau); - void Update(const CRITERION &criterion) override; + double epsilon_lambda); + bool Update(const CRITERION &criterion) override; void Init() override; private: @@ -34,4 +36,6 @@ class MasterUpdateBase : public IMasterUpdate { double lambda_max_ = -1; // tau double dichotomy_weight_coeff_ = 0.5; + double epsilon_lambda_ = 1e-1; + bool stop_update_ = true; }; diff --git a/src/cpp/benders/factories/BendersFactory.cpp b/src/cpp/benders/factories/BendersFactory.cpp index 6231a1f7b..37e68e9fd 100644 --- a/src/cpp/benders/factories/BendersFactory.cpp +++ b/src/cpp/benders/factories/BendersFactory.cpp @@ -168,11 +168,12 @@ int RunExternalLoop_(char** argv, const std::filesystem::path& options_file, auto benders = PrepareForExecution(benders_loggers, options, argv[0], true, env, world); double tau = 0.5; + double epsilon_lambda = 0.1; std::shared_ptr criterion = std::make_shared( options.GetExternalLoopOptions()); std::shared_ptr master_updater = - std::make_shared(benders, tau); + std::make_shared(benders, tau, epsilon_lambda); std::shared_ptr cuts_manager = std::make_shared(); diff --git a/tests/cpp/ext_loop/ext_loop_test.cpp b/tests/cpp/ext_loop/ext_loop_test.cpp index 4b68c7f1f..5c5b46a6b 100644 --- a/tests/cpp/ext_loop/ext_loop_test.cpp +++ b/tests/cpp/ext_loop/ext_loop_test.cpp @@ -176,21 +176,20 @@ TEST_P(MasterUpdateBaseTest, ConstraintIsAddedBendersMPI) { benders->InitializeProblems(); benders->launch(); - MasterUpdateBase master_updater(benders, 0.5); + MasterUpdateBase master_updater(benders, 0.5, 0.1); // update lambda_max master_updater.Init(); benders->ResetData(3.0); benders->launch(); auto num_constraints_master_before = benders->MasterGetnrows(); - master_updater.Update(CRITERION::LOW); + master_updater.Update(CRITERION::HIGH); auto num_constraints_master_after = benders->MasterGetnrows(); auto master_variables = benders->MasterVariables(); auto expected_coeffs = benders->MasterObjectiveFunctionCoeffs(); // criterion is low <=> lambda_max = min(lambda_max, invest_cost) - auto lambda_max = (std::min)(LambdaMax(benders), - benders->GetBestIterationData().invest_cost); + auto lambda_max = LambdaMax(benders); auto expected_rhs = 0.5 * lambda_max; // @@ -233,7 +232,7 @@ TEST_P(MasterUpdateBaseTest, InitialRhs) { benders->launch(); - MasterUpdateBase master_updater(benders, 0.5); + MasterUpdateBase master_updater(benders, 0.5, 0.1); // update lambda_max master_updater.Init(); auto lambda_max = LambdaMax(benders); From 11eb3001b8c9c30da1687403ce17a16ea9594ede Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Wed, 20 Mar 2024 17:01:50 +0100 Subject: [PATCH 07/15] fix --- .../benders_by_batch/BendersByBatch.cpp | 4 +- src/cpp/benders/benders_core/BendersBase.cpp | 7 ++- .../benders_core/BendersMathLogger.cpp | 2 +- .../benders_core/include/BendersBase.h | 1 + .../include/BendersStructsDatas.h | 2 +- src/cpp/benders/benders_mpi/BendersMPI.cpp | 4 +- src/cpp/benders/external_loop/OuterLoop.cpp | 22 ++++--- .../external_loop/OuterloopCriterion.cpp | 22 +------ .../include/OuterLoopCriterion.h | 11 +--- tests/cpp/ext_loop/ext_loop_test.cpp | 57 +++---------------- 10 files changed, 35 insertions(+), 97 deletions(-) diff --git a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp index 7ec91945a..c1f3b9707 100644 --- a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp +++ b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp @@ -151,7 +151,7 @@ void BendersByBatch::SeparationLoop() { SolveBatches(); if (Rank() == rank_0) { - outer_loop_criterion_.push_back(_data.external_loop_criterion); + outer_loop_criterion_.push_back(_data.outer_loop_criterion); UpdateTrace(); SaveCurrentBendersData(); } @@ -209,7 +209,7 @@ void BendersByBatch::SolveBatches() { _data.number_of_subproblem_solved += batch_sub_problems.size(); _data.cumulative_number_of_subproblem_solved += batch_sub_problems.size(); remaining_epsilon_ -= batch_subproblems_costs_contribution_in_gap; - _data.external_loop_criterion += external_loop_criterion_current_batch; + _data.outer_loop_criterion += external_loop_criterion_current_batch; } BroadCast(remaining_epsilon_, rank_0); diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index 34bb7b3c0..b32f1f1f1 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -936,17 +936,20 @@ WorkerMasterData BendersBase::BestIterationWorkerMaster() const { void BendersBase::ResetData(double criterion) { init_data(); - _data.external_loop_criterion = criterion; + _data.outer_loop_criterion = criterion; } void BendersBase::InitExternalValues() { - // _data.external_loop_criterion = 0; + // _data.outer_loop_criterion = 0; _data.benders_num_run = 0; } CurrentIterationData BendersBase::GetCurrentIterationData() const { return _data; } +double BendersBase::GetOuterLoopCriterion() const { + return _data.outer_loop_criterion; +} double BendersBase::ComputeOuterLoopCriterion( const std::string &subproblem_name, diff --git a/src/cpp/benders/benders_core/BendersMathLogger.cpp b/src/cpp/benders/benders_core/BendersMathLogger.cpp index ccf2ace3d..e93f33c25 100644 --- a/src/cpp/benders/benders_core/BendersMathLogger.cpp +++ b/src/cpp/benders/benders_core/BendersMathLogger.cpp @@ -159,7 +159,7 @@ void PrintExternalLoopData(LogDestination& log_destination, const BENDERSMETHOD& method) { log_destination << data.benders_num_run; log_destination << std::scientific << std::setprecision(10) - << data.external_loop_criterion; + << data.outer_loop_criterion; PrintBendersData(log_destination, data, type, method); } void MathLoggerBaseExternalLoop::Print(const CurrentIterationData& data) { diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index 03ff633b2..dd6b499b3 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -85,6 +85,7 @@ class BendersBase { void InitExternalValues(); int GetBendersRunNumber() const { return _data.benders_num_run; } CurrentIterationData GetCurrentIterationData() const; + double GetOuterLoopCriterion() const; protected: CurrentIterationData _data; diff --git a/src/cpp/benders/benders_core/include/BendersStructsDatas.h b/src/cpp/benders/benders_core/include/BendersStructsDatas.h index 30318ab6b..f0f5c9667 100644 --- a/src/cpp/benders/benders_core/include/BendersStructsDatas.h +++ b/src/cpp/benders/benders_core/include/BendersStructsDatas.h @@ -40,7 +40,7 @@ struct CurrentIterationData { int max_simplexiter; // ugly int benders_num_run; - double external_loop_criterion; + double outer_loop_criterion; }; // /*! \struct to store benders cuts data diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index 2de79de96..5a69cb837 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -139,10 +139,10 @@ void BendersMpi::gather_subproblems_cut_package_and_build_cuts( Reduce(GetSubproblemsCpuTime(), cumulative_subproblems_timer_per_iter, std::plus(), rank_0); SetSubproblemsCumulativeCpuTime(cumulative_subproblems_timer_per_iter); - _data.external_loop_criterion = + _data.outer_loop_criterion = ComputeSubproblemsContributionToOuterLoopCriterion(subproblem_data_map); if (_world.rank() == rank_0) { - outer_loop_criterion_.push_back(_data.external_loop_criterion); + outer_loop_criterion_.push_back(_data.outer_loop_criterion); } // only rank_0 receive non-emtpy gathered_subproblem_map master_build_cuts(gathered_subproblem_map); diff --git a/src/cpp/benders/external_loop/OuterLoop.cpp b/src/cpp/benders/external_loop/OuterLoop.cpp index 8f12a7f8d..cfb7bb4f7 100644 --- a/src/cpp/benders/external_loop/OuterLoop.cpp +++ b/src/cpp/benders/external_loop/OuterLoop.cpp @@ -21,7 +21,7 @@ void OuterLoop::Run() { benders_->DoFreeProblems(false); benders_->InitializeProblems(); benders_->InitExternalValues(); - CRITERION criterion = CRITERION::IS_MET; + CRITERION criterion_check = CRITERION::IS_MET; std::vector obj_coeff; if (world_.rank() == 0) { obj_coeff = benders_->MasterObjectiveFunctionCoeffs(); @@ -38,9 +38,9 @@ void OuterLoop::Run() { // de-comment for general case // cuts_manager_->Save(benders_->AllCuts()); // auto cuts = cuts_manager_->Load(); - criterion = - criterion_->IsCriterionSatisfied(benders_->BestIterationWorkerMaster()); - if (criterion == CRITERION::HIGH) { + criterion_check = + criterion_->IsCriterionSatisfied(benders_->GetOuterLoopCriterion()); + if (criterion_check == CRITERION::HIGH) { std::ostringstream err_msg; err_msg << PrefixMessage(LogUtils::LOGLEVEL::FATAL, "External Loop") << "Criterion cannot be satisfied for your study:\n" @@ -51,25 +51,23 @@ void OuterLoop::Run() { master_updater_->Init(); } - mpi::broadcast(world_, criterion, 0); + mpi::broadcast(world_, criterion_check, 0); bool stop_update_master = false; while (!stop_update_master) { benders_->ResetData(criterion_->CriterionValue()); PrintLog(); benders_->launch(); if (world_.rank() == 0) { - criterion = criterion_->IsCriterionSatisfied( - benders_->BestIterationWorkerMaster()); - stop_update_master = master_updater_->Update(criterion); + criterion_check = + criterion_->IsCriterionSatisfied(benders_->GetOuterLoopCriterion()); + stop_update_master = master_updater_->Update(criterion_check); } - mpi::broadcast(world_, criterion, 0); + mpi::broadcast(world_, criterion_check, 0); } // last prints PrintLog(); - auto benders_data = benders_->GetCurrentIterationData(); - benders_data.external_loop_criterion = criterion_->CriterionValue(); - benders_->mathLoggerDriver_->Print(benders_data); + benders_->mathLoggerDriver_->Print(benders_->GetCurrentIterationData()); // TODO general-case // cuts_manager_->Save(benders_->AllCuts()); diff --git a/src/cpp/benders/external_loop/OuterloopCriterion.cpp b/src/cpp/benders/external_loop/OuterloopCriterion.cpp index 842546b7a..6c12739dc 100644 --- a/src/cpp/benders/external_loop/OuterloopCriterion.cpp +++ b/src/cpp/benders/external_loop/OuterloopCriterion.cpp @@ -6,9 +6,8 @@ OuterloopCriterionLossOfLoad::OuterloopCriterionLossOfLoad( const ExternalLoopOptions& options) : options_(options) {} -CRITERION OuterloopCriterionLossOfLoad::IsCriterionSatisfied( - const WorkerMasterData& worker_master_data) { - ProcessSum(worker_master_data); +CRITERION OuterloopCriterionLossOfLoad::IsCriterionSatisfied(double sum_loss) { + sum_loss_ = sum_loss; if (sum_loss_ <= options_.EXT_LOOP_CRITERION_VALUE + options_.EXT_LOOP_CRITERION_TOLERANCE) { @@ -22,23 +21,6 @@ CRITERION OuterloopCriterionLossOfLoad::IsCriterionSatisfied( } } -void OuterloopCriterionLossOfLoad::ProcessSum( - const WorkerMasterData& worker_master_data) { - sum_loss_ = 0; - for (const auto& [sub_problem_name, sub_problem_data] : - worker_master_data._cut_trace) { - for (auto i(0); i < sub_problem_data.variables.names.size(); ++i) { - auto var_name = sub_problem_data.variables.names[i]; - auto solution = sub_problem_data.variables.values[i]; - if (std::regex_search(var_name, rgx_) && - solution > options_.EXT_LOOP_CRITERION_COUNT_THRESHOLD) { - // 1h of unsupplied energy - sum_loss_ += 1; - } - } - } -} - std::string OuterloopCriterionLossOfLoad::StateAsString() const { std::ostringstream msg; msg << "Sum loss = " << sum_loss_ << "\n" diff --git a/src/cpp/benders/external_loop/include/OuterLoopCriterion.h b/src/cpp/benders/external_loop/include/OuterLoopCriterion.h index 128380873..0a0c921ac 100644 --- a/src/cpp/benders/external_loop/include/OuterLoopCriterion.h +++ b/src/cpp/benders/external_loop/include/OuterLoopCriterion.h @@ -14,8 +14,7 @@ class CriterionCouldNotBeSatisfied enum class CRITERION { LOW, IS_MET, HIGH }; class IOuterLoopCriterion { public: - virtual CRITERION IsCriterionSatisfied( - const WorkerMasterData& worker_master_data) = 0; + virtual CRITERION IsCriterionSatisfied(double criterion_value) = 0; virtual std::string StateAsString() const = 0; virtual double CriterionValue() const = 0; }; @@ -23,17 +22,11 @@ class IOuterLoopCriterion { class OuterloopCriterionLossOfLoad : public IOuterLoopCriterion { public: explicit OuterloopCriterionLossOfLoad(const ExternalLoopOptions& options); - CRITERION IsCriterionSatisfied( - const WorkerMasterData& milp_solution) override; + CRITERION IsCriterionSatisfied(double sum_loss) override; std::string StateAsString() const override; double CriterionValue() const override { return sum_loss_; } private: - void ProcessSum(const WorkerMasterData& worker_master_data); - const std::string positive_unsupplied_vars_prefix_ = - "^PositiveUnsuppliedEnergy::"; - const std::regex rgx_ = std::regex(positive_unsupplied_vars_prefix_); - ExternalLoopOptions options_; double sum_loss_ = 0.0; }; diff --git a/tests/cpp/ext_loop/ext_loop_test.cpp b/tests/cpp/ext_loop/ext_loop_test.cpp index 5c5b46a6b..d9e56dc8a 100644 --- a/tests/cpp/ext_loop/ext_loop_test.cpp +++ b/tests/cpp/ext_loop/ext_loop_test.cpp @@ -35,25 +35,12 @@ TEST_F(OuterLoopCriterionTest, IsCriterionHigh) { double epsilon = 1e-1; double max_unsup_energy = 0.1; const ExternalLoopOptions options = {threshold, epsilon, max_unsup_energy}; - PlainData::Variables variables = { - {"PositiveUnsuppliedEnergy::1", "PositiveUnsuppliedEnergy::2", "var3"}, - {0.2, 0.3, 68}}; - double criterion_value = 2.0; // two vars named ^PositiveUnsuppliedEnergy - // with value > max_unsup_energy - - PlainData::SubProblemData subProblemData; - subProblemData.variables = variables; - SubProblemDataMap cut_trace = { - std::make_pair(std::string("P1"), subProblemData)}; - - WorkerMasterData worker_master_data; - worker_master_data._cut_trace = cut_trace; + double criterion_value = 2.0; OuterloopCriterionLossOfLoad criterion(options); - EXPECT_EQ(criterion.IsCriterionSatisfied(worker_master_data), - CRITERION::HIGH); - EXPECT_EQ(criterion.CriterionValue(), criterion_value); + // criterion_value = 2 > threshold+epsilon + EXPECT_EQ(criterion.IsCriterionSatisfied(criterion_value), CRITERION::HIGH); } TEST_F(OuterLoopCriterionTest, IsCriterionLow) { @@ -61,24 +48,11 @@ TEST_F(OuterLoopCriterionTest, IsCriterionLow) { double epsilon = 1e-1; double max_unsup_energy = 0.1; const ExternalLoopOptions options = {threshold, epsilon, max_unsup_energy}; - PlainData::Variables variables = { - {"PositiveUnsuppliedEnergy::1", "PositiveUnsuppliedEnergy::2", "var3"}, - {0.2, 0.3, 68}}; - double criterion_value = 2.0; // two vars named PositiveUnsuppliedEnergy with - // value > max_unsup_energy - - PlainData::SubProblemData subProblemData; - subProblemData.variables = variables; - SubProblemDataMap cut_trace = { - std::make_pair(std::string("P1"), subProblemData)}; - - WorkerMasterData worker_master_data; - worker_master_data._cut_trace = cut_trace; - + double criterion_value = 2.0; OuterloopCriterionLossOfLoad criterion(options); - EXPECT_EQ(criterion.IsCriterionSatisfied(worker_master_data), CRITERION::LOW); - EXPECT_EQ(criterion.CriterionValue(), criterion_value); + // criterion_value < threshold - epsilon + EXPECT_EQ(criterion.IsCriterionSatisfied(criterion_value), CRITERION::LOW); } TEST_F(OuterLoopCriterionTest, IsMet) { @@ -86,25 +60,12 @@ TEST_F(OuterLoopCriterionTest, IsMet) { double epsilon = 1e-1; double max_unsup_energy = 0.1; const ExternalLoopOptions options = {threshold, epsilon, max_unsup_energy}; - PlainData::Variables variables = { - {"PositiveUnsuppliedEnergy::1", "PositiveUnsuppliedEnergy::2", "var3"}, - {0.2, 0.3, 68}}; - double criterion_value = 2.0; // two vars named PositiveUnsuppliedEnergy with - // value > max_unsup_energy - - PlainData::SubProblemData subProblemData; - subProblemData.variables = variables; - SubProblemDataMap cut_trace = { - std::make_pair(std::string("P1"), subProblemData)}; - - WorkerMasterData worker_master_data; - worker_master_data._cut_trace = cut_trace; + double criterion_value = 2.0; OuterloopCriterionLossOfLoad criterion(options); - EXPECT_EQ(criterion.IsCriterionSatisfied(worker_master_data), - CRITERION::IS_MET); - EXPECT_EQ(criterion.CriterionValue(), criterion_value); + // threshold - epsilon <= criterion_value <= threshold + epsilon + EXPECT_EQ(criterion.IsCriterionSatisfied(criterion_value), CRITERION::IS_MET); } //-------------------- MasterUpdateBaseTest ------------------------- From 49b38be58494d190be50294d20c8899acdbc524f Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 21 Mar 2024 13:11:02 +0100 Subject: [PATCH 08/15] big jump --- .../benders_by_batch/BendersByBatch.cpp | 13 ++++-- .../benders_by_batch/include/BendersByBatch.h | 2 +- src/cpp/benders/benders_core/BendersBase.cpp | 46 ++++++++++++++----- src/cpp/benders/benders_core/CMakeLists.txt | 1 + .../benders/benders_core/VariablesGroup.cpp | 22 +++++++++ .../benders_core/include/BendersBase.h | 18 +++++++- .../include/BendersStructsDatas.h | 2 +- .../benders_core/include/CustomVector.h | 11 +++++ .../benders_core/include/VariablesGroup.h | 17 +++++++ src/cpp/benders/benders_mpi/BendersMPI.cpp | 21 ++++++--- .../benders/benders_mpi/include/BendersMPI.h | 3 +- src/cpp/benders/external_loop/OuterLoop.cpp | 3 +- .../external_loop/OuterloopCriterion.cpp | 28 ++++++----- .../include/OuterLoopCriterion.h | 12 +++-- 14 files changed, 155 insertions(+), 44 deletions(-) create mode 100644 src/cpp/benders/benders_core/VariablesGroup.cpp create mode 100644 src/cpp/benders/benders_core/include/CustomVector.h create mode 100644 src/cpp/benders/benders_core/include/VariablesGroup.h diff --git a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp index c1f3b9707..710f516d7 100644 --- a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp +++ b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp @@ -6,6 +6,7 @@ #include #include "BatchCollection.h" +#include "CustomVector.h" #include "RandomBatchShuffler.h" #include "glog/logging.h" BendersByBatch::BendersByBatch( @@ -46,6 +47,10 @@ void BendersByBatch::InitializeProblems() { problem_count++; } } + + // if (Rank() == rank_0) { + SetSubproblemsVariablesIndex(); + // } init_problems_ = false; } void BendersByBatch::BroadcastSingleSubpbCostsUnderApprox() { @@ -196,7 +201,7 @@ void BendersByBatch::SolveBatches() { const auto &batch_sub_problems = batch.sub_problem_names; double batch_subproblems_costs_contribution_in_gap_per_proc = 0; double batch_subproblems_costs_contribution_in_gap = 0; - double external_loop_criterion_current_batch = 0; + std::vector external_loop_criterion_current_batch = 0; BuildCut(batch_sub_problems, &batch_subproblems_costs_contribution_in_gap_per_proc, external_loop_criterion_current_batch); @@ -205,11 +210,13 @@ void BendersByBatch::SolveBatches() { rank_0); Reduce(GetSubproblemsCpuTime(), cumulative_subproblems_timer_per_iter_, std::plus(), rank_0); + AddVectors vector_add; if (Rank() == rank_0) { _data.number_of_subproblem_solved += batch_sub_problems.size(); _data.cumulative_number_of_subproblem_solved += batch_sub_problems.size(); remaining_epsilon_ -= batch_subproblems_costs_contribution_in_gap; - _data.outer_loop_criterion += external_loop_criterion_current_batch; + vector_add(_data.outer_loop_criterion, + external_loop_criterion_current_batch); } BroadCast(remaining_epsilon_, rank_0); @@ -227,7 +234,7 @@ void BendersByBatch::SolveBatches() { void BendersByBatch::BuildCut( const std::vector &batch_sub_problems, double *batch_subproblems_costs_contribution_in_gap_per_proc, - double &external_loop_criterion_current_batch) { + std::vector &external_loop_criterion_current_batch) { SubProblemDataMap subproblem_data_map; Timer subproblems_timer_per_proc; GetSubproblemCut(subproblem_data_map, batch_sub_problems, diff --git a/src/cpp/benders/benders_by_batch/include/BendersByBatch.h b/src/cpp/benders/benders_by_batch/include/BendersByBatch.h index 41c6a13c8..03dde786e 100644 --- a/src/cpp/benders/benders_by_batch/include/BendersByBatch.h +++ b/src/cpp/benders/benders_by_batch/include/BendersByBatch.h @@ -14,7 +14,7 @@ class BendersByBatch : public BendersMpi { ~BendersByBatch() override = default; void Run() override; void BuildCut(const std::vector &batch_sub_problems, double *sum, - double &external_loop_criterion_current_batch); + std::vector &external_loop_criterion_current_batch); std::string BendersName() const override { return "Benders By Batch mpi"; } protected: diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index b32f1f1f1..9d4ad3caa 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -9,6 +9,7 @@ #include "LastIterationReader.h" #include "LastIterationWriter.h" #include "LogUtils.h" +#include "VariablesGroup.h" #include "glog/logging.h" #include "solver_utils.h" @@ -731,6 +732,16 @@ void BendersBase::MatchProblemToId() { } } +void BendersBase::SetSubproblemsVariablesIndex() { + if (!subproblem_map.empty()) { + auto subproblem = subproblem_map.begin(); + subproblems_vars_names_.clear(); + subproblems_vars_names_ = subproblem->second->_solver->get_col_names(); + VariablesGroup variablesGroup(subproblems_vars_names_, patterns_); + var_indices_ = variablesGroup.Indices(); + } +} + void BendersBase::AddSubproblemName(const std::string &name) { subproblems.push_back(name); } @@ -947,22 +958,35 @@ void BendersBase::InitExternalValues() { CurrentIterationData BendersBase::GetCurrentIterationData() const { return _data; } -double BendersBase::GetOuterLoopCriterion() const { +std::vector BendersBase::GetOuterLoopCriterion() const { return _data.outer_loop_criterion; } -double BendersBase::ComputeOuterLoopCriterion( +std::vector BendersBase::ComputeOuterLoopCriterion( const std::string &subproblem_name, const PlainData::SubProblemData &sub_problem_data) { - double outer_loop_criterion_per_sub_problem = 0.0; - for (auto i(0); i < sub_problem_data.variables.names.size(); ++i) { - auto var_name = sub_problem_data.variables.names[i]; - auto solution = sub_problem_data.variables.values[i]; - if (std::regex_search(var_name, rgx_) && - solution > - _options.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_COUNT_THRESHOLD) { - // 1h of unsupplied energy - outer_loop_criterion_per_sub_problem += 1; + std::vector outer_loop_criterion_per_sub_problem(patterns_.size(), + {}); + // for (auto i(0); i < sub_problem_data.variables.names.size(); ++i) { + // auto var_name = sub_problem_data.variables.names[i]; + // auto solution = sub_problem_data.variables.values[i]; + // if (std::regex_search(var_name, rgx_) && + // solution > + // _options.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_COUNT_THRESHOLD) + // { + // // 1h of unsupplied energy + // outer_loop_criterion_per_sub_problem += 1; + // } + // } + for (int pattern_index(0); pattern_index < patterns_.size(); + ++pattern_index) { + auto pattern_variables_indices = var_indices_[pattern_index]; + for (auto variables_index : pattern_variables_indices) { + if (auto solution = sub_problem_data.variables.values[variables_index]; + solution > + _options.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_COUNT_THRESHOLD) + // 1h of unsupplied energy + outer_loop_criterion_per_sub_problem[pattern_index] += 1; } } return outer_loop_criterion_per_sub_problem; diff --git a/src/cpp/benders/benders_core/CMakeLists.txt b/src/cpp/benders/benders_core/CMakeLists.txt index e3f38ffac..10d127fbe 100644 --- a/src/cpp/benders/benders_core/CMakeLists.txt +++ b/src/cpp/benders/benders_core/CMakeLists.txt @@ -27,6 +27,7 @@ add_library (benders_core STATIC ${CMAKE_CURRENT_SOURCE_DIR}/LastIterationPrinter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/StartUp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/BendersMathLogger.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/VariablesGroup.cpp ) get_target_property(JSON_INC_PATH jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES) diff --git a/src/cpp/benders/benders_core/VariablesGroup.cpp b/src/cpp/benders/benders_core/VariablesGroup.cpp new file mode 100644 index 000000000..fcde4ee52 --- /dev/null +++ b/src/cpp/benders/benders_core/VariablesGroup.cpp @@ -0,0 +1,22 @@ +#include "VariablesGroup.h" + +VariablesGroup::VariablesGroup(const std::vector& all_variables, + const std::vector& patterns) + : all_variables_(all_variables), patterns_(patterns) { + Search(); +} + +void VariablesGroup::Search() { + indices_.assign(patterns_.size(), {}); + int var_index(0); + for (const auto& variable : all_variables_) { + ++var_index; + int pattern_index(0); + for (const auto& pattern : patterns_) { + ++pattern_index; + if (std::regex_search(variable, pattern)) { + indices_[pattern_index].push_back(var_index); + } + } + } +} \ No newline at end of file diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index dd6b499b3..ff5eedea0 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -85,7 +85,7 @@ class BendersBase { void InitExternalValues(); int GetBendersRunNumber() const { return _data.benders_num_run; } CurrentIterationData GetCurrentIterationData() const; - double GetOuterLoopCriterion() const; + std::vector GetOuterLoopCriterion() const; protected: CurrentIterationData _data; @@ -102,6 +102,10 @@ class BendersBase { "^PositiveUnsuppliedEnergy::"; const std::regex rgx_ = std::regex(positive_unsupplied_vars_prefix_); std::vector outer_loop_criterion_; + std::vector subproblems_vars_names_ = {}; + // tmp + std::vector patterns_ = {rgx_}; + std::vector> var_indices_; protected: virtual void Run() = 0; @@ -136,6 +140,15 @@ class BendersBase { void AddSubproblem(const std::pair &kvp); [[nodiscard]] WorkerMasterPtr get_master() const; void MatchProblemToId(); + /** + * for the nth variable name, Subproblems shares the same prefix , only the + suffix is different + * ex variable at index = 0 is named in: + + * subproblems-1-1 --> NTCDirect::link::hour<0> + * subproblems-3-5 --> NTCDirect::link::hour<672> + */ + void SetSubproblemsVariablesIndex(); void AddSubproblemName(const std::string &name); [[nodiscard]] std::string get_master_name() const; [[nodiscard]] std::string get_solver_name() const; @@ -198,7 +211,8 @@ class BendersBase { SolverLogManager solver_log_manager_; - double ComputeOuterLoopCriterion( + // outer loop criterion per pattern + std::vector ComputeOuterLoopCriterion( const std::string &subproblem_name, const PlainData::SubProblemData &sub_problem_data); diff --git a/src/cpp/benders/benders_core/include/BendersStructsDatas.h b/src/cpp/benders/benders_core/include/BendersStructsDatas.h index f0f5c9667..990ad5aa9 100644 --- a/src/cpp/benders/benders_core/include/BendersStructsDatas.h +++ b/src/cpp/benders/benders_core/include/BendersStructsDatas.h @@ -40,7 +40,7 @@ struct CurrentIterationData { int max_simplexiter; // ugly int benders_num_run; - double outer_loop_criterion; + std::vector outer_loop_criterion; }; // /*! \struct to store benders cuts data diff --git a/src/cpp/benders/benders_core/include/CustomVector.h b/src/cpp/benders/benders_core/include/CustomVector.h new file mode 100644 index 000000000..ed6e67fa8 --- /dev/null +++ b/src/cpp/benders/benders_core/include/CustomVector.h @@ -0,0 +1,11 @@ +#pragma once +#include + +template +struct AddVectors { + void operator()(const std::vector& a, const std::vector& b) const { + if (a.size() == b.size()) { + std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus()); + } + } +}; \ No newline at end of file diff --git a/src/cpp/benders/benders_core/include/VariablesGroup.h b/src/cpp/benders/benders_core/include/VariablesGroup.h new file mode 100644 index 000000000..777a6917a --- /dev/null +++ b/src/cpp/benders/benders_core/include/VariablesGroup.h @@ -0,0 +1,17 @@ +#pragma once +#include +#include +#include + +class VariablesGroup { + public: + explicit VariablesGroup(const std::vector& all_variables, + const std::vector& patterns); + std::vector> Indices() const { return indices_; } + + private: + void Search(); + const std::vector& all_variables_; + std::vector patterns_; + std::vector> indices_; +}; \ No newline at end of file diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index 5a69cb837..18a268aff 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -4,6 +4,7 @@ #include #include +#include "CustomVector.h" #include "Timer.h" #include "glog/logging.h" @@ -40,6 +41,10 @@ void BendersMpi::InitializeProblems() { } current_problem_id++; } + + if (_world.rank() == rank_0) { + SetSubproblemsVariablesIndex(); + } init_problems_ = false; } void BendersMpi::BuildMasterProblem() { @@ -149,19 +154,23 @@ void BendersMpi::gather_subproblems_cut_package_and_build_cuts( } } -double BendersMpi::ComputeSubproblemsContributionToOuterLoopCriterion( +std::vector +BendersMpi::ComputeSubproblemsContributionToOuterLoopCriterion( const SubProblemDataMap &subproblem_data_map) { - double outer_loop_criterion_sub_problems_map = 0.0; - double outer_loop_criterion_sub_problems_map_result = 0.0; + std::vector outer_loop_criterion_per_sub_problem_per_pattern( + patterns_.size(), {}); + std::vector outer_loop_criterion_sub_problems_map_result( + patterns_.size(), {}); + AddVectors vector_add; for (const auto &[subproblem_name, subproblem_data] : subproblem_data_map) { - outer_loop_criterion_sub_problems_map += + vector_add(outer_loop_criterion_per_sub_problem_per_pattern, ComputeOuterLoopCriterion(subproblem_name, subproblem_data); } - Reduce(outer_loop_criterion_sub_problems_map, + Reduce(outer_loop_criterion_per_sub_problem_per_pattern, outer_loop_criterion_sub_problems_map_result, std::plus(), rank_0); - return outer_loop_criterion_sub_problems_map; + return outer_loop_criterion_sub_problems_map_result; } SubProblemDataMap BendersMpi::get_subproblem_cut_package() { diff --git a/src/cpp/benders/benders_mpi/include/BendersMPI.h b/src/cpp/benders/benders_mpi/include/BendersMPI.h index b54eb2bde..2041cebd0 100644 --- a/src/cpp/benders/benders_mpi/include/BendersMPI.h +++ b/src/cpp/benders/benders_mpi/include/BendersMPI.h @@ -85,6 +85,7 @@ class BendersMpi : public BendersBase { void AllReduce(const T &in_value, T &out_value, Op op) const { mpi::all_reduce(_world, in_value, out_value, op); } - virtual double ComputeSubproblemsContributionToOuterLoopCriterion( + virtual std::vector + ComputeSubproblemsContributionToOuterLoopCriterion( const SubProblemDataMap &subproblem_data_map); }; diff --git a/src/cpp/benders/external_loop/OuterLoop.cpp b/src/cpp/benders/external_loop/OuterLoop.cpp index cfb7bb4f7..cedcfb93d 100644 --- a/src/cpp/benders/external_loop/OuterLoop.cpp +++ b/src/cpp/benders/external_loop/OuterLoop.cpp @@ -51,7 +51,6 @@ void OuterLoop::Run() { master_updater_->Init(); } - mpi::broadcast(world_, criterion_check, 0); bool stop_update_master = false; while (!stop_update_master) { benders_->ResetData(criterion_->CriterionValue()); @@ -63,7 +62,7 @@ void OuterLoop::Run() { stop_update_master = master_updater_->Update(criterion_check); } - mpi::broadcast(world_, criterion_check, 0); + mpi::broadcast(world_, stop_update_master, 0); } // last prints PrintLog(); diff --git a/src/cpp/benders/external_loop/OuterloopCriterion.cpp b/src/cpp/benders/external_loop/OuterloopCriterion.cpp index 6c12739dc..904d96818 100644 --- a/src/cpp/benders/external_loop/OuterloopCriterion.cpp +++ b/src/cpp/benders/external_loop/OuterloopCriterion.cpp @@ -6,24 +6,28 @@ OuterloopCriterionLossOfLoad::OuterloopCriterionLossOfLoad( const ExternalLoopOptions& options) : options_(options) {} -CRITERION OuterloopCriterionLossOfLoad::IsCriterionSatisfied(double sum_loss) { - sum_loss_ = sum_loss; - - if (sum_loss_ <= options_.EXT_LOOP_CRITERION_VALUE + - options_.EXT_LOOP_CRITERION_TOLERANCE) { - if (sum_loss_ >= options_.EXT_LOOP_CRITERION_VALUE - - options_.EXT_LOOP_CRITERION_TOLERANCE) { - return CRITERION::IS_MET; +CRITERION OuterloopCriterionLossOfLoad::IsCriterionSatisfied( + const std::vector& criterion_value) { + criterion_values_ = criterion_value; + for (criterion_value : criterion_values_) { + // options_.EXT_LOOP_CRITERION_VALUE --> to vect + // options_.EXT_LOOP_CRITERION_TOLERANCE --> to vect + if (criterion_value <= options_.EXT_LOOP_CRITERION_VALUE + + options_.EXT_LOOP_CRITERION_TOLERANCE) { + if (criterion_values >= options_.EXT_LOOP_CRITERION_VALUE - + options_.EXT_LOOP_CRITERION_TOLERANCE) { + return CRITERION::IS_MET; + } + return CRITERION::LOW; + } else { + return CRITERION::HIGH; } - return CRITERION::LOW; - } else { - return CRITERION::HIGH; } } std::string OuterloopCriterionLossOfLoad::StateAsString() const { std::ostringstream msg; - msg << "Sum loss = " << sum_loss_ << "\n" + msg << "Sum loss = " << criterion_values_ << "\n" << "threshold: " << options_.EXT_LOOP_CRITERION_VALUE << "\n" << "epsilon: " << options_.EXT_LOOP_CRITERION_TOLERANCE << "\n"; diff --git a/src/cpp/benders/external_loop/include/OuterLoopCriterion.h b/src/cpp/benders/external_loop/include/OuterLoopCriterion.h index 0a0c921ac..9a3c2d1c2 100644 --- a/src/cpp/benders/external_loop/include/OuterLoopCriterion.h +++ b/src/cpp/benders/external_loop/include/OuterLoopCriterion.h @@ -14,19 +14,21 @@ class CriterionCouldNotBeSatisfied enum class CRITERION { LOW, IS_MET, HIGH }; class IOuterLoopCriterion { public: - virtual CRITERION IsCriterionSatisfied(double criterion_value) = 0; + virtual CRITERION IsCriterionSatisfied( + const std::vector& criterion_value) = 0; virtual std::string StateAsString() const = 0; - virtual double CriterionValue() const = 0; + virtual double CriterionValues() const = 0; }; class OuterloopCriterionLossOfLoad : public IOuterLoopCriterion { public: explicit OuterloopCriterionLossOfLoad(const ExternalLoopOptions& options); - CRITERION IsCriterionSatisfied(double sum_loss) override; + CRITERION IsCriterionSatisfied( + const std::vector& criterion_values) override; std::string StateAsString() const override; - double CriterionValue() const override { return sum_loss_; } + double CriterionValues() const override { return criterion_values_; } private: ExternalLoopOptions options_; - double sum_loss_ = 0.0; + const std::vector& criterion_values_ = {}; }; From 176753c52a4faf041a078cedc3d0fb547cadbb3e Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 21 Mar 2024 15:04:51 +0100 Subject: [PATCH 09/15] ok --- .../benders/benders_by_batch/BendersByBatch.cpp | 7 +++---- src/cpp/benders/benders_core/BendersBase.cpp | 5 ----- .../benders/benders_core/BendersMathLogger.cpp | 5 ++++- .../benders/benders_core/include/BendersBase.h | 5 ++--- .../benders/benders_core/include/CustomVector.h | 10 ++++------ src/cpp/benders/benders_mpi/BendersMPI.cpp | 6 +++--- src/cpp/benders/external_loop/OuterLoop.cpp | 6 +++--- .../benders/external_loop/OuterloopCriterion.cpp | 16 ++++++++++++---- .../external_loop/include/OuterLoopCriterion.h | 10 +++++++--- tests/cpp/ext_loop/ext_loop_test.cpp | 10 +++++----- 10 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp index 710f516d7..db421c3ec 100644 --- a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp +++ b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp @@ -201,7 +201,7 @@ void BendersByBatch::SolveBatches() { const auto &batch_sub_problems = batch.sub_problem_names; double batch_subproblems_costs_contribution_in_gap_per_proc = 0; double batch_subproblems_costs_contribution_in_gap = 0; - std::vector external_loop_criterion_current_batch = 0; + std::vector external_loop_criterion_current_batch = {}; BuildCut(batch_sub_problems, &batch_subproblems_costs_contribution_in_gap_per_proc, external_loop_criterion_current_batch); @@ -210,13 +210,12 @@ void BendersByBatch::SolveBatches() { rank_0); Reduce(GetSubproblemsCpuTime(), cumulative_subproblems_timer_per_iter_, std::plus(), rank_0); - AddVectors vector_add; if (Rank() == rank_0) { _data.number_of_subproblem_solved += batch_sub_problems.size(); _data.cumulative_number_of_subproblem_solved += batch_sub_problems.size(); remaining_epsilon_ -= batch_subproblems_costs_contribution_in_gap; - vector_add(_data.outer_loop_criterion, - external_loop_criterion_current_batch); + AddVectors(_data.outer_loop_criterion, + external_loop_criterion_current_batch); } BroadCast(remaining_epsilon_, rank_0); diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index 9d4ad3caa..14fcc852f 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -945,11 +945,6 @@ WorkerMasterData BendersBase::BestIterationWorkerMaster() const { return relevantIterationData_.best; } -void BendersBase::ResetData(double criterion) { - init_data(); - _data.outer_loop_criterion = criterion; -} - void BendersBase::InitExternalValues() { // _data.outer_loop_criterion = 0; _data.benders_num_run = 0; diff --git a/src/cpp/benders/benders_core/BendersMathLogger.cpp b/src/cpp/benders/benders_core/BendersMathLogger.cpp index e93f33c25..708144b06 100644 --- a/src/cpp/benders/benders_core/BendersMathLogger.cpp +++ b/src/cpp/benders/benders_core/BendersMathLogger.cpp @@ -158,8 +158,11 @@ void PrintExternalLoopData(LogDestination& log_destination, const HEADERSTYPE& type, const BENDERSMETHOD& method) { log_destination << data.benders_num_run; + // TODO + // log_destination << std::scientific << std::setprecision(10) + // << data.outer_loop_criterion; log_destination << std::scientific << std::setprecision(10) - << data.outer_loop_criterion; + << data.outer_loop_criterion[0]; PrintBendersData(log_destination, data, type, method); } void MathLoggerBaseExternalLoop::Print(const CurrentIterationData& data) { diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index ff5eedea0..5b996729d 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -80,12 +80,12 @@ class BendersBase { _options.MAX_ITERATIONS = max_iteration; } BendersBaseOptions Options() const { return _options; } - void ResetData(double criterion); virtual void free() = 0; void InitExternalValues(); int GetBendersRunNumber() const { return _data.benders_num_run; } CurrentIterationData GetCurrentIterationData() const; std::vector GetOuterLoopCriterion() const; + virtual void init_data(); protected: CurrentIterationData _data; @@ -101,7 +101,7 @@ class BendersBase { const std::string positive_unsupplied_vars_prefix_ = "^PositiveUnsuppliedEnergy::"; const std::regex rgx_ = std::regex(positive_unsupplied_vars_prefix_); - std::vector outer_loop_criterion_; + std::vector> outer_loop_criterion_; std::vector subproblems_vars_names_ = {}; // tmp std::vector patterns_ = {rgx_}; @@ -109,7 +109,6 @@ class BendersBase { protected: virtual void Run() = 0; - virtual void init_data(); void update_best_ub(); bool ShouldBendersStop(); bool is_initial_relaxation_requested() const; diff --git a/src/cpp/benders/benders_core/include/CustomVector.h b/src/cpp/benders/benders_core/include/CustomVector.h index ed6e67fa8..60844a510 100644 --- a/src/cpp/benders/benders_core/include/CustomVector.h +++ b/src/cpp/benders/benders_core/include/CustomVector.h @@ -2,10 +2,8 @@ #include template -struct AddVectors { - void operator()(const std::vector& a, const std::vector& b) const { - if (a.size() == b.size()) { - std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus()); - } +void AddVectors(std::vector& a, const std::vector& b) { + if (a.size() == b.size()) { + std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus()); } -}; \ No newline at end of file +} diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index 18a268aff..af4df2dab 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -161,10 +161,10 @@ BendersMpi::ComputeSubproblemsContributionToOuterLoopCriterion( patterns_.size(), {}); std::vector outer_loop_criterion_sub_problems_map_result( patterns_.size(), {}); - AddVectors vector_add; for (const auto &[subproblem_name, subproblem_data] : subproblem_data_map) { - vector_add(outer_loop_criterion_per_sub_problem_per_pattern, - ComputeOuterLoopCriterion(subproblem_name, subproblem_data); + AddVectors( + outer_loop_criterion_per_sub_problem_per_pattern, + ComputeOuterLoopCriterion(subproblem_name, subproblem_data)); } Reduce(outer_loop_criterion_per_sub_problem_per_pattern, outer_loop_criterion_sub_problems_map_result, std::plus(), diff --git a/src/cpp/benders/external_loop/OuterLoop.cpp b/src/cpp/benders/external_loop/OuterLoop.cpp index cedcfb93d..490c7ee39 100644 --- a/src/cpp/benders/external_loop/OuterLoop.cpp +++ b/src/cpp/benders/external_loop/OuterLoop.cpp @@ -53,7 +53,7 @@ void OuterLoop::Run() { bool stop_update_master = false; while (!stop_update_master) { - benders_->ResetData(criterion_->CriterionValue()); + benders_->init_data(); PrintLog(); benders_->launch(); if (world_.rank() == 0) { @@ -80,8 +80,8 @@ void OuterLoop::PrintLog() { msg << "*** Outer loop: " << benders_->GetBendersRunNumber(); logger->display_message(msg.str()); msg.str(""); - msg << "*** Criterion value: " << std::scientific << std::setprecision(10) - << criterion_->CriterionValue(); + msg << "*** Sum loss: " << std::scientific << std::setprecision(10) + << criterion_->SumCriterions(); logger->display_message(msg.str()); logger->PrintIterationSeparatorEnd(); } \ No newline at end of file diff --git a/src/cpp/benders/external_loop/OuterloopCriterion.cpp b/src/cpp/benders/external_loop/OuterloopCriterion.cpp index 904d96818..1460a2058 100644 --- a/src/cpp/benders/external_loop/OuterloopCriterion.cpp +++ b/src/cpp/benders/external_loop/OuterloopCriterion.cpp @@ -1,5 +1,7 @@ #include "OuterLoopCriterion.h" +#include + #include "LoggerUtils.h" OuterloopCriterionLossOfLoad::OuterloopCriterionLossOfLoad( @@ -9,13 +11,13 @@ OuterloopCriterionLossOfLoad::OuterloopCriterionLossOfLoad( CRITERION OuterloopCriterionLossOfLoad::IsCriterionSatisfied( const std::vector& criterion_value) { criterion_values_ = criterion_value; - for (criterion_value : criterion_values_) { + for (const auto& criterion_value : criterion_values_) { // options_.EXT_LOOP_CRITERION_VALUE --> to vect // options_.EXT_LOOP_CRITERION_TOLERANCE --> to vect if (criterion_value <= options_.EXT_LOOP_CRITERION_VALUE + options_.EXT_LOOP_CRITERION_TOLERANCE) { - if (criterion_values >= options_.EXT_LOOP_CRITERION_VALUE - - options_.EXT_LOOP_CRITERION_TOLERANCE) { + if (criterion_value >= options_.EXT_LOOP_CRITERION_VALUE - + options_.EXT_LOOP_CRITERION_TOLERANCE) { return CRITERION::IS_MET; } return CRITERION::LOW; @@ -25,9 +27,15 @@ CRITERION OuterloopCriterionLossOfLoad::IsCriterionSatisfied( } } +double OuterloopCriterionLossOfLoad::SumCriterions() const { + return std::accumulate(criterion_values_.begin(), criterion_values_.end(), + 0.0); +} std::string OuterloopCriterionLossOfLoad::StateAsString() const { std::ostringstream msg; - msg << "Sum loss = " << criterion_values_ << "\n" + auto sum_loss = + std::accumulate(criterion_values_.begin(), criterion_values_.end(), 0.0); + msg << "Sum loss = " << sum_loss << "\n" << "threshold: " << options_.EXT_LOOP_CRITERION_VALUE << "\n" << "epsilon: " << options_.EXT_LOOP_CRITERION_TOLERANCE << "\n"; diff --git a/src/cpp/benders/external_loop/include/OuterLoopCriterion.h b/src/cpp/benders/external_loop/include/OuterLoopCriterion.h index 9a3c2d1c2..2c57e2849 100644 --- a/src/cpp/benders/external_loop/include/OuterLoopCriterion.h +++ b/src/cpp/benders/external_loop/include/OuterLoopCriterion.h @@ -17,7 +17,8 @@ class IOuterLoopCriterion { virtual CRITERION IsCriterionSatisfied( const std::vector& criterion_value) = 0; virtual std::string StateAsString() const = 0; - virtual double CriterionValues() const = 0; + virtual std::vector CriterionValues() const = 0; + virtual double SumCriterions() const = 0; }; class OuterloopCriterionLossOfLoad : public IOuterLoopCriterion { @@ -26,9 +27,12 @@ class OuterloopCriterionLossOfLoad : public IOuterLoopCriterion { CRITERION IsCriterionSatisfied( const std::vector& criterion_values) override; std::string StateAsString() const override; - double CriterionValues() const override { return criterion_values_; } + std::vector CriterionValues() const override { + return criterion_values_; + } + double SumCriterions() const override; private: ExternalLoopOptions options_; - const std::vector& criterion_values_ = {}; + std::vector criterion_values_ = {}; }; diff --git a/tests/cpp/ext_loop/ext_loop_test.cpp b/tests/cpp/ext_loop/ext_loop_test.cpp index d9e56dc8a..75c34e7e6 100644 --- a/tests/cpp/ext_loop/ext_loop_test.cpp +++ b/tests/cpp/ext_loop/ext_loop_test.cpp @@ -36,7 +36,7 @@ TEST_F(OuterLoopCriterionTest, IsCriterionHigh) { double max_unsup_energy = 0.1; const ExternalLoopOptions options = {threshold, epsilon, max_unsup_energy}; - double criterion_value = 2.0; + std::vector criterion_value = {2.0}; OuterloopCriterionLossOfLoad criterion(options); // criterion_value = 2 > threshold+epsilon @@ -48,7 +48,7 @@ TEST_F(OuterLoopCriterionTest, IsCriterionLow) { double epsilon = 1e-1; double max_unsup_energy = 0.1; const ExternalLoopOptions options = {threshold, epsilon, max_unsup_energy}; - double criterion_value = 2.0; + std::vector criterion_value = {2.0}; OuterloopCriterionLossOfLoad criterion(options); // criterion_value < threshold - epsilon @@ -60,7 +60,7 @@ TEST_F(OuterLoopCriterionTest, IsMet) { double epsilon = 1e-1; double max_unsup_energy = 0.1; const ExternalLoopOptions options = {threshold, epsilon, max_unsup_energy}; - double criterion_value = 2.0; + std::vector criterion_value = {2.0}; OuterloopCriterionLossOfLoad criterion(options); @@ -140,7 +140,7 @@ TEST_P(MasterUpdateBaseTest, ConstraintIsAddedBendersMPI) { MasterUpdateBase master_updater(benders, 0.5, 0.1); // update lambda_max master_updater.Init(); - benders->ResetData(3.0); + benders->init_data(); benders->launch(); auto num_constraints_master_before = benders->MasterGetnrows(); master_updater.Update(CRITERION::HIGH); @@ -197,7 +197,7 @@ TEST_P(MasterUpdateBaseTest, InitialRhs) { // update lambda_max master_updater.Init(); auto lambda_max = LambdaMax(benders); - benders->ResetData(3.0); + benders->init_data(); benders->launch(); master_updater.Update(CRITERION::HIGH); auto expected_initial_rhs = lambda_max * 0.5; From 809b66062b245e8b446b16458c88bac15df79865 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 21 Mar 2024 15:37:51 +0100 Subject: [PATCH 10/15] update --- src/cpp/benders/benders_core/VariablesGroup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/benders/benders_core/VariablesGroup.cpp b/src/cpp/benders/benders_core/VariablesGroup.cpp index fcde4ee52..029c381f3 100644 --- a/src/cpp/benders/benders_core/VariablesGroup.cpp +++ b/src/cpp/benders/benders_core/VariablesGroup.cpp @@ -10,13 +10,13 @@ void VariablesGroup::Search() { indices_.assign(patterns_.size(), {}); int var_index(0); for (const auto& variable : all_variables_) { - ++var_index; int pattern_index(0); for (const auto& pattern : patterns_) { - ++pattern_index; if (std::regex_search(variable, pattern)) { indices_[pattern_index].push_back(var_index); } + ++pattern_index; } + ++var_index; } } \ No newline at end of file From 6b0d973e3d48a45f72540fe32088f5232df7a266 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Thu, 21 Mar 2024 19:33:09 +0100 Subject: [PATCH 11/15] make crterion an array --- src/cpp/benders/benders_core/BendersBase.cpp | 4 +- .../benders/benders_core/SubproblemWorker.cpp | 10 ++--- .../benders_core/include/BendersBase.h | 5 ++- .../benders_core/include/SubproblemCut.h | 13 +----- .../benders_core/include/SubproblemWorker.h | 2 +- .../benders_core/include/VariablesGroup.h | 2 +- src/cpp/benders/benders_mpi/BendersMPI.cpp | 1 + .../external_loop/MasterUpdateBase.cpp | 19 ++++----- src/cpp/benders/external_loop/OuterLoop.cpp | 9 ++-- .../external_loop/OuterloopCriterion.cpp | 42 ++++++++++++------- .../external_loop/include/MasterUpdate.h | 4 +- .../include/OuterLoopCriterion.h | 6 ++- tests/cpp/ext_loop/ext_loop_test.cpp | 28 ++++++------- 13 files changed, 73 insertions(+), 72 deletions(-) diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index 14fcc852f..6b6ae5e83 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -380,7 +380,7 @@ 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.variables); + worker->get_solution(subproblem_data.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(); @@ -977,7 +977,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.variables.values[variables_index]; + if (auto solution = sub_problem_data.solution[variables_index]; solution > _options.EXTERNAL_LOOP_OPTIONS.EXT_LOOP_CRITERION_COUNT_THRESHOLD) // 1h of unsupplied energy diff --git a/src/cpp/benders/benders_core/SubproblemWorker.cpp b/src/cpp/benders/benders_core/SubproblemWorker.cpp index e88cea2a5..5778710da 100644 --- a/src/cpp/benders/benders_core/SubproblemWorker.cpp +++ b/src/cpp/benders/benders_core/SubproblemWorker.cpp @@ -73,14 +73,12 @@ void SubproblemWorker::get_subgradient(Point &s) const { * * \param lb : reference to a map */ -void SubproblemWorker::get_solution(PlainData::Variables &vars) const { - vars.values = std::vector(_solver->get_ncols()); +void SubproblemWorker::get_solution(std::vector &solution) const { + solution = std::vector(_solver->get_ncols()); if (_solver->get_n_integer_vars() > 0) { - _solver->get_mip_sol(vars.values.data()); + _solver->get_mip_sol(solution.data()); } else { - _solver->get_lp_sol(vars.values.data(), NULL, NULL); + _solver->get_lp_sol(solution.data(), NULL, NULL); } - - vars.names = _solver->get_col_names(); } \ No newline at end of file diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index 5b996729d..5c8f6d1fc 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -100,11 +100,14 @@ class BendersBase { bool free_problems_ = true; const std::string positive_unsupplied_vars_prefix_ = "^PositiveUnsuppliedEnergy::"; + const std::string negative_unsupplied_vars_prefix_ = + "^NegativeUnsuppliedEnergy::"; const std::regex rgx_ = std::regex(positive_unsupplied_vars_prefix_); + const std::regex nrgx_ = std::regex(negative_unsupplied_vars_prefix_); std::vector> outer_loop_criterion_; std::vector subproblems_vars_names_ = {}; // tmp - std::vector patterns_ = {rgx_}; + std::vector patterns_ = {rgx_, nrgx_}; std::vector> var_indices_; protected: diff --git a/src/cpp/benders/benders_core/include/SubproblemCut.h b/src/cpp/benders/benders_core/include/SubproblemCut.h index ac85fbeba..69c0f392c 100644 --- a/src/cpp/benders/benders_core/include/SubproblemCut.h +++ b/src/cpp/benders/benders_core/include/SubproblemCut.h @@ -5,20 +5,11 @@ #include "Worker.h" #include "common.h" namespace PlainData { -struct Variables { - std::vector names; - std::vector values; - template - void serialize(Archive &ar, const unsigned int version) { - ar & names; - ar & values; - } -}; struct SubProblemData { double subproblem_cost; Point var_name_and_subgradient; - Variables variables; + std::vector solution; double single_subpb_costs_under_approx; double subproblem_timer; int simplex_iter; @@ -28,7 +19,7 @@ struct SubProblemData { void serialize(Archive &ar, const unsigned int version) { ar & subproblem_cost; ar & var_name_and_subgradient; - ar & variables; + ar & solution; ar & single_subpb_costs_under_approx; ar & subproblem_timer; ar & simplex_iter; diff --git a/src/cpp/benders/benders_core/include/SubproblemWorker.h b/src/cpp/benders/benders_core/include/SubproblemWorker.h index f84c80d93..1369b2a8d 100644 --- a/src/cpp/benders/benders_core/include/SubproblemWorker.h +++ b/src/cpp/benders/benders_core/include/SubproblemWorker.h @@ -22,7 +22,7 @@ class SubproblemWorker : public Worker { SolverLogManager&solver_log_manager, Logger logger); virtual ~SubproblemWorker() = default; - void get_solution(PlainData::Variables &vars) const; + void get_solution(std::vector &solution) const; public: void fix_to(Point const &x0) const; diff --git a/src/cpp/benders/benders_core/include/VariablesGroup.h b/src/cpp/benders/benders_core/include/VariablesGroup.h index 777a6917a..8059d014c 100644 --- a/src/cpp/benders/benders_core/include/VariablesGroup.h +++ b/src/cpp/benders/benders_core/include/VariablesGroup.h @@ -12,6 +12,6 @@ class VariablesGroup { private: void Search(); const std::vector& all_variables_; - std::vector patterns_; + std::vector patterns_; // pos + zone1 // pos zon 2 std::vector> indices_; }; \ No newline at end of file diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index af4df2dab..e86e87c8d 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -169,6 +169,7 @@ BendersMpi::ComputeSubproblemsContributionToOuterLoopCriterion( 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; } diff --git a/src/cpp/benders/external_loop/MasterUpdateBase.cpp b/src/cpp/benders/external_loop/MasterUpdateBase.cpp index 98aea7cde..4e1e56ab7 100644 --- a/src/cpp/benders/external_loop/MasterUpdateBase.cpp +++ b/src/cpp/benders/external_loop/MasterUpdateBase.cpp @@ -58,19 +58,14 @@ void MasterUpdateBase::SetLambdaMaxToMaxInvestmentCosts() { lambda_max_ += obj[var_id] * max_invest.at(var_name); } } -bool MasterUpdateBase::Update(const CRITERION &criterion) { - switch (criterion) { - case CRITERION::LOW: - lambda_max_ = - std::min(lambda_max_, benders_->GetBestIterationData().invest_cost); - break; - case CRITERION::HIGH: - lambda_min_ = lambda_; - break; - - default: - return true; +bool MasterUpdateBase::Update(bool is_criterion_high) { + if (is_criterion_high) { + lambda_min_ = lambda_; + } else { + lambda_max_ = + std::min(lambda_max_, benders_->GetBestIterationData().invest_cost); } + stop_update_ = std::abs(lambda_max_ - lambda_min_) < epsilon_lambda_; if (!stop_update_) { lambda_ = dichotomy_weight_coeff_ * lambda_max_ + diff --git a/src/cpp/benders/external_loop/OuterLoop.cpp b/src/cpp/benders/external_loop/OuterLoop.cpp index 490c7ee39..85cc31833 100644 --- a/src/cpp/benders/external_loop/OuterLoop.cpp +++ b/src/cpp/benders/external_loop/OuterLoop.cpp @@ -21,7 +21,7 @@ void OuterLoop::Run() { benders_->DoFreeProblems(false); benders_->InitializeProblems(); benders_->InitExternalValues(); - CRITERION criterion_check = CRITERION::IS_MET; + bool criterion_check = false; std::vector obj_coeff; if (world_.rank() == 0) { obj_coeff = benders_->MasterObjectiveFunctionCoeffs(); @@ -39,8 +39,9 @@ void OuterLoop::Run() { // cuts_manager_->Save(benders_->AllCuts()); // auto cuts = cuts_manager_->Load(); criterion_check = - criterion_->IsCriterionSatisfied(benders_->GetOuterLoopCriterion()); - if (criterion_check == CRITERION::HIGH) { + criterion_->IsCriterionHigh(benders_->GetOuterLoopCriterion()); + // High + if (criterion_check) { std::ostringstream err_msg; err_msg << PrefixMessage(LogUtils::LOGLEVEL::FATAL, "External Loop") << "Criterion cannot be satisfied for your study:\n" @@ -58,7 +59,7 @@ void OuterLoop::Run() { benders_->launch(); if (world_.rank() == 0) { criterion_check = - criterion_->IsCriterionSatisfied(benders_->GetOuterLoopCriterion()); + criterion_->IsCriterionHigh(benders_->GetOuterLoopCriterion()); stop_update_master = master_updater_->Update(criterion_check); } diff --git a/src/cpp/benders/external_loop/OuterloopCriterion.cpp b/src/cpp/benders/external_loop/OuterloopCriterion.cpp index 1460a2058..efc92f86c 100644 --- a/src/cpp/benders/external_loop/OuterloopCriterion.cpp +++ b/src/cpp/benders/external_loop/OuterloopCriterion.cpp @@ -1,28 +1,38 @@ #include "OuterLoopCriterion.h" +#include #include #include "LoggerUtils.h" - +bool OuterloopCriterionLossOfLoad::DoubleCompare(double a, double b) { + return a > b + options_.EXT_LOOP_CRITERION_TOLERANCE; +} OuterloopCriterionLossOfLoad::OuterloopCriterionLossOfLoad( const ExternalLoopOptions& options) : options_(options) {} -CRITERION OuterloopCriterionLossOfLoad::IsCriterionSatisfied( - const std::vector& criterion_value) { - criterion_values_ = criterion_value; - for (const auto& criterion_value : criterion_values_) { - // options_.EXT_LOOP_CRITERION_VALUE --> to vect - // options_.EXT_LOOP_CRITERION_TOLERANCE --> to vect - if (criterion_value <= options_.EXT_LOOP_CRITERION_VALUE + - options_.EXT_LOOP_CRITERION_TOLERANCE) { - if (criterion_value >= options_.EXT_LOOP_CRITERION_VALUE - - options_.EXT_LOOP_CRITERION_TOLERANCE) { - return CRITERION::IS_MET; - } - return CRITERION::LOW; - } else { - return CRITERION::HIGH; +bool OuterloopCriterionLossOfLoad::IsCriterionHigh( + const std::vector& criterion_values) { + // tmp EXT_LOOP_CRITERION_VALUES must be a vector of size + // criterion_values.size() + EXT_LOOP_CRITERION_VALUES_ = std::vector( + criterion_values.size(), options_.EXT_LOOP_CRITERION_VALUE); + // si une zone est depassé sur au moins + criterion_values_ = criterion_values; + // options_.EXT_LOOP_CRITERION_VALUE --> to vect + // options_.EXT_LOOP_CRITERION_TOLERANCE --> to vect + + // return std::equal(criterion_value.begin(), criterion_value.end(), + // options_.EXT_LOOP_CRITERION_VALUE.begin(), + // DoubleCompare); + // return std::equal(criterion_values.begin(), criterion_values.end(), + // EXT_LOOP_CRITERION_VALUES_.begin(), + // &OuterloopCriterionLossOfLoad::DoubleCompare); + + for (int index(0); index < criterion_values_.size(); ++index) { + if (criterion_values_[index] > EXT_LOOP_CRITERION_VALUES_[index] + + options_.EXT_LOOP_CRITERION_TOLERANCE) { + return true; } } } diff --git a/src/cpp/benders/external_loop/include/MasterUpdate.h b/src/cpp/benders/external_loop/include/MasterUpdate.h index 538690a18..15566c893 100644 --- a/src/cpp/benders/external_loop/include/MasterUpdate.h +++ b/src/cpp/benders/external_loop/include/MasterUpdate.h @@ -3,7 +3,7 @@ class IMasterUpdate { public: - virtual bool Update(const CRITERION &criterion) = 0; + virtual bool Update(bool is_criterion_high) = 0; virtual void Init() = 0; }; @@ -19,7 +19,7 @@ class MasterUpdateBase : public IMasterUpdate { const std::string &name, double epsilon_lambda); explicit MasterUpdateBase(pBendersBase benders, double tau, double epsilon_lambda); - bool Update(const CRITERION &criterion) override; + bool Update(bool is_criterion_high) override; void Init() override; private: diff --git a/src/cpp/benders/external_loop/include/OuterLoopCriterion.h b/src/cpp/benders/external_loop/include/OuterLoopCriterion.h index 2c57e2849..9a214699b 100644 --- a/src/cpp/benders/external_loop/include/OuterLoopCriterion.h +++ b/src/cpp/benders/external_loop/include/OuterLoopCriterion.h @@ -14,7 +14,7 @@ class CriterionCouldNotBeSatisfied enum class CRITERION { LOW, IS_MET, HIGH }; class IOuterLoopCriterion { public: - virtual CRITERION IsCriterionSatisfied( + virtual bool IsCriterionHigh( const std::vector& criterion_value) = 0; virtual std::string StateAsString() const = 0; virtual std::vector CriterionValues() const = 0; @@ -24,7 +24,7 @@ class IOuterLoopCriterion { class OuterloopCriterionLossOfLoad : public IOuterLoopCriterion { public: explicit OuterloopCriterionLossOfLoad(const ExternalLoopOptions& options); - CRITERION IsCriterionSatisfied( + bool IsCriterionHigh( const std::vector& criterion_values) override; std::string StateAsString() const override; std::vector CriterionValues() const override { @@ -33,6 +33,8 @@ class OuterloopCriterionLossOfLoad : public IOuterLoopCriterion { double SumCriterions() const override; private: + bool DoubleCompare(double a, double b); ExternalLoopOptions options_; + std::vector EXT_LOOP_CRITERION_VALUES_; std::vector criterion_values_ = {}; }; diff --git a/tests/cpp/ext_loop/ext_loop_test.cpp b/tests/cpp/ext_loop/ext_loop_test.cpp index 75c34e7e6..87d584dd3 100644 --- a/tests/cpp/ext_loop/ext_loop_test.cpp +++ b/tests/cpp/ext_loop/ext_loop_test.cpp @@ -40,7 +40,7 @@ TEST_F(OuterLoopCriterionTest, IsCriterionHigh) { OuterloopCriterionLossOfLoad criterion(options); // criterion_value = 2 > threshold+epsilon - EXPECT_EQ(criterion.IsCriterionSatisfied(criterion_value), CRITERION::HIGH); + EXPECT_EQ(criterion.IsCriterionHigh(criterion_value), true); } TEST_F(OuterLoopCriterionTest, IsCriterionLow) { @@ -52,21 +52,21 @@ TEST_F(OuterLoopCriterionTest, IsCriterionLow) { OuterloopCriterionLossOfLoad criterion(options); // criterion_value < threshold - epsilon - EXPECT_EQ(criterion.IsCriterionSatisfied(criterion_value), CRITERION::LOW); + EXPECT_EQ(criterion.IsCriterionHigh(criterion_value), false); } -TEST_F(OuterLoopCriterionTest, IsMet) { - double threshold = 2.0; - double epsilon = 1e-1; - double max_unsup_energy = 0.1; - const ExternalLoopOptions options = {threshold, epsilon, max_unsup_energy}; - std::vector criterion_value = {2.0}; +// TEST_F(OuterLoopCriterionTest, IsMet) { +// double threshold = 2.0; +// double epsilon = 1e-1; +// double max_unsup_energy = 0.1; +// const ExternalLoopOptions options = {threshold, epsilon, max_unsup_energy}; +// std::vector criterion_value = {2.0}; - OuterloopCriterionLossOfLoad criterion(options); +// OuterloopCriterionLossOfLoad criterion(options); - // threshold - epsilon <= criterion_value <= threshold + epsilon - EXPECT_EQ(criterion.IsCriterionSatisfied(criterion_value), CRITERION::IS_MET); -} +// // threshold - epsilon <= criterion_value <= threshold + epsilon +// EXPECT_EQ(criterion.IsCriterionHigh(criterion_value), CRITERION::IS_MET); +// } //-------------------- MasterUpdateBaseTest ------------------------- const auto STUDY_PATH = @@ -143,7 +143,7 @@ TEST_P(MasterUpdateBaseTest, ConstraintIsAddedBendersMPI) { benders->init_data(); benders->launch(); auto num_constraints_master_before = benders->MasterGetnrows(); - master_updater.Update(CRITERION::HIGH); + master_updater.Update(true); auto num_constraints_master_after = benders->MasterGetnrows(); auto master_variables = benders->MasterVariables(); @@ -199,7 +199,7 @@ TEST_P(MasterUpdateBaseTest, InitialRhs) { auto lambda_max = LambdaMax(benders); benders->init_data(); benders->launch(); - master_updater.Update(CRITERION::HIGH); + master_updater.Update(true); auto expected_initial_rhs = lambda_max * 0.5; auto added_row_index = benders->MasterGetnrows() - 1; From 732ba652b95bff9f713d89a3a6f4c47176a18466 Mon Sep 17 00:00:00 2001 From: Abdoulbari Zakir Date: Mon, 25 Mar 2024 12:21:49 +0100 Subject: [PATCH 12/15] try fix --- src/cpp/benders/benders_core/include/BendersBase.h | 3 ++- src/cpp/benders/benders_mpi/BendersMPI.cpp | 8 ++++---- src/cpp/benders/external_loop/OuterloopCriterion.cpp | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index 5c8f6d1fc..40ec9e886 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -107,7 +107,8 @@ class BendersBase { std::vector> outer_loop_criterion_; std::vector subproblems_vars_names_ = {}; // tmp - std::vector patterns_ = {rgx_, nrgx_}; + // std::vector patterns_ = {rgx_, nrgx_}; + std::vector patterns_ = {rgx_}; std::vector> var_indices_; protected: diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index e86e87c8d..46662bf75 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -42,10 +42,10 @@ void BendersMpi::InitializeProblems() { current_problem_id++; } - if (_world.rank() == rank_0) { - SetSubproblemsVariablesIndex(); - } - init_problems_ = false; + // if (_world.rank() == rank_0) { + SetSubproblemsVariablesIndex(); + // } + init_problems_ = false; } void BendersMpi::BuildMasterProblem() { if (_world.rank() == rank_0) { diff --git a/src/cpp/benders/external_loop/OuterloopCriterion.cpp b/src/cpp/benders/external_loop/OuterloopCriterion.cpp index efc92f86c..b480fad26 100644 --- a/src/cpp/benders/external_loop/OuterloopCriterion.cpp +++ b/src/cpp/benders/external_loop/OuterloopCriterion.cpp @@ -35,6 +35,7 @@ bool OuterloopCriterionLossOfLoad::IsCriterionHigh( return true; } } + return false; } double OuterloopCriterionLossOfLoad::SumCriterions() const { From 7f8760be9fbd7e1a96c8936b6d69c6b66c67a041 Mon Sep 17 00:00:00 2001 From: Jason Marechal Date: Tue, 26 Mar 2024 11:22:54 +0100 Subject: [PATCH 13/15] delete w --- .github/workflows/build_centos7.yml | 167 ---------- .github/workflows/build_oracle8.yml | 151 --------- .github/workflows/build_windows.yml | 150 --------- .github/workflows/centos-release.yml | 297 ------------------ .../workflows/centos7-system-deps-build.yml | 139 -------- .github/workflows/doxygen.yml | 45 --- .github/workflows/ol8-release.yml | 274 ---------------- .github/workflows/publish_centos_docker.yml | 27 -- .github/workflows/release.yml | 17 - .github/workflows/sonarcloud.yml | 144 --------- .github/workflows/ubuntu-release.yml | 242 -------------- .../workflows/ubuntu-system-deps-build.yml | 106 ------- .../workflows/windows-vcpkg-deps-build.yml | 117 ------- .github/workflows/windows-vcpkg.yml | 280 ----------------- 14 files changed, 2156 deletions(-) delete mode 100644 .github/workflows/build_centos7.yml delete mode 100644 .github/workflows/build_oracle8.yml delete mode 100644 .github/workflows/build_windows.yml delete mode 100644 .github/workflows/centos-release.yml delete mode 100644 .github/workflows/centos7-system-deps-build.yml delete mode 100644 .github/workflows/doxygen.yml delete mode 100644 .github/workflows/ol8-release.yml delete mode 100644 .github/workflows/publish_centos_docker.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/sonarcloud.yml delete mode 100644 .github/workflows/ubuntu-release.yml delete mode 100644 .github/workflows/ubuntu-system-deps-build.yml delete mode 100644 .github/workflows/windows-vcpkg-deps-build.yml delete mode 100644 .github/workflows/windows-vcpkg.yml diff --git a/.github/workflows/build_centos7.yml b/.github/workflows/build_centos7.yml deleted file mode 100644 index da87fd5bd..000000000 --- a/.github/workflows/build_centos7.yml +++ /dev/null @@ -1,167 +0,0 @@ -name: Centos7 Build - -on: - merge_group: - push: - branches: - - develop - - dependabot/* - pull_request: - release: - types: [ created ] - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - docker_publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - with: - fetch-depth: 0 - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v32 - with: - files: | - docker/centos7-system-deps - - - name: Docker file push - id: docker_push - if: steps.changed-files.outputs.any_changed == 'true' - uses: elgohr/Publish-Docker-Github-Action@main - with: - name: antaresrte/rte-antares - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - workdir: docker - dockerfile: centos7-system-deps - cache: false - tags: centos7-system-deps - - versions: - runs-on: ubuntu-latest - outputs: - antares-version: ${{steps.antares-version.outputs.result}} - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - steps: - - uses: actions/checkout@v3 #Keep at 3. v4 uses node 20 which uses glibc_2.27 - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - build: - runs-on: ubuntu-latest - needs: [ docker_publish, versions ] - container: 'antaresrte/rte-antares:centos7-system-deps' - strategy: - matrix: - xprs: [ - # { value: XPRESS-ON, ref: 8.13a }, - { value: XPRESS-ON, ref: 9.2.5 }, - # { value: XPRESS-OFF } - ] - env: - XPRESSDIR: ${{ github.workspace }}/xpress - XPRESS: ${{ github.workspace }}/xpress/bin - XPRS_LIB_Path: ${{ github.workspace }}/xpress/lib - XPRESSDIR_CONTAINER: ${GITHUB_WORKSPACE}/xpress - XPRESS_CONTAINER: ${GITHUB_WORKSPACE}/xpress/bin - XPRS_LIB_Path_CONTAINER: ${GITHUB_WORKSPACE}/xpress/lib - - steps: - - name: Get release - if: github.event_name == 'release' && github.event.action == 'created' - id: get_release - uses: bruceadams/get-release@v1.3.2 - - - uses: actions/checkout@v3 #Keep at 3 - with: - submodules: true - - - uses: ./.github/workflows/compile-gtest - - name: Checkout xpressmp linux - uses: actions/checkout@v3 #keep v3 - with: - token: ${{ secrets.AS_TOKEN }} - repository: rte-france/xpress-mp - path: ${{ env.XPRESSDIR }} - github-server-url: https://github.com - ref: ${{matrix.xprs.ref}} - if: matrix.xprs.value == 'XPRESS-ON' - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-tgz - with: - antares-deps-version: ${{needs.versions.outputs.antares-deps-version}} - antares-version: ${{needs.versions.outputs.antares-version}} - os: centos7 - os-full-name: CentOS-7.9.2009 - #variant: -ortools-xpress - - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - - - name: Compile tbb - uses: ./.github/workflows/compile-tbb - with: - cmake: 'cmake3' - - - name: Install dependencies - run: | - pip3 install --upgrade pip - pip3 install wheel #Does not work in requirements - pip3 install -r requirements-tests.txt - pip3 install -r requirements-ui.txt - - name: Configure - run: | - [[ ${{ matrix.xprs.value }} == "XPRESS-ON" ]] && XPRESS_VALUE="ON" || XPRESS_VALUE="OFF" - source /opt/rh/devtoolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake3 -B _build -S . \ - -DDEPS_INSTALL_DIR=rte-antares-deps-Release \ - -DBUILD_TESTING=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=_install \ - -DBUILD_UI=ON \ - -DXPRESS=${{ env.XPRESS_VALUE }} \ - -DXPRESS_ROOT=${{ env.XPRESSDIR }} \ - -DALLOW_RUN_AS_ROOT=ON - - name: Build - run: | - source /opt/rh/devtoolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake3 --build _build --config Release -j8 --target install - - name: Running unit tests - timeout-minutes: 120 - shell: bash - run: | - source /etc/profile.d/modules.sh - module load mpi - export LD_LIBRARY_PATH=LD_LIBRARY_PATH:${{ env.XPRS_LIB_Path_CONTAINER }} - export XPRESS=${{ env.XPRESS_CONTAINER }} - cd _build - ctest3 -C Release --output-on-failure -L "unit|benders|lpnamer|medium" diff --git a/.github/workflows/build_oracle8.yml b/.github/workflows/build_oracle8.yml deleted file mode 100644 index 132444be4..000000000 --- a/.github/workflows/build_oracle8.yml +++ /dev/null @@ -1,151 +0,0 @@ -name: Oracle 8 Build - -on: - merge_group: - push: - branches: - - develop - - dependabot/* - pull_request: - release: - types: [ created ] - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - versions: - runs-on: ubuntu-latest - outputs: - antares-version: ${{steps.antares-version.outputs.result}} - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - steps: - - uses: actions/checkout@v4 - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - build: - name: Build - runs-on: ubuntu-latest - container: 'oraclelinux:8' - strategy: - matrix: - xprs: [ #{ value: XPRESS-ON, ref: 8.13a }, - { value: XPRESS-ON, ref: 9.2.5 }, - # { value: XPRESS-OFF } - ] - needs: [ versions ] - env: - XPRESSDIR: ${{ github.workspace }}/xpress - XPRESS: ${{ github.workspace }}/xpress/bin - XPRS_LIB_Path: ${{ github.workspace }}/xpress/lib - XPRESSDIR_CONTAINER: ${GITHUB_WORKSPACE}/xpress - XPRESS_CONTAINER: ${GITHUB_WORKSPACE}/xpress/bin - XPRS_LIB_Path_CONTAINER: ${GITHUB_WORKSPACE}/xpress/lib - - steps: - - - name: Install System - run: | - dnf install -y epel-release git cmake wget rpm-build redhat-lsb-core openmpi-devel - dnf install -y unzip libuuid-devel boost-test boost-devel gcc-toolset-10-toolchain zlib-devel python3-devel - - - uses: actions/checkout@v4 - with: - submodules: true - - - uses: ./.github/workflows/compile-gtest - - - name: Checkout xpressmp linux - uses: actions/checkout@v4 - with: - token: ${{ secrets.AS_TOKEN }} - repository: rte-france/xpress-mp - path: ${{ env.XPRESSDIR }} - github-server-url: https://github.com - ref: ${{matrix.xprs.ref}} - if: matrix.xprs.value == 'XPRESS-ON' - - - name: Set up Python - run: | - dnf update -y - dnf install -y python3 python3-pip - - - run: - echo ${{needs.versions.outputs.antares-deps-version}} - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-tgz - with: - antares-deps-version: ${{needs.versions.outputs.antares-deps-version}} - antares-version: ${{needs.versions.outputs.antares-version}} - os: Oracle8 - os-full-name: OracleServer-8.9 - - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - - name: Compile TBB - uses: ./.github/workflows/compile-tbb - - - name: Install dependencies - run: | - source /opt/rh/gcc-toolset-10/enable - pip3 install wheel #Too late to install in requirements.txt - pip3 install -r requirements-tests.txt - - - name: Configure - run: | - [[ ${{ matrix.xprs.value }} == "XPRESS-ON" ]] && XPRESS_VALUE="ON" || XPRESS_VALUE="OFF" - source /opt/rh/gcc-toolset-10/enable - dnf install jsoncpp-devel - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake3 -B _build -S . \ - -DDEPS_INSTALL_DIR=rte-antares-deps-Release \ - -DBUILD_TESTING=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=_install \ - -DBUILD_UI=OFF \ - -DXPRESS=${{ env.XPRESS_VALUE }} \ - -DXPRESS_ROOT=${{ env.XPRESSDIR }} \ - -DALLOW_RUN_AS_ROOT=ON - - - - name: Build - run: | - source /opt/rh/gcc-toolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake --build _build --config Release -j2 - - - name: Running unit tests - timeout-minutes: 120 - shell: bash - run: | - source /etc/profile.d/modules.sh - module load mpi - export LD_LIBRARY_PATH=LD_LIBRARY_PATH:${{ env.XPRS_LIB_Path_CONTAINER }} - export XPRESS=${{ env.XPRESS_CONTAINER }} - cd _build - ctest3 -C Release --output-on-failure -L "unit|benders|lpnamer|medium" diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml deleted file mode 100644 index be2f6cfd8..000000000 --- a/.github/workflows/build_windows.yml +++ /dev/null @@ -1,150 +0,0 @@ -name: Windows build - -on: - merge_group: - push: - branches: - - main - - develop - - dependabot/* - pull_request: - release: - types: [ created ] - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - windows: - runs-on: ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, '[skip ci]')" - strategy: - matrix: - os: [ windows-latest ] - triplet: [ x64-windows ] - xprs: [ #{ value: XPRESS-ON, ref: 8.13a }, - { value: XPRESS-ON, ref: 9.2.5 }, - #{ value: XPRESS-OFF } - ] - env: - XPRESSDIR: ${{ github.workspace }}\xpress - XPRESS: ${{ github.workspace }}\xpress\bin - XPRS_LIB_Path: ${{ github.workspace }}\xpress\lib - # Indicates the location of the vcpkg as a Git submodule of the project repository. - VCPKG_ROOT: ${{ github.workspace }}/vcpkg - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Checkout xpressmp linux - if: matrix.xprs.value == 'XPRESS-ON' - uses: actions/checkout@v4 - with: - repository: rte-france/xpress-mp-temp - path: ${{ env.XPRESSDIR }} - ref: ${{matrix.xprs.ref}} - token: ${{ secrets.AS_TOKEN }} - - - name: Get release - if: github.event_name == 'release' && github.event.action == 'created' - id: get_release - uses: - bruceadams/get-release@v1.3.2 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - cache: 'pip' - cache-dependency-path: requirements*.txt - - # Restore both vcpkg and its artifacts from the GitHub cache service. - - name: Restore vcpkg and its artifacts. - uses: actions/cache@v4 - with: - # The first path is the location of vcpkg (it contains the vcpkg executable and data files). - # The other paths starting with '!' are exclusions: they contain termporary files generated during the build of the installed packages. - path: | - ${{ env.VCPKG_ROOT }} - !${{ env.VCPKG_ROOT }}/buildtrees - !${{ env.VCPKG_ROOT }}/packages - !${{ env.VCPKG_ROOT }}/downloads - # The key is composed in a way that it gets properly invalidated: this must happen whenever vcpkg's Git commit id changes, or the list of packages changes. In this case a cache miss must happen and a new entry with a new key with be pushed to GitHub the cache service. - # The key includes: hash of the vcpkg.json file, the hash of the vcpkg Git commit id, and the used vcpkg's triplet. The vcpkg's commit id would suffice, but computing an hash out it does not harm. - # Note: given a key, the cache content is immutable. If a cache entry has been created improperly, in order the recreate the right content the key must be changed as well, and it must be brand new (i.e. not existing already). - key: | - ${{ hashFiles( 'vcpkg.json' ) }}-${{ hashFiles( '.git/modules/vcpkg/HEAD' )}}-${{ matrix.triplet }} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-tests.txt - pip install -r requirements-ui.txt - - - name: Pre-requisites - shell: cmd - run: | - choco install wget zip unzip --no-progress - wget -nv https://github.com/microsoft/Microsoft-MPI/releases/download/v10.1.1/msmpisetup.exe - msmpisetup.exe -unattend - - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - - name: Install deps with VCPKG - run: | - cd vcpkg - ./bootstrap-vcpkg.sh - vcpkg install --triplet ${{matrix.triplet}} - rm -rf buildtrees - rm -rf packages - rm -rf downloads - shell: bash - - - name: Compile tbb - uses: ./.github/workflows/compile-tbb - with: - cmake: 'cmake' - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-zip - with: - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - antares-version: ${{steps.antares-version.outputs.result}} - os: ${{matrix.os}} - - - name: Expand xpress value in env - #I can't seem to expand the variable in the cmake command line so export it in env - shell: bash - run: | - [[ ${{ matrix.xprs.value }} == "XPRESS-ON" ]] && XPRESS_VALUE="ON" || XPRESS_VALUE="OFF" - echo "XPRESS_VALUE=$XPRESS_VALUE" >> $GITHUB_ENV - - - name: Configure - run: | - $pwd=Get-Location - cmake -B _build -S . -DDEPS_INSTALL_DIR=rte-antares-deps-Release -DCMAKE_PREFIX_PATH="$pwd\rte-antares-${{steps.antares-version.outputs.result}}-installer-64bits" -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{env.VCPKG_ROOT}}/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} -DCMAKE_INSTALL_PREFIX=_install -DBUILD_UI=ON -DXPRESS=${{ env.XPRESS_VALUE }} -DXPRESS_ROOT="${{ env.XPRESSDIR }}" - - name: Build - run: | - cmake --build _build --config Release -j2 --target install - - name: Running unit tests - timeout-minutes: 120 - shell: cmd - run: | - set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin - set PATH=%PATH%;${{ env.XPRESS }} - set XPRESSDIR=${{ env.XPRESSDIR }} - cd _build - ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" \ No newline at end of file diff --git a/.github/workflows/centos-release.yml b/.github/workflows/centos-release.yml deleted file mode 100644 index 509140cc5..000000000 --- a/.github/workflows/centos-release.yml +++ /dev/null @@ -1,297 +0,0 @@ -name: Centos7 release - -on: - push: - branches: - - main - - develop - - ci/* - - dependabot/* - workflow_dispatch: - workflow_run: - workflows: [ "Publish Release" ] - types: - - completed - release: - types: [ created ] - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - - docker_publish: - runs-on: ubuntu-latest - steps: - - - uses: actions/checkout@master - with: - fetch-depth: 0 - - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v32 - with: - files: | - docker/centos7-system-deps - - - name: Docker file push - id: docker_push - if: steps.changed-files.outputs.any_changed == 'true' - uses: elgohr/Publish-Docker-Github-Action@main - with: - name: antaresrte/rte-antares - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - workdir: docker - dockerfile: centos7-system-deps - cache: false - tags: centos7-system-deps - - userguide: - runs-on: ubuntu-latest - outputs: - pdf-name: ${{ steps.create-user-guide.outputs.pdf-name }} - - steps: - - uses: actions/checkout@v3 - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - id: create-user-guide - name: user guide pdf creation - uses: ./.github/workflows/generate-userguide-pdf - with: - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - - - name: user guide upload - id: userguide_upload - uses: actions/upload-artifact@v3 - with: - name: user-guide - path: ${{ steps.create-user-guide.outputs.pdf-path }} - - versions: - runs-on: ubuntu-latest - outputs: - antares-version: ${{steps.antares-version.outputs.result}} - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - steps: - - uses: actions/checkout@v3 - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - build: - runs-on: ubuntu-latest - needs: [ docker_publish, userguide, versions ] - container: 'antaresrte/rte-antares:centos7-system-deps' - strategy: - matrix: - xprs: [ - XPRESS-ON, - #XPRESS-OFF - ] - env: - XPRESSDIR: ${{ github.workspace }}/xpress - XPRESS: ${{ github.workspace }}/xpress/bin - XPRS_LIB_Path: ${{ github.workspace }}/xpress/lib - XPRESSDIR_CONTAINER: ${GITHUB_WORKSPACE}/xpress - XPRESS_CONTAINER: ${GITHUB_WORKSPACE}/xpress/bin - XPRS_LIB_Path_CONTAINER: ${GITHUB_WORKSPACE}/xpress/lib - outputs: - zip_name: ${{ steps.zip_name.outputs.zip_name }} - singlefile_name: ${{ steps.zip_name.outputs.singlefile_name }} - steps: - - id: branch-name - uses: tj-actions/branch-names@v6 - - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: true - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-tgz - with: - antares-deps-version: ${{needs.versions.outputs.antares-deps-version}} - antares-version: ${{needs.versions.outputs.antares-version}} - os: centos7 - os-full-name: CentOS-7.9.2009 - #variant: -ortools-xpress - - - uses: ./.github/workflows/compile-gtest - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - - - name: Compile tbb - uses: ./.github/workflows/compile-tbb - with: - cmake: 'cmake3' - - - name: Install dependencies - run: | - pip3 install --upgrade pip - pip3 install wheel #Does not work in requirements - pip3 install -r requirements-tests.txt - pip3 install -r requirements-ui.txt - - - name: Download userguide - uses: actions/download-artifact@v3 - with: - name: user-guide - path: docs/ - - - name: Checkout xpressmp linux - uses: actions/checkout@v3 - with: - token: ${{ secrets.AS_TOKEN }} - repository: rte-france/xpress-mp - path: ${{ env.XPRESSDIR }} - github-server-url: https://github.com - ref: 8.13a - if: matrix.xprs == 'XPRESS-ON' - - - name: Configure - shell: bash - run: | - if [ ${{ matrix.xprs }} == "XPRESS-ON" ]; then - export XPRESS_VALUE="ON" - else - export XPRESS_VALUE="OFF" - fi - source /opt/rh/devtoolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake3 -B _build -S . \ - -DDEPS_INSTALL_DIR=rte-antares-deps-Release \ - -DBUILD_TESTING=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=_install \ - -DBUILD_UI=ON \ - -DUSER_GUIDE_PATH="docs/${{ needs.userguide.outputs.pdf-name }}" \ - -DXPRESS=${XPRESS_VALUE} \ - -DXPRESS_ROOT=${XPRESSDIR} \ - -DALLOW_RUN_AS_ROOT=ON - - - name: Build - shell: bash - run: | - source /opt/rh/devtoolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake3 --build _build --config Release -j2 --target install - - - name: Running unit tests - timeout-minutes: 120 - shell: bash - run: | - source /etc/profile.d/modules.sh - module load mpi - export LD_LIBRARY_PATH=LD_LIBRARY_PATH:${{ env.XPRS_LIB_Path_CONTAINER }} - export XPRESS=${{ env.XPRESS_CONTAINER }} - cd _build - ctest3 -C Release --output-on-failure -L "unit|benders|lpnamer|medium" - - - name: set name variables - id: single_file_name - shell: bash - run: | - if [ ${{ matrix.xprs }} == "XPRESS-ON" ]; then - WITH_XPRS="-xpress" - else - WITH_XPRS="" - fi - VERSION=${{needs.versions.outputs.antares-xpansion-version}}${WITH_XPRS} - echo "VERSION_WITH_XPRESS=$VERSION" >> $GITHUB_ENV - - - name: .tar.gz creation - run: | - cd _build - export FILE_NAME="antaresXpansion-${{env.VERSION_WITH_XPRESS}}-CentOS-7.9.2009" - cpack3 -G TGZ -D CPACK_PACKAGE_FILE_NAME=$FILE_NAME - echo "TGZ_NAME=$FILE_NAME.tar.gz" >> $GITHUB_ENV - - - name: Upload .tar.gz - uses: actions/upload-artifact@v3 - with: - name: ${{env.TGZ_NAME}} - path: _build/${{env.TGZ_NAME}} - - - id: create-single-file - name: Single file .tar.gz creation - uses: ./.github/workflows/single-file-creation-tgz - with: - antares-xpansion-version: ${{env.VERSION_WITH_XPRESS}} - - - name: Upload single file - uses: actions/upload-artifact@v3 - with: - name: ${{ steps.create-single-file.outputs.archive-name }} - path: ${{ steps.create-single-file.outputs.archive-path }} - - - id: zip_name - run: | - echo "singlefile_name=${{steps.create-single-file.outputs.archive-name}}" >> "$GITHUB_OUTPUT" - echo "zip_name=${{env.TGZ_NAME}}" >> "$GITHUB_OUTPUT" - ####################### - - upload_asset_to_release: - if: github.event_name == 'release' && github.event.action == 'created' - runs-on: ubuntu-latest - needs: build - env: - ZIP_NAME: ${{needs.build.outputs.zip_name}} - SINGLEFILE_NAME: ${{needs.build.outputs.singlefile_name}} - steps: - - name: Get release - if: github.event_name == 'release' && github.event.action == 'created' - id: get_release - uses: bruceadams/get-release@main - - - name: Download Artifact - uses: actions/download-artifact@v3 - with: - name: ${{ env.ZIP_NAME}} - path: . - - - name: Download Artifact - uses: actions/download-artifact@v3 - with: - name: ${{env.SINGLEFILE_NAME}} - path: . - - - name: Upload Release Asset - env: - GH_REPO: ${{ github.repository }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release upload --repo ${{env.GH_REPO}} ${{ steps.get_release.outputs.tag_name }} ${{env.ZIP_NAME}} - gh release upload --repo ${{env.GH_REPO}} ${{ steps.get_release.outputs.tag_name }} ${{env.SINGLEFILE_NAME}} - - ######################## \ No newline at end of file diff --git a/.github/workflows/centos7-system-deps-build.yml b/.github/workflows/centos7-system-deps-build.yml deleted file mode 100644 index 7be482647..000000000 --- a/.github/workflows/centos7-system-deps-build.yml +++ /dev/null @@ -1,139 +0,0 @@ -name: Centos7 CI (build dependencies) - -on: - push: - branches: - - main - - develop - - release/* - - ci/* - - dependabot/* -jobs: - docker_publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - with: - fetch-depth: 0 - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v32 - with: - files: | - docker/centos7-system-deps - - - name: Docker file push - id: docker_push - if: steps.changed-files.outputs.any_changed == 'true' - uses: elgohr/Publish-Docker-Github-Action@main - with: - name: antaresrte/rte-antares - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - workdir: docker - dockerfile: centos7-system-deps - cache: false - tags: centos7-system-deps - - versions: - runs-on: ubuntu-latest - outputs: - antares-version: ${{steps.antares-version.outputs.result}} - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - steps: - - uses: actions/checkout@v3 - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - build: - - runs-on: ubuntu-latest - needs: [ docker_publish, versions ] - container: 'antaresrte/rte-antares:centos7-system-deps' - - steps: - - id: branch-name - uses: tj-actions/branch-names@v6 - - - uses: actions/checkout@v3 - with: - submodules: true - - - name: Install dependencies - run: | - pip3 install wheel #Does not work in requirements - pip3 install -r requirements-tests.txt - - - uses: ./.github/workflows/compile-gtest - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - - - name: Compile tbb - uses: ./.github/workflows/compile-tbb - with: - cmake: 'cmake3' - - - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1.13 - with: - cmake-version: '3.22.x' - - - name: Configure - run: | - source /opt/rh/devtoolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake -B _build -S . \ - -DDEPS_INSTALL_DIR=rte-antares-deps-Release \ - -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=_install -DBUILD_UI=ON -DALLOW_RUN_AS_ROOT=ON - - - name: Build - run: | - source /opt/rh/devtoolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake --build _build --config Release -j2 --target install - - - name: Running unit tests - run: | - source /etc/profile.d/modules.sh - module load mpi - cd _build - ctest3 -C Release --output-on-failure -L "unit|benders|lpnamer|medium" - - - name: .tar.gz creation - run: | - cd _build - cpack3 -G TGZ - - - name: Installer .rpm creation - run: | - cd _build - cpack3 -G RPM - - - id: create-single-file - name: Single file .tar.gz creation - uses: ./.github/workflows/single-file-creation-tgz - with: - antares-xpansion-version: ${{needs.version.outputs.antares-xpansion-version}} diff --git a/.github/workflows/doxygen.yml b/.github/workflows/doxygen.yml deleted file mode 100644 index 23c0cab37..000000000 --- a/.github/workflows/doxygen.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: GitHub Pages - -on: - push: - branches: - - develop # Set a branch name to trigger deployment - - dependabot/* - -jobs: - deploy: - runs-on: ubuntu-22.04 - permissions: - contents: write - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - steps: - - uses: actions/checkout@v4 - with: - submodules: true # Fetch Hugo themes (true OR recursive) - fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod - - - name: theme - run: | - git clone https://github.com/jothepro/doxygen-awesome-css.git - cd doxygen-awesome-css - git checkout v2.2.1 - git apply ../docs/antares-xpansion.patch - - - name: Doxygen - uses: mattnotmitt/doxygen-action@1.9.5 - with: - doxyfile-path: docs/Doxyfile - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - # If you're changing the branch from main, - # also change the `main` in `refs/heads/main` - # below accordingly. - if: github.ref == 'refs/heads/develop' - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./html - - - diff --git a/.github/workflows/ol8-release.yml b/.github/workflows/ol8-release.yml deleted file mode 100644 index 12883b9f9..000000000 --- a/.github/workflows/ol8-release.yml +++ /dev/null @@ -1,274 +0,0 @@ -name: Oracle-linux8 release - -on: - push: - branches: - - main - - develop - - ci/* - - dependabot/* - workflow_dispatch: - workflow_run: - workflows: [ "Publish Release" ] - types: - - completed - release: - types: [ created ] - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - userguide: - runs-on: ubuntu-latest - outputs: - pdf-name: ${{ steps.create-user-guide.outputs.pdf-name }} - - steps: - - uses: actions/checkout@v4 - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - id: create-user-guide - name: user guide pdf creation - uses: ./.github/workflows/generate-userguide-pdf - with: - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - - - name: user guide upload - id: userguide_upload - uses: actions/upload-artifact@v3 - with: - name: user-guide - path: ${{ steps.create-user-guide.outputs.pdf-path }} - - versions: - runs-on: ubuntu-latest - outputs: - antares-version: ${{steps.antares-version.outputs.result}} - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - steps: - - uses: actions/checkout@v4 - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - build: - runs-on: ubuntu-latest - needs: [ userguide, versions ] - container: 'oraclelinux:8' - strategy: - matrix: - xprs: [ - { value: XPRESS-ON, ref: 9.2.5 }, - #{ value: XPRESS-OFF } - ] - env: - XPRESSDIR: ${{ github.workspace }}/xpress - XPRESS: ${{ github.workspace }}/xpress/bin - XPRS_LIB_Path: ${{ github.workspace }}/xpress/lib - XPRESSDIR_CONTAINER: ${GITHUB_WORKSPACE}/xpress - XPRESS_CONTAINER: ${GITHUB_WORKSPACE}/xpress/bin - XPRS_LIB_Path_CONTAINER: ${GITHUB_WORKSPACE}/xpress/lib - outputs: - zip_name: ${{ steps.zip_name.outputs.zip_name }} - singlefile_name: ${{ steps.zip_name.outputs.singlefile_name }} - steps: - - id: branch-name - uses: tj-actions/branch-names@v6 - - - name: Install System - run: | - dnf install -y epel-release git cmake wget rpm-build redhat-lsb-core openmpi-devel - dnf install -y unzip libuuid-devel boost-test boost-devel gcc-toolset-10-toolchain zlib-devel python3-devel - source /opt/rh/gcc-toolset-10/enable - dnf install -y jsoncpp-devel - - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: true - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-tgz - with: - antares-deps-version: ${{needs.versions.outputs.antares-deps-version}} - antares-version: ${{needs.versions.outputs.antares-version}} - os: oracle8 - os-full-name: OracleServer-8.9 - #variant: -ortools-xpress - - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - - - name: Compile tbb - uses: ./.github/workflows/compile-tbb - - - uses: ./.github/workflows/compile-gtest - - - name: Install dependencies - run: | - pip3 install --upgrade pip - pip3 install wheel #Does not work in requirements - pip3 install -r requirements-tests.txt - pip3 install -r requirements-ui.txt - - - name: Download userguide - uses: actions/download-artifact@v3 - with: - name: user-guide - path: docs/ - - - name: Checkout xpressmp linux - uses: actions/checkout@v4 - with: - token: ${{ secrets.AS_TOKEN }} - repository: rte-france/xpress-mp - path: ${{ env.XPRESSDIR }} - github-server-url: https://github.com - ref: ${{matrix.xprs.ref}} - if: matrix.xprs.value == 'XPRESS-ON' - - - name: Configure - shell: bash - run: | - if [ ${{ matrix.xprs.value }} == "XPRESS-ON" ]; then - export XPRESS_VALUE="ON" - else - export XPRESS_VALUE="OFF" - fi - source /opt/rh/gcc-toolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake3 -B _build -S . \ - -DDEPS_INSTALL_DIR=rte-antares-deps-Release \ - -DBUILD_TESTING=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=_install \ - -DBUILD_UI=ON \ - -DUSER_GUIDE_PATH="docs/${{ needs.userguide.outputs.pdf-name }}" \ - -DXPRESS=${XPRESS_VALUE} \ - -DXPRESS_ROOT=${XPRESSDIR} \ - -DALLOW_RUN_AS_ROOT=ON - - - name: Build - shell: bash - run: | - source /opt/rh/gcc-toolset-10/enable - export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH - export PATH=/usr/lib64/openmpi/bin:$PATH - cmake3 --build _build --config Release -j2 --target install - - - name: Running unit tests - timeout-minutes: 120 - shell: bash - run: | - source /etc/profile.d/modules.sh - module load mpi - export LD_LIBRARY_PATH=LD_LIBRARY_PATH:${{ env.XPRS_LIB_Path_CONTAINER }} - export XPRESS=${{ env.XPRESS_CONTAINER }} - cd _build - ctest3 -C Release --output-on-failure -L "unit|benders|lpnamer|medium" - - - name: set name variables - id: single_file_name - shell: bash - run: | - if [ ${{ matrix.xprs.value }} == "XPRESS-ON" ]; then - WITH_XPRS="-xpress" - else - WITH_XPRS="" - fi - VERSION=${{needs.versions.outputs.antares-xpansion-version}}${WITH_XPRS} - echo "VERSION_WITH_XPRESS=$VERSION" >> $GITHUB_ENV - - - name: .tar.gz creation - run: | - cd _build - export FILE_NAME="antaresXpansion-${{env.VERSION_WITH_XPRESS}}-OracleServer-8.9" - cpack3 -G TGZ -D CPACK_PACKAGE_FILE_NAME=$FILE_NAME - echo "TGZ_NAME=$FILE_NAME.tar.gz" >> $GITHUB_ENV - - - name: Upload .tar.gz - uses: actions/upload-artifact@v3 - with: - name: ${{env.TGZ_NAME}} - path: _build/${{env.TGZ_NAME}} - - - id: create-single-file - name: Single file .tar.gz creation - uses: ./.github/workflows/single-file-creation-tgz - with: - antares-xpansion-version: ${{env.VERSION_WITH_XPRESS}} - - - name: Upload single file - uses: actions/upload-artifact@v3 - with: - name: ${{ steps.create-single-file.outputs.archive-name }} - path: ${{ steps.create-single-file.outputs.archive-path }} - - - id: zip_name - run: | - echo "singlefile_name=${{steps.create-single-file.outputs.archive-name}}" >> "$GITHUB_OUTPUT" - echo "zip_name=${{env.TGZ_NAME}}" >> "$GITHUB_OUTPUT" - ####################### - - upload_asset_to_release: - if: github.event_name == 'release' && github.event.action == 'created' - runs-on: ubuntu-latest - needs: build - env: - ZIP_NAME: ${{needs.build.outputs.zip_name}} - SINGLEFILE_NAME: ${{needs.build.outputs.singlefile_name}} - steps: - - name: Get release - if: github.event_name == 'release' && github.event.action == 'created' - id: get_release - uses: bruceadams/get-release@main - - - name: Download Artifact - uses: actions/download-artifact@v3 - with: - name: ${{env.ZIP_NAME}} - path: . - - - name: Download Artifact - uses: actions/download-artifact@v3 - with: - name: ${{env.SINGLEFILE_NAME}} - path: . - - - name: Upload Release Asset - env: - GH_REPO: ${{ github.repository }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release upload --repo ${{env.GH_REPO}} ${{ steps.get_release.outputs.tag_name }} ${{env.ZIP_NAME}} - gh release upload --repo ${{env.GH_REPO}} ${{ steps.get_release.outputs.tag_name }} ${{env.SINGLEFILE_NAME}} - - ######################## \ No newline at end of file diff --git a/.github/workflows/publish_centos_docker.yml b/.github/workflows/publish_centos_docker.yml deleted file mode 100644 index 12d7aa448..000000000 --- a/.github/workflows/publish_centos_docker.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Publish docker image - -on: - workflow_dispatch: - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - docker_publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - with: - fetch-depth: 0 - - - name: Docker file push - id: docker_push - uses: elgohr/Publish-Docker-Github-Action@main - with: - name: antaresrte/rte-antares - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - workdir: docker - dockerfile: centos7-system-deps - cache: false - tags: centos7-system-deps \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index d1ea7a841..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Publish Release - -on: - push: - tags: - - "v*.*.*" - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Release - uses: softprops/action-gh-release@v1 - with: - prerelease: ${{ contains(github.ref, '-rc') }} \ No newline at end of file diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml deleted file mode 100644 index 960fee6e9..000000000 --- a/.github/workflows/sonarcloud.yml +++ /dev/null @@ -1,144 +0,0 @@ -name: SonarCloud - -on: - push: - branches: - - main - - develop - - release/* - - dependabot/* - pull_request: - -jobs: - sonarcloud: - name: SonarCloud - runs-on: ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, '[skip ci]')" - strategy: - matrix: - os: [ ubuntu-20.04 ] - - env: - SONAR_SCANNER_VERSION: 4.7.0.2747 # Find the latest version in the "Linux" link on this page: - # https://sonarcloud.io/documentation/analysis/scan/sonarscanner/ - SONAR_SERVER_URL: "https://sonarcloud.io" - - steps: - - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install sonar-scanner and build-wrapper - uses: SonarSource/sonarcloud-github-c-cpp@v2 - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: sonarcloud-${{ env.SONAR_SCANNER_VERSION }} - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.8 - - - name: Install gcovr - run: sudo pip install gcovr==5.0 #5.1 generate issues with sonarcloud report parsing - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip3 install -r requirements-tests.txt - - - name: Install libraries - run: | - sudo apt-get update --fix-missing - sudo apt-get install libjsoncpp-dev libgtest-dev libboost-mpi-dev libboost-program-options-dev libtbb-dev - sudo apt-get install g++-10 gcc-10 - cd /usr/src/googletest/ - sudo cmake . - sudo cmake --build . --target install - - - name: Update alternatives - #mpicxx uses "g++" so we need g++ to be symbolic link to g++-10 - run: | - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10 - sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 - sudo update-alternatives --set cc /usr/bin/gcc - sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 - sudo update-alternatives --set c++ /usr/bin/g++ - - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-tgz - with: - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - antares-version: ${{steps.antares-version.outputs.result}} - os: ${{matrix.os}} - os-full-name: Ubuntu-20.04 - - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - load-toolset: 'false' - - - - name: Init submodule - run: | - git submodule update --init --recursive . - - - name: Configure - shell: bash - run: | - cmake -B _build -S . \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \ - -DDEPS_INSTALL_DIR=rte-antares-deps-Release \ - -DCODE_COVERAGE=ON \ - -DBUILD_TESTING=ON \ - -DBUILD_antares_solver=OFF \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=_install - - - name: Build - run: build-wrapper-linux-x86-64 --out-dir $GITHUB_WORKSPACE/_build/output cmake --build _build --config Release -j2 - - - name: Test and generate coverage - continue-on-error: true - run: | - cd $GITHUB_WORKSPACE/_build - ctest -C Release --output-on-failure -L "unit" - - - name: Compile coverage reports - run: | - cmake --build $GITHUB_WORKSPACE/_build --target code-coverage - - - name: Run sonar-scanner - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_2022 }} - run: sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" \ No newline at end of file diff --git a/.github/workflows/ubuntu-release.yml b/.github/workflows/ubuntu-release.yml deleted file mode 100644 index 102369ea3..000000000 --- a/.github/workflows/ubuntu-release.yml +++ /dev/null @@ -1,242 +0,0 @@ -name: Ubuntu Release - -on: - push: - branches: - - main - - develop - - ci/* - - dependabot/* - workflow_dispatch: - workflow_run: - workflows: [ "Publish Release" ] - types: - - completed - release: - types: [ created ] - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - - userguide: - runs-on: ubuntu-latest - outputs: - pdf-name: ${{ steps.create-user-guide.outputs.pdf-name }} - - steps: - - uses: actions/checkout@v4 - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - id: create-user-guide - name: user guide pdf creation - uses: ./.github/workflows/generate-userguide-pdf - with: - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - - - name: user guide upload - id: userguide_upload - uses: actions/upload-artifact@v3 - with: - name: user-guide - path: ${{ steps.create-user-guide.outputs.pdf-path }} - - build: - - needs: userguide - runs-on: ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, '[skip ci]')" - strategy: - matrix: - os: [ ubuntu-20.04 ] - xprs: [ - XPRESS-ON, - #XPRESS-OFF - ] - env: - XPRESSDIR: ${{ github.workspace }}/xpress - XPRESS: ${{ github.workspace }}/xpress/bin - XPRS_LIB_Path: ${{ github.workspace }}/xpress/lib - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Checkout xpressmp linux - if: matrix.xprs == 'XPRESS-ON' - uses: actions/checkout@v4 - with: - repository: rte-france/xpress-mp - path: ${{ env.XPRESSDIR }} - ref: 8.13a - token: ${{ secrets.AS_TOKEN }} #reniew token periodically - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2.3 - with: - key: ${{ matrix.os }}-${{ matrix.xprs }} - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-tests.txt - pip install -r requirements-ui.txt - - - name: Install mandatory system libraries - run: | - sudo apt-get update --fix-missing - sudo apt-get install libjsoncpp-dev libgtest-dev libboost-mpi-dev libboost-program-options-dev libtbb-dev - cd /usr/src/googletest/ - sudo cmake . - sudo cmake --build . --target install - sudo apt-get install -y g++-10 gcc-10 - - - name: Update alternatives - #mpicxx uses "g++" so we need g++ to be symbolic link to g++-10 - run: | - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10 - sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 - sudo update-alternatives --set cc /usr/bin/gcc - sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 - sudo update-alternatives --set c++ /usr/bin/g++ - - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-tgz - with: - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - antares-version: ${{steps.antares-version.outputs.result}} - os: ${{matrix.os}} - os-full-name: Ubuntu-20.04 - - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - load-toolset: 'false' - - - name: Download userguide - uses: actions/download-artifact@v3 - with: - name: user-guide - path: docs/ - - - name: Configure - shell: bash - run: | - if [ ${{ matrix.xprs }} == "XPRESS-ON" ]; then - XPRESS_VALUE="ON" - else - XPRESS_VALUE="OFF" - fi - cmake -B _build -S . \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DDEPS_INSTALL_DIR=rte-antares-deps-Release \ - -DBUILD_TESTING=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=_install \ - -DBUILD_UI=ON \ - -DUSER_GUIDE_PATH="docs/${{ needs.userguide.outputs.pdf-name }}" \ - -DXPRESS=${{ env.XPRESS_VALUE }} \ - -DXPRESS_ROOT=${{ env.XPRESSDIR }} - - - name: Build - run: | - cmake --build _build --config Release -j8 --target install - - - name: set name variables - id: single_file_name - shell: bash - run: | - if [ ${{ matrix.xprs }} == "XPRESS-ON" ]; then - WITH_XPRS="-xpress" - else - WITH_XPRS="" - fi - VERSION=${{steps.antares-xpansion-version.outputs.result}}${WITH_XPRS} - echo "VERSION_WITH_XPRESS=$VERSION" >> $GITHUB_ENV - - - id: create-single-file - name: Single file .tar.gz creation - uses: ./.github/workflows/single-file-creation-tgz - with: - antares-xpansion-version: ${{env.VERSION_WITH_XPRESS}} - - - name: Installer .tar.gz creation - run: | - cd _build - export FILE_NAME="antaresXpansion-${{env.VERSION_WITH_XPRESS}}-${{ matrix.os }}" - cpack -G TGZ -D CPACK_PACKAGE_FILE_NAME=$FILE_NAME - #Need to differentiate between xpress/no_xpress files - #Cpack command line doesn't seem to care about -P or -R options - echo "TGZ_NAME=$FILE_NAME.tar.gz" >> $GITHUB_ENV - - - name: Running unit tests - run: | - cd _build - ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" - - #Uploads are not necessary for release but useful in other cases - - name: Upload .tar.gz - uses: actions/upload-artifact@v3 - with: - name: ${{env.TGZ_NAME}} - path: _build/${{env.TGZ_NAME}} - - - name: Upload single file - uses: actions/upload-artifact@v3 - with: - name: ${{ steps.create-single-file.outputs.archive-name }} - path: ${{ steps.create-single-file.outputs.archive-path }} - - ####################### - - - name: Get release - if: github.event_name == 'release' && github.event.action == 'created' - id: get_release - uses: bruceadams/get-release@main - - - name: Upload Release Asset - if: github.event_name == 'release' && github.event.action == 'created' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release upload ${{ steps.get_release.outputs.tag_name }} _build/${{env.TGZ_NAME}} - gh release upload ${{ steps.get_release.outputs.tag_name }} ${{ steps.create-single-file.outputs.archive-path }} - - ######################## \ No newline at end of file diff --git a/.github/workflows/ubuntu-system-deps-build.yml b/.github/workflows/ubuntu-system-deps-build.yml deleted file mode 100644 index 1670a9c88..000000000 --- a/.github/workflows/ubuntu-system-deps-build.yml +++ /dev/null @@ -1,106 +0,0 @@ -name: Ubuntu CI full build - -on: - push: - branches: - - main - - develop - - release/* - - ci/* - - dependabot/* -jobs: - - build: - - runs-on: ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, '[skip ci]')" - strategy: - matrix: - os: [ ubuntu-20.04 ] - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2.3 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-tests.txt - pip install -r requirements-ui.txt - - - name: Install mandatory system libraries - run: | - sudo apt-get update --fix-missing - sudo apt-get install libjsoncpp-dev libgtest-dev libboost-mpi-dev libboost-program-options-dev libtbb-dev - cd /usr/src/googletest/ - sudo cmake . - sudo cmake --build . --target install - sudo apt-get install -y g++-10 gcc-10 - - - name: Update alternatives - #mpicxx uses "g++" so we need g++ to be symbolic link to g++-10 - run: | - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10 - sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 - sudo update-alternatives --set cc /usr/bin/gcc - sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 - sudo update-alternatives --set c++ /usr/bin/g++ - - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - load-toolset: 'false' - - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Configure - run: | - cmake -B _build -S . \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=_install \ - -DBUILD_UI=ON - - - name: Build - run: | - cmake --build _build --config Release -j2 --target install - - - name: Running unit tests - run: | - cd _build - ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" - - - id: create-single-file - name: Single file .tar.gz creation - uses: ./.github/workflows/single-file-creation-tgz - with: - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - - - name: Installer .tar.gz creation - run: | - cd _build - cpack -G TGZ - - - name: Installer .deb creation - run: | - cd _build - cpack -G DEB - diff --git a/.github/workflows/windows-vcpkg-deps-build.yml b/.github/workflows/windows-vcpkg-deps-build.yml deleted file mode 100644 index 594c9a94f..000000000 --- a/.github/workflows/windows-vcpkg-deps-build.yml +++ /dev/null @@ -1,117 +0,0 @@ -name: Windows CI full build - -on: - push: - branches: - - main - - develop - - release/* - - ci/* - - dependabot/* -jobs: - - windows: - - runs-on: ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, '[skip ci]')" - strategy: - matrix: - os: [ windows-latest ] - triplet: [ x64-windows ] - - env: - # Indicates the location of the vcpkg as a Git submodule of the project repository. - VCPKG_ROOT: ${{ github.workspace }}/vcpkg - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Enable git longpaths - run: git config --system core.longpaths true - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - # Restore both vcpkg and its artifacts from the GitHub cache service. - - name: Restore vcpkg and its artifacts. - uses: actions/cache@v4 - with: - # The first path is the location of vcpkg (it contains the vcpkg executable and data files). - # The other paths starting with '!' are exclusions: they contain termporary files generated during the build of the installed packages. - path: | - ${{ env.VCPKG_ROOT }} - !${{ env.VCPKG_ROOT }}/buildtrees - !${{ env.VCPKG_ROOT }}/packages - !${{ env.VCPKG_ROOT }}/downloads - # The key is composed in a way that it gets properly invalidated: this must happen whenever vcpkg's Git commit id changes, or the list of packages changes. In this case a cache miss must happen and a new entry with a new key with be pushed to GitHub the cache service. - # The key includes: hash of the vcpkg.json file, the hash of the vcpkg Git commit id, and the used vcpkg's triplet. The vcpkg's commit id would suffice, but computing an hash out it does not harm. - # Note: given a key, the cache content is immutable. If a cache entry has been created improperly, in order the recreate the right content the key must be changed as well, and it must be brand new (i.e. not existing already). - key: | - ${{ hashFiles( 'vcpkg.json' ) }}-${{ hashFiles( '.git/modules/vcpkg/HEAD' )}}-${{ matrix.triplet }}-invalidate - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-tests.txt - pip install -r requirements-ui.txt - - - name: Pre-requisites - shell: cmd - run: | - choco install wget zip unzip --no-progress - wget -nv https://github.com/microsoft/Microsoft-MPI/releases/download/v10.1.1/msmpisetup.exe - msmpisetup.exe -unattend - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Install deps with VCPKG - run: | - cd vcpkg - ./bootstrap-vcpkg.sh - vcpkg install --triplet ${{matrix.triplet}} - rm -rf buildtrees - rm -rf packages - rm -rf downloads - shell: bash - - - name: Compile tbb - uses: ./.github/workflows/compile-tbb - with: - cmake: 'cmake' - - - name: Configure - run: | - $pwd=Get-Location - cmake -B _build -S . -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} -DCMAKE_INSTALL_PREFIX=_install -DBUILD_UI=ON - - - name: Build - run: | - cmake --build _build --config Release -j2 --target install - - - name: Running unit tests - shell: cmd - run: | - set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin\ - cd _build - ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" - - - name: Installer .zip creation - run: | - cd _build - cpack -G ZIP - - - id: create-single-file - name: Single file .zip creation - uses: ./.github/workflows/single-file-creation-zip - with: - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - diff --git a/.github/workflows/windows-vcpkg.yml b/.github/workflows/windows-vcpkg.yml deleted file mode 100644 index aa8418099..000000000 --- a/.github/workflows/windows-vcpkg.yml +++ /dev/null @@ -1,280 +0,0 @@ -name: Windows release - -on: - push: - branches: - - main - - develop - - ci/* - - dependabot/* - workflow_dispatch: - workflow_run: - workflows: [ "Publish Release" ] - types: - - completed - release: - types: [ created ] - -env: - GITHUB_TOKEN: ${{ github.token }} - -jobs: - - userguide: - runs-on: ubuntu-latest - outputs: - pdf-name: ${{ steps.create-user-guide.outputs.pdf-name }} - - steps: - - uses: actions/checkout@v4 - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - id: create-user-guide - name: user guide pdf creation - uses: ./.github/workflows/generate-userguide-pdf - with: - antares-xpansion-version: ${{steps.antares-xpansion-version.outputs.result}} - - - name: user guide upload - id: userguide_upload - uses: actions/upload-artifact@v3 - with: - name: user-guide - path: ${{ steps.create-user-guide.outputs.pdf-path }} - - build: - needs: userguide - runs-on: ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, '[skip ci]')" - strategy: - matrix: - os: [ windows-latest ] - triplet: [ x64-windows ] - xprs: [ - XPRESS-ON, - #XPRESS-OFF - ] - env: - XPRESSDIR: ${{ github.workspace }}\xpress - XPRESS: ${{ github.workspace }}\xpress\bin - XPRS_LIB_Path: ${{ github.workspace }}\xpress\lib - # Indicates the location of the vcpkg as a Git submodule of the project repository. - VCPKG_ROOT: ${{ github.workspace }}/vcpkg - outputs: - zip_name: ${{ steps.zip_name.outputs.zip_name }} - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Enable git longpaths - run: git config --system core.longpaths true - - - name: Checkout xpressmp linux - if: matrix.xprs == 'XPRESS-ON' - uses: actions/checkout@v4 - with: - repository: rte-france/xpress-mp-temp - path: ${{ env.XPRESSDIR }} - ref: 8.13a - token: ${{ secrets.AS_TOKEN }} - - - name: Get release - if: github.event_name == 'release' && github.event.action == 'created' - id: get_release - uses: - bruceadams/get-release@main - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - # Restore both vcpkg and its artifacts from the GitHub cache service. - - name: Restore vcpkg and its artifacts. - uses: actions/cache@v4 - with: - # The first path is the location of vcpkg (it contains the vcpkg executable and data files). - # The other paths starting with '!' are exclusions: they contain termporary files generated during the build of the installed packages. - path: | - ${{ env.VCPKG_ROOT }} - !${{ env.VCPKG_ROOT }}/buildtrees - !${{ env.VCPKG_ROOT }}/packages - !${{ env.VCPKG_ROOT }}/downloads - # The key is composed in a way that it gets properly invalidated: this must happen whenever vcpkg's Git commit id changes, or the list of packages changes. In this case a cache miss must happen and a new entry with a new key with be pushed to GitHub the cache service. - # The key includes: hash of the vcpkg.json file, the hash of the vcpkg Git commit id, and the used vcpkg's triplet. The vcpkg's commit id would suffice, but computing an hash out it does not harm. - # Note: given a key, the cache content is immutable. If a cache entry has been created improperly, in order the recreate the right content the key must be changed as well, and it must be brand new (i.e. not existing already). - key: | - ${{ hashFiles( 'vcpkg.json' ) }}-${{ hashFiles( '.git/modules/vcpkg/HEAD' )}}-${{ matrix.triplet }}-invalidate - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-tests.txt - pip install -r requirements-ui.txt - - - name: Pre-requisites - shell: cmd - run: | - choco install wget zip unzip --no-progress - wget -nv https://github.com/microsoft/Microsoft-MPI/releases/download/v10.1.1/msmpisetup.exe - msmpisetup.exe -unattend - - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - - name: Install deps with VCPKG - run: | - cd vcpkg - ./bootstrap-vcpkg.sh - vcpkg install --triplet ${{matrix.triplet}} - rm -rf buildtrees - rm -rf packages - rm -rf downloads - shell: bash - - - name: Compile tbb - uses: ./.github/workflows/compile-tbb - with: - cmake: 'cmake' - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-zip - with: - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - antares-version: ${{steps.antares-version.outputs.result}} - os: ${{matrix.os}} - - - name: Download userguide - uses: actions/download-artifact@v3 - with: - name: user-guide - path: docs/ - - - name: Expand xpress value in env - #I can't seem to expand the variable in the cmake command line so export it in env - shell: bash - run: | - [[ ${{ matrix.xprs }} == "XPRESS-ON" ]] && XPRESS_VALUE="ON" || XPRESS_VALUE="OFF" - echo "XPRESS_VALUE=$XPRESS_VALUE" >> $GITHUB_ENV - - - name: Configure - #Inverted ternary : @({'condition is false'},{'condition is true'})[$condition] => ({true}, {false})[!$condition] - run: | - $pwd=Get-Location - cmake -B _build -S . -DDEPS_INSTALL_DIR=rte-antares-deps-Release -DCMAKE_PREFIX_PATH="$pwd\rte-antares-${{steps.antares-version.outputs.result}}-installer-64bits" -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{env.VCPKG_ROOT}}/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} -DCMAKE_INSTALL_PREFIX=_install -DBUILD_UI=ON -DUSER_GUIDE_PATH="docs/${{ needs.userguide.outputs.pdf-name }}" -DXPRESS=${{ env.XPRESS_VALUE }} -DXPRESS_ROOT="${{ env.XPRESSDIR }}" - - - name: Build - run: | - cmake --build _build --config Release -j2 --target install - - - name: Running unit tests - shell: cmd - run: | - set PATH=%PATH%;C:\Program Files\Microsoft MPI\Bin\ - set PATH=%PATH%;${{ env.XPRESS }} - set XPRESSDIR=${{ env.XPRESSDIR }} - cd _build - ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" - - - name: Create installer .zip - shell: bash - run: | - cd _build - cpack -G ZIP - export ZIP_NAME=$(ls *.zip) - echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV - - - name: set name variables - id: single_file_name - shell: bash - run: | - [[ ${{ matrix.xprs }} == "XPRESS-ON" ]] && XPRESS_VALUE="ON" || XPRESS_VALUE="OFF" - XPRS=${{ env.XPRESS_VALUE }} - [ $XPRS == "ON" ] && WITH_XPRS="-xpress" || WITH_XPRS="" - VERSION=${{steps.antares-xpansion-version.outputs.result}}${WITH_XPRS} - echo "VERSION_WITH_XPRESS=$VERSION" - echo "VERSION_WITH_XPRESS=$VERSION" >> $GITHUB_ENV - - - name: Upload installer - uses: actions/upload-artifact@v3 - with: - name: ${{env.ZIP_NAME}} - path: _build/${{env.ZIP_NAME}} - - - name: Create single file .zip - id: create-single-file - uses: ./.github/workflows/single-file-creation-zip - with: - antares-xpansion-version: ${{env.VERSION_WITH_XPRESS}} - - - name: Upload single file - uses: actions/upload-artifact@v3 - with: - name: ${{ steps.create-single-file.outputs.archive-name }} - path: ${{ steps.create-single-file.outputs.archive-path }} - - - id: zip_name - shell: bash - run: | - echo "zip_name=${{env.ZIP_NAME}}" >> "$GITHUB_OUTPUT" - echo "singlefile_name=${{steps.create-single-file.outputs.archive-name}}" >> "$GITHUB_OUTPUT" - - upload_asset_to_release: - if: github.event_name == 'release' && github.event.action == 'created' - runs-on: ubuntu-latest - needs: build - env: - ZIP_NAME: ${{needs.build.outputs.zip_name}} - SINGLEFILE_NAME: ${{needs.build.outputs.singlefile_name}} - steps: - - name: Get release - if: github.event_name == 'release' && github.event.action == 'created' - id: get_release - uses: bruceadams/get-release@main - - - name: Download Artifact - uses: actions/download-artifact@v3 - with: - name: ${{env.ZIP_NAME}} - path: . - - - name: Download Artifact - uses: actions/download-artifact@v3 - with: - name: ${{env.SINGLEFILE_NAME}} - path: . - - - name: Upload Release Asset - env: - GH_REPO: ${{ github.repository }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release upload --repo ${{env.GH_REPO}} ${{ steps.get_release.outputs.tag_name }} ${{env.ZIP_NAME}} - gh release upload --repo ${{env.GH_REPO}} ${{ steps.get_release.outputs.tag_name }} ${{env.SINGLEFILE_NAME}} - - ######################## \ No newline at end of file From 25c82bedb058804178657942c470d98a2365124f Mon Sep 17 00:00:00 2001 From: Jason Marechal Date: Tue, 26 Mar 2024 11:23:04 +0100 Subject: [PATCH 14/15] echo --- .github/workflows/build_ubuntu.yml | 111 ++--------------------------- 1 file changed, 6 insertions(+), 105 deletions(-) diff --git a/.github/workflows/build_ubuntu.yml b/.github/workflows/build_ubuntu.yml index 902bbbf97..36d4eada8 100644 --- a/.github/workflows/build_ubuntu.yml +++ b/.github/workflows/build_ubuntu.yml @@ -23,8 +23,8 @@ jobs: os: [ ubuntu-20.04 ] xprs: [ #{ value: XPRESS-ON, ref: 8.13a }, - { value: XPRESS-ON, ref: 9.2.5 }, - # { value: XPRESS-OFF } + { value: XPRESS-ON, ref: 9.2.5 }, + # { value: XPRESS-OFF } ] env: XPRESSDIR: ${{ github.workspace }}/xpress @@ -36,106 +36,7 @@ jobs: with: submodules: true - - name: Checkout xpressmp linux - if: matrix.xprs.value == 'XPRESS-ON' - uses: actions/checkout@v4 - with: - repository: rte-france/xpress-mp - path: ${{ env.XPRESSDIR }} - ref: ${{ matrix.xprs.ref}} - token: ${{ secrets.AS_TOKEN }} #reniew token periodically - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2.3 - with: - key: ${{ matrix.os }}-${{ matrix.xprs.value }} - - - name: Set up Python - uses: actions/setup-python@v5 - with: - cache: 'pip' - python-version: 3.8 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-tests.txt - pip install -r requirements-ui.txt - - - name: Install mandatory system libraries - run: | - sudo apt-get update --fix-missing - sudo apt-get install -y ccache cmake libgtest-dev libjsoncpp-dev libtbb-dev libopenmpi-dev - sudo apt-get install -y g++-10 gcc-10 - - - name: Update alternatives - #mpicxx uses "g++" so we need g++ to be symbolic link to g++-10 - run: | - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10 - sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 - sudo update-alternatives --set cc /usr/bin/gcc - sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 - sudo update-alternatives --set c++ /usr/bin/g++ - - - name: Read antares-solver version - id: antares-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_version' - - - name: Read antares-xpansion version - id: antares-xpansion-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_xpansion_version' - - - name: Read antares-deps version - id: antares-deps-version - uses: ./.github/actions/read-json-value - with: - path: 'antares-version.json' - key: 'antares_deps_version' - - - name: Download pre-compiled librairies - uses: ./.github/workflows/download-extract-precompiled-libraries-tgz - with: - antares-deps-version: ${{steps.antares-deps-version.outputs.result}} - antares-version: ${{steps.antares-version.outputs.result}} - os: ${{matrix.os}} - os-full-name: Ubuntu-20.04 - - - name: Compile Boost - uses: ./.github/workflows/compile-boost - with: - prefix: "../rte-antares-deps-Release/" - load-toolset: 'false' - - - name: Configure - shell: bash - #XPRESS_VALUE = ${{ matrix.xprs }} == "XPRESS-ON" ? "ON" : "OFF" - run: | - [[ ${{ matrix.xprs.value }} == "XPRESS-ON" ]] && XPRESS_VALUE="ON" || XPRESS_VALUE="OFF" - cmake -B _build -S . \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \ - -DDEPS_INSTALL_DIR=rte-antares-deps-Release \ - -DBUILD_TESTING=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=_install \ - -DBUILD_UI=ON \ - -DXPRESS=${{ env.XPRESS_VALUE }} \ - -DXPRESS_ROOT=${{ env.XPRESSDIR }} - - - name: Build - run: | - cmake --build _build --config Release -j8 - - - name: Test - run: | - cd _build - ctest -C Release --output-on-failure -L "medium|unit|benders|lpnamer" + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" From dc8b915bf8eb8c09c9c61b7c705fe5999b54895a Mon Sep 17 00:00:00 2001 From: Jason Marechal Date: Tue, 26 Mar 2024 11:28:03 +0100 Subject: [PATCH 15/15] on push --- .github/workflows/build_ubuntu.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build_ubuntu.yml b/.github/workflows/build_ubuntu.yml index 36d4eada8..7417fd034 100644 --- a/.github/workflows/build_ubuntu.yml +++ b/.github/workflows/build_ubuntu.yml @@ -3,10 +3,6 @@ name: Ubuntu build on: merge_group: push: - branches: - - main - - develop - - dependabot/* pull_request: release: types: [ created ]