JWally / jsLPSolver

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

Binary variables #60

Open rgesulfo opened 7 years ago

rgesulfo commented 7 years ago

Does this package handle binary variables?

I tried this in the Tableau format, but I'm not getting the expected result.

rawModel = [ "max: 21 x11 22.5 x21 22.5 x12 24.5 x22 23 x13 25.5 x23 1500 y1 2000 y2 3000 y3", "1 x11 1 x21 <= 425", "1 x12 1 x22 >= 400", "1 x13 1 x23 >= 750", "1 x11 1 x12 1 x13 >= 550", "1 x21 1 x22 1 x23 >= 450", "1 x11 1 x21 -425 y1 <= 0", "1 x12 1 x22 -400 y2 <= 0", "1 x13 1 x23 -750 y3 <= 0", "1 x11 >= 0", "1 x12 >= 0", "1 x13 >= 0", "1 x21 >= 0", "1 x22 >= 0", "1 x23 >= 0", "y1 = {0,1}", "y2 = {0,1}", "y3 = {0,1}", "int x11", "int x21", "int x12", "int x22", "int x13", "int x23", ];

Thank you for your help.

JWally commented 7 years ago

Sorry for the late response.

At the moment, the re-format functionality needs to be cleaned up and updated. The library itself handles binary variables; however ReformatLP doesn't (yet).

In the mean time, would this hacky solution work?:

var problem = [ 
    "max: 21x11 22.5x21 22.5x12 24.5x22 23x13 25.5x23 1500y1 2000y2 3000y3", 
    "1x11 1x21 <= 425", 
    "1x12 1x22 >= 400", 
    "1x13 1x23 >= 750", 
    "1x11 1x12 1x13 >= 550", 
    "1x21 1x22 1x23 >= 450", 
    "1x11 1x21 -425y1 <= 0", 
    "1x12 1x22 -400y2 <= 0", 
    "1x13 1x23 -750y3 <= 0", 
    // I think these are redundant
    "1x11 >= 0", 
    "1x12 >= 0",
    "1x13 >= 0", 
    "1x21 >= 0", 
    "1x22 >= 0", 
    "1x23 >= 0", 
    "int x11", 
    "int x21", 
    "int x12", 
    "int x22", 
    "int x13", 
    "int x23",
    // AKA CHEATING
    "int y1",
    "int y2",
    "int y3",
    "1y1 <= 1",
    "1y2 <= 1",
    "1y3 <= 1"
    ];