Skip to content

Commit

Permalink
Detect infeasibility
Browse files Browse the repository at this point in the history
  • Loading branch information
octachrome committed Jul 21, 2014
1 parent 32a95f7 commit 31cbe25
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion js/simplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function firstInfeasibility(mat) {
}

if (col === null) {
throw new Error('Failed to find a suitable pivot var for infeasible row ' + row);
return 'infeasible';
}
return {
row: row,
Expand Down Expand Up @@ -231,6 +231,10 @@ function solve(mat, debug) {
mat.status = 'optimal';
break;
}
if (pv === 'infeasible') {
mat.status = 'infeasible';
break;
}
var pr = pivotRow(mat, pv);
if (debug) {
console.log(pr);
Expand Down
15 changes: 15 additions & 0 deletions test/simplexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,21 @@ describe('simplex', function () {
expect(finalMat.status).toBe('unbounded');
});

it('should detect an infeasible problem', function () {
var prob = readLp(
"maximise x\n\
subject to\n\
x <= 10\n\
x >= 20\n\
end\n"
);

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

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

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

0 comments on commit 31cbe25

Please sign in to comment.