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

Enumerating OptionRecords using C API #1114

Closed
cyderize opened this issue Jan 27, 2023 · 7 comments
Closed

Enumerating OptionRecords using C API #1114

cyderize opened this issue Jan 27, 2023 · 7 comments

Comments

@cyderize
Copy link

Hi, I'm in the process of converting MiniZinc's new HiGHS interface to use the C API rather than the C++ API (this way we can turn it into a plugin which dynamically loads the HiGHS library at runtime).

However, there are a few C++ APIs which are not available using the C interface. Most of these I've been able to easily add in my fork (I'll open a pull request soon).

We need to be able to get all of the available options, so that we can generate a GUI for setting the options from the MiniZinc IDE. Currently in C++, we loop through the records field of HighsOptions, but I'm not entirely sure what an API for accessing these records in C should look like (we need access to the default values and bounds of the options).

Gurobi provides GRBgetnumparams and GRBgetparamname to get the number of parameters, and then get the name from the index. Perhaps something similar could be done here, with additional functions to access the descriptions, default values, and bounds of options.

@jajhall
Copy link
Sponsor Member

jajhall commented Jan 27, 2023

By "number of parameters", do you mean the number of options? I've searched for GRBgetnumparams in the Gurobi documentation, but nothing comes up.

Creating a method in the C API to achieve what you want won't be difficult. I'll get on with it this weekend

Note that there are some methods in the C++ API that are for internal use only, so shouldn't be in the C API. I'll see what you've put in your PR - please make this to latest, not master - and delete as appropriate.

@cyderize
Copy link
Author

Indeed those Gurobi functions seem to appear in the headers but apparently aren't documented anywhere. The functions we use for Gurobi have these signatures:

int GRBgetnumparams(GRBenv *env);
int GRBgetparamname(GRBenv *env, int i, char **paramnameP);
int GRBgetparamtype(GRBenv *env, const char *paramname);
int GRBgetintparaminfo(GRBenv *env, const char *paramname, int *valueP, int *minP, int *maxP, int *defP);
int GRBgetdblparaminfo(GRBenv *env, const char *paramname, double *valueP, double *minP, double *maxP, double *defP);
int GRBgetstrparaminfo(GRBenv *env, const char *paramname, char *valueP, char *defP);

Thanks, I'll make sure I target the latest branch.

@jajhall
Copy link
Sponsor Member

jajhall commented Jan 28, 2023

Thanks, I'll match these methods

@jajhall jajhall mentioned this issue Jan 30, 2023
@jajhall
Copy link
Sponsor Member

jajhall commented Feb 2, 2023

The methods are written and sitting in the option-info branch. I've written some testing code that's failing in TestCAPPI.c for some CI tests with Windows, but I think that's due to my dodgy C programming rather than any errors in the C API or C++ methods that I've added to the Highs class.

It would be good if you (@cyderize) could let me know how they are to work with.

@jajhall
Copy link
Sponsor Member

jajhall commented Feb 3, 2023

The bug exposed on Windows has been fixed, and the option-info branch has been merged in to latest

@jajhall jajhall closed this as completed Feb 3, 2023
@cyderize
Copy link
Author

cyderize commented Feb 4, 2023

Great, I tried the new functions in the latest branch and it all works perfectly 👍

Thanks!

@jajhall
Copy link
Sponsor Member

jajhall commented Feb 4, 2023

Thanks. We've tried to mimic Gurobi when we needed inspiration - so we could always quote Gurobi if anyone demurred. We picked up on their string-named options (parameters) years ago - but missed the details of the methods you've brought to out attention, so thanks. 🙂

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

2 participants