public static BigTableau CreateBigTableau(ArtEqSimplexProblem p, Action<string, object> notify) { if (notify != null) { notify("Problem:", p); } int m = p.A.Length; int n = p.c.Length; int nVars = n - m; double[][] t = new double[m + 1][]; for (int i = 0; i < m; i++) { t[i] = new double[n + 1]; Array.Copy(p.A[i], t[i], n); t[i][n] = p.b[i]; } t[m] = new double[n + 1]; for (int i = 0; i < n; i++) { t[m][i] = -p.c[i]; } int[] ind = new int[m]; for (int i = 0; i < ind.Length; i++) { ind[i] = nVars + i; } BigTableau bt = new BigTableau(m, n, t, ind); if (notify != null) { notify("Artificial tableau before new objectives:", bt); } // Solving the new objective function. for (int j = 0; j <= n; j++) { t[m][j] = 0; } for (int i = 0; i < p.art.Length; i++) { for (int j = 0; j < m; j++) { t[m][j] -= t[p.art[i] - nVars][j]; } t[m][n] -= t[p.art[i] - nVars][n]; } if (notify != null) { notify("Artificial tableau after new objectives:", bt); } return bt; }
public static BigTableau EliminateArtificials(BigTableau bt, ArtEqSimplexProblem p, EqSimplexProblem pOrig) { int nVars = bt.n - bt.m; int n2 = bt.n - p.art.Length; double[][] t = new double[bt.m + 1][]; for (int i = 0; i <= bt.m; i++) { t[i] = new double[n2 + 1]; } int k = 0; for (int j = 0; j < bt.n; j++) { if (j >= nVars && p.baseVar[j - nVars] == -1) { continue; } for (int i = 0; i < bt.m; i++) { t[i][k] = bt.t[i][j]; } k++; } // Copy RHS. for (int i = 0; i < bt.m; i++) { t[i][n2] = bt.t[i][bt.n]; } // Restoring the indices. int[] ind = (int[])bt.ind.Clone(); for (int i = 0; i < ind.Length; i++) { if (ind[i] >= nVars) { ind[i] = p.baseVar[ind[i] - nVars]; } } bool[] nonBase = NonBase2(ind, n2); // Solving the new objective function. for (int j = 0; j <= n2; j++) { if (!nonBase[j]) { continue; } for (int i = 0; i < bt.m; i++) { Console.WriteLine(j + " " + i + " ::: " + ind[i] + " " + t[i][j] + " " + pOrig.c[ind[i]]); t[bt.m][j] += t[i][j] * pOrig.c[ind[i]]; } } return new BigTableau(bt.m, n2, t, ind); }
public BigTableau simplexEqArtTableau(ArtEqSimplexProblem p) { return Simplex.CreateBigTableau(p, notify); }