Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy ortools behind API - user story 3.1 #2455

Merged
merged 35 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ab11215
Legacy ortools behind API : in CI, run tests with ortools + sirius
guilpier-code Oct 8, 2024
2f704ca
Legacy ortools behind API : mainly preparing the field for further ch…
guilpier-code Oct 9, 2024
0a308a9
Legacy ortools behind API : put solver creation behind or-tools
guilpier-code Oct 10, 2024
51d19d8
Legacy ortools behind API : fix crash in modeler unit tests
guilpier-code Oct 10, 2024
8223c47
Legacy ortools behind API : fix a crash - smart pointer on ortools so…
guilpier-code Oct 10, 2024
f588590
Legacy ortools behind API : remove duplicate code
guilpier-code Oct 10, 2024
b4ef65f
Legacy ortools behind API : correction due to review
guilpier-code Oct 11, 2024
ef29f1d
Legacy ortools behind API : correction due to review
guilpier-code Oct 11, 2024
b6c9758
activate some tests on new simtest reference
pet-mit Oct 14, 2024
499f548
activate ortools in end-to-end tests
pet-mit Oct 14, 2024
3fdc8fc
fix simtest version
pet-mit Oct 14, 2024
89724ea
fix clang format
pet-mit Oct 14, 2024
f03e705
fix simtest version
pet-mit Oct 14, 2024
96707ac
Merge branch 'develop' into feature/legacy-ortools-behind-api-3.1
pet-mit Oct 14, 2024
836a73a
fix after merge
pet-mit Oct 14, 2024
d326428
fix clang format
pet-mit Oct 14, 2024
c2a02d8
Improve 3.1 (#2461)
pet-mit Oct 14, 2024
8d89138
Merge branch 'develop' into feature/legacy-ortools-behind-api-3.1
pet-mit Oct 14, 2024
678fea0
some fixes
pet-mit Oct 14, 2024
41b9c83
some fixes
pet-mit Oct 14, 2024
c37bf6c
activate long tests
pet-mit Oct 15, 2024
9d9dcfe
Merge branch 'develop' into feature/legacy-ortools-behind-api-3.1
pet-mit Oct 15, 2024
0c7d054
Update src/solver/optimisation/LegacyFiller.cpp
pet-mit Oct 15, 2024
4aa95a2
fix
pet-mit Oct 15, 2024
a0463b8
revert CI test changes
pet-mit Oct 16, 2024
d0a0686
revert CI test changes
pet-mit Oct 16, 2024
342b926
Merge branch 'develop' into feature/legacy-ortools-behind-api-3.1
pet-mit Oct 16, 2024
6a018aa
revert CI test changes
pet-mit Oct 16, 2024
7fc4d93
Merge remote-tracking branch 'origin/feature/legacy-ortools-behind-ap…
pet-mit Oct 16, 2024
33abc2f
revert CI test changes
pet-mit Oct 16, 2024
bf386b9
add message in case of MPS check failure
pet-mit Oct 17, 2024
6b217e9
revert ortools activation in test
pet-mit Oct 17, 2024
399f634
Merge branch 'develop' into feature/legacy-ortools-behind-api-3.1
pet-mit Oct 17, 2024
62863e7
PR comments
pet-mit Oct 22, 2024
5237a6f
remove useless include
pet-mit Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ jobs:
run: |
git submodule update --init --remote --recursive src/tests/resources/Antares_Simulator_Tests_NR

- name: Run named mps tests
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{ env.SIMTEST }}
batch-name: valid-named-mps
os: ${{ env.os }}
variant: "named-mps"
#- name: Run named mps tests
# if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
# uses: ./.github/workflows/run-tests
# with:
# simtest-tag: ${{ env.SIMTEST }}
# batch-name: valid-named-mps
# os: ${{ env.os }}
# variant: "named-mps"

- name: Run unfeasibility-related tests
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
Expand Down Expand Up @@ -240,13 +240,13 @@ jobs:
with:
feature: "features/short_tests.feature"

- name: Run mps tests
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{ env.SIMTEST }}
batch-name: valid-mps
os: ${{ env.os }}
#- name: Run mps tests
# if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
# uses: ./.github/workflows/run-tests
# with:
# simtest-tag: ${{ env.SIMTEST }}
# batch-name: valid-mps
# os: ${{ env.os }}

- name: Run tests for adequacy patch (CSR)
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
Expand All @@ -257,7 +257,7 @@ jobs:
os: ${{ env.os }}

- name: Run parallel tests
if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }}
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{ env.SIMTEST }}
Expand All @@ -275,7 +275,7 @@ jobs:
variant: "tsgenerator"

- name: Run medium-tests
if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }}
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{ env.SIMTEST }}
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ jobs:
run: |
git submodule update --init --remote src/tests/resources/Antares_Simulator_Tests_NR

