Skip to content
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

Open
vitaut opened this issue Feb 4, 2015 · 3 comments
Open

Add an NL writer #30

vitaut opened this issue Feb 4, 2015 · 3 comments

Comments

@vitaut
Copy link
Contributor

vitaut commented Feb 4, 2015

Add an NL writer. Requirements:

  • Reusable: not tied to a specific problem representation
  • Complete: should support both text and binary format and all NL features
  • High performance

This can potentially be used in casadi/casadi#755.

@tkelman
Copy link
Contributor

tkelman commented Feb 4, 2015

Having an extern "C" API that's accessible from high-level languages would be a nice plus. We could write our own if necessary though. edit: done in /~https://github.com/JackDunnNZ/NL.jl, so probably not necessary

@vitaut
Copy link
Contributor Author

vitaut commented Feb 21, 2015

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 ProblemInfo object must be populated manually and Jacobian/gradient nonzero pattern too. Should be pretty easy to improve the API to reduce the above code to something like:

  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.

glebbelov added a commit that referenced this issue Oct 23, 2023
Templates, inline C++
glebbelov added a commit that referenced this issue Oct 25, 2023
glebbelov added a commit that referenced this issue Oct 26, 2023
Also allow indexing of namespace mp::internal
glebbelov added a commit that referenced this issue Nov 1, 2023
gen-expr-info.cc generates them in nl-opcodes.h
glebbelov added a commit that referenced this issue Nov 2, 2023
79-82 are assigned to denote MP internal expression kinds
glebbelov added a commit that referenced this issue Nov 8, 2023
glebbelov added a commit that referenced this issue Nov 9, 2023
glebbelov added a commit that referenced this issue Nov 10, 2023
Finished high-level example code
glebbelov added a commit that referenced this issue Nov 10, 2023
Stub C++ connector classes
glebbelov added a commit that referenced this issue Nov 10, 2023
Extract NLHeader definition into C structs
glebbelov added a commit that referenced this issue Nov 14, 2023
Mechanism to write gradients: pass void* to std::function<void(int, double)>
glebbelov added a commit that referenced this issue Nov 14, 2023
glebbelov added a commit that referenced this issue Nov 14, 2023
glebbelov added a commit that referenced this issue Nov 14, 2023
glebbelov added a commit that referenced this issue Nov 15, 2023
No suffixes, no names output
glebbelov added a commit that referenced this issue Nov 17, 2023
glebbelov added a commit that referenced this issue Nov 21, 2023
glebbelov added a commit that referenced this issue Nov 24, 2023
glebbelov added a commit that referenced this issue Nov 27, 2023
glebbelov added a commit that referenced this issue Nov 29, 2023
glebbelov added a commit that referenced this issue Nov 29, 2023
glebbelov added a commit that referenced this issue Nov 30, 2023
Manually citing major structs. Ideal would be automatic
glebbelov added a commit that referenced this issue Nov 30, 2023
Breaking is the change of NLSOL_C accessor names
glebbelov added a commit that referenced this issue Feb 13, 2024
glebbelov added a commit that referenced this issue Feb 13, 2024
glebbelov added a commit that referenced this issue Feb 16, 2024
glebbelov added a commit that referenced this issue Feb 19, 2024
No need to keep the arrays around
glebbelov added a commit that referenced this issue Feb 19, 2024
glebbelov added a commit that referenced this issue Feb 20, 2024
glebbelov added a commit that referenced this issue Feb 20, 2024
Breaking: remove counters from Python API because we receive vectors
glebbelov added a commit that referenced this issue Feb 21, 2024
glebbelov added a commit that referenced this issue Feb 21, 2024
glebbelov added a commit that referenced this issue Feb 21, 2024
glebbelov added a commit that referenced this issue Feb 21, 2024
Using nl-writer2/include as originally
glebbelov added a commit that referenced this issue Feb 21, 2024
glebbelov added a commit that referenced this issue Feb 22, 2024
glebbelov added a commit that referenced this issue Feb 22, 2024
For conformance with C++ and Python
glebbelov added a commit that referenced this issue Feb 23, 2024
glebbelov added a commit that referenced this issue Feb 23, 2024
glebbelov added a commit that referenced this issue Feb 23, 2024
glebbelov added a commit that referenced this issue Feb 23, 2024
glebbelov added a commit that referenced this issue Feb 26, 2024
glebbelov added a commit that referenced this issue Feb 28, 2024
glebbelov added a commit that referenced this issue Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants