| Prev | Next |  |  |  |  |  | qp_interior.cpp |

abs_normal qp_interior: Example and Test
Problem
Our original problem is minimize | u - 1 | w . r . t u ∈ R We reformulate this as the following problem minimize v w . r . t ( u , v ) ∈ R 2 subject to u - 1 ≤ v 1 - u ≤ v This is equivalent to minimize ( 0 , 1 ) · ( u , v ) T w . r . t ( u , v ) ∈ R 2 subject to ( 1 -1 -1 -1 ) ( u v ) + ( -1 1 ) ≤ 0 which is in the form expected by qp_interior .
Source

    # include <limits>
    # include <cppad/utility/vector.hpp>
    # include "qp_interior.hpp"

    bool qp_interior(void)
    {     bool ok = true;
         typedef CppAD::vector<double> vector;
         //
         size_t n = 2;
         size_t m = 2;
         vector C(m*n), c(m), G(n*n), g(n), xin(n), xout(n), yout(m), sout(m);
         C[ 0 * n + 0 ] =  1.0; // C(0,0)
         C[ 0 * n + 1 ] = -1.0; // C(0,1)
         C[ 1 * n + 0 ] = -1.0; // C(1,0)
         C[ 1 * n + 1 ] = -1.0; // C(1,1)
         //
         c[0]           = -1.0;
         c[1]           =  1.0;
         //
         g[0]           =  0.0;
         g[1]           =  1.0;
         //
         // G = 0
         for(size_t i = 0; i < n * n; i++)
              G[i] = 0.0;
         //
         // If (u, v) = (0,2), C * (u, v) + c = (-2,-2)^T + (1,-1)^T < 0
         // Hence (0, 2) is feasible.
         xin[0] = 0.0;
         xin[1] = 2.0;
         //
         double epsilon = 99.0 * std::numeric_limits<double>::epsilon();
         size_t maxitr  = 10;
         size_t level   = 0;
         //
         ok &= CppAD::qp_interior(
              level, c, C, g, G, epsilon, maxitr, xin, xout, yout, sout
         );
         //
         // check optimal value for u
         ok &= std::fabs( xout[0] - 1.0 ) < epsilon;
         // check optimal value for v
         ok &= std::fabs( xout[1] ) < epsilon;
         //
         return ok;
    }

Input File: example/abs_normal/qp_interior.cpp