|
Prev
| Next
|
|
|
|
|
|
qp_box.hpp |
Headings |
@(@\newcommand{\W}[1]{ \; #1 \; }
\newcommand{\R}[1]{ {\rm #1} }
\newcommand{\B}[1]{ {\bf #1} }
\newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} }
\newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} }
\newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} }
\newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@This is cppad-20221105 documentation. Here is a link to its
current documentation
.
qp_box Source Code
namespace CppAD { // BEGIN_CPPAD_NAMESPACE
// BEGIN PROTOTYPE
template <class Vector>
bool qp_box(
size_t level ,
const Vector& a ,
const Vector& b ,
const Vector& c ,
const Vector& C ,
const Vector& g ,
const Vector& G ,
double epsilon ,
size_t maxitr ,
const Vector& xin ,
Vector& xout )
// END PROTOTYPE
{ double inf = std::numeric_limits<double>::infinity();
//
size_t n = a.size();
size_t m = c.size();
//
CPPAD_ASSERT_KNOWN(level <= 2, "qp_interior: level is greater than 2");
CPPAD_ASSERT_KNOWN(
size_t(b.size()) == n, "qp_box: size of b is not n"
);
CPPAD_ASSERT_KNOWN(
size_t(C.size()) == m * n, "qp_box: size of C is not m * n"
);
CPPAD_ASSERT_KNOWN(
size_t(g.size()) == n, "qp_box: size of g is not n"
);
CPPAD_ASSERT_KNOWN(
size_t(G.size()) == n * n, "qp_box: size of G is not n * n"
);
if( level > 0 )
{ std::cout << "start qp_box\n";
CppAD::abs_print_mat("a", n, 1, a);
CppAD::abs_print_mat("b", n, 1, b);
CppAD::abs_print_mat("c", m, 1, c);
CppAD::abs_print_mat("C", m, n, C);
CppAD::abs_print_mat("g", 1, n, g);
CppAD::abs_print_mat("G", n, n, G);
CppAD::abs_print_mat("xin", n, 1, xin);
}
//
// count number of lower and upper limits
size_t n_limit = 0;
for(size_t j = 0; j < n; j++)
{ CPPAD_ASSERT_KNOWN(G[j * n + j] >= 0.0, "qp_box: G_{j,j} < 0.0");
if( -inf < a[j] )
++n_limit;
if( b[j] < inf )
++n_limit;
}
//
// C_int and c_int define the extended constraints
Vector C_int((m + n_limit) * n ), c_int(m + n_limit);
for(size_t i = 0; i < size_t(C_int.size()); i++)
C_int[i] = 0.0;
//
// put C * x + c <= 0 in C_int, c_int
for(size_t i = 0; i < m; i++)
{ c_int[i] = c[i];
for(size_t j = 0; j < n; j++)
C_int[i * n + j] = C[i * n + j];
}
//
// put I * x - b <= 0 in C_int, c_int
size_t i_limit = 0;
for(size_t j = 0; j < n; j++) if( b[j] < inf )
{ c_int[m + i_limit] = - b[j];
C_int[(m + i_limit) * n + j] = 1.0;
++i_limit;
}
//
// put a - I * x <= 0 in C_int, c_int
for(size_t j = 0; j < n; j++) if( -inf < a[j] )
{ c_int[m + i_limit] = a[j];
C_int[(m + i_limit) * n + j] = -1.0;
++i_limit;
}
Vector yout(m + n_limit), sout(m + n_limit);
size_t level_int = 0;
if( level == 2 )
level_int = 1;
bool ok = qp_interior( level_int,
c_int, C_int, g, G, epsilon, maxitr, xin, xout, yout, sout
);
if( level > 0 )
{ if( level < 2 )
CppAD::abs_print_mat("xout", n, 1, xout);
if( ok )
std::cout << "end q_box: ok = true\n";
else
std::cout << "end q_box: ok = false\n";
}
return ok;
}
} // END_CPPAD_NAMESPACE
Input File: example/abs_normal/qp_box.omh