Skip to content

Commit

Permalink
NLWPY: remove NLW2_ prefix #30
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Feb 23, 2024
1 parent 0275be5 commit 38c972f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
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
22 changes: 11 additions & 11 deletions nl-writer2/nlwpy/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
import numpy as np
from scipy.sparse import csr_matrix

import nlwpy as m
import nlwpy

assert m.__version__ == "0.0.1"
assert nlwpy.__version__ == "0.0.1"

nlwo = m.NLW2_MakeNLOptionsBasic_Default()
nlwo = nlwpy.MakeNLOptionsBasic_Default()
assert 0 == nlwo.n_text_mode_
assert 0 == nlwo.want_nl_comments_
assert 1 == nlwo.flags_

## ---------------------------------------------------------------
class ModelBuilder:
def GetModel(self):
nlme = m.NLW2_NLModel(self.prob_name_)
nlme = nlwpy.NLModel(self.prob_name_)

nlme.SetCols(self.var_lb_, self.var_ub_, self.var_type_)
nlme.SetColNames(self.var_names_)
Expand All @@ -62,10 +62,10 @@ def GetModel(self):
if len(self.ini_y_i_)>0:
nlme.SetDualWarmstart(self.ini_y_i_, self.ini_y_v_)
if len(self.bas_x_)>0:
suf = m.NLW2_NLSuffix("status", 0, self.bas_x_)
suf = nlwpy.NLSuffix("status", 0, self.bas_x_)
nlme.AddSuffix(suf)
if len(self.bas_y_)>0:
suf = m.NLW2_NLSuffix("status", 1, self.bas_y_)
suf = nlwpy.NLSuffix("status", 1, self.bas_y_)
nlme.AddSuffix(suf)

return nlme
Expand Down Expand Up @@ -116,17 +116,17 @@ def __init__(self):
self.var_type_ = [0, 1, 1, 1, 0, 0]
self.var_names_ = \
["x1_4", "x2_6", "x3_5", "x4_3", "x5_1", "x6_2"]
self.A_format_ = m.NLW2_MatrixFormat.Rowwise
self.A_format_ = nlwpy.MatrixFormat.Rowwise
self.A_ = np.array([
[0,1,1,1,0,1],
[0,1,-1,-1,0,1]])
self.row_lb_ = [15, 10]
self.row_ub_ = [15, np.inf]
self.row_names_ = ["C1", "C2"]
self.obj_sense_ = m.NLW2_ObjSense.Minimize
self.obj_sense_ = nlwpy.ObjSense.Minimize
self.obj_c0_ = 3.24
self.obj_c_ = [0,1,0,0,0,0]
self.Q_format_ = m.NLW2_HessianFormat.Square
self.Q_format_ = nlwpy.HessianFormat.Square
self.Q_ = np.zeros([6, 6])
self.Q_[3, 3] = 10
self.Q_[3, 5] = 12
Expand All @@ -148,8 +148,8 @@ def __init__(self):
def SolveAndCheck(solver, sopts, binary, stub):
mb = ModelBuilder()
nlme = mb.GetModel()
nlse = m.NLW2_NLSolver()
nlopts = m.NLW2_MakeNLOptionsBasic_Default()
nlse = nlwpy.NLSolver()
nlopts = nlwpy.MakeNLOptionsBasic_Default()
nlopts.n_text_mode_ = not binary
nlopts.want_nl_comments_ = 1
nlse.SetNLOptions(nlopts)
Expand Down

0 comments on commit 38c972f

Please sign in to comment.