-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an NL writer #30
Comments
Having an |
It is already possible to write an NL file using existing APIs: #include "asl/aslbuilder.h"
using namespace mp;
int main() {
// Build problem in ASL form.
ASL *asl = ASL_alloc(ASL_read_fg);
asl::internal::ASLBuilder b(asl);
auto info = ProblemInfo();
info.num_vars = info.num_nl_vars_in_objs = 1;
info.num_nl_objs = info.num_objs = 1;
b.SetInfo(info);
b.AddVar(-100, 100, var::CONTINUOUS);
// x - 42
auto expr = b.MakeBinary(expr::SUB, b.MakeVariable(0), b.MakeNumericConstant(42));
// minimize o: (x - 42) ^ 2
b.AddObj(obj::MIN, b.MakeUnary(expr::POW2, expr), 1).AddTerm(0, 0);
// Write .nl file.
fg_write("test.nl", 0, ASL_write_ASCII);
} However, this is not very user friendly as asl::ASLBuilder b;
auto x = b.AddVar(-100, 100);
b.AddObj(obj::MIN, pow2(x - 2));
WriteNLFile(b, "test.nl"); which is like a poor man's modeling language without model/data separation, presolve and other goodies =). The next step would be to provide a more advanced reverse-SAX-like API for writing NL files without building any problem representation. |
Also allow indexing of namespace mp::internal
gen-expr-info.cc generates them in nl-opcodes.h
79-82 are assigned to denote MP internal expression kinds
Extract NLHeader definition into C structs
Mechanism to write gradients: pass void* to std::function<void(int, double)>
Manually citing major structs. Ideal would be automatic
Breaking is the change of NLSOL_C accessor names
Breaking: remove counters from Python API because we receive vectors
Using nl-writer2/include as originally
For conformance with C++ and Python
Add an NL writer. Requirements:
This can potentially be used in casadi/casadi#755.
The text was updated successfully, but these errors were encountered: