Example 3: Solve a Quadratic Programming Problem with Inconsistent System Constraints

In the quadratic programming problem variables 2 and 6 are fixed at the value zero by the equality constraints. The inequalities propose that the sums of the variables are at least 5.1 and no more than 4.9. These last two are inconsistent conditions, causing the NoLPSolutionException to be thrown.

using System;
using Imsl.Math;

public class QuadraticProgrammingEx3
{

   public static void Main(System.String[] args)
   {
      double[,] h = {
            {2.000, 0.000, 0.000, 0.000, 0.000, 0.000},
            {0.000, 2.000, 0.000, 0.000, 0.000, 0.000},
            {0.000, 0.000, 2.000, 0.000, 0.000, 0.000},
            {0.000, 0.000, 0.000, 2.000, 0.000, 0.000},
            {0.000, 0.000, 0.000, 0.000, 2.000, 0.000},
            {0.000, 0.000, 0.000, 0.000, 0.000, 2.000}};
      double[] g = { 5.000, 5.000, 5.000, 5.000, 5.000, 5.000 };
      double[,] aEquality = {
            {0.000, 1.000, 0.000, 0.000, 0.000, 0.000},
            {0.000, 0.000, 0.000, 0.000, 0.000, 1.000}};
      double[] bEquality = { 0.000, 0.000 };

      double[,] aInequality = {
            {1.000, 1.000, 1.000, 1.000, 1.000, 1.000},
            {-1.000, -1.000, -1.000, -1.000, -1.000, -1.000}};
      double delta = 0.1; // change to 0.0 to pass
      double[] bInequality = { 5 + delta, -5 + delta };

      try
      {
         QuadraticProgramming qp = new QuadraticProgramming(h, g,
             aEquality, bEquality, aInequality, bInequality);
         double[] x = qp.GetSolution();
         new Imsl.Math.PrintMatrix("Solution").Print(x);
      }
      catch (Imsl.Math.NoLPSolutionException e)
      {
         WriteCutString(e.Message, 72);

      }
      catch (System.Exception e)
      {
         WriteCutString(e.Message, 72);
      }
   }

   public static void WriteCutString(string value, int interval)
   {
      int rem = value.Length % interval;
      int result = value.Length / interval + rem / 
          (1 > rem ? 1 : rem);
      for (int i = 0; i < result; i++)
      {
         Console.WriteLine(value.Substring(i * interval,
            (interval < (value.Length - i * interval)) ? interval : 
            (value.Length - i * interval)));
      }
   }
}

Output

No solution for the LP problem was found. All constraints are not satisf
ied. L1 minimization was applied to all constraints (including bounds an
d simple variables) but the equalities, to approximate violated non-equa
lities as well as possible.  If a feasible solution is possible then try
 using refinement.

Link to C# source.