Skip to content

Commit

Permalink
cherry pick 1
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes authored and payetvin committed Feb 12, 2024
1 parent 79fddc7 commit e9b03b4
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/centos7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Config OR-Tools URL
run: |
echo "URL_ORTOOLS=https://github.com/rte-france/or-tools/releases/download/v9.5-rte2.0/ortools_cxx_centos7_static_sirius.zip" >> $GITHUB_ENV
echo "URL_ORTOOLS=https://github.com/rte-france/or-tools/releases/download/$(cat ortools_tag)/ortools_cxx_centos7_static_sirius.zip" >> $GITHUB_ENV
- name: Download OR-Tools
id: ortools
Expand Down
20 changes: 8 additions & 12 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ jobs:
# https://sonarcloud.io/documentation/analysis/scan/sonarscanner/
SONAR_SERVER_URL: "https://sonarcloud.io"
ORTOOLS_DIR: ${{ github.workspace }}/or-tools
ORTOOLS_URL: "https://github.com/rte-france/or-tools/releases/download/v9.5-rte2.0/ortools_cxx_ubuntu-20.04_static_sirius.zip"

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Config OR-Tools URL
run: |
echo "ORTOOLS_URL=https://github.com/rte-france/or-tools/releases/download/$(cat ortools_tag)/ortools_cxx_ubuntu-20.04_static_sirius.zip" >> $GITHUB_ENV
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v2

- name: ccache
uses: hendrikmuhs/[email protected]
Expand All @@ -42,16 +48,6 @@ jobs:
key: ${{ runner.os }}-sonar-${{ env.SONAR_SCANNER_VERSION }}
restore-keys: ${{ runner.os }}-sonar-${{ env.SONAR_SCANNER_VERSION }}

- name: Download and setup sonar-scanner
shell: bash
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
if: steps.sonarcloud-cache.outputs.cache-hit != 'true'
run: |
mkdir -p $HOME/.sonar
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
- name: Download and setup build-wrapper
shell: bash
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Config OR-Tools URL
run: |
echo "ORTOOLS_URL=https://github.com/rte-france/or-tools/releases/download/v9.5-rte2.0/ortools_cxx_ubuntu-20.04_static_sirius.zip" >> $GITHUB_ENV
echo "ORTOOLS_URL=https://github.com/rte-france/or-tools/releases/download/$(cat ortools_tag)/ortools_cxx_ubuntu-20.04_static_sirius.zip" >> $GITHUB_ENV
- name: Download pre-compiled librairies
uses: ./.github/workflows/download-extract-precompiled-libraries-tgz
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/windows-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ jobs:
# Indicates the location of the vcpkg as a Git submodule of the project repository.
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
ORTOOLS_DIR: ${{ github.workspace }}/or-tools
ORTOOLS_URL: "https://github.com/rte-france/or-tools/releases/download/v9.5-rte2.0/ortools_cxx_windows-latest_static_sirius.zip"

steps:
- uses: actions/checkout@v3

- name: Config OR-Tools URL
run: |
echo "ORTOOLS_URL=https://github.com/rte-france/or-tools/releases/download/$(cat ortools_tag)/ortools_cxx_windows-latest_static_sirius.zip" >> $GITHUB_ENV
shell: bash

- name: Pre-requisites
shell: cmd
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ jobs:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
ORTOOLS_DIR: ${{ github.workspace }}/or-tools
ORTOOLS_URL: "https://github.com/rte-france/or-tools/releases/download/v9.5-rte2.0/ortools_cxx_windows-latest_static_sirius.zip"
RUN_EXTENDED_TESTS: ${{ github.event_name == 'schedule'}}

steps:
- uses: actions/checkout@v3

- name: Config OR-Tools URL
run: |
echo "ORTOOLS_URL=https://github.com/rte-france/or-tools/releases/download/$(cat ortools_tag)/ortools_cxx_windows-latest_static_sirius.zip" >> $GITHUB_ENV
shell: bash

- name: Pre-requisites
shell: cmd
run: |
Expand Down
2 changes: 1 addition & 1 deletion ortools_tag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v9.5-rte2.0
v9.5-rte3.0
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ message(STATUS "OR-Tools tag ${ORTOOLS_TAG}")
set(BUILD_SAMPLES "OFF" CACHE INTERNAL "")
set(BUILD_FLATZINC "OFF" CACHE INTERNAL "")
set(BUILD_EXAMPLES "OFF" CACHE INTERNAL "")
set(USE_SCIP "OFF" CACHE INTERNAL "")
set(USE_SCIP "ON" CACHE INTERNAL "")
set(USE_GLPK "ON" CACHE INTERNAL "")
# We build OR-Tools as a static lib. Cyclic dependencies are detected
# without this flag.
set(BUILD_SHARED_LIBS "OFF" CACHE INTERNAL "")
Expand Down
13 changes: 9 additions & 4 deletions src/solver/optimisation/opt_structure_probleme_a_resoudre.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <vector>
#include <string>
#include "opt_constants.h"
#include "ortools/linear_solver/linear_solver.h"

/*--------------------------------------------------------------------------------------*/

