jvail / glpk.js

GLPK for browser & node
GNU General Public License v3.0
106 stars 19 forks source link

Adding solver settings & shadow price #17

Closed saeid3 closed 4 years ago

saeid3 commented 4 years ago

In this PR, I added shadow prices to the output of LP solutions. I also added an object of solver settings to the API with values of mipGap, tmLim & msgLev which are the important ones. I pass these settings as function args in glpk.js.c hardcoded. A better way would be to create an object of these settings in js and pass it to the solve_mip (something like following), but I couldn't manage to do it.

int solve_mip(glp_prob *P, setting_obj settings) {
    glp_iocp parm;
    glp_init_iocp(&parm);
    parm.presolve = 1;
    parm.msg_lev = msg_lev;
    parm.mip_gap = settings.mip_gap;
    parm.tm_lim = settings.tm_lim;
    return glp_intopt(P, &parm);
}

This PR addresses https://github.com/jvail/glpk.js/issues/16

jvail commented 4 years ago

First of all thank you for this contribution - very interesting improvements. Just two comments here the rest will take a bit of time:

I will add comments and suggestions to the sources - quite a lot I am afraid. I can of course do some work as well. But that might take some time.

saeid3 commented 4 years ago

Thank you for the suggestion.

Also please go ahead and leave your comments and suggestions, that would help a lot

jvail commented 4 years ago

Alright, thank you @Saeid3 for the changes. I think I misunderstood what you try do do with "dual". I thought you want to achieve the same as passing "--dual" to glpsol. If we just add an additional output (const dual) that it wont be optional.

I looked a bit through the glpk.pdf and I think I will probably change the naming of the options so they are identical with glpsol. For a version 4 with a changed API i might need more time since I would like to change a lot on the emscripten part (e.g ES6 export etc.). So I will change the solve function to allow both passing either the msg_lvl or an options object. Then I can quickly make a 3.2 release including all of your changes.

Could you add an AUTHORS file with your and maybe your colleagues names? - if you want. I don't know what should appear there.

saeid3 commented 4 years ago

That's awesome! Thank you @jvail for reviewing the changes. I changed the cons object not to be optional. but dual still remains optional because we won't have dual for problems that aren't LP. Let me know if you want me to make any changes. I also didn't know what should a AUTHOR file include, I just made a .md file manually with the names. Feel free to change as you like.

jvail commented 4 years ago

All right @Saeid3. Thank for the Authors file and your changes. I try to get it done and released as soon as possible.