-
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.
Templates, inline C++
- Loading branch information
Showing
23 changed files
with
11,539 additions
and
10 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
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
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,32 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(NLWriter2) | ||
|
||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
|
||
set(NLW2_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
set(NLW2_LIB_FILES | ||
${NLW2_DIR}/src/nl-writer2.cc | ||
${NLW2_DIR}/src/nl-utils2.cc | ||
${NLW2_DIR}/src/dtoa.c) | ||
|
||
# Create library | ||
set(NLW2_LIB_NAME "nlw2") | ||
add_library(${NLW2_LIB_NAME} STATIC ${NLW2_LIB_FILES}) | ||
target_include_directories( | ||
${NLW2_LIB_NAME} PUBLIC ${NLW2_DIR}/include) | ||
|
||
if (MSVC) ## Set the same as for your parent project | ||
## target_compile_options( | ||
## ${NLW2_LIB_NAME} PRIVATE ${AMPL_MSVC_COMPILE_OPTIONS}) | ||
endif() | ||
|
||
# NLW2 example | ||
add_executable(nl-writer-example | ||
${NLW2_DIR}/examples/nlsol_ex.cc) | ||
target_include_directories(nl-writer-example PUBLIC | ||
${NLW2_DIR}/include) | ||
target_link_libraries(nl-writer-example ${NLW2_LIB_NAME}) |
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,3 @@ | ||
A lightweight AMPL NL file writer and SOL file reader. | ||
|
||
See mp.ampl.com. |
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,55 @@ | ||
/** | ||
* Example using NLWriter2 and SOLReader2 | ||
* to write NL file, execute solver, and read SOL file. | ||
* | ||
*/ | ||
|
||
#include <cstdlib> | ||
|
||
#include "nlsol_ex_mdl.h" | ||
#include "nlsol_ex_nl.h" | ||
#include "nlsol_ex_sol.h" | ||
|
||
#include "mp/nlsol.h" | ||
#include "mp/nl-writer2.h" | ||
#include "mp/nl-writer2.hpp" | ||
#include "mp/sol-reader2.h" | ||
#include "mp/sol-reader2.hpp" | ||
|
||
/// Invoke: | ||
/// <this_exe> ipopt ["outlev=1 timelim=500" [text [filestub]]] | ||
int main(int argc, const char* const* argv) { | ||
if (argc<2) { | ||
printf("%s\n", | ||
"AMPL NL writer 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> ipopt \"\" text /tmp/stub\n" | ||
" <this_exe> gurobi \"nonconvex=2 funcpieces=-2 funcpieceratio=1e-4\""); | ||
exit(0); | ||
} | ||
std::string solver = (argc>1) ? argv[1] : "minos"; | ||
std::string sopts = (argc>2) ? argv[2] : ""; | ||
bool binary = (argc<=3) || std::strcmp("text", argv[3]); | ||
std::string stub = (argc>4) ? argv[4] : "stub"; | ||
|
||
ExampleModel emdl; | ||
ExampleNLFeeder2 nlf(emdl, binary); | ||
ExampleSOLHandler2 esolh(emdl); | ||
mp::NLUtils utils; | ||
|
||
mp::NLSOL<ExampleNLFeeder2, ExampleSOLHandler2> | ||
nlsol(nlf, esolh, utils); | ||
nlsol.SetSolver(solver); | ||
nlsol.SetSolverOptions(sopts); | ||
if (!nlsol.Solve(stub)) { | ||
printf("%s\n", nlsol.GetErrorMessage()); | ||
exit(EXIT_FAILURE); | ||
} | ||
esolh.PrintSolution(stub); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.