jsLPSolver icon indicating copy to clipboard operation
jsLPSolver copied to clipboard

Constraints as expressions using variable attributes?

Open Ramenhotep opened this issue 4 years ago • 3 comments

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},
  },

Ramenhotep avatar Mar 18 '20 21:03 Ramenhotep

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 avatar Apr 22 '20 08:04 diligence-dev

I found a workaround:

  • "wood": {"max": "storage"}, means wood <= storage or wood - storage <= 0
  • add a new constraint "wood - storage": {"max": "0"},
  • change the variables: "wood": {"wood - storage": 1} and "storage": {"wood - storage": -1} Same thing can be done for the other constraint, add "labor + storage": 1 to the labor and the storage variable.

diligence-dev avatar Apr 22 '20 08:04 diligence-dev

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

apolinario avatar Dec 17 '20 01:12 apolinario