Skip to content

Commit

Permalink
Take into account breaking change in OR-Tools's API, enable SCIP & GL…
Browse files Browse the repository at this point in the history
…PK solvers, bump OR-Tools (#1825)

- `SetStartingLpBasisInt` and `GetFinalBasisInt` have been removed from
recent versions, due to redundancy with their non-Int counterparts.
- Bump OR-Tools v9.5-rte2.0 -> v9.5-rte3.0 
- Add SCIP solver in lookup list (works better for MILP) and GLPK
  • Loading branch information
flomnes authored Jan 8, 2024
1 parent f4321a2 commit d8b2407
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/centos7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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
5 changes: 4 additions & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ jobs:
env:
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 # 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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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: 5 additions & 1 deletion .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ 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"
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 @@ -269,7 +269,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
8 changes: 6 additions & 2 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 Down Expand Up @@ -117,8 +118,11 @@ struct PROBLEME_ANTARES_A_RESOUDRE

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

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

};

Expand Down
11 changes: 7 additions & 4 deletions src/solver/utils/include/antares/solver/utils/named_problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
#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(const std::vector<std::string>& NomDesVariables,
const std::vector<std::string>& NomDesContraintes,
const std::vector<bool>& VariablesEntieres,
std::vector<int>& StatutDesVariables,
std::vector<int>& StatutDesContraintes,
std::vector<BasisStatus>& StatutDesVariables,
std::vector<BasisStatus>& StatutDesContraintes,
bool UseNamedProblems,
bool SolverLogs);

Expand All @@ -30,8 +33,8 @@ struct PROBLEME_SIMPLEXE_NOMME : public PROBLEME_SIMPLEXE
bool solverLogs_;

public:
std::vector<int>& StatutDesVariables;
std::vector<int>& StatutDesContraintes;
std::vector<BasisStatus>& StatutDesVariables;
std::vector<BasisStatus>& StatutDesContraintes;
const std::vector<bool>& VariablesEntieres;

bool isMIP() const;
Expand Down
6 changes: 4 additions & 2 deletions src/solver/utils/named_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
namespace Antares::Optimization
{

using BasisStatus = operations_research::MPSolver::BasisStatus;

PROBLEME_SIMPLEXE_NOMME::PROBLEME_SIMPLEXE_NOMME(const std::vector<std::string>& NomDesVariables,
const std::vector<std::string>& NomDesContraintes,
const std::vector<bool>& VariablesEntieres,
std::vector<int>& StatutDesVariables,
std::vector<int>& StatutDesContraintes,
std::vector<BasisStatus>& StatutDesVariables,
std::vector<BasisStatus>& StatutDesContraintes,
bool UseNamedProblems,
bool SolverLogs) : PROBLEME_SIMPLEXE(),

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 @@ -288,6 +288,17 @@ MPSolver* ORTOOLS_ConvertIfNeeded(const std::string& solverName,
}
}

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 @@ -298,7 +309,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 @@ -307,8 +319,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 @@ -373,7 +385,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 d8b2407

Please sign in to comment.