Skip to content

Commit

Permalink
updateFinals should be called even if optimal
Browse files Browse the repository at this point in the history
  • Loading branch information
fusion809 committed Nov 22, 2020
1 parent 05d73a1 commit dd495c0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion calcEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function calcEntries(A, b, cj, x, xB) {

// Input validation
if (m != xB.length) {
console.error("Length of A does not match the length of xB in calcEntries.");
alert("Length of A does not match the length of xB in calcEntries.");
return;
}

Expand Down
10 changes: 5 additions & 5 deletions matrixOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
*/
function dimsCheck(A, b, cj, x, xB) {
if (b.length != xB.length ) {
console.error("The lengths of b and xB do not match!");
alert("The lengths of b and xB do not match!");
return;
} else if (A.length != b.length) {
var msg = "The number of rows in A does not match the number of rows";
msg += "in b!";
console.error(msg);
alert(msg);
return;
} else if (A.length != xB.length) {
var msg = "xB has a number of elements that exceeds the number of";
msg += " elements in A!";
console.error(msg);
alert(msg);
return;
} else if (A[0].length != x.length) {
var msg = "A has a number of columns that exceeds the number of";
msg += " elements in x!";
console.error(msg);
alert(msg);
return;
} else if (A[0].length != cj.length) {
var msg = "A has a number of columns that exceeds the number of ";
msg += "elements in c."
console.error(msg);
alert(msg);
return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions nConstr.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function newConstraint() {
// error
if (newARows.length != newbRows.length) {
shouldDie = true;
console.error("An equal number of rows must be added to A and b!");
alert("An equal number of rows must be added to A and b!");
return [A, b, cj, x, xB, shouldDie];
}

Expand All @@ -179,7 +179,7 @@ function newConstraint() {
document.getElementById("newcRows").checked) {
shouldDie = true;
var msg = "The number of new b rows and new entries in c must match!";
console.error(msg);
alert(msg);
return [A, b, cj, x, xB, shouldDie];
}

Expand All @@ -190,7 +190,7 @@ function newConstraint() {
var msg = "Remember your new A rows must have a number of columns ";
msg += "equal to that of the old A matrix plus the number of new ";
msg += "constraints!";
console.error(msg);
alert(msg);
return [A, b, cj, x, xB, shouldDie];
}

Expand Down
14 changes: 7 additions & 7 deletions readMatrices.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ function read1dNumArr(name) {
var msg = "b has unsuitable elements in it. Remember b is meant";
msg += " to be full of members separated by commas, spaces or ";
msg += "semicolons."
console.error(msg);
alert(msg);
} else if (name == "c") {
var msg = "c has unsuitable elements in it. Remember c is meant";
msg += " to be full of numbers separated by commas, spaces or ";
msg += "semicolons.";
console.error(msg);
alert(msg);
} else if (name == "A") {
var msg = "A has unsuitable elements in it. Remember A is meant";
msg += " to be full of numbers separated by commas, spaces or ";
msg += "semicolons.";
console.error(msg);
alert(msg);
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ function read2dNumArr(name) {

// Input validation
if ((len != undefined) && (A[k].length != len)) {
console.error("A row length mismatch! For some reason your A matrix has rows of different lengths!");
alert("A row length mismatch! For some reason your A matrix has rows of different lengths!");
throw console.error("A's rows must be equal in length!");
}
len = A[k].length;
Expand All @@ -144,14 +144,14 @@ function read2dNumArr(name) {
var msg = "A has unsuitable elements in it. Remember A is ";
msg += "meant to be full of numbers separated by commas, ";
msg += "spaces or semicolons.";
console.error(msg);
alert(msg);
}
}

// Input validation for final row
if ((len != undefined) && (A[k].length != len)) {
console.error("A row length mismatch! For some reason your A matrix has rows of different lengths!");
throw console.error("A's rows must be equal in length!");
alert("A row length mismatch! For some reason your A matrix has rows of different lengths!");
console.error("A's rows must be equal in length!");
}

return A;
Expand Down
2 changes: 1 addition & 1 deletion readNonMat.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function probTypeCheck(maxReg, minReg, objVarName, type) {
} else {
var msg = "Odd, your problem doesn't seem to be either a maximization";
msg += " or minimization problem";
console.error(msg);
alert(msg);
}
return type;
}
Expand Down
14 changes: 7 additions & 7 deletions sensAnalysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ function addVariable() {
if (newACols.length != m) {
var msg = "The newly entered A does not have the same number of ";
msg += "rows as the original A";
console.error(msg);
alert(msg);
shouldDie = true;
return [A, b, cj, x, xB, shouldDie];
} else if (newcRows.length != newACols[0].length) {
var msg = "The number of elements in the c field does not equal the ";
msg += "number of columns in the A field.";
console.error(msg);
alert(msg);
shouldDie = true;
return [A, b, cj, x, xB, shouldDie];
} else if (newcRows.length != newxRows.length) {
var msg = "The number of elements in the c field does not equal the ";
msg += "number of elements in the x field.";
console.error(msg);
alert(msg);
shouldDie = true;
return [A, b, cj, x, xB, shouldDie];
}
Expand Down Expand Up @@ -115,7 +115,7 @@ function constrCoeffsChange() {
shouldDie = true;
var msg = "The dimensions of the new A do not match the dimensions";
msg += " of A in the final tableau.";
console.error(msg);
alert(msg);
return [A, b, cj, x, xB, shouldDie];
}

Expand All @@ -132,7 +132,7 @@ function constrCoeffsChange() {
// variables have been modified
var msg = "If the coefficients of basic variables change,";
msg += " you must solve the problem from scratch again!";
console.error(msg);
alert(msg);
shouldDie = true;
return [A, b, cj, x, xB, shouldDie];
}
Expand Down Expand Up @@ -171,7 +171,7 @@ function objectiveChange() {
// of decision variables
if (cj.length != x.length) {
shouldDie = true;
console.error("c and x do not match in length!");
alert("c and x do not match in length!");
return [A, b, cj, x, xB, shouldDie];
}

Expand Down Expand Up @@ -200,7 +200,7 @@ function resourceChange() {
// New b array should have the same number of rows as A
if (b.length != A.length) {
shouldDie = true;
console.error("A and b do not match in their row length!");
alert("A and b do not match in their row length!");
return [A, b, cj, x, xB, shouldDie];
}

Expand Down
7 changes: 7 additions & 0 deletions simplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ function simplexIterator(A, b, cj, x, xB, sign, objVarName) {
// If problem is already optimal, just tabulate the solution
if (isOptim) {
tempStr += "Solution is already optimal.";

// Draw final tableau
genTableau(A, b, cj, x, xB, {isFeas: isFeas, isOptim: isOptim});

// Update finals before showSolution, in case there's alt sol
updateFinals(A, b, cj, x, xB, zj, zc);

// Show solution
showSolution(A, b, cj, x, xB, zj, zc, sign, objVarName);
}

Expand Down

0 comments on commit dd495c0

Please sign in to comment.