JWally / jsLPSolver

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

Solutions in Integer Mode #46

Closed alfox24 closed 8 years ago

alfox24 commented 8 years ago

Hi, basically, what I want to accomplish is to get all the solutions in the integer mode, not only the optimal solution. Is this function/method supported by your solver? Thank you for your answer in advance! Have a great day, Alex

JWally commented 8 years ago

Are you trying to solve a problem like this where you can only have integer variable results?

You run a small custom furniture shop and make custom tables and dressers.

Each week you're limited to 300 square feet of wood, 110 hours of labor, and 400 square feet of storage.

A table uses 30sf of wood, 5 hours of labor, requires 30sf of storage and has a gross profit of $1,200. A dresser uses 20sf of wood, 10 hours of work to put together, requires 50 square feet to store and has a gross profit of $1,600.

How much of each do you product to maximize profit, given that partial furniture isn't allowed in this dumb word problem?

var solver = require("./src/solver"),
    model = {
        "optimize": "profit",
        "opType": "max",
        "constraints": {
            "wood": {"max": 300},
            "labor": {"max": 110},
            "storage": {"max": 400}
        },
        "variables": {
            "table": {"wood": 30,"labor": 5,"profit": 1200,"table": 1, "storage": 30},
            "dresser": {"wood": 20,"labor": 10,"profit": 1600,"dresser": 1, "storage": 50}
        },
        "ints": {"table": 1,"dresser": 1}
    }

console.log(solver.Solve(model));
// {feasible: true, result: 1440-0, table: 8, dresser: 3}
bchevalier commented 8 years ago

Hi Alex,

Unfortunately the solver does not provide this functionality, do you really want an exhaustive list of all the feasible solutions? Or simply want several of them?

The number of feasible solutions can explose with respect to the number of variables (the number of feasible solutions grows exponentially with the number of variables). I can quickly add this functionality into the solver but to get an idea, how many variables does your problem have?

For instance, a knapsack problem with 30 variables will have in the order of magnitude of 10^9 solutions.

alfox24 commented 8 years ago

Oh my mistake, should have probably explained it a little bit more.. basically I'm using this solver to create a graph. On this graph I want to have all the feasible solutions in the positive areas, which means x>0 y>0. Than I want to have those solutions ( points of x's and y's) visualized on the graph (which I know how to do..). I'm quite aware that the solver might not have such a functionality, therefore I'm working on a way to solve this...

Anyway thank you for your answer!

bchevalier commented 8 years ago

It would not be too much work for me to add this functionality to the solver. Also, that would help us improve the solver if you described the model you are trying to solve.

alfox24 commented 8 years ago

That would be something! Let me explain it to you, basically we are trying to build a graphical solver for linear programming. selection_003

As you can see I've got my objective function which can either be maximized or minimized, in this case MAX. Than I have my two constraints consisting of only two unknowns (we are bound to use only 2 unknowns, but multiply restrictions.. so we can stale it in 2D). Now this works perfectly and as you can see I already managed to visualize my "optimal area".

In my current example I would need in the integer mode to be able to get the feasible solutions which would be, in this case the points [{x:0, y:3} -> which is my optimum that the solver already calculated, {0,2},{0,1},{0,0},{1,2},{1,1},{1,0},{2,2},{2,1},{2,0},{3,1},{3,0},{4,0}].

Obviously it always depends on the restrictions, whether they are <=, >= or =. If you need any more details, examples ... just ask me, you would do me a great favor! Sadly I don't have much time left for the project ( max 1 week ) :/

bchevalier commented 8 years ago

Thank you for showing your project, that's interesting.

You need to show the value of the objective function on all those points? Can I ask what is the purpose of this feature?

Can't you simply return the value when the user clicks one of them?

By the way, what will happen to this project after 1 week?

alfox24 commented 8 years ago

Hi, so since I visualize my project with d3js I solved this by simply creating an object with all the points in the graph and then simply deleting the ones who are not in my solution area :)

There's a deadline for the project, which is next week, since it's a project we have to do for our course during the semester.

Anyway thanks for your help.

JWally commented 8 years ago

@alfox24 do you still need this? I'm going to move to close this if not.

Thanks! -JWW

alfox24 commented 8 years ago

I don't need this anymore, you can close it. Thank you.

2016-07-08 18:59 GMT+02:00 Justin Wolcott notifications@github.com:

@alfox24 https://github.com/alfox24 do you still need this? I'm going to move to close this if not.

Thanks! -JWW

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JWally/jsLPSolver/issues/46#issuecomment-231414255, or mute the thread https://github.com/notifications/unsubscribe/AJHCCxdDqSPBV5bVBN1tXBkxMEVZBCYgks5qToIFgaJpZM4I6zCo .

ASIF-Mahmud1 commented 4 years ago

var solver = require("./src/solver"), model = { "optimize": "profit", "opType": "max", "constraints": { "wood": {"max": 300}, "labor": {"max": 110}, "storage": {"max": 400} }, "variables": { "table": {"wood": 30,"labor": 5,"profit": 1200,"table": 1, "storage": 30}, "dresser": {"wood": 20,"labor": 10,"profit": 1600,"dresser": 1, "storage": 50} }, "ints": {"table": 1,"dresser": 1} }

console.log(solver.Solve(model));

For this problem, could you tell , what is the use of mentioning "table":1 in the following line?
"table": {"wood": 30,"labor": 5,"profit": 1200,"table": 1, "storage": 30},

JWally commented 4 years ago

Probably just sloppy coding on my part since its not necessary here. It does however allow you to add a constraint on "tables" if you ever needed it.

Say the optimal solution to this LP came out as 30 tables, 0 dressers or whatever. You could add a constraint to set a max on tables of say 15.