JWally / jsLPSolver

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

Constraints as expressions using variable attributes? #108

Open Ramenhotep opened 4 years ago

Ramenhotep commented 4 years ago

This is working great for simple problems, but is there no way to build constraints as expressions using variable attributes, like:

constraints": {
            "wood": {"max": "storage"},
            "labor" + "storage": {"max": 110},
  },
diligence-dev commented 4 years ago

Would also be interested in this. https://github.com/njoubert/csp.js seems to support this with functions, but it does not run in the browser.

diligence-dev commented 4 years ago

I found a workaround:

apolinario commented 3 years ago

I have the same issue. I have this lp file format array:

var model = [
          "max: x00 + x01 + x10 + x11",
          "x10 + x11 = 1.00 x00 + 1.00 x01 + 1.00 x10 + 1.00 x11",
          "x01 + x11 = 0.15 x00 + 0.15 x01 + 0.15 x10 + 0.15 x11",
          "x01 + x00 = 0.00 x00 + 0.00 x01 + 0.00 x10 + 0.00 x11",
          "x10 + x00 = 0.85 x00 + 0.85 x01 + 0.85 x10 + 0.85 x11",
          "x00 <= 60",
          "x01 <= 30",
          "x10 <= 100",
          "x11 <= 50",
];

And can't get it to work on jsLPSolver. If I use the solver.ReformatLP() function, I believe it is a bug because it thinks my value is 11 (probably because of this last variable x11). I also tried scaling everything up by multiplying by 100 without results

I also didn't find a way to natively create this array from scratch