Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions solvers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ function(add_ampl_solver name)
endif()
add_executable(${exename} ${dir}main.cc)
target_link_libraries(${exename} PRIVATE ${static_lib})
if(add_ampl_solver_ADDITIONAL_DEPS)
add_dependencies(${exename} ${add_ampl_solver_ADDITIONAL_DEPS})
endif()
install(TARGETS ${exename} DESTINATION bin)
if(add_ampl_solver_ADDITIONAL_DEPS)
add_dependencies(${exename} ${add_ampl_solver_ADDITIONAL_DEPS})
Expand Down Expand Up @@ -255,11 +258,17 @@ add_ampl_backend(cbcmp DLL_RUNTIME SHARED_LIB MODULE CBC
LIBRARIES ${CBC_LIBS} ${CMAKE_DL_LIBS})


add_ampl_backend(gcgmp DLL_RUNTIME SHARED_LIB MODULE GCG
LIBRARIES ${GCG_LIBS} ${CMAKE_DL_LIBS}
ADDITIONAL_DEPS gcg)

add_ampl_backend(scipmp DLL_RUNTIME SHARED_LIB MODULE SCIP
LIBRARIES ${SCIP_LIBS} ${CMAKE_DL_LIBS})
LIBRARIES ${SCIP_LIBS} ${CMAKE_DL_LIBS}
ADDITIONAL_DEPS scip)

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

add_ampl_backend(ortoolsmp DLL_RUNTIME SHARED_LIB MODULE ortoolsmp
LIBRARIES ${ortoolsmp_LIBS} ${CMAKE_DL_LIBS})
Expand Down
5 changes: 5 additions & 0 deletions solvers/gcgmp/CHANGES.gcgmp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Summary of recent updates to GCG for AMPL
=============================================

## 20220420
- First release of mock driver
5 changes: 5 additions & 0 deletions solvers/gcgmp/README.gcgmp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
gcg tutorial driver
=======================

The solver "gcg" is a mock solver, provided as an example - and as a template -
on how to getting started using mp with FlatAPI to develop an mp-based solver interface.
33 changes: 33 additions & 0 deletions solvers/gcgmp/gcgmp-ampls-c-api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef GCGAMPLSCAPI_H
#define GCGAMPLSCAPI_H
/*
* C API for MP/Gcg
*/

//#include "gcg.h"

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

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

/// Initialize AMPLS gcg.

/// @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* AMPLSOpenGcg(const char* slv_opt, CCallbacks cb);

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

/// Extract the Gcg model handle
void* GetGcgmodel(AMPLS_MP_Solver* slv);


#endif // GCGAMPLSCAPI_H


30 changes: 30 additions & 0 deletions solvers/gcgmp/gcgmp-lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "gcgmp/gcgmp-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 = AMPLSOpenGcg(slv_opt, cb);
if (!slv)
return NULL;
AMPLSLoadNLModel(slv, nl_filename);
return slv;
}
APIEXPORT void* AMPLgetGcgmodel(void* slv) {
return GetGcgmodel(slv);
}

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

APIEXPORT void AMPLclosesolver(AMPLS_MP_Solver* slv) {
AMPLSCloseGcg(slv);
}
18 changes: 18 additions & 0 deletions solvers/gcgmp/gcgmp-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 "gcgmpmodelapi.h"


namespace mp {

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

} // namespace mp
Loading