8

I've been writing a lot of my scripts in NodeJs, but I need to use something like the GLPK libraries in order to handle some of the optimizations in my scripts. Has anyone heard of a javascript driver? I wonder how hard it would be to port coin to a V8 library.. probably above my pay grade.

BHP
  • 916
  • 1
  • 13
  • 18

4 Answers4

6

Javascript Simplex Libraries

YASMIJ Example:

var input = {
    type: "maximize",
    objective : "x1 + 2x2 - x3",
    constraints : [
        "2x1 + x2 + x3 <= 14",
        "4x1 + 2x2 + 3x3 <= 28",
        "2x1 + 5x2 + 5x3 <= 30"
    ]
};
YASMIJ.solve( input ).toString();
// returns
"{"result":{"slack1":0,"slack2":0,"slack3":0,"x1":5,"x2":4,"x3":0,"z":13}}"
Larry Battle
  • 8,222
  • 4
  • 39
  • 54
  • Thanks for sharing that! Your library is very useful. – Roman May 22 '13 at 13:35
  • 5
    I have tried all of these and they are junk unfortunately :( _SimplexJS_ is for mixed-linear program (doesn't actually implement the Simplex method, seems to have just chosen that name for fun). _SimpleSimplex_ has `document.write` in the code... not something you are going to use inside another project, just a demo. _YASMIJ.js_ never made it out of beta and you pass the objective function in as a string, which can't be a good sign... – Meekohi Nov 12 '15 at 19:24
  • 2
    There are two completely different optimisations algorithms that both go by the name "simplex algorithm": The linear programming optimisation problem where the space is bounded by a simplex and the solution point is moved from vertex to vertex, and the Nelder-Mead simplex algorithm for optimising an arbitrary function in a continuous space by repeatedly making a simplex and estimating the integral within that simplex. Super-confusing! Stumps many people searching for implementations. The example above is a linear programming problem. https://en.wikipedia.org/wiki/Simplex_algorithm – Max Murphy Apr 20 '16 at 11:56
6

Not sure if its what the OP is looking for, but I'm working on something here that might work. You would use it like this:

var solver = new Solver,
    results,
    model = {
    optimize: "profit",
    opType: "max",
    constraints: {
        "Costa Rican" : {max: 200},
        "Etheopian": {max: 330}
    },
    variables: {
        "Yusip": {"Costa Rican" : 0.5, "Etheopian": 0.5, profit: 3.5},
        "Exotic": {"Costa Rican" : 0.25, "Etheopian": 0.75, profit: 4}
    }
};

results = solver.solve(model);
console.log(results);

Where the results would end up being:

{feasible: true, Yusip: 270, Exotic: 260, result: 1985}

Its probably not the fastest solver in the world, but its easy enough to work with.

JWally
  • 550
  • 11
  • 18
3

I don't know if this will help, but please have a look at numericjs.com. It's a javascript numerical analysis library that I'm working on that has a rudimentary implementation of a linear programming algorithm.

2

GLPK has actually been ported to JavaScript using emScripten. The resulting js is about 1 MB minified and 230 KB zipped.

As of today August 2018

1) Last committed Dec 2015: https://github.com/hgourvest/node-glpk

2) Last committed Dec 2017: https://github.com/jvail/glpk.js

Try them out!

peter.cyc
  • 1,597
  • 1
  • 10
  • 19