-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from ampl/ortools
Merge preliminary ortools driver
- Loading branch information
Showing
13 changed files
with
808 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.