Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ampl/mp into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mapgccv committed Feb 23, 2024
2 parents ac2001b + dc148dc commit 3abf58f
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 204 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ include(init)

project(MP)

# Set the c++11 flag without GNU extensions.
set(CMAKE_CXX_STANDARD 11)
# Set the c++17 flag without GNU extensions.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Expand Down Expand Up @@ -258,7 +258,7 @@ function (add_mp_library name)
PUBLIC ${add_mp_library_COMPILE_DEFINITIONS})
target_include_directories(${name}
PUBLIC ${add_mp_library_INCLUDE_DIRECTORIES})
set_property(TARGET ${name} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${name} PROPERTY CXX_STANDARD 17)
if (add_mp_library_DEPENDS)
add_dependencies(${name} ${add_mp_library_DEPENDS})
endif ()
Expand Down
8 changes: 5 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ stages:
inputs: {pathtoPublish: 'nl-writer2/nlwpy/wheelhouse'}
- job: macos
pool: {vmImage: 'macos-latest'}
variables:
MACOSX_DEPLOYMENT_TARGET: 10.15
steps:
- task: UsePythonVersion@0
- bash: |
Expand All @@ -45,9 +47,9 @@ stages:
- task: PublishBuildArtifacts@1
inputs: {pathtoPublish: 'nl-writer2/nlwpy/wheelhouse'}

- stage: qemu
displayName: 'Build with QEMU'
jobs:
# - stage: qemu
# displayName: 'Build with QEMU'
# jobs:
- job: qemu
pool: {vmImage: 'Ubuntu-20.04'}
strategy:
Expand Down
2 changes: 1 addition & 1 deletion nl-writer2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10)
project(NLWriter2)


set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)


Expand Down
7 changes: 4 additions & 3 deletions nl-writer2/include/mp/nl-solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

