//by Ftkvyn public static void ExampleGenIt9() { //ans = [0 0 0 5 0.5 4.5] Matrix a = MatrixGenerator.From( new double[,]{{0, 2, 0, 1, -2, 0}, {0, 3, 2, 0, -3, 1}, {1, 4, 1, 0, 4, 0}}); Matrix c = MatrixGenerator.From(new double[,] { { -3, 2, 4, 5, 1, 6 } }).Transpose(); Matrix xBase = MatrixGenerator.From(new double[,] { {2, 0, 0, 4, 0, 3 } }).Transpose(); List<int> baseIndexes = new List<int>(new[] { 0, 3, 5 }); var sm = new SimplexMethodGeneralIteration(a, c, xBase, baseIndexes); Matrix ans = null; bool isSolved = sm.Solve(out ans); Console.WriteLine("IsSolved: {0}\nSolution:\n{1}", isSolved, isSolved ? ans.ToString() : ""); }
public bool SolveWithoutXBase(out Matrix x) { int n = m_matrixA.ColumnsCount; int m = m_matrixA.RowsCount; Matrix cNew = new Matrix(n +m, 1); for (int i = 0; i < n + m; i++) { cNew[i, 0] = i < n ? m_matrixC[i, 0] : -100000000; } Matrix aNew = new Matrix(m, n + m); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { aNew[i, j] = m_matrixA[i, j]; } } for (int j=0; j < m; j++) { aNew[j, j + n] = m_matrixB[j, 0] < 0 ? -1 : 1; } Matrix xBaseNew = new Matrix(n + m, 1); for (int i = 0; i < m_matrixB.RowsCount; i++) { xBaseNew[i + n, 0] = Math.Abs(m_matrixB[i, 0]); } List<int> jBNew = Enumerable.Range(n, m).ToList(); var sm = new SimplexMethodGeneralIteration(aNew, cNew, xBaseNew, jBNew); Matrix ansNew = null; x = null; if (!sm.Solve(out ansNew)) { return false; } for (int i = n; i < m + n; i++) { if (!IsEqualToZero(ansNew[i, 0])) { return false; } } x = new Matrix(n, 1); for (int i = 0; i < n; i++) { x[i, 0] = ansNew[i, 0]; } return true; }
//from p.15/task5/ex3 public static void ExampleGenIt6() { //det = 0 Matrix a = MatrixGenerator.From( new double[,]{ {3,1,2,6,9,3}, {1,2,-1,2,3,1}}); Matrix c = MatrixGenerator.From(new double[,] { {-2,1,1,-1,4,1 } }).Transpose(); Matrix xBase = MatrixGenerator.From(new double[,] { {1,0,0,0,0,4 } }).Transpose(); List<int> baseIndexes = new List<int>(new[] { 0,5 }); var sm = new SimplexMethodGeneralIteration(a, c, xBase, baseIndexes); Matrix ans = null; bool isSolved = sm.Solve(out ans); Console.WriteLine("IsSolved: {0}\nSolution:\n{1}", isSolved, isSolved ? ans.ToString() : ""); }
//by Ftkvyn public static void ExampleGenIt8() { //ans = [0 80 200 0 0] Matrix a = MatrixGenerator.From( new double[,]{{5, 10, 6, 1, 0}, {4, 5, 8, 0, 1}}); Matrix c = MatrixGenerator.From(new double[,] { { 1, 3, 3, 0, 0 } }).Transpose(); Matrix xBase = MatrixGenerator.From(new double[,] { { 0, 0, 0, 2000, 2000 } }).Transpose(); List<int> baseIndexes = new List<int>(new[] { 3, 4 }); var sm = new SimplexMethodGeneralIteration(a, c, xBase, baseIndexes); Matrix ans = null; bool isSolved = sm.Solve(out ans); Console.WriteLine("IsSolved: {0}\nSolution:\n{1}", isSolved, isSolved ? ans.ToString() : ""); }
//from p.15/task5/ex1 public static void ExampleGenIt4() { //1 0 0 4 Matrix a = MatrixGenerator.From( new double[,]{ {1, 4, 4, 1}, {1, 7, 8, 2}}); Matrix c = MatrixGenerator.From(new double[,] { { 1, -3, -5, -1 } }).Transpose(); Matrix xBase = MatrixGenerator.From(new double[,] { { 1, 0, 1, 0 } }).Transpose(); List<int> baseIndexes = new List<int>(new[] { 0,2 }); var sm = new SimplexMethodGeneralIteration(a, c, xBase, baseIndexes); Matrix ans = null; bool isSolved = sm.Solve(out ans); Console.WriteLine("IsSolved: {0}\nSolution:\n{1}", isSolved, isSolved ? ans.ToString() : ""); }
//by S.Majonov public static void ExampleGenIt2() { //ans = (5,1,3,0,0) Matrix a = MatrixGenerator.From( new double[,]{{1, 7, -1, 7, -8}, {0, 1, 8, 9, 7}, {0, 0, 1, 1, 1}}); Matrix c = MatrixGenerator.From(new double[,] {{1, 2, 1, 3, -2}}).Transpose(); Matrix xBase = MatrixGenerator.From(new double[,] {{3, 0, 0, 2, 1}}).Transpose(); List<int> baseIndexes = new List<int>(new[] { 0, 3, 4 }); var sm = new SimplexMethodGeneralIteration(a, c, xBase, baseIndexes); Matrix ans = null; bool isSolved = sm.Solve(out ans); Console.WriteLine("IsSolved: {0}\nSolution:\n{1}", isSolved, isSolved ? ans.ToString() : ""); }
//on Lab Ex. 5.139 public static void ExampleGenIt12() { //[3 0 7 0 5 0 5 0] Matrix a = MatrixGenerator.From( new double[,]{{0,3,1,0,1,3,1,5}, {1,6,0,0,2,3,2,5}, {1,4,2,-2,0,5,2,11}, {1,2,2,2,2,7,0,7}}); Matrix c = MatrixGenerator.From(new double[,] { { 1, 2, 1, -2, 1, 2, 1, -2 } }).Transpose(); Matrix xBase = MatrixGenerator.From(new double[,] { { 0,2,0,1,0,2,0,1} }).Transpose(); List<int> baseIndexes = new List<int>(new[] { 1,3,5,7 }); var sm = new SimplexMethodGeneralIteration(a, c, xBase, baseIndexes); Matrix ans = null; bool isSolved = sm.Solve(out ans); Console.WriteLine("IsSolved: {0}\nSolution:\n{1}", isSolved, isSolved ? ans.ToString() : ""); }
//by Ftkvyn public static void ExampleGenIt10() { //ans = [0 0 0 3,(5) 14,(4) 2,(3)] //by ftkvyn ans=[] Matrix a = MatrixGenerator.From( new double[,]{{1, 0, 0, 2, -1, 4}, {0, 1, 0, -3, 0, 5}, {0, 0, 1, 1, 1, -6}}); Matrix c = MatrixGenerator.From(new double[,] { { 1, 1, 1, 2, 4, -2 } }).Transpose(); Matrix xBase = MatrixGenerator.From(new double[,] { { 2, 1, 4, 0, 0, 0 } }).Transpose(); List<int> baseIndexes = new List<int>(new[] { 0, 1, 2 }); var sm = new SimplexMethodGeneralIteration(a, c, xBase, baseIndexes); Matrix ans = null; bool isSolved = sm.Solve(out ans); Console.WriteLine("IsSolved: {0}\nSolution:\n{1}", isSolved, isSolved ? ans.ToString() : ""); }
//page 13 //ans = [0, 1, 0, 3] public static void ExampleGenIt1() { Matrix a = new Matrix(2, 4); a[0, 0] = 3; a[0, 1] = 1; a[0, 2] = 1; a[0, 3] = 0; a[1, 0] = 1; a[1, 1] = -2; a[1, 2] = 0; a[1, 3] = 1; Matrix c = new Matrix(4, 1); c[0, 0] = 1; c[1, 0] = 4; c[2, 0] = 1; c[3, 0] = -1; Matrix xBase = new Matrix(4, 1); xBase[0, 0] = 0; xBase[1, 0] = 0; xBase[2, 0] = 1; xBase[3, 0] = 1; List<int> baseIndexes = new List<int>(new[] { 2, 3 }); var sm = new SimplexMethodGeneralIteration(a, c, xBase, baseIndexes); Matrix ans = null; bool isSolved = sm.Solve(out ans); Console.WriteLine("IsSolved: {0}\nSolution:\n{1}", isSolved, ans.ToString()); }