Expand All @@ -40,7 +41,7 @@ typedef struct
} PROBLEMES_SIMPLEXE;

/* Le probleme a resoudre */
typedef struct
struct PROBLEME_ANTARES_A_RESOUDRE
{
/* La matrice des contraintes */
int NombreDeVariables;
Expand Down Expand Up @@ -111,10 +112,14 @@ typedef struct
std::vector<std::string> NomDesVariables;
std::vector<std::string> NomDesContraintes;

std::vector<bool> VariablesEntieres; // true = int, false = continuous

private:
using BasisStatus = operations_research::MPSolver::BasisStatus;
public:
std::vector<int> StatutDesVariables;
std::vector<int> StatutDesContraintes;
std::vector<BasisStatus> StatutDesVariables;
std::vector<BasisStatus> StatutDesContraintes;

} PROBLEME_ANTARES_A_RESOUDRE;
};

#endif /* __SOLVER_OPTIMISATION_STRUCTURE_PROBLEME_A_RESOUDRE_H__ */
37 changes: 37 additions & 0 deletions src/solver/utils/include/antares/solver/utils/named_problem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "spx_definition_arguments.h"
#include "spx_fonctions.h"

#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include "ortools/linear_solver/linear_solver.h"

namespace Antares
{
namespace Optimization
{
struct PROBLEME_SIMPLEXE_NOMME : public PROBLEME_SIMPLEXE
{
private:
using BasisStatus = operations_research::MPSolver::BasisStatus;
public:
PROBLEME_SIMPLEXE_NOMME(std::vector<std::string>& NomDesVariables,
std::vector<std::string>& NomDesContraintes,
std::vector<BasisStatus>& StatutDesVariables,
std::vector<BasisStatus>& StatutDesContraintes);

std::vector<std::string>& NomDesVariables;
std::vector<std::string>& NomDesContraintes;

std::vector<BasisStatus>& StatutDesVariables;
std::vector<BasisStatus>& StatutDesContraintes;

bool isMIP() const;
bool basisExists() const;

};
} // namespace Optimization
} // namespace Antares
8 changes: 5 additions & 3 deletions src/solver/utils/named_problem.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "named_problem.h"
#include "antares/solver/utils/named_problem.h"

namespace Antares
{
namespace Optimization
{
using BasisStatus = operations_research::MPSolver::BasisStus;

PROBLEME_SIMPLEXE_NOMME::PROBLEME_SIMPLEXE_NOMME(const std::vector<std::string>& NomDesVariables,
const std::vector<std::string>& NomDesContraintes,
std::vector<int>& StatutDesVariables,
std::vector<int>& StatutDesContraintes) :
std::vector<BasisStatus>& StatutDesVariables,
std::vector<BasisStatus>& StatutDesContraintes) :
NomDesVariables(NomDesVariables),
NomDesContraintes(NomDesContraintes),
StatutDesVariables(StatutDesVariables),
Expand Down
21 changes: 17 additions & 4 deletions src/solver/utils/ortools_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,17 @@ MPSolver* ORTOOLS_ConvertIfNeeded(const Antares::Optimization::PROBLEME_SIMPLEXE
}
}

template<class SourceT>
static void transferBasis(std::vector<operations_research::MPSolver::BasisStatus>& destination,
const SourceT& source)
{
destination.resize(source.size());
for (size_t idx = 0; idx < source.size(); idx++)
{
destination[idx] = source[idx]->basis_status();
}
}

MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probleme,
MPSolver* solver,
bool keepBasis)
Expand All @@ -309,7 +320,8 @@ MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probl
// Provide an initial simplex basis, if any
if (warmStart && Probleme->basisExists())
{
solver->SetStartingLpBasisInt(Probleme->StatutDesVariables, Probleme->StatutDesContraintes);
solver->SetStartingLpBasis(Probleme->StatutDesVariables,
Probleme->StatutDesContraintes);
}

if (solveAndManageStatus(solver, Probleme->ExistenceDUneSolution, params))
Expand All @@ -318,8 +330,8 @@ MPSolver* ORTOOLS_Simplexe(Antares::Optimization::PROBLEME_SIMPLEXE_NOMME* Probl
// Save the final simplex basis for next resolutions
if (warmStart && keepBasis)
{
solver->GetFinalLpBasisInt(Probleme->StatutDesVariables,
Probleme->StatutDesContraintes);
transferBasis(Probleme->StatutDesVariables, solver->variables());
transferBasis(Probleme->StatutDesContraintes, solver->constraints());
}
}

Expand Down Expand Up @@ -370,7 +382,8 @@ const std::map<std::string, struct OrtoolsUtils::SolverNames> OrtoolsUtils::solv
= {{"xpress", {"xpress_lp", "xpress"}},
{"sirius", {"sirius_lp", "sirius"}},
{"coin", {"clp", "cbc"}},
{"glpk", {"glpk_lp", "glpk"}}};
{"glpk", {"glpk_lp", "glpk"}},
{"scip", {"scip", "scip"}}};

std::list<std::string> getAvailableOrtoolsSolverName()
{
Expand Down

0 comments on commit e9b03b4

Please sign in to comment.