From 4bffb5f0b650cd939137334692fd14ef33b37985 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Thu, 19 Oct 2023 11:38:22 +0200 Subject: [PATCH] Add a check to unfeasible analyzer : mainly extract class VariablesBoundsConsistency in separate source files --- .github/workflows/windows-vcpkg.yml | 2 +- .../CMakeLists.txt | 2 + .../constraint-slack-analysis.h | 2 +- .../unfeasible-pb-analyzer.cpp | 47 +------------------ .../unfeasible-pb-analyzer.h | 26 ---------- .../variables-bounds-consistency.cpp | 41 ++++++++++++++++ .../variables-bounds-consistency.h | 33 +++++++++++++ 7 files changed, 79 insertions(+), 74 deletions(-) create mode 100644 src/solver/infeasible-problem-analysis/variables-bounds-consistency.cpp create mode 100644 src/solver/infeasible-problem-analysis/variables-bounds-consistency.h diff --git a/.github/workflows/windows-vcpkg.yml b/.github/workflows/windows-vcpkg.yml index bd441f625c..e54c221cdb 100644 --- a/.github/workflows/windows-vcpkg.yml +++ b/.github/workflows/windows-vcpkg.yml @@ -89,7 +89,7 @@ jobs: uses: actions/setup-python@v4 with: architecture: 'x64' - python-version: '3.11' + python-version: '3.12' - name: Install pip dependencies if necessary run: pip install -r src/tests/examples/requirements.txt diff --git a/src/solver/infeasible-problem-analysis/CMakeLists.txt b/src/solver/infeasible-problem-analysis/CMakeLists.txt index 2215a8e6a9..4fed265811 100644 --- a/src/solver/infeasible-problem-analysis/CMakeLists.txt +++ b/src/solver/infeasible-problem-analysis/CMakeLists.txt @@ -5,6 +5,8 @@ set(SRC_INFEASIBLE_PROBLEM_ANALYSIS unfeasibility-analysis.cpp constraint-slack-analysis.h constraint-slack-analysis.cpp + variables-bounds-consistency.h + variables-bounds-consistency.cpp unfeasible-pb-analyzer.cpp unfeasible-pb-analyzer.h report.h diff --git a/src/solver/infeasible-problem-analysis/constraint-slack-analysis.h b/src/solver/infeasible-problem-analysis/constraint-slack-analysis.h index 5aea3363c1..1b021c09ac 100644 --- a/src/solver/infeasible-problem-analysis/constraint-slack-analysis.h +++ b/src/solver/infeasible-problem-analysis/constraint-slack-analysis.h @@ -11,7 +11,7 @@ class ConstraintSlackAnalysis : public UnfeasibilityAnalysis public: void run() override; void printReport() override; - std::string title() override { return "Slack variables diagnostic"; } + std::string title() override { return "Slack variables analysis"; } private: void buildObjective() const; diff --git a/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.cpp b/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.cpp index e226ad802f..1432fafc8d 100644 --- a/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.cpp +++ b/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.cpp @@ -2,6 +2,7 @@ #include #include "unfeasible-pb-analyzer.h" +#include "variables-bounds-consistency.h" #include "constraint-slack-analysis.h" #include @@ -11,52 +12,6 @@ using namespace operations_research; namespace Antares::Optimization { -// ============================ -// Variables bounds analysis -// ============================ - -void VariablesBoundsConsistency::run() -{ - for (auto& var : problem_->variables()) - { - double lowBound = var->lb(); - double upBound = var->ub(); - std::string name = var->name(); - if (lowBound > upBound) - { - storeIncorrectVariable(name, lowBound, upBound); - } - } - - if (foundIncorrectVariables()) - hasDetectedInfeasibilityCause_ = true; -} - -void VariablesBoundsConsistency::storeIncorrectVariable(std::string name, double lowBound, double upBound) -{ - incorrectVars_.push_back(VariableBounds(name, lowBound, upBound)); -} - -bool VariablesBoundsConsistency::foundIncorrectVariables() -{ - return !incorrectVars_.empty(); -} - -void VariablesBoundsConsistency::printReport() -{ - for (auto& var : incorrectVars_) - { - logs.notice() << var.name << " : low bound = " << var.lowBound << ", up bound = " << var.upBound; - } -} - - -// =============================== -// Unfeasibility analyzer -// =============================== - -// gp : this class should be renamed into UnfeasibilityAnalyzer - UnfeasiblePbAnalyzer::UnfeasiblePbAnalyzer(const std::string& solverName, const PROBLEME_SIMPLEXE_NOMME* ProbSpx) { // gp : Here we have a dependency on PROBLEME_SIMPLEXE_NOMME and MPSolver. diff --git a/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h b/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h index d8b2123e64..d5445fba00 100644 --- a/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h +++ b/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h @@ -10,32 +10,6 @@ namespace Antares::Optimization { -struct VariableBounds -{ - VariableBounds(std::string var_name, double low_bound, double up_bound) - : name(var_name), lowBound(low_bound), upBound(up_bound) - {} - - std::string name; - double lowBound; - double upBound; -}; - -class VariablesBoundsConsistency : public UnfeasibilityAnalysis -{ - using UnfeasibilityAnalysis::UnfeasibilityAnalysis; -public: - void run() override; - void printReport() override; - std::string title() override { return "Variables bounds check"; } - -private: - void storeIncorrectVariable(std::string name, double lowBound, double upBound); - bool foundIncorrectVariables(); - - std::vector incorrectVars_; -}; - class UnfeasiblePbAnalyzer { public: diff --git a/src/solver/infeasible-problem-analysis/variables-bounds-consistency.cpp b/src/solver/infeasible-problem-analysis/variables-bounds-consistency.cpp new file mode 100644 index 0000000000..9d145f5a03 --- /dev/null +++ b/src/solver/infeasible-problem-analysis/variables-bounds-consistency.cpp @@ -0,0 +1,41 @@ +#include "variables-bounds-consistency.h" +#include + +namespace Antares::Optimization +{ + +void VariablesBoundsConsistency::run() +{ + for (auto& var : problem_->variables()) + { + double lowBound = var->lb(); + double upBound = var->ub(); + std::string name = var->name(); + if (lowBound > upBound) + { + storeIncorrectVariable(name, lowBound, upBound); + } + } + + if (foundIncorrectVariables()) + hasDetectedInfeasibilityCause_ = true; +} + +void VariablesBoundsConsistency::storeIncorrectVariable(std::string name, double lowBound, double upBound) +{ + incorrectVars_.push_back(VariableBounds(name, lowBound, upBound)); +} + +bool VariablesBoundsConsistency::foundIncorrectVariables() +{ + return !incorrectVars_.empty(); +} + +void VariablesBoundsConsistency::printReport() +{ + for (auto& var : incorrectVars_) + { + logs.notice() << var.name << " : low bound = " << var.lowBound << ", up bound = " << var.upBound; + } +} +} // namespace Antares::Optimization \ No newline at end of file diff --git a/src/solver/infeasible-problem-analysis/variables-bounds-consistency.h b/src/solver/infeasible-problem-analysis/variables-bounds-consistency.h new file mode 100644 index 0000000000..efd9a1db19 --- /dev/null +++ b/src/solver/infeasible-problem-analysis/variables-bounds-consistency.h @@ -0,0 +1,33 @@ +#pragma once + +#include "unfeasibility-analysis.h" + +namespace Antares::Optimization +{ + +struct VariableBounds +{ + VariableBounds(std::string var_name, double low_bound, double up_bound) + : name(var_name), lowBound(low_bound), upBound(up_bound) + {} + + std::string name; + double lowBound; + double upBound; +}; + +class VariablesBoundsConsistency : public UnfeasibilityAnalysis +{ + using UnfeasibilityAnalysis::UnfeasibilityAnalysis; +public: + void run() override; + void printReport() override; + std::string title() override { return "Variables bounds consistency check"; } + +private: + void storeIncorrectVariable(std::string name, double lowBound, double upBound); + bool foundIncorrectVariables(); + + std::vector incorrectVars_; +}; +}