Skip to content

Commit

Permalink
Add a check to unfeasible analyzer : mainly extract class VariablesBo…
Browse files Browse the repository at this point in the history
…undsConsistency in separate source files
  • Loading branch information
guilpier-code committed Oct 19, 2023
1 parent 7dc22fb commit 4bffb5f
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/solver/infeasible-problem-analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <algorithm>

#include "unfeasible-pb-analyzer.h"
#include "variables-bounds-consistency.h"
#include "constraint-slack-analysis.h"
#include <antares/logs/logs.h>

Expand All @@ -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.
Expand Down
26 changes: 0 additions & 26 deletions src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VariableBounds> incorrectVars_;
};

class UnfeasiblePbAnalyzer
{
public:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "variables-bounds-consistency.h"
#include <antares/logs/logs.h>

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
Original file line number Diff line number Diff line change
@@ -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<VariableBounds> incorrectVars_;
};
}

0 comments on commit 4bffb5f

Please sign in to comment.