-
-
Save clhodapp/1359172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Tableau makeArtificial() { | |
Matrix tmp = getA().mergeRight(Matrix.identity(constraints)).mergeRight(getRHS()); //insert identity | |
tmp = tmp.mergeDown(new Matrix(1,vars).extend(0,constraints,1d).extend(0,1)); //add new cost row | |
return new Tableau(tmp); | |
} | |
vs | |
public Tableau makeArtificial() { | |
Double[][] tmp = new Double[height][width+height-1]; | |
int tmpwidth = width+height-1; | |
int tmpcost = costRow; | |
int tmpbCol = tmpwidth - 1; | |
for(int i = 0; i < constraints; i++) { //rows but cost row | |
for (int j = 0; j < vars; j++) { //original cols | |
tmp[i][j] = matrix[i][j]; | |
} | |
for (int j = 0; j < constraints; j++) { //artificial cols | |
tmp[i][vars+j] = (i == j) ? 1d : 0d; | |
} | |
} | |
for (int i = 0; i < constraints; i++) { //bCol | |
tmp[i][tmpbCol] = matrix[i][bCol]; | |
} | |
for(int j = 0; j < vars+constraints; j++) { //cost row | |
tmp[tmpcost][j] = (j < vars) ? 0d : 1d; | |
} | |
tmp[tmpcost][tmpbCol] = 0d; //-z | |
return new Tableau(tmp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment