-
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.
- Loading branch information
Showing
9 changed files
with
169 additions
and
28 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,36 @@ | ||
/** | ||
* C API example using NLWriter2 and SOLReader2 | ||
* to write NL file, execute solver, and read SOL file. | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "api/c/nl-feeder2.h" | ||
|
||
#include "nlsol_ex_c_model.h" | ||
|
||
int main(int argc, const char* const* argv) { | ||
if (argc<2) { | ||
printf("%s\n", | ||
"AMPL NL writer C API example.\n" | ||
"Usage:\n" | ||
" <this_exe> <solver> [\"<solver_options>\" [binary/text [<stub>]]],\n\n" | ||
"where <solver> is ipopt, gurobi, minos, ...;\n" | ||
"binary/text is the NL format (default: binary.)\n" | ||
"Examples:\n" | ||
" <this_exe> highs \"\" text /tmp/stub\n" | ||
" <this_exe> gurobi \"mip:return_gap=1\""); | ||
exit(0); | ||
} | ||
|
||
const char* solver = (argc>1) ? argv[1] : "highs"; | ||
const char* sopts = (argc>2) ? argv[2] : ""; | ||
int binary = (argc<=3) || strcmp("text", argv[3]); | ||
const char* stub = (argc>4) ? argv[4] : "stub"; | ||
|
||
|
||
return 0; | ||
} |
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,41 @@ | ||
#ifndef NLSOL_EX_C_MODEL_H | ||
#define NLSOL_EX_C_MODEL_H | ||
|
||
// #include "api/c/nl-header.h" | ||
//#include "mp/nl-opcodes.h" | ||
|
||
/** | ||
* A linear model for NL Writer C API example. | ||
* Illustrates NL variable order (continuous -> integer), | ||
* linear constraints. | ||
* | ||
## In AMPL, set option presolve 0; to reproduce | ||
## | ||
## To write NL file and name files in AMPL, use commands | ||
## ampl: option nl_comments 1; | ||
## ampl: option auxfiles rc; | ||
## ampl: write gmodel; | ||
var x >=0, integer; | ||
var y >=-17, <=504; | ||
maximize TotalSum: | ||
x + 13*y; | ||
subj to C2: | ||
3700*x + 0.6*y <= 3e4; | ||
subj to C3: | ||
22*x + 14536*y <= 3e5; | ||
## Initial guess | ||
let x := 1.5; | ||
let y := 0.11; | ||
## A suffix | ||
suffix zork; | ||
let C2.zork := 5; | ||
* | ||
*/ | ||
|
||
|
||
#endif // NLSOL_EX_C_MODEL_H |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,18 @@ | ||
/** | ||
* C API: extern "C" wrapper for the NLFeeder2 interface | ||
* | ||
*/ | ||
|
||
#ifndef NLFEEDER2_H | ||
#define NLFEEDER2_H | ||
|
||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#endif // NLFEEDER2_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,6 @@ | ||
/** | ||
* C API implementation | ||
* | ||
*/ | ||
|
||
#include "api/c/nl-feeder2.h" |