namespace mp {

class NLHeader;
struct NLHeader;

/**
\rst
Expand Down Expand Up @@ -229,14 +229,15 @@ class NLSolver {
bool ReadSolution(SOLHandler& solh);

protected:
void Init();
void Destroy();
void InitAutoStub();
void DestroyAutoStub();
mp::NLUtils& Utils() const { return *p_ut_; }

private:
mp::NLUtils utils_;
mp::NLUtils* p_ut_ = nullptr;

std::string pathstr_;
std::string filestub_;
bool filestubCustom_ = false;
NLW2_NLOptionsBasic_C nl_opts_;
Expand Down
2 changes: 1 addition & 1 deletion nl-writer2/include/mp/nl-solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace mp {
template <class NLFeeder>
bool NLSolver::LoadModel(NLFeeder& nlf) {
if (GetFileStub().empty())
return (err_msg_="WriteNL error: provide filestub.", false);
InitAutoStub();
auto result = mp::WriteNLFile(GetFileStub(), nlf, Utils());
if (NLW2_WriteNL_OK != result.first)
return (err_msg_ = "WriteNL error: " + result.second, false);
Expand Down
2 changes: 1 addition & 1 deletion nl-writer2/include/mp/sol-reader2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ NLW2_SOLReadResultCode SOLReader2<SOLHandler>::gsufread(FILE* f) {
if (!fgets(buf, sizeof(buf)-1, f))
return ReportEarlyEof();
if (!(L = strlen(buf)) || buf[--L] != '\n'
|| L >= se - s)
|| L >= (size_t)(se - s))
return ReportBadLine(buf);
if (L) {
if (buf[L-1] != '\r' || --L) {
Expand Down
44 changes: 22 additions & 22 deletions nl-writer2/nlwpy/src/nlw_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,48 +267,48 @@ PYBIND11_MODULE(nlwpy, m)
.. autosummary::
:toctree: _generate
NLW2_ObjSense
NLW2_VarType
NLW2_MatrixFormat
NLW2_HessianFormat
NLW2_NLOptionsBasic
NLW2_MakeNLOptionsBasic_Default
NLW2_NLSuffix
NLW2_NLModel
NLW2_NLSolution
NLW2_NLSolver
ObjSense
VarType
MatrixFormat
HessianFormat
NLOptionsBasic
MakeNLOptionsBasic_Default
NLSuffix
NLModel
NLSolution
NLSolver
)pbdoc";

py::enum_<NLW2_ObjSense>(m, "NLW2_ObjSense", py::arithmetic())
py::enum_<NLW2_ObjSense>(m, "ObjSense", py::arithmetic())
.value("Minimize", NLW2_ObjSenseMinimize)
.value("Maximize", NLW2_ObjSenseMaximize);
// .export_values(); -- Leave them scoped

py::enum_<NLW2_VarType>(m, "NLW2_VarType", py::arithmetic())
py::enum_<NLW2_VarType>(m, "VarType", py::arithmetic())
.value("Continuous", NLW2_VarTypeContinuous)
.value("Integer", NLW2_VarTypeInteger);

py::enum_<NLW2_MatrixFormat>(m, "NLW2_MatrixFormat", py::arithmetic())
py::enum_<NLW2_MatrixFormat>(m, "MatrixFormat", py::arithmetic())
.value("Rowwise", NLW2_MatrixFormatRowwise);

py::enum_<NLW2_HessianFormat>(m, "NLW2_HessianFormat", py::arithmetic())
py::enum_<NLW2_HessianFormat>(m, "HessianFormat", py::arithmetic())
.value("Triangular", NLW2_HessianFormatTriangular)
.value("Square", NLW2_HessianFormatSquare);

/// NLOptionsBasic
py::class_<NLW2_NLOptionsBasic_C>(m, "NLW2_NLOptionsBasic")
py::class_<NLW2_NLOptionsBasic_C>(m, "NLOptionsBasic")
.def(py::init<>())
.def_readwrite("n_text_mode_", &NLW2_NLOptionsBasic_C::n_text_mode_)
.def_readwrite("want_nl_comments_", &NLW2_NLOptionsBasic_C::want_nl_comments_)
.def_readwrite("flags_", &NLW2_NLOptionsBasic_C::flags_);

m.def("NLW2_MakeNLOptionsBasic_Default", &NLW2_MakeNLOptionsBasic_C_Default, R"pbdoc(
m.def("MakeNLOptionsBasic_Default", &NLW2_MakeNLOptionsBasic_C_Default, R"pbdoc(
Use this to create default options for NLModel.
)pbdoc");

/// NLSuffix
py::class_<mp::NLSuffix>(m, "NLW2_NLSuffix")
py::class_<mp::NLSuffix>(m, "NLSuffix")
.def(py::init<std::string, int, std::vector<double>>())
.def(py::init<std::string, std::string, int, std::vector<double>>())
.def_readwrite("name_", &mp::NLSuffix::name_)
Expand All @@ -317,7 +317,7 @@ NLW2_NLSolver
.def_readwrite("values_", &mp::NLSuffix::values_);

/// NLSuffixSet
py::class_<mp::NLSuffixSet>(m, "NLW2_NLSuffixSet")
py::class_<mp::NLSuffixSet>(m, "NLSuffixSet")
.def("Find", // Find(): return None if not found
[=](mp::NLSuffixSet const& ss,
std::string const& name, int kind) -> py::object {
Expand All @@ -335,7 +335,7 @@ NLW2_NLSolver
;

/// NLModel
py::class_<NLWPY_NLModel>(m, "NLW2_NLModel")
py::class_<NLWPY_NLModel>(m, "NLModel")
.def(py::init<const char *>())
.def("SetCols", &NLWPY_NLModel::SetCols)
.def("SetColNames", &NLWPY_NLModel::SetColNames)
Expand All @@ -350,7 +350,7 @@ NLW2_NLSolver
;

/// NLSolution
py::class_<mp::NLSolution>(m, "NLW2_NLSolution")
py::class_<mp::NLSolution>(m, "NLSolution")
.def_readwrite("solve_result_", &mp::NLSolution::solve_result_)
.def_readwrite("nbs_", &mp::NLSolution::nbs_)
.def_readwrite("solve_message_", &mp::NLSolution::solve_message_)
Expand All @@ -360,7 +360,7 @@ NLW2_NLSolver
.def_readwrite("suffixes_", &mp::NLSolution::suffixes_);

/// NLSolver
py::class_<mp::NLSolver>(m, "NLW2_NLSolver")
py::class_<mp::NLSolver>(m, "NLSolver")
.def(py::init<>())
.def("SetFileStub", &mp::NLSolver::SetFileStub)
.def("SetNLOptions", &mp::NLSolver::SetNLOptions)
Expand Down
Loading

0 comments on commit 3abf58f

Please sign in to comment.