Skip to content

Commit

Permalink
Draft: Add SCIP driver (#205)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jurgen-lentz authored Apr 27, 2023
1 parent bdec071 commit 5ecade4
Show file tree
Hide file tree
Showing 22 changed files with 2,122 additions and 11 deletions.
5 changes: 4 additions & 1 deletion solvers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function(add_ampl_solver name)

if (TARGET ${module}-library)
get_target_property(TRG_PROP_IMPRT_LOC ${module}-library IMPORTED_LOCATION)
if (NOT libraries OR TRG_PROP_IMPRT_LOC)
if (NOT libraries)#OR TRG_PROP_IMPRT_LOC)
set(libraries ${module}-library)
endif()
endif ()
Expand Down Expand Up @@ -245,6 +245,9 @@ 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
LIBRARIES ${SCIP_LIBS} ${CMAKE_DL_LIBS})

add_ampl_backend(highsmp DLL_RUNTIME SHARED_LIB MODULE HIGHS
LIBRARIES ${HIGHS_LIBS} ${CMAKE_DL_LIBS})

Expand Down
5 changes: 5 additions & 0 deletions solvers/scip/CHANGES.scip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Summary of recent updates to SCIP for AMPL
==========================================

## Unreleased
- First release of mock driver
34 changes: 34 additions & 0 deletions solvers/scip/README.scip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
SCIP driver for AMPL
====================

SCIP (Solving Constraint Integer Programs) is currently one of the
fastest non-commercial solvers for mixed integer programming (MIP)
and mixed integer nonlinear programming (MINLP). It is also a framework
for constraint integer programming and branch-cut-and-price.
More information can be found in https://scipopt.org/#scipoptsuite.

Normally SCIP is invoked by AMPL's solve command, which gives the
invocation

scip stub -AMPL

in which stub.nl is an AMPL generic output file (possibly written
by "ampl -obstub" or "ampl -ogstub"). After solving the problem,
scip writes a stub.sol file for use by AMPL's solve and solution
commands. When you run ampl, this all happens automatically if you
give the AMPL commands

option solver scip;
solve;

You can control scip either by setting the environment variable
scip_options appropriately (either by using ampl's option command,
or by using the shell's set and export commands before you invoke ampl),
or by passing the options on the command line:

scip stub [-AMPL] option1=value option2=value ...

You can put one or more (white-space separated) phrases in $scip_options.
To see the possibilities, invoke

scip -=
9 changes: 9 additions & 0 deletions solvers/scip/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "mp/backend-app.h"

/// Declare a backend factory
std::unique_ptr<mp::BasicBackend> CreateScipBackend();

extern "C" int main1(int, char **argv) {
return
mp::RunBackendApp(argv, CreateScipBackend);
}
8 changes: 8 additions & 0 deletions solvers/scip/model-mgr-with-std-pb.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Generate ModelManagerWithPB<mp::Problem>
*
* Having a separate .cc should improve compilation speed
*/

#include "mp/model-mgr-with-std-pb.hpp"

33 changes: 33 additions & 0 deletions solvers/scip/scip-ampls-c-api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef SCIPAMPLSCAPI_H
#define SCIPAMPLSCAPI_H
/*
* C API for MP/Scip
*/

//#include "scip.h"

#include "mp/ampls-c-api.h"

/*
* Below are Scip-specific AMPLS API functions.
* They complement the 'public' AMPLS API defined in ampls-c-api.h.
*/

/// Initialize AMPLS scip.

/// @param slv_opt: a string of solver options
/// (normally provided in the <solver>_options string).
/// Can be NULL.
/// @return pointer to struct AMPLS_MP_Solver to be populated.
void* AMPLSOpenScip(const char* slv_opt, CCallbacks cb);

/// Shut down solver instance
void AMPLSCloseScip(AMPLS_MP_Solver* slv);

/// Extract the Scip model handle
void* GetScipmodel(AMPLS_MP_Solver* slv);


#endif // SCIPAMPLSCAPI_H


30 changes: 30 additions & 0 deletions solvers/scip/scip-lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "scip/scip-ampls-c-api.h"

#ifdef _WIN32
#define APIEXPORT __declspec(dllexport)
#else
#define APIEXPORT __attribute__((visibility("default")))
#endif


APIEXPORT void* AMPLloadmodel(int argc, char** argv, CCallbacks cb) {
const char* nl_filename = argv[1];
const char *slv_opt= argv[2];
AMPLS_MP_Solver* slv;
slv = AMPLSOpenScip(slv_opt, cb);
if (!slv)
return NULL;
AMPLSLoadNLModel(slv, nl_filename);
return slv;
}
APIEXPORT void* AMPLgetScipmodel(void* slv) {
return GetScipmodel(slv);
}

APIEXPORT void AMPLwritesolution(AMPLS_MP_Solver* slv, const char* solFileName) {
AMPLSReportResults(slv, solFileName);
}

APIEXPORT void AMPLclosesolver(AMPLS_MP_Solver* slv) {
AMPLSCloseScip(slv);
}
18 changes: 18 additions & 0 deletions solvers/scip/scip-modelapi-connect.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "mp/flat/redef/MIP/converter_mip.h"
#include "mp/flat/model_api_connect.h"

#include "scipmodelapi.h"


namespace mp {

/// Defining the function in ...-modelapi-connect.cc
/// for recompilation speed
std::unique_ptr<BasicModelManager>
CreateScipModelMgr(ScipCommon& cc, Env& e,
pre::BasicValuePresolver*& pPre) {
return CreateModelMgrWithFlatConverter<
ScipModelAPI, MIPFlatConverter >(cc, e, pPre);
}

} // namespace mp
Loading

0 comments on commit 5ecade4

Please sign in to comment.