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

Preconditioners not wrapped in C++ ... #177

Open
bobmyhill opened this issue Mar 16, 2018 · 2 comments · May be fixed by #410
Open

Preconditioners not wrapped in C++ ... #177

bobmyhill opened this issue Mar 16, 2018 · 2 comments · May be fixed by #410

Comments

@bobmyhill
Copy link

bobmyhill commented Mar 16, 2018

...and therefore also not implemented in fortran (#52), python, etc.

The NLOPT_LD_CCSAQ algorithm allows the user to supply an approximation to the Hessian, via
the set_precond_min_objective() and set_precond_max_objective() functions. Unfortunately, it looks like these are not included in nlopt-in.hpp (at least I assume this is the problem). I'm not well-versed in writing wrappers; can someone give me a hand to implement the changes?

@jschueller
Copy link
Collaborator

I'd try mimic the existing code, set_min_objective is what's most similar:

In nlopt.h (C API)

NLOPT_EXTERN(nlopt_result) nlopt_set_min_objective(nlopt_opt opt, nlopt_func f, void *f_data);

this is wrapped in nlopt-in.hpp as:

void set_min_objective(func f, void *f_data) {
      myfunc_data *d = new myfunc_data;
      if (!d) throw std::bad_alloc();
      d->o = this; d->f = f; d->f_data = f_data; d->mf = NULL; d->vf = NULL;
      d->munge_destroy = d->munge_copy = NULL;
      mythrow(nlopt_set_min_objective(o, myfunc, d)); // d freed via o
    }

What changes is that you may have to create a new struct equivalent to myfunc_data adapted for the preconditioner signature nlopt_precond:

NLOPT_EXTERN(nlopt_result) nlopt_set_precond_min_objective(nlopt_opt opt, nlopt_func f, nlopt_precond pre, void *f_data);

nlopt_precond is declared as follows:

typedef void (*nlopt_precond)(unsigned n, const double *x, const double *v,
			      double *vpre, void *data);

also there is a std::vector prototype for set_min_objective, you might want to add the same.

@bobmyhill
Copy link
Author

Thanks @jschueller.

It turns out that my current problem is better posed as a (quite non-linear) bounded root-finding exercise, so I might not get to this straight away. But I'd like to get it running for other problems, and your comments are really helpful.

@smartalecH smartalecH linked a pull request Aug 27, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants