Exemplo n.º 1
0
 public void Test03()
 {
     for (var i = 0; i < 10000; ++i)
     {
         // x + y <= 1, -y->max
         var A = new[] { new[] { 1m, 1 } };
         var b = new[] { 1m };
         var c = new[] { 0m, -1 };
         var eq = new SeideProblem(A, b, c);
         decimal[] x;
         decimal val;
         var res = eq.Solv(out x, out val);
         Assert.AreEqual(res, SimplexResult.Optimal);
         Assert.AreEqual(0, x[1]);
         Assert.AreEqual(1, x[0]);
         Assert.AreEqual(0, val);
     }
 }
Exemplo n.º 2
0
 public void Test05()
 {
     for (var i = 0; i < 10000; ++i)
     {
         // 2x1 + x2 <= 64, x1 + 3x2 <= 72, x2 <= 20, 4x1 + 6x2->max
         var A = new[]
         {
             new[] { 2m, 1 },
             new[] { 1m, 3 },
             new[] { 0m, 1 }
         };
         var b = new[] { 64m, 72, 20 };
         var c = new[] { 4m, 6 };
         var eq = new SeideProblem(A, b, c);
         decimal[] x;
         decimal val;
         var res = eq.Solv(out x, out val);
         Assert.AreEqual(res, SimplexResult.Optimal);
         Assert.AreEqual(24m, x[0]);
         Assert.AreEqual(16m, x[1]);
         Assert.AreEqual(192m, val);
     }
 }
Exemplo n.º 3
0
 public void Test04()
 {
     for (var i = 0; i < 10000; ++i)
     {
         //x+y+z<=1, x-y <= 0, -x-y->max
         var A = new[]
         {
             new[] { 1m, 1, 1 },
             new[] { 1m, -1, 0 }
         };
         var b = new[] { 1m, 0 };
         var c = new[] { -1m, -1, 0 };
         var eq = new SeideProblem(A, b, c);
         decimal[] x;
         decimal val;
         var res = eq.Solv(out x, out val);
         Assert.AreEqual(res, SimplexResult.Optimal);
         Assert.AreEqual(0m, x[0]);
         Assert.AreEqual(0m, x[1]);
         Assert.AreEqual(1m, x[2]);
         Assert.AreEqual(0m, val);
     }
 }
Exemplo n.º 4
0
 public void Test06()
 {
     for (var i = 0; i < 10000; ++i)
     {
         //-3x1 - 4x2 <= -6, x1 + 3x2 - y <= 3, 2x1 + x2 <= 4, y <= 0 4x1 + 16x2->max
         var A = new[]
         {
             new[] { -3m, -4, 0 },
             new[] { 1m, 3, -1 },
             new[] { 2m, 1, 0 },
             new[] { 0m, 0, 1 }
         };
         var b = new[] { -6m, 3, 4, 0 };
         var c = new[] { 4m, 16, 0 };
         var eq = new SeideProblem(A, b, c);
         decimal[] x;
         decimal val;
         var res = eq.Solv(out x, out val);
         Assert.AreEqual(SimplexResult.Optimal, res);
         Assert.AreEqual(6m / 5, Math.Round(x[0], 2));
         Assert.AreEqual(3m / 5, Math.Round(x[1], 2));
         Assert.AreEqual(0m, x[2]);
         Assert.AreEqual(72m / 5, Math.Round(val, 2));
     }
 }