Skip to content

Commit

Permalink
Enable string redirection for model I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
whart222 committed Sep 22, 2024
1 parent ef655e7 commit 1b9c32c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/poek/poek/poek_pybind11.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def print_equations(self, ostream=None):

setattr(model, "print_equations", print_equations)

def print_values(self, ostream=None):
if ostream is None:
self.print_values_()
else:
ostream.write( self.print_values_(0) );
return ostream

setattr(model, "print_values", print_values)

def constraint_is_numeric_type(self, *args, **kwds):
return True

Expand Down
15 changes: 13 additions & 2 deletions lib/pycoek/pybind11/pycoek_pybind11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>

#include <sstream>
#include <cmath>
#include <iostream>
#include <typeinfo>
Expand Down Expand Up @@ -1906,8 +1907,18 @@ PYBIND11_MODULE(pycoek_pybind11, m)
.def("write", [](coek::Model& m, const std::string& s) { m.write(s); })
//.def("write", [](coek::Model& m, const std::string& s, std::map<int,int>& varmap,
// std::map<int,int>& conmap){m.write(s,varmap,conmap);})
.def("print_equations", [](coek::Model& m) { m.print_equations(); })
.def("print_values", [](coek::Model& m) { m.print_values(); });
.def("print_equations_", [](coek::Model& m) { m.print_equations(); })
.def("print_equations_", [](coek::Model& m, bool) {
std::stringstream ostr;
m.print_equations(ostr);
return ostr.str();
})
.def("print_values_", [](coek::Model& m) { m.print_values(); })
.def("print_values_", [](coek::Model& m, bool) {
std::stringstream ostr;
m.print_values(ostr);
return ostr.str();
});

//
// Functions for Compact Expressions
Expand Down

0 comments on commit 1b9c32c

Please sign in to comment.