From ecccb29f0cd959b3d3e98c99794992ce9219a87f Mon Sep 17 00:00:00 2001 From: guilpier-code <62292552+guilpier-code@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:55:04 +0200 Subject: [PATCH] Infeasibility analyzer : small simplifications (#2226) Purpose : as the title says This PR is attached to ticket [ticket ANT-1825](https://gopro-tickets.rte-france.com/browse/ANT-1825). Some improvements were made or tried by taking care of the ticket. The result is this PR. --------- Co-authored-by: Florian OMNES <26088210+flomnes@users.noreply.github.com> --- .../constraint.cpp | 22 ++++--------------- .../infeasible-problem-analysis/report.cpp | 6 ++--- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/solver/infeasible-problem-analysis/constraint.cpp b/src/solver/infeasible-problem-analysis/constraint.cpp index c9aacb06aa..b43dc7dd95 100644 --- a/src/solver/infeasible-problem-analysis/constraint.cpp +++ b/src/solver/infeasible-problem-analysis/constraint.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include + namespace { const std::string kUnknown = ""; @@ -40,24 +43,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 bc493ff6bd..0964c251ab 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()