- name: Run named mps tests
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && ! cancelled() }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{ env.SIMTEST }}
batch-name: valid-named-mps
os: ${{ env.os }}
variant: "named-mps"
#- name: Run named mps tests
# if: ${{ env.RUN_SIMPLE_TESTS == 'true' && ! cancelled() }}
# uses: ./.github/workflows/run-tests
# with:
# simtest-tag: ${{ env.SIMTEST }}
# batch-name: valid-named-mps
# os: ${{ env.os }}
# variant: "named-mps"

- name: Run unfeasibility-related tests
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && ! cancelled() }}
Expand Down Expand Up @@ -250,16 +250,16 @@ jobs:
with:
feature: "features/short_tests.feature"

- name: Run mps tests
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{ env.SIMTEST }}
batch-name: valid-mps
os: ${{ env.os }}
#- name: Run mps tests
# if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
# uses: ./.github/workflows/run-tests
# with:
# simtest-tag: ${{ env.SIMTEST }}
# batch-name: valid-mps
# os: ${{ env.os }}

- name: Run parallel tests
if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }}
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{ env.SIMTEST }}
Expand All @@ -277,7 +277,7 @@ jobs:
variant: "tsgenerator"

- name: Run medium-tests
if: ${{ env.RUN_EXTENDED_TESTS == 'true' && !cancelled() }}
if: ${{ env.RUN_SIMPLE_TESTS == 'true' && !cancelled() }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{ env.SIMTEST }}
Expand Down
43 changes: 22 additions & 21 deletions src/packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
include(GNUInstallDirs)
# generate and install export file
set(TARGET_LIBS #No alias
#each "block" of dependency describe the dependency for a target
#not dependency is present since once a dependency is in the export set
#it is available for everything
# each "block" of dependency describe the dependency for a target
# not dependency is present since once a dependency is in the export set
# it is available for everything

solver_api #What we want to export
solver_api # What we want to export

#solver_api
# solver_api
study
study-loader
file-tree-study-loader
antares-solver-simulation
#study
# study
yuni-static-core
array
date
Expand All @@ -37,56 +37,57 @@ set(TARGET_LIBS #No alias
antares-solver-variable
lps

#study-loader
#nothing
# study-loader : nothing

#file-tree-study-loader
# file-tree-study-loader
application

#run-mode
# run-mode
infoCollection

#antares-solver-simulation
# antares-solver-simulation
concurrency
misc
model_antares
antares-solver-ts-generator

#lps
#nothing
# lps : nothing

#array
# array
io
jit
AntaresMemory

#date
# date
logs

#correlation
# correlation
locator

#antares-core
# antares-core
antares-config-lib

#application
# application
solver-lib
sys
signal-handling
antares-solver-variable-info
optimization-options
resources

#model_antares
# model_antares
infeasible_problem_analysis
modeler_api
modeler-ortools-impl

#solver-lib
# solver-lib
args_helper
checks
locale
yuni-static-uuid

antares-solver #executable
# executable
antares-solver
)

install(TARGETS ${TARGET_LIBS}
Expand Down
2 changes: 2 additions & 0 deletions src/solver/modeler/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ set(SRC_API
include/antares/solver/modeler/api/linearProblemFiller.h
include/antares/solver/modeler/api/linearProblemBuilder.h

include/antares/solver/modeler/api/fillers/LegacyOrtoolsFiller.h

linearProblemData.cpp
linearProblemBuilder.cpp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#pragma once

#include "antares/solver/modeler/api/linearProblemFiller.h"
#include "ortools/linear_solver/linear_solver.h"
#include "antares/solver/utils/named_problem.h"
#include "antares/solver/utils/ortools_utils.h"

using namespace Antares::Optimization;

namespace Antares::Solver::Modeler::Api
{
class LegacyOrtoolsFiller: public LinearProblemFiller
{
public:
explicit LegacyOrtoolsFiller(operations_research::MPSolver* mpSolver,
const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* problemeSimplexe);
void addVariables(ILinearProblem& pb, LinearProblemData& data) override;
void addConstraints(ILinearProblem& pb, LinearProblemData& data) override;
void addObjective(ILinearProblem& pb, LinearProblemData& data) override;

private:
operations_research::MPSolver* mpSolver_ = nullptr;
const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* problemeSimplexe_;
Nomenclature variableNameManager_ = Nomenclature('x');
Nomenclature constraintNameManager_ = Nomenclature('c');

void CreateVariable(unsigned idxVar, MPSolver* solver, MPObjective* const objective) const;
void CopyVariables(MPSolver* solver) const;
void UpdateContraints(unsigned idxRow, MPSolver* solver) const;
void CopyRows(MPSolver* solver) const;
void CopyMatrix(const MPSolver* solver) const;
};

LegacyOrtoolsFiller::LegacyOrtoolsFiller(operations_research::MPSolver* mpSolver,
const Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* problemeSimplexe) :
mpSolver_(mpSolver),
problemeSimplexe_(problemeSimplexe)
{
if (problemeSimplexe_->UseNamedProblems())
{
variableNameManager_.SetTarget(problemeSimplexe_->VariableNames());
constraintNameManager_.SetTarget(problemeSimplexe_->ConstraintNames());
}
}

void LegacyOrtoolsFiller::addVariables(ILinearProblem& pb, LinearProblemData& data)
{
// Create the variables and set objective cost.
CopyVariables(mpSolver_);
}

void LegacyOrtoolsFiller::addConstraints(ILinearProblem& pb, LinearProblemData& data)
{
// Create constraints and set coefs
CopyRows(mpSolver_);

CopyMatrix(mpSolver_);
}

void LegacyOrtoolsFiller::addObjective(ILinearProblem& pb, LinearProblemData& data)
{
}

void LegacyOrtoolsFiller::CopyMatrix(const MPSolver* solver) const
{
auto variables = solver->variables();
auto constraints = solver->constraints();

for (int idxRow = 0; idxRow < problemeSimplexe_->NombreDeContraintes; ++idxRow)
{
MPConstraint* const ct = constraints[idxRow];
int debutLigne = problemeSimplexe_->IndicesDebutDeLigne[idxRow];
for (int idxCoef = 0; idxCoef < problemeSimplexe_->NombreDeTermesDesLignes[idxRow];
++idxCoef)
{
int pos = debutLigne + idxCoef;
ct->SetCoefficient(variables[problemeSimplexe_->IndicesColonnes[pos]],
problemeSimplexe_->CoefficientsDeLaMatriceDesContraintes[pos]);
}
}
}

void LegacyOrtoolsFiller::CreateVariable(unsigned idxVar,
MPSolver* solver,
MPObjective* const objective) const
{
double min_l = problemeSimplexe_->Xmin[idxVar];
double max_l = problemeSimplexe_->Xmax[idxVar];
bool isIntegerVariable = problemeSimplexe_->IntegerVariable(idxVar);
const MPVariable* var = solver->MakeVar(min_l,
max_l,
isIntegerVariable,
variableNameManager_.GetName(idxVar));
objective->SetCoefficient(var, problemeSimplexe_->CoutLineaire[idxVar]);
}

void LegacyOrtoolsFiller::CopyVariables(MPSolver* solver) const

{
MPObjective* const objective = solver->MutableObjective();
for (int idxVar = 0; idxVar < problemeSimplexe_->NombreDeVariables; ++idxVar)
{
CreateVariable(idxVar, solver, objective);
}
}

void LegacyOrtoolsFiller::UpdateContraints(unsigned idxRow, MPSolver* solver) const
{
double bMin = -MPSolver::infinity(), bMax = MPSolver::infinity();
if (problemeSimplexe_->Sens[idxRow] == '=')
{
bMin = bMax = problemeSimplexe_->SecondMembre[idxRow];
}
else if (problemeSimplexe_->Sens[idxRow] == '<')
{
bMax = problemeSimplexe_->SecondMembre[idxRow];
}
else if (problemeSimplexe_->Sens[idxRow] == '>')
{
bMin = problemeSimplexe_->SecondMembre[idxRow];
}

solver->MakeRowConstraint(bMin, bMax, constraintNameManager_.GetName(idxRow));
}

void LegacyOrtoolsFiller::CopyRows(MPSolver* solver) const
{
for (int idxRow = 0; idxRow < problemeSimplexe_->NombreDeContraintes; ++idxRow)
{
UpdateContraints(idxRow, solver);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ class OrtoolsLinearProblem final: public Api::ILinearProblem
bool isMaximization() const override;

OrtoolsMipSolution* solve(bool verboseSolver) override;
operations_research::MPSolver* MPSolver();

private:
OrtoolsMipVariable* addVariable(double lb, double ub, bool integer, const std::string& name);

std::shared_ptr<operations_research::MPSolver> mpSolver_;
operations_research::MPSolver* mpSolver_;
operations_research::MPObjective* objective_;
operations_research::MPSolverParameters params_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OrtoolsMipSolution final: public Api::IMipSolution
{
public:
OrtoolsMipSolution(operations_research::MPSolver::ResultStatus& responseStatus,
std::shared_ptr<operations_research::MPSolver> solver);
operations_research::MPSolver* solver);

~OrtoolsMipSolution() override = default;

Expand All @@ -47,7 +47,7 @@ class OrtoolsMipSolution final: public Api::IMipSolution

private:
operations_research::MPSolver::ResultStatus status_;
std::shared_ptr<operations_research::MPSolver> mpSolver_;
operations_research::MPSolver* mpSolver_;
std::map<std::string, double> solution_;
};

Expand Down
Loading
Loading