我一直在NodeJs中编写很多脚本,但我需要使用像GLPK库这样的东西来处理脚本中的一些优化。有没有人听说过javascript驱动程序?我想知道将硬币移植到V8库有多难...可能高于我的工资等级。
Javascript Simplex库
YASMIJ示例:
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}}"
不确定OP是否正在寻找,但我正在研究可能有效的here。你会像这样使用它:
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);
结果最终会是:
{feasible: true, Yusip: 270, Exotic: 260, result: 1985}
它可能不是世界上最快的解算器,但它很容易使用。
我不知道这是否有帮助,但请看看numericjs.com。这是一个我正在研究的javascript数值分析库,它具有线性编程算法的基本实现。
GLPK实际上已经使用emScripten移植到JavaScript。得到的js约1 MB缩小,230 KB拉链。
截至今天的2018年8月
1)最后承诺2015年12月:https://github.com/hgourvest/node-glpk
2)2017年12月最后一次承诺:https://github.com/jvail/glpk.js
试试吧!