From 52500d3ab3b38084fac0562365ce2e4b5942b478 Mon Sep 17 00:00:00 2001 From: Jurgen Lentz <42538773+jurgen-lentz@users.noreply.github.com> Date: Wed, 3 May 2023 07:19:20 +0200 Subject: [PATCH] change scip to scipmp (#206) * init scip solver driver * minimal driver * add basic functionalities * fix primal solution * change getPROBDATA to cons * change getPROBDATA v2 * fix test * add indicator constraint LinLE * add indicator constraint LinGE * add indicator constraint LinEQ * change indicator constraint to recommended * add or, and constraint * handle char and bool param * add more options * improve readme and changes * disable sepa of indicator cons * improve memory handling * add linearHelper method * add indicator helper method * add quadratic helper method * add pool solution * add abs, sin and cosfunctions * add exp and log function * add pow function * add more options and concurrent mode * improve tests * add more options * add last options * adapt mipstart header * Update CHANGES.scip.md * add option to x-multimip1 * change cmake * add variable names * change scip to scipmp * change cmake * add docu * add scipmp test * delete scip --- doc/rst/intro.rst | 12 ++++++++++++ solvers/CMakeLists.txt | 2 +- .../CHANGES.scip.md => scipmp/CHANGES.scipmp.md} | 0 .../README.scip.txt => scipmp/README.scipmp.txt} | 0 solvers/{scip => scipmp}/main.cc | 2 +- solvers/{scip => scipmp}/model-mgr-with-std-pb.cc | 0 .../scipmp-ampls-c-api.h} | 0 solvers/{scip/scip-lib.c => scipmp/scipmp-lib.c} | 2 +- .../scipmp-modelapi-connect.cc} | 2 +- .../{scip/scipbackend.cc => scipmp/scipmpbackend.cc} | 4 ++-- .../{scip/scipbackend.h => scipmp/scipmpbackend.h} | 2 +- .../{scip/scipcommon.cc => scipmp/scipmpcommon.cc} | 2 +- solvers/{scip/scipcommon.h => scipmp/scipmpcommon.h} | 0 .../scipmodelapi.cc => scipmp/scipmpmodelapi.cc} | 8 +++++--- .../{scip/scipmodelapi.h => scipmp/scipmpmodelapi.h} | 2 +- test/end2end/scripts/python/SolverCollection.py | 1 + 16 files changed, 27 insertions(+), 12 deletions(-) rename solvers/{scip/CHANGES.scip.md => scipmp/CHANGES.scipmp.md} (100%) rename solvers/{scip/README.scip.txt => scipmp/README.scipmp.txt} (100%) rename solvers/{scip => scipmp}/main.cc (81%) rename solvers/{scip => scipmp}/model-mgr-with-std-pb.cc (100%) rename solvers/{scip/scip-ampls-c-api.h => scipmp/scipmp-ampls-c-api.h} (100%) rename solvers/{scip/scip-lib.c => scipmp/scipmp-lib.c} (94%) rename solvers/{scip/scip-modelapi-connect.cc => scipmp/scipmp-modelapi-connect.cc} (93%) rename solvers/{scip/scipbackend.cc => scipmp/scipmpbackend.cc} (99%) rename solvers/{scip/scipbackend.h => scipmp/scipmpbackend.h} (99%) rename solvers/{scip/scipcommon.cc => scipmp/scipmpcommon.cc} (99%) rename solvers/{scip/scipcommon.h => scipmp/scipmpcommon.h} (100%) rename solvers/{scip/scipmodelapi.cc => scipmp/scipmpmodelapi.cc} (98%) rename solvers/{scip/scipmodelapi.h => scipmp/scipmpmodelapi.h} (99%) diff --git a/doc/rst/intro.rst b/doc/rst/intro.rst index b4265030d..2f3c07bc8 100644 --- a/doc/rst/intro.rst +++ b/doc/rst/intro.rst @@ -113,6 +113,18 @@ does not have automatic dependency detection), you can use the following:: -DCOPT_LIBS=d:/copt/libs/win64/copt.lib -DCOPT_INCLUDE_DIRS=d:/copt/include +To build the solver *scipmp* statically (on Linux or MacOS), you need to make sure +to add all its dependencies. The following cmake command builds *scipmp* assuming +that it is installed with the LP solver SoPlex, the arithmetic library GMP and +the library bliss for symmetry detection (*SCIP* and its dependencies are all +installed in the standard location):: + + cmake .. -DBUILD=scipmp + -DSCIP_LIBS="/usr/local/lib/libscip.a;/usr/local/lib/libsoplex.a;/usr/local/lib/libgmp.a;/usr/local/lib/libbliss.a" + -DSCIP_INCLUDE_DIRS=/usr/local/include + +Note: Any other dependency can be used in the same way. + Similarly, for *ortoolsmp* (on MacOS) assuming *ortools* is installed in the standard location:: diff --git a/solvers/CMakeLists.txt b/solvers/CMakeLists.txt index a0cc14b0d..7824ec1f4 100644 --- a/solvers/CMakeLists.txt +++ b/solvers/CMakeLists.txt @@ -246,7 +246,7 @@ add_ampl_backend(cbcmp DLL_RUNTIME SHARED_LIB MODULE CBC LIBRARIES ${CBC_LIBS} ${CMAKE_DL_LIBS}) -add_ampl_backend(scip DLL_RUNTIME SHARED_LIB MODULE SCIP +add_ampl_backend(scipmp DLL_RUNTIME SHARED_LIB MODULE SCIP LIBRARIES ${SCIP_LIBS} ${CMAKE_DL_LIBS}) add_ampl_backend(highsmp DLL_RUNTIME SHARED_LIB MODULE HIGHS diff --git a/solvers/scip/CHANGES.scip.md b/solvers/scipmp/CHANGES.scipmp.md similarity index 100% rename from solvers/scip/CHANGES.scip.md rename to solvers/scipmp/CHANGES.scipmp.md diff --git a/solvers/scip/README.scip.txt b/solvers/scipmp/README.scipmp.txt similarity index 100% rename from solvers/scip/README.scip.txt rename to solvers/scipmp/README.scipmp.txt diff --git a/solvers/scip/main.cc b/solvers/scipmp/main.cc similarity index 81% rename from solvers/scip/main.cc rename to solvers/scipmp/main.cc index b558be280..33eec30dc 100644 --- a/solvers/scip/main.cc +++ b/solvers/scipmp/main.cc @@ -3,7 +3,7 @@ /// Declare a backend factory std::unique_ptr CreateScipBackend(); -extern "C" int main1(int, char **argv) { +int main(int, char **argv) { return mp::RunBackendApp(argv, CreateScipBackend); } diff --git a/solvers/scip/model-mgr-with-std-pb.cc b/solvers/scipmp/model-mgr-with-std-pb.cc similarity index 100% rename from solvers/scip/model-mgr-with-std-pb.cc rename to solvers/scipmp/model-mgr-with-std-pb.cc diff --git a/solvers/scip/scip-ampls-c-api.h b/solvers/scipmp/scipmp-ampls-c-api.h similarity index 100% rename from solvers/scip/scip-ampls-c-api.h rename to solvers/scipmp/scipmp-ampls-c-api.h diff --git a/solvers/scip/scip-lib.c b/solvers/scipmp/scipmp-lib.c similarity index 94% rename from solvers/scip/scip-lib.c rename to solvers/scipmp/scipmp-lib.c index 20736312f..59f64c36f 100644 --- a/solvers/scip/scip-lib.c +++ b/solvers/scipmp/scipmp-lib.c @@ -1,4 +1,4 @@ -#include "scip/scip-ampls-c-api.h" +#include "scipmp/scipmp-ampls-c-api.h" #ifdef _WIN32 #define APIEXPORT __declspec(dllexport) diff --git a/solvers/scip/scip-modelapi-connect.cc b/solvers/scipmp/scipmp-modelapi-connect.cc similarity index 93% rename from solvers/scip/scip-modelapi-connect.cc rename to solvers/scipmp/scipmp-modelapi-connect.cc index 77641e7a5..7445e9b4a 100644 --- a/solvers/scip/scip-modelapi-connect.cc +++ b/solvers/scipmp/scipmp-modelapi-connect.cc @@ -1,7 +1,7 @@ #include "mp/flat/redef/MIP/converter_mip.h" #include "mp/flat/model_api_connect.h" -#include "scipmodelapi.h" +#include "scipmpmodelapi.h" namespace mp { diff --git a/solvers/scip/scipbackend.cc b/solvers/scipmp/scipmpbackend.cc similarity index 99% rename from solvers/scip/scipbackend.cc rename to solvers/scipmp/scipmpbackend.cc index 3f0315340..6b7fe4caf 100644 --- a/solvers/scip/scipbackend.cc +++ b/solvers/scipmp/scipmpbackend.cc @@ -4,10 +4,10 @@ #include "mp/env.h" #include "mp/flat/model_api_base.h" -#include "scipbackend.h" +#include "scipmpbackend.h" extern "C" { - #include "scip-ampls-c-api.h" // Scip AMPLS C API + #include "scipmp-ampls-c-api.h" // Scip AMPLS C API } #include "mp/ampls-cpp-api.h" diff --git a/solvers/scip/scipbackend.h b/solvers/scipmp/scipmpbackend.h similarity index 99% rename from solvers/scip/scipbackend.h rename to solvers/scipmp/scipmpbackend.h index bedcf3599..e1f7eafa8 100644 --- a/solvers/scip/scipbackend.h +++ b/solvers/scipmp/scipmpbackend.h @@ -5,7 +5,7 @@ #include "mp/backend-mip.h" #include "mp/flat/backend_flat.h" -#include "scipcommon.h" +#include "scipmpcommon.h" namespace mp { diff --git a/solvers/scip/scipcommon.cc b/solvers/scipmp/scipmpcommon.cc similarity index 99% rename from solvers/scip/scipcommon.cc rename to solvers/scipmp/scipmpcommon.cc index fa7a97f18..cd4a862ad 100644 --- a/solvers/scip/scipcommon.cc +++ b/solvers/scipmp/scipmpcommon.cc @@ -1,5 +1,5 @@ #include "mp/format.h" -#include "scipcommon.h" +#include "scipmpcommon.h" static SCIP_DECL_PROBDELORIG(probdataDelOrigNl) diff --git a/solvers/scip/scipcommon.h b/solvers/scipmp/scipmpcommon.h similarity index 100% rename from solvers/scip/scipcommon.h rename to solvers/scipmp/scipmpcommon.h diff --git a/solvers/scip/scipmodelapi.cc b/solvers/scipmp/scipmpmodelapi.cc similarity index 98% rename from solvers/scip/scipmodelapi.cc rename to solvers/scipmp/scipmpmodelapi.cc index 2cf118efb..67596f0b6 100644 --- a/solvers/scip/scipmodelapi.cc +++ b/solvers/scipmp/scipmpmodelapi.cc @@ -1,4 +1,4 @@ -#include "scipmodelapi.h" +#include "scipmpmodelapi.h" namespace mp { @@ -28,8 +28,10 @@ void ScipModelAPI::AddVariables(const VarArrayDef& v) { vartype = SCIP_VARTYPE_INTEGER; else vartype = SCIP_VARTYPE_CONTINUOUS; - //const char* name = v.pnames()[i]; - SCIP_CCALL( SCIPcreateVarBasic(getSCIP(), &var, NULL, lb, ub, objcoef, vartype) ); + const char* name = NULL; + if (v.pnames() != NULL) + const char* name = v.pnames()[i]; + SCIP_CCALL( SCIPcreateVarBasic(getSCIP(), &var, name, lb, ub, objcoef, vartype) ); SCIP_CCALL( SCIPaddVar(getSCIP(), var) ); getPROBDATA()->vars[i] = var; } diff --git a/solvers/scip/scipmodelapi.h b/solvers/scipmp/scipmpmodelapi.h similarity index 99% rename from solvers/scip/scipmodelapi.h rename to solvers/scipmp/scipmpmodelapi.h index 3ae4293d6..c8a33dc2e 100644 --- a/solvers/scip/scipmodelapi.h +++ b/solvers/scipmp/scipmpmodelapi.h @@ -4,7 +4,7 @@ #include #include "mp/env.h" -#include "scipcommon.h" +#include "scipmpcommon.h" #include "mp/flat/model_api_base.h" #include "mp/flat/constr_std.h" diff --git a/test/end2end/scripts/python/SolverCollection.py b/test/end2end/scripts/python/SolverCollection.py index cda4dfbe0..7302b12e6 100644 --- a/test/end2end/scripts/python/SolverCollection.py +++ b/test/end2end/scripts/python/SolverCollection.py @@ -42,6 +42,7 @@ def addStdSolvers(solvers: SolverCollection, binPath=""): solvers.addSolver(Solver.MosekSolver(path.join(binPath,"mosek"))) solvers.addSolver(Solver.CbcMPSolver(path.join(binPath, "cbc"))) solvers.addSolver(Solver.SCIPSolver(path.join(binPath, "scip"))) + solvers.addSolver(Solver.SCIPSolver(path.join(binPath, "scipmp"))) solvers.addSolver(Solver.CPLEXODHSolver(path.join(binPath, "cplexodh"))) solvers.addSolver(Solver.GUROBIODHSolver(path.join(binPath, "gurobiodh")))