Skip to content

Commit

Permalink
Merge pull request #178 from ampl/ortools
Browse files Browse the repository at this point in the history
Merge preliminary ortools driver
  • Loading branch information
mapgccv authored May 30, 2022
2 parents 6718593 + 17d1c1b commit 50e83c1
Show file tree
Hide file tree
Showing 13 changed files with 808 additions and 0 deletions.
4 changes: 4 additions & 0 deletions solvers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ add_ampl_backend(copt DLL_RUNTIME SHARED_LIB MODULE COPT LIBRARIES ${COPT_LIBS}
add_ampl_backend(highsdirect DLL_RUNTIME SHARED_LIB
MODULE HIGHS LIBRARIES ${HIGHS_LIBS} ${CMAKE_DL_LIBS})


add_ampl_backend(ortoolsmp DLL_RUNTIME SHARED_LIB
MODULE ortoolsmp LIBRARIES ${ortoolsmp_LIBS} ${CMAKE_DL_LIBS})

## TODO Cannot use 'add_ampl_backend' because of the -direct name suffix
add_ampl_solver(cplexdirect DLL_RUNTIME SHARED_LIB MODULE CPLEX
cplex-ampls-c-api.h
Expand Down
5 changes: 5 additions & 0 deletions solvers/ortoolsmp/CHANGES.ortoolsmp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Summary of recent updates to ORTOOLS for AMPL
=============================================

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

The solver "ortools" 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.
10 changes: 10 additions & 0 deletions solvers/ortoolsmp/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "mp/backend-app.h"
#include "ortoolsmpbackend.h"

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

int main(int, char** argv) {
return
mp::RunBackendApp(argv, CreateOrtoolsBackend);
}
8 changes: 8 additions & 0 deletions solvers/ortoolsmp/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"

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

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

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

/// Initialize AMPLS ortools.
/// @param slv: pointer to struct AMPLS_MP_Solver to be populated.
/// @param slv_opt: a string of solver options
/// (normally provided in the <solver>_options string).
/// Can be NULL.
/// @return 0 on success, otherwise see slv->warnings_and_or_errors_
int AMPLSOpenOrtools(AMPLS_MP_Solver* slv, const char* slv_opt);

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

/// Extract the Ortools model handle
void* GetOrtoolsmodel(AMPLS_MP_Solver* slv);


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

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

APIEXPORT void* AMPLloadmodel(int argc, char** argv, void* slvout) {
const char* nl_filename = argv[1];
const char *slv_opt= argv[2];
AMPLS_MP_Solver slv;
int ret = -1;
ret = AMPLSOpenOrtools(&slv, slv_opt);
ret = AMPLSLoadNLModel(&slv, nl_filename);
void* mdl = GetOrtoolsmodel(&slv);
slvout = &slv;
return mdl;
}

APIEXPORT void AMPLwritesolution(AMPLS_MP_Solver* slv) {
AMPLSReportResults(&slv);
}

APIEXPORT void AMPLclosesolver(AMPLS_MP_Solver* slv) {
AMPLSCloseOrtools(&slv);
}
Loading

0 comments on commit 50e83c1

Please sign in to comment.