JWally/jsLPSolver

Cannot solve simplest 2-dimensional example

Daniel-Alievsky opened this issue · 1 comments

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!

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