JWally / jsLPSolver

Simple OOP javaScript library to solve linear programs, and mixed integer linear programs
The Unlicense
420 stars 69 forks source link

Termination Tolerance Option #55

Closed chrispahm closed 5 years ago

chrispahm commented 7 years ago

Most of the times the solution to a MIP problem does not have to be the absolute best possible solution, but rather a solution relatively close to the relaxed one. Modelling systems like GAMS or Gurobi therefore introduce a termination tolerance, where the solver will stop the solution process when the proportional difference between the solution found and the best theoretical objective function is guaranteed to be smaller than the given termination tolerance. I tried to add this option to the jsLPSolver, which can be used by passing the option „optcr“ as follows:

results = solver.Solve(model, 0.5);

This generally reduces the solve time for large scale MIPs significantly. The default value of Optcr is set to 0.1.

bchevalier commented 7 years ago

Thanks for the PR, that's a nice addition! Did you try on any particular model?

What would be nice:

If that's too much work, we can actually make a PR with changes that would implement the functionality you are suggesting.

chrispahm commented 7 years ago

Thanks for the replies! To be honest, I never questioned the name optcr, even on the GAMS homepage it is not further explained. So I think calling it tolerance make a lot of sense. When solving the attached model, I found that the solver would not come up with a result within a reasonable time. When checking what parts took especially long, it looked like the sheer amount of branches is making the branch & cut loop take exceptionally long. If you run the model with a tolerance level of 0.2, it will solve in less than a second. You can also notice the change in the evaluation value if you increase the value further. I also tried solving the model mentioned in the following issue, however it turned out to be infeasible.

I will try to work in your suggestions over the weekend or the course of the next week.

LargeFarmMIP.json.zip

bchevalier commented 7 years ago

Thanks for the GAMS parser!

Actually, I think the reason why the model you linked (in this issue) is not feasible is simply that the solver is not able to tackle problems that are too big without experiencing numerical instability (rounding error propagation). We are currently working on solving that issue.

Also, I think that the tolerance should be updated at every iteration of the branch and cut to consider the new best possible evaluation. In the current state, I think your heuristic works well for small instances, but not for big ones where the evaluation of the relaxed solution can be less than 20% (if your tolerance is 20%) smaller than the best evaluation of the non-relaxed solution.

chrispahm commented 7 years ago

Alright, I tried to work in most of your suggestions (sorry for the delay). For updating the acceptableThreshold variable at every iteration I am not 100% sure on how to implement it, so here's a small gist displaying the issue I'm currently facing. Thanks for having a look!

JWally commented 7 years ago

@Toffi-123 this is slick! Thanks!

Sorry its take me so long to get around to this.

@bchevalier @lvenerosy does this step on anyone's toes with what you're working on?

lvenerosy commented 7 years ago

@JWally currently checking.