From eec4b4fe0315abd87025f746b892753fbdfb9265 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Tue, 2 Jul 2024 17:39:51 +0200 Subject: [PATCH] Simplifying infeasibility analyzer --- .../constraint.cpp | 25 ++++--------------- .../infeasible-problem-analysis/report.cpp | 6 ++--- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/solver/infeasible-problem-analysis/constraint.cpp b/src/solver/infeasible-problem-analysis/constraint.cpp index c9aacb06aa..0ac031184a 100644 --- a/src/solver/infeasible-problem-analysis/constraint.cpp +++ b/src/solver/infeasible-problem-analysis/constraint.cpp @@ -18,12 +18,14 @@ * You should have received a copy of the Mozilla Public Licence 2.0 * along with Antares_Simulator. If not, see . */ -#include "antares/solver/infeasible-problem-analysis/constraint.h" - #include #include #include #include +#include +#include + +#include "antares/solver/infeasible-problem-analysis/constraint.h" namespace { @@ -40,24 +42,7 @@ Constraint::Constraint(const std::string& input, const double slackValue): std::size_t Constraint::extractComponentsFromName() { - const auto beg = name_.begin(); - const auto end = name_.end(); - std::size_t newPos = 0; - const std::size_t sepSize = 2; - const std::size_t inputSize = name_.size(); - for (std::size_t pos = 0; pos < inputSize; pos = newPos + sepSize) - { - newPos = name_.find("::", pos); - if (newPos == std::string::npos) - { - nameComponents_.emplace_back(beg + pos, end); - break; - } - if (newPos > pos) - { - nameComponents_.emplace_back(beg + pos, beg + newPos); - } - } + boost::algorithm::split_regex(nameComponents_, name_, boost::regex("::")); return nameComponents_.size(); } diff --git a/src/solver/infeasible-problem-analysis/report.cpp b/src/solver/infeasible-problem-analysis/report.cpp index 58b1f4b757..f0a515c4bb 100644 --- a/src/solver/infeasible-problem-analysis/report.cpp +++ b/src/solver/infeasible-problem-analysis/report.cpp @@ -63,10 +63,8 @@ void InfeasibleProblemReport::sortConstraints() void InfeasibleProblemReport::trimConstraints() { - if (nbMaxVariables <= constraints_.size()) - { - constraints_.resize(nbMaxVariables); - } + unsigned int nbConstraints = constraints_.size(); + constraints_.resize(std::min(nbMaxVariables, nbConstraints)); } void InfeasibleProblemReport::sortConstraintsByType()