JWally / jsLPSolver

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

Returning a subset of possible solutions #93

Closed alhambra1 closed 5 years ago

alhambra1 commented 5 years ago

Hi,

Is there a way to retrieve a subset of optimal solutions rather than just one? If you could even point me towards where to look to possibly tweak to accomplish that, that would be great.

Sincerely,

JWally commented 5 years ago

Are you looking for a subset of mixed-integer-LPs or just plain LP's?

alhambra1 commented 5 years ago

At the moment, I'm using it with integers only.

On Mon, 28 Oct 2019, 9:54 pm Justin Wolcott, notifications@github.com wrote:

Are you looking for a subset of mixed-integer-LPs or just plain LP's?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JWally/jsLPSolver/issues/93?email_source=notifications&email_token=AANRFJPGLA3PUSH7SN6LLETQQ6JUXA5CNFSM4JAFS4GKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECO62AI#issuecomment-547220737, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANRFJJ2AGYSLANQQOV6KMLQQ6JUXANCNFSM4JAFS4GA .

JWally commented 5 years ago

https://github.com/JWally/jsLPSolver/blob/be561df57cc6cea45ad828b0dfc22cdc903c3c7f/src/Tableau/branchAndCut.js#L162-L175

This if block, between 161 and 175 is where the MILP has a valid solution. You could add the following bit of code there:

            //
            //
            //
            //
            //
            //
            var nowSolution = (this.model.tableau.getSolution());
            var store = nowSolution.generateSolutionSet();
            store.result = nowSolution.evaluation;

            if(!this.model.solutions){
                this.model.solutions = [];
            }

            this.model.solutions.push(store);
            //
            //
            //
            //
            //
            //
            //

and access them like this:

        var a = solver.Solve(model,1e-8,true);
        console.log(a._tableau.model.solutions);
alhambra1 commented 5 years ago

Thank you so much. I really appreciate it!

On Wed, 30 Oct 2019 at 15:43, Justin Wolcott notifications@github.com wrote:

https://github.com/JWally/jsLPSolver/blob/be561df57cc6cea45ad828b0dfc22cdc903c3c7f/src/Tableau/branchAndCut.js#L162-L175

This if block, between 161 and 175 is where the MILP has a valid solution. You could add the following bit of code there:

        //
        //
        //
        //
        //
        //
        var nowSolution = (this.model.tableau.getSolution());
        var store = nowSolution.generateSolutionSet();
        store.result = nowSolution.evaluation;

        if(!this.model.solutions){
            this.model.solutions = [];
        }

        this.model.solutions.push(store);
        //
        //
        //
        //
        //
        //
        //

and access them like this:

    var a = solver.Solve(model,1e-8,true);
    console.log(a._tableau.model.solutions);

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JWally/jsLPSolver/issues/93?email_source=notifications&email_token=AANRFJM5M7K5ZE4VCAIU2UDQRHPVHA5CNFSM4JAFS4GKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECVQYUI#issuecomment-548080721, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANRFJLLTUBJNMYCEWM4H7TQRHPVHANCNFSM4JAFS4GA .

JWally commented 5 years ago

FWIW, it doesn't seem to slow down the solver too much; so its an option you can get at through:

{
    "options": {
        "keep_solutions": true
    }
}

which puts the solutions on _tableau.model.solutions.

Next update I send, it'll be in there :-)

Hope it helps!