Has anyone seen a simplex library for javascript/nodejs
I've been writing a lot of m开发者_高级运维y 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.
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.
Javascript Simplex Libraries
- SimplexJS
- SimpleSimplex
- YASMIJ.js
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}}"
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.
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!
精彩评论