Skip to content

Commit

Permalink
Detect unbounded problem
Browse files Browse the repository at this point in the history
  • Loading branch information
octachrome committed Jul 21, 2014
1 parent e07c08f commit ef60915
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
14 changes: 10 additions & 4 deletions js/simplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,24 @@ function solve(mat, debug) {
if (pv === null) {
pv = pivotVar(mat);
}
if (debug) {
console.log(pv);
}
if (pv === null) {
break;
}
var pr = pivotRow(mat, pv);
if (pr === null) {
break;
}
if (debug) {
console.log(pv);
console.log(pr);
}
if (pr === null) {
mat.status = 'unbounded';
break;
}
mat = pivot(mat, pr, pv.col);
}
if (!mat.status) {
mat.status = 'optimal';
}
return mat;
}
15 changes: 15 additions & 0 deletions test/simplexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,21 @@ describe('simplex', function () {
expect(sol._obj).toBeCloseTo(200);
});

iit('should detect an unbouned problem', function () {
var prob = readLp(
"maximise\n\
3x - 2y\n\
subject to\n\
y <= 100\n\
end\n"
);

var mat = toMatrix(prob);
var finalMat = solve(mat);

expect(finalMat.status).toBe('unbounded');
});

it('should solve a small MPS problem', function () {
var prob = readMps("\
NAME T \n\
Expand Down

0 comments on commit ef60915

Please sign in to comment.