package com.imsl.test.example.math; import com.imsl.math.*; /** *

Illustrates the exception thrown by the solver when it encounters * inconsistent style 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 InconsistentSystemException to be thrown.

* @see Code * @see Output */ public class QuadraticProgrammingEx3 { public static void main(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 com.imsl.math.PrintMatrix("Solution").print(x); } catch (Exception e) { WriteCutString(e.getMessage(), 72); } } public static void WriteCutString(String value, int interval) { int rem = value.length() % interval; int len = value.length() / interval + rem / (1 > rem ? 1 : rem); for (int i = 0; i < len; i++) { System.out.println(value.substring(i * interval, (i * interval) + (interval < (value.length() - i * interval) ? interval : (value.length() - i * interval)))); } } }