From 96df4e8ae3f1b42e0afac851cd4809974d855907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20Mar=C3=A9chal?= <45510813+JasonMarechal25@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:47:29 +0200 Subject: [PATCH] Improve dependency requirements (#2009) Several improvement centered around infeasible_problem_analysis lib. Breaking as many PUBLIC dependency as possible in favour of PRIVATE ones --- .../CMakeLists.txt | 39 +++++++------ .../constraint-slack-analysis.cpp | 46 ++++++++------- .../constraint.cpp | 40 ++++++------- .../constraint-slack-analysis.h | 44 ++++++++------- .../infeasible-problem-analysis}/constraint.h | 45 +++++++-------- .../infeasible-problem-analysis/report.h | 54 ++++++++++++++++++ .../unfeasibility-analysis.h | 51 +++++++++++++++++ .../unfeasible-pb-analyzer.h | 56 +++++++++++++++++++ .../variables-bounds-consistency.h | 39 ++++++------- .../infeasible-problem-analysis/report.cpp | 46 ++++++++------- .../infeasible-problem-analysis/report.h | 56 ------------------- .../unfeasibility-analysis.h | 50 ----------------- .../unfeasible-pb-analyzer.cpp | 44 +++++++-------- .../unfeasible-pb-analyzer.h | 52 ----------------- .../variables-bounds-consistency.cpp | 44 ++++++++------- src/solver/optimisation/CMakeLists.txt | 3 +- .../opt_appel_solveur_lineaire.cpp | 43 +++++++------- .../CMakeLists.txt | 1 + .../test-unfeasible-problem-analyzer.cpp | 45 +++++++-------- 19 files changed, 411 insertions(+), 387 deletions(-) rename src/solver/infeasible-problem-analysis/{ => include/antares/solver/infeasible-problem-analysis}/constraint-slack-analysis.h (52%) rename src/solver/infeasible-problem-analysis/{ => include/antares/solver/infeasible-problem-analysis}/constraint.h (51%) create mode 100644 src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/report.h create mode 100644 src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/unfeasibility-analysis.h create mode 100644 src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h rename src/solver/infeasible-problem-analysis/{ => include/antares/solver/infeasible-problem-analysis}/variables-bounds-consistency.h (57%) delete mode 100644 src/solver/infeasible-problem-analysis/report.h delete mode 100644 src/solver/infeasible-problem-analysis/unfeasibility-analysis.h delete mode 100644 src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h diff --git a/src/solver/infeasible-problem-analysis/CMakeLists.txt b/src/solver/infeasible-problem-analysis/CMakeLists.txt index 51edbcd527..720842fd6a 100644 --- a/src/solver/infeasible-problem-analysis/CMakeLists.txt +++ b/src/solver/infeasible-problem-analysis/CMakeLists.txt @@ -1,25 +1,30 @@ project(infeasible-problem-analysis) set(SRC_INFEASIBLE_PROBLEM_ANALYSIS - unfeasibility-analysis.h - 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 - report.cpp - constraint.h - constraint.cpp - ) + include/antares/solver/infeasible-problem-analysis/unfeasibility-analysis.h + include/antares/solver/infeasible-problem-analysis/constraint-slack-analysis.h + constraint-slack-analysis.cpp + include/antares/solver/infeasible-problem-analysis/variables-bounds-consistency.h + variables-bounds-consistency.cpp + unfeasible-pb-analyzer.cpp + include/antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h + include/antares/solver/infeasible-problem-analysis/report.h + report.cpp + include/antares/solver/infeasible-problem-analysis/constraint.h + constraint.cpp +) add_library(infeasible_problem_analysis ${SRC_INFEASIBLE_PROBLEM_ANALYSIS}) target_link_libraries(infeasible_problem_analysis - PUBLIC ortools::ortools sirius_solver - utils #ortools-utils, not Antares::utils - ) + PRIVATE + ortools::ortools + Antares::logs +) target_include_directories(infeasible_problem_analysis - PUBLIC - $ + PUBLIC + $ +) + +install(DIRECTORY include/antares + DESTINATION "include" ) diff --git a/src/solver/infeasible-problem-analysis/constraint-slack-analysis.cpp b/src/solver/infeasible-problem-analysis/constraint-slack-analysis.cpp index 4ab48991eb..02595165ce 100644 --- a/src/solver/infeasible-problem-analysis/constraint-slack-analysis.cpp +++ b/src/solver/infeasible-problem-analysis/constraint-slack-analysis.cpp @@ -1,27 +1,31 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include -#include "constraint-slack-analysis.h" +#include "antares/solver/infeasible-problem-analysis/constraint-slack-analysis.h" #include -#include "report.h" +#include "antares/solver/infeasible-problem-analysis/report.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include "ortools/linear_solver/linear_solver.h" +#pragma GCC diagnostic pop using namespace operations_research; diff --git a/src/solver/infeasible-problem-analysis/constraint.cpp b/src/solver/infeasible-problem-analysis/constraint.cpp index b5e37b4c66..ecd1c14d25 100644 --- a/src/solver/infeasible-problem-analysis/constraint.cpp +++ b/src/solver/infeasible-problem-analysis/constraint.cpp @@ -1,26 +1,26 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include -#include "constraint.h" +#include "antares/solver/infeasible-problem-analysis/constraint.h" #include #include #include diff --git a/src/solver/infeasible-problem-analysis/constraint-slack-analysis.h b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/constraint-slack-analysis.h similarity index 52% rename from src/solver/infeasible-problem-analysis/constraint-slack-analysis.h rename to src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/constraint-slack-analysis.h index a2cacb2058..51e66375a2 100644 --- a/src/solver/infeasible-problem-analysis/constraint-slack-analysis.h +++ b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/constraint-slack-analysis.h @@ -1,27 +1,33 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #pragma once #include "unfeasibility-analysis.h" +namespace operations_research +{ +class MPVariable; +class MPSolver; +} + namespace Antares::Optimization { diff --git a/src/solver/infeasible-problem-analysis/constraint.h b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/constraint.h similarity index 51% rename from src/solver/infeasible-problem-analysis/constraint.h rename to src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/constraint.h index 262e6c01ed..b0b8dddee7 100644 --- a/src/solver/infeasible-problem-analysis/constraint.h +++ b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/constraint.h @@ -1,31 +1,29 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #pragma once #include #include -namespace Antares -{ -namespace Optimization +namespace Antares::Optimization { enum class ConstraintType { @@ -64,5 +62,4 @@ class Constraint std::string getTimeStepInYear() const; std::string getBindingConstraintName() const; }; -} // namespace Optimization -} // namespace Antares +} // namespace Antares::Optimization diff --git a/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/report.h b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/report.h new file mode 100644 index 0000000000..48d843aa5c --- /dev/null +++ b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/report.h @@ -0,0 +1,54 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ +#pragma once + +#include +#include +#include + +#include "constraint.h" + +namespace operations_research +{ +class MPVariable; +} + +namespace Antares::Optimization +{ +class InfeasibleProblemReport +{ +public: + InfeasibleProblemReport() = delete; + explicit InfeasibleProblemReport(const std::vector& slackVariables); + void prettyPrint(); + +private: + void turnSlackVarsIntoConstraints(const std::vector& slackVariables); + void sortConstraints(); + void trimConstraints(); + void extractItems(); + void logSuspiciousConstraints(); + + std::vector mConstraints; + std::map mTypes; + const unsigned int nbVariables = 10; +}; +} // namespace Antares::Optimization diff --git a/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/unfeasibility-analysis.h b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/unfeasibility-analysis.h new file mode 100644 index 0000000000..2107ff6fd8 --- /dev/null +++ b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/unfeasibility-analysis.h @@ -0,0 +1,51 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ +#pragma once + +#include +#include + +namespace operations_research +{ +class MPSolver; +} +namespace Antares::Optimization +{ + +/*! + * Interface for all elementary analysis. + */ +class UnfeasibilityAnalysis +{ +public: + UnfeasibilityAnalysis() = default; + virtual ~UnfeasibilityAnalysis() = default; + + virtual void run(operations_research::MPSolver* problem) = 0; + virtual void printReport() const = 0; + virtual std::string title() const = 0; + bool hasDetectedInfeasibilityCause() const { return hasDetectedInfeasibilityCause_; } + +protected: + bool hasDetectedInfeasibilityCause_ = false; +}; + +} diff --git a/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h new file mode 100644 index 0000000000..7f44249bcd --- /dev/null +++ b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h @@ -0,0 +1,56 @@ +/* + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ +#pragma once + +#include +#include +#include + +#include "unfeasibility-analysis.h" + +namespace operations_research +{ +class MPSolver; +} + +namespace Antares::Optimization +{ + +/*! + * In charge of anayzing the possible reasons for the unfeasibility of an optimization problem. + * + * The analyzer relies on the execution of possibly multiple UnfeasibilityAnalysis. + */ +class UnfeasiblePbAnalyzer +{ +public: + UnfeasiblePbAnalyzer() = delete; + explicit UnfeasiblePbAnalyzer(std::vector> analysisList); + void run(operations_research::MPSolver* problem); + void printReport() const; + +private: + std::vector> analysisList_; +}; + +std::unique_ptr makeUnfeasiblePbAnalyzer(); + +} // 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/include/antares/solver/infeasible-problem-analysis/variables-bounds-consistency.h similarity index 57% rename from src/solver/infeasible-problem-analysis/variables-bounds-consistency.h rename to src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/variables-bounds-consistency.h index e6c05d68e9..663fc88421 100644 --- a/src/solver/infeasible-problem-analysis/variables-bounds-consistency.h +++ b/src/solver/infeasible-problem-analysis/include/antares/solver/infeasible-problem-analysis/variables-bounds-consistency.h @@ -1,26 +1,27 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #pragma once #include "unfeasibility-analysis.h" +#include namespace Antares::Optimization { diff --git a/src/solver/infeasible-problem-analysis/report.cpp b/src/solver/infeasible-problem-analysis/report.cpp index 0fbd7ed0a3..518dbab679 100644 --- a/src/solver/infeasible-problem-analysis/report.cpp +++ b/src/solver/infeasible-problem-analysis/report.cpp @@ -1,27 +1,31 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ -#include "report.h" -#include "constraint.h" + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * 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/report.h" +#include "antares/solver/infeasible-problem-analysis/constraint.h" #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include "ortools/linear_solver/linear_solver.h" +#pragma GCC diagnostic pop using namespace operations_research; diff --git a/src/solver/infeasible-problem-analysis/report.h b/src/solver/infeasible-problem-analysis/report.h deleted file mode 100644 index 9b2b2e6985..0000000000 --- a/src/solver/infeasible-problem-analysis/report.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ -#pragma once - -#include -#include -#include - -#include "constraint.h" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#include "ortools/linear_solver/linear_solver.h" -#pragma GCC diagnostic pop - -namespace Antares -{ -namespace Optimization -{ -class InfeasibleProblemReport -{ -public: - InfeasibleProblemReport() = delete; - explicit InfeasibleProblemReport(const std::vector& slackVariables); - void prettyPrint(); - -private: - void turnSlackVarsIntoConstraints(const std::vector& slackVariables); - void sortConstraints(); - void trimConstraints(); - void extractItems(); - void logSuspiciousConstraints(); - - std::vector mConstraints; - std::map mTypes; - const unsigned int nbVariables = 10; -}; -} // namespace Optimization -} // namespace Antares diff --git a/src/solver/infeasible-problem-analysis/unfeasibility-analysis.h b/src/solver/infeasible-problem-analysis/unfeasibility-analysis.h deleted file mode 100644 index d9f432b392..0000000000 --- a/src/solver/infeasible-problem-analysis/unfeasibility-analysis.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ -#pragma once - -#include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#include "ortools/linear_solver/linear_solver.h" -#pragma GCC diagnostic pop - -namespace Antares::Optimization -{ - -/*! - * Interface for all elementary analysis. - */ -class UnfeasibilityAnalysis -{ -public: - UnfeasibilityAnalysis() = default; - virtual ~UnfeasibilityAnalysis() = default; - - virtual void run(operations_research::MPSolver* problem) = 0; - virtual void printReport() const = 0; - virtual std::string title() const = 0; - bool hasDetectedInfeasibilityCause() const { return hasDetectedInfeasibilityCause_; } - -protected: - bool hasDetectedInfeasibilityCause_ = false; -}; - -} diff --git a/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.cpp b/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.cpp index c63ebe84df..b7a7e94aac 100644 --- a/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.cpp +++ b/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.cpp @@ -1,29 +1,29 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include #include -#include "unfeasible-pb-analyzer.h" -#include "variables-bounds-consistency.h" -#include "constraint-slack-analysis.h" +#include "antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h" +#include "antares/solver/infeasible-problem-analysis/variables-bounds-consistency.h" +#include "antares/solver/infeasible-problem-analysis/constraint-slack-analysis.h" #include diff --git a/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h b/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h deleted file mode 100644 index 2cf2dedfa1..0000000000 --- a/src/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ -#pragma once - -#include -#include -#include - -#include "antares/solver/utils/ortools_utils.h" -#include "unfeasibility-analysis.h" - -namespace Antares::Optimization -{ - -/*! - * In charge of anayzing the possible reasons for the unfeasibility of an optimization problem. - * - * The analyzer relies on the execution of possibly multiple UnfeasibilityAnalysis. - */ -class UnfeasiblePbAnalyzer -{ -public: - UnfeasiblePbAnalyzer() = delete; - explicit UnfeasiblePbAnalyzer(std::vector> analysisList); - void run(MPSolver* problem); - void printReport() const; - -private: - std::vector> analysisList_; -}; - -std::unique_ptr makeUnfeasiblePbAnalyzer(); - -} // namespace Antares::Optimization \ No newline at end of file diff --git a/src/solver/infeasible-problem-analysis/variables-bounds-consistency.cpp b/src/solver/infeasible-problem-analysis/variables-bounds-consistency.cpp index a05565ac9a..28b13d4656 100644 --- a/src/solver/infeasible-problem-analysis/variables-bounds-consistency.cpp +++ b/src/solver/infeasible-problem-analysis/variables-bounds-consistency.cpp @@ -1,25 +1,29 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ -#include "variables-bounds-consistency.h" + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * 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/variables-bounds-consistency.h" #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include "ortools/linear_solver/linear_solver.h" +#pragma GCC diagnostic pop using namespace operations_research; diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index 082f391b89..ede327410e 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -195,9 +195,10 @@ target_link_libraries(model_antares PUBLIC utils sirius_solver - infeasible_problem_analysis antares-solver-simulation Antares::benchmarking + PRIVATE + infeasible_problem_analysis ) target_include_directories(model_antares diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 351db618c9..d1747f9fb3 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #include #include "antares/solver/optimisation/opt_structure_probleme_a_resoudre.h" @@ -39,10 +39,7 @@ extern "C" #include "antares/solver/utils/mps_utils.h" #include "antares/solver/utils/filename.h" - -#include "../infeasible-problem-analysis/unfeasible-pb-analyzer.h" -#include "../infeasible-problem-analysis/variables-bounds-consistency.h" -#include "../infeasible-problem-analysis/constraint-slack-analysis.h" +#include "antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h" #include diff --git a/src/tests/src/solver/infeasible-problem-analysis/CMakeLists.txt b/src/tests/src/solver/infeasible-problem-analysis/CMakeLists.txt index ee78b2bee3..8a8a0e9544 100644 --- a/src/tests/src/solver/infeasible-problem-analysis/CMakeLists.txt +++ b/src/tests/src/solver/infeasible-problem-analysis/CMakeLists.txt @@ -6,6 +6,7 @@ target_link_libraries(test-unfeasible-problem-analyzer PRIVATE Boost::unit_test_framework infeasible_problem_analysis + ortools::ortools ) add_test(NAME test-unfeasible-problem-analyzer COMMAND test-unfeasible-problem-analyzer) diff --git a/src/tests/src/solver/infeasible-problem-analysis/test-unfeasible-problem-analyzer.cpp b/src/tests/src/solver/infeasible-problem-analysis/test-unfeasible-problem-analyzer.cpp index 2f838995ae..01913254fa 100644 --- a/src/tests/src/solver/infeasible-problem-analysis/test-unfeasible-problem-analyzer.cpp +++ b/src/tests/src/solver/infeasible-problem-analysis/test-unfeasible-problem-analyzer.cpp @@ -1,23 +1,23 @@ /* -** Copyright 2007-2024, RTE (https://www.rte-france.com) -** See AUTHORS.txt -** SPDX-License-Identifier: MPL-2.0 -** This file is part of Antares-Simulator, -** Adequacy and Performance assessment for interconnected energy networks. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the Mozilla Public Licence 2.0 as published by -** the Mozilla Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Antares_Simulator is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** Mozilla Public Licence 2.0 for more details. -** -** You should have received a copy of the Mozilla Public Licence 2.0 -** along with Antares_Simulator. If not, see . -*/ + * Copyright 2007-2024, RTE (https://www.rte-france.com) + * See AUTHORS.txt + * SPDX-License-Identifier: MPL-2.0 + * This file is part of Antares-Simulator, + * Adequacy and Performance assessment for interconnected energy networks. + * + * Antares_Simulator is free software: you can redistribute it and/or modify + * it under the terms of the Mozilla Public Licence 2.0 as published by + * the Mozilla Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Antares_Simulator is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Mozilla Public Licence 2.0 for more details. + * + * You should have received a copy of the Mozilla Public Licence 2.0 + * along with Antares_Simulator. If not, see . + */ #define WIN32_LEAN_AND_MEAN #define BOOST_TEST_MODULE unfeasible_problem_analyzer #define BOOST_TEST_DYN_LINK @@ -26,9 +26,10 @@ #include #include -#include "infeasible-problem-analysis/unfeasible-pb-analyzer.h" -#include "infeasible-problem-analysis/variables-bounds-consistency.h" -#include "infeasible-problem-analysis/constraint-slack-analysis.h" +#include "antares/solver/infeasible-problem-analysis/unfeasible-pb-analyzer.h" +#include "antares/solver/infeasible-problem-analysis/variables-bounds-consistency.h" +#include "antares/solver/infeasible-problem-analysis/constraint-slack-analysis.h" +#include "ortools/linear_solver/linear_solver.h" namespace bdata = boost::unit_test::data;