libprima / prima

PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for Powell's derivative-free optimization methods, i.e., COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. PRIMA means Reference Implementation for Powell's methods with Modernization and Amelioration, P for Powell.
http://libprima.net
BSD 3-Clause "New" or "Revised" License
304 stars 40 forks source link

Add additional const in prima.h and prima.c #169

Closed amontoison closed 6 months ago

amontoison commented 7 months ago

@zaikunzhang I checked all routines, except this one because it's a callback:

typedef void (*prima_callback_t)(const int n, const double x[],
            const double f, int nf, int tr,
            const double cstrv, int m_nlcon,
            const double nlconstr[], bool *terminate);

I think that we can add const for all arguments. What do you think?

zaikunzhang commented 7 months ago

@zaikunzhang I checked all routines, except this one because it's a callback:

typedef void (*prima_callback_t)(const int n, const double x[],
            const double f, int nf, int tr,
            const double cstrv, int m_nlcon,
            const double nlconstr[], bool *terminate);

I think that we can add const for all arguments. What do you think?

Thank you @amontoison . Yes, I think so.

zaikunzhang commented 6 months ago

Hi @amontoison ,

I hope you are safely home.

  1. Could you add const in the following?

    I think that we can add const for all arguments. What do you think? Thank you @amontoison . Yes, I think so.

  2. The build fails. See https://github.com/amontoison/prima/actions/runs/8169119061 Could you have a look?

Thank you.

Zaikun

amontoison commented 6 months ago

Hi @zaikunzhang! Yes, I came home safely, thanks!

I updated the PR, let's see if all tests passed now. :crossed_fingers: For the other modifications that we talked about, i.e. update the signature of

int prima_minimize(const prima_algorithm_t algorithm, prima_problem_t *problem, prima_options_t *options, prima_result_t *const result)

into

int prima_minimize(const prima_algorithm_t algorithm, prima_problem_t problem, prima_options_t options, prima_result_t *const result)

we also need to update these two routines because they are called in prima_minimize:

int prima_check_problem(prima_problem_t *const problem, prima_options_t *const options, const int use_constr, const prima_algorithm_t algorithm)
int prima_init_result(prima_result_t *const result, prima_problem_t *const problem)

Is it fine to also update these two functions? If yes, I will open another PR.

zaikunzhang commented 6 months ago

Hi @amontoison ,

Yes, I came home safely, thanks!

Super !

I updated the PR, let's see if all tests passed now. 🤞

Excellent! Everything has passed. I will check the code, but I do not think there will be much to change since we talked about it and agreed.

Is it fine to also update these two functions? If yes, I will open another PR.

I agree. Yes, please.

Merci beaucoup !

A+, Zaikun