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.
4 Answers
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.

- 582
- 11
- 18
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}}"

- 9,008
- 4
- 41
- 55
-
5I 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
-
3There 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
-
Be careful - YASMIJ.js works only for maximization (type: "maximize"). Moreover, currently is not supported - it is written in the readme. – Svetlana K Oct 24 '21 at 21:08
-
SimpleSimplex is a nelder mead optimizer, not a linear programming solver. – Justin Meiners Jun 25 '22 at 03:37
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!

- 1,763
- 1
- 12
- 19
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.

- 518
- 5
- 9
-
3numericsjs is seriously busted and hasn't been updated since 2012. Don't use it. – Meekohi Nov 12 '15 at 19:15