Skip to content

Commit

Permalink
Add stub MP2NL #237
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Sep 5, 2024
1 parent 82ff3cf commit 507b489
Show file tree
Hide file tree
Showing 17 changed files with 1,256 additions and 11 deletions.
3 changes: 3 additions & 0 deletions solvers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ add_ampl_backend(cplex DLL_RUNTIME SHARED_LIB MODULE CPLEX
add_ampl_backend(xpress DLL_RUNTIME SHARED_LIB MODULE XPRESS
LIBRARIES ${xpress_LIBS} ${CMAKE_DL_LIBS})

add_ampl_backend(mp2nl DLL_RUNTIME SHARED_LIB
LIBRARIES nlw2 ${CMAKE_DL_LIBS})


set(GRBSRC gurobibackend.cc gurobibackend.h
gurobicommon.cc gurobicommon.h
Expand Down
6 changes: 6 additions & 0 deletions solvers/mp2nl/CHANGES.mp2nl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Summary of recent updates to SCIP for AMPL
==========================================


## unreleased
- First release of the MP2NL driver
31 changes: 31 additions & 0 deletions solvers/mp2nl/README.mp2nl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
MP2NL driver for AMPL
====================

MP2NL is a metadriver to run existing NL solvers through
the MP library. See documentation at https://mp.ampl.com/.

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

mp2nl stub -AMPL

in which stub.nl is an AMPL generic output file (possibly written
by "ampl -obstub" or "ampl -ogstub"). After solving the problem,
mp2nl 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 mp2nl;
solve;

You can control mp2nl either by setting the environment variable
mp2nl_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:

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

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

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

std::unique_ptr<mp::BasicBackend> CreateMP2NLBackend();

#ifndef SOLVER_LICNAME
int main(int, char** argv) {
return mp::RunBackendApp(argv, CreateMP2NLBackend);
}
#endif

extern "C" int main2(int, char** argv, CCallbacks cb) {
return mp::RunBackendApp(argv, CreateMP2NLBackend, cb);
}
8 changes: 8 additions & 0 deletions solvers/mp2nl/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"

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

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


DECLARE_SOLVER_API_FUNCTIONS(MP2NL)


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

AMPLS_C_EXPORT AMPLS_MP_Solver* AMPLSOpen_scip(int argc, char** argv)
{
CCallbacks cb = { NULL };
return Open_MP2NL(cb);
}
18 changes: 18 additions & 0 deletions solvers/mp2nl/mp2nl-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 "mp2nlmodelapi.h"


namespace mp {

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

} // namespace mp
Loading

0 comments on commit 507b489

Please sign in to comment.