javascript-lp-solver
Version:
Easy to use, JSON oriented Linear Programming and Mixed Int. Programming Solver
36 lines (29 loc) • 1.09 kB
JavaScript
/*global module*/
function Solution(tableau, evaluation, feasible, bounded) {
this.feasible = feasible;
this.evaluation = evaluation;
this.bounded = bounded;
this._tableau = tableau;
}
module.exports = Solution;
Solution.prototype.generateSolutionSet = function () {
var solutionSet = {};
var tableau = this._tableau;
var varIndexByRow = tableau.varIndexByRow;
var variablesPerIndex = tableau.variablesPerIndex;
var matrix = tableau.matrix;
var rhsColumn = tableau.rhsColumn;
var lastRow = tableau.height - 1;
var roundingCoeff = Math.round(1 / tableau.precision);
for (var r = 1; r <= lastRow; r += 1) {
var varIndex = varIndexByRow[r];
var variable = variablesPerIndex[varIndex];
if (variable === undefined || variable.isSlack === true) {
continue;
}
var varValue = matrix[r][rhsColumn];
solutionSet[variable.id] =
Math.round((Number.EPSILON + varValue) * roundingCoeff) / roundingCoeff;
}
return solutionSet;
};