JWally / jsLPSolver

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

Cannot solve simplest 2-dimensional example #121

Open Daniel-Alievsky opened 2 years ago

Daniel-Alievsky commented 2 years ago

Can you consult me, I didn't understand this from your documentation. Usually, the common task of linear programming is like the following (2-dimensional example): v1 = a1x + b1y v2 = a2x + b2y goal = ax + by min1 <= v1 <= max1 min2 <= v2 <= max2 I need to maximize "goal". What JSON I need to create to describe this task?

For example, I tried to resolve the simplest task. -1 <= x + y <= 1 -1 <= -x + y <= 1 (rhomb) I want to maximize "x". Result should be x=1, y=0.

I entered the JSON:

{
    "optimize": "x",
    "opType": "max",
    "constraints": {
        "v1": {"min": -1, "max":  1},
        "v2": {"min": -1, "max":  1}
    },
    "variables": {
        "x": {
            "v1": 1,
            "v2": 1
        },
        "y": {
            "v1": 1,
            "v2": -1
        }
    }
}

I expected to see: x=1, y=0, result=1. Instead of this, your solver returns:

{
    "feasible": true,
    "result": 0,
    "bounded": true
}

What does it mean??

Also, how can I specify that I want to maximize some linear combination of x, y, for example, 3.2x+1.4y? Should I do the following?

{
    "optimize": "g",
    "opType": "max",
    "constraints": {
        "v1": {"min": -1, "max":  1},
        "v2": {"min": -1, "max":  1}
    },
    "variables": {
        "x": {
            "v1": 1,
            "v2": 1,
            "g": 3.2
        },
        "y": {
            "v1": 1,
            "v2": -1,
            "g": 1.4
        }
    }
}

Thank you!

reidev275 commented 1 year ago

@Daniel-Alievsky your final question regarding 3.2x + 1.4y has a correct example. Given a max occurrence of 1 for both v1 and v2 the best option is to do 1 x which provides a g value of 3.2.

{ feasible: true, result: 3.2, bounded: true, x: 1 }