-
Notifications
You must be signed in to change notification settings - Fork 0
/
permDegn.js
45 lines (43 loc) · 1.29 KB
/
permDegn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Update tempStr to mention if problem is degenerate.
*
* @param b 1d array of solution values for the final solution.
* @param xB 1d array of basic variables as strings.
* @return Nothing, just adds to tempStr.
*/
function checkForDegn(b, xB) {
// Formatting details for subscripts of degenerate basis variable.
var format = {isBold: false, isRow: false, isLeftArrow: false, isDownArrow: false};
var loc = zeroIndices(b);
var noOfZeros = loc.length;
if (noOfZeros > 0) {
tempStr += "Solution is permanently degenerate in ";
}
// Loop through b, look for zero entry and print degeneracy message
for (let i = 0 ; i < noOfZeros; i++) {
var j = loc[i];
tempStr += subscripts(xB[j], format);
if (i == noOfZeros-2) {
tempStr += " and ";
} else if (i < noOfZeros-2) {
tempStr += ", ";
} else {
tempStr += ". ";
}
}
}
/**
* Return a 1d array of where in b zeros are found.
*
* @param b Array for which the location of zeros is to be determined.
* @return 1d array of indices (integers).
*/
function zeroIndices(b) {
var loc = [];
for (let i = 0 ; i < b.length; i++) {
if (floatCor(b[i]) == 0) {
loc.push(i);
}
}
return loc;
}