JWally / jsLPSolver

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

Giving out wrong cost minimization results #89

Closed k1muza closed 5 years ago

k1muza commented 5 years ago

I have been testing this library for sometime before using it in my production project.

I tried the below model:

model = { "optimize": "cost", "opType": "min", "constraints": { "protein": { "min": 16.5 }, "me": { "min": 12 }, "calcium": { "min": 4.08 }, "phosphorus": { "min": 0.45 }, "chloride": { "min": 0.17 }, "sodium": { "min": 0.17 }, }, "variables": { "corn": { "cost": 13, "protein": 7.5, "me": 14.12, "calcium": 0.01, "phosphorus": 0.12, "chloride": 0.04, "sodium": 0.02, "corn": 100 }, "mono_phosphate": { "cost": 522, "protein": 0.00, "me": 0.00, "calcium": 15.0, "phosphorus": 21, "chloride": 0.00, "sodium": 0.00, "mono_phosphate": 100 }, "soya": { "cost": 40, "protein": 38, "me": 14.08, "calcium": 0.25, "phosphorus": 0.2, "chloride": 0.03, "sodium": 0.04, "soya": 100 }, "limestone": { "cost": 1, "protein": 0.00, "me": 0.00, "calcium": 38, "phosphorus": 0.00, "chloride": 0.03, "sodium": 0.06, "limestone": 100 }, "salt": { "cost": 10, "protein": 0.00, "me": 0.00, "calcium": 0.00, "phosphorus": 0.00, "chloride": 60.66, "sodium": 39.34, "salt": 100 }, "wheat": { "cost": 13, "protein": 13.5, "me": 13.2, "calcium": 0.05, "phosphorus": 0.12, "chloride": 0.07, "sodium": 0.06, "wheat": 100 } }, };

The result should be something like:

corn 178.4, mono_calcium 15.5, soybean 231, limestone 99.1, salt 3.1, wheat 473

But i am getting this instead:

bounded: true feasible: true limestone: 0.10005848 mono_phosphate: 0.01444444 result: 23.55199342 salt: 0.0023046 wheat: 1.22222222

I hope i am not doing something wrong

JWally commented 5 years ago

Not sure.

When I put this in excel, the numbers appear to tie out.

Your result-set shows mono_calcium and soy-bean which aren't variables I see in your model.

When I plug your numbers in (assuming mono_calcium = mono_phosphate and soya=soybean) I get the following cost:

25,929.30

Which does satisfy all of your constraints; but is way more than the result-set you provide, which also satisfies the constraints for a cost of 23.55.

Am I missing something?

JWally commented 5 years ago

going through clean-up; please re-open if unresolved...