Prev Next Index-> contents reference index search external Up-> CppAD ADFun abs_normal lp_box lp_box.hpp ADFun-> record_adfun drivers Forward Reverse sparsity_pattern sparse_derivative optimize abs_normal FunCheck check_for_nan abs_normal-> abs_normal_fun abs_print_mat abs_eval simplex_method lp_box abs_min_linear min_nso_linear qp_interior qp_box abs_min_quad min_nso_quad lp_box-> lp_box.cpp lp_box.hpp lp_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}} }$
lp_box Source Code
namespace CppAD { // BEGIN_CPPAD_NAMESPACE

// BEGIN PROTOTYPE
template <class Vector>
bool lp_box(
size_t        level   ,
const Vector& A       ,
const Vector& b       ,
const Vector& c       ,
const Vector& d       ,
size_t        maxitr  ,
Vector&       xout    )
// END PROTOTYPE
{     double inf = std::numeric_limits<double>::infinity();
//
size_t m = b.size();
size_t n = c.size();
//
level <= 3, "lp_box: level is greater than 3");
size_t(A.size()) == m * n, "lp_box: size of A is not m * n"
);
size_t(d.size()) == n, "lp_box: size of d is not n"
);
if( level > 0 )
{     std::cout << "start lp_box\n";
}
//
// count number of limits
size_t n_limit = 0;
for(size_t j = 0; j < n; j++)
{     if( d[j] < inf )
n_limit += 1;
}
//
// A_simplex and b_simplex define the extended constraints
Vector A_simplex((m + 2 * n_limit) * (2 * n) ), b_simplex(m + 2 * n_limit);
for(size_t i = 0; i < size_t(A_simplex.size()); i++)
A_simplex[i] = 0.0;
//
// put A * x + b <= 0 in A_simplex, b_simplex
for(size_t i = 0; i < m; i++)
{     b_simplex[i] = b[i];
for(size_t j = 0; j < n; j++)
{     // x_j^+ coefficient (positive component)
A_simplex[i * (2 * n) + 2 * j]     =   A[i * n + j];
// x_j^- coefficient (negative component)
A_simplex[i * (2 * n) + 2 * j + 1] = - A[i * n + j];
}
}
//
// put | x_j | <= d_j in A_simplex, b_simplex
size_t i_limit = 0;
for(size_t j = 0; j < n; j++) if( d[j] < inf )
{
// x_j^+ <= d_j constraint
b_simplex[ m + 2 * i_limit]                         = - d[j];
A_simplex[(m + 2 * i_limit) * (2 * n) + 2 * j]      = 1.0;
//
// x_j^- <= d_j constraint
b_simplex[ m + 2 * i_limit + 1]                         = - d[j];
A_simplex[(m + 2 * i_limit + 1) * (2 * n) + 2 * j + 1]  = 1.0;
//
++i_limit;
}
//
// c_simples
Vector c_simplex(2 * n);
for(size_t j = 0; j < n; j++)
{     // x_j+ component
c_simplex[2 * j]     = c[j];
// x_j^- component
c_simplex[2 * j + 1] = - c[j];
}
size_t level_simplex = 0;
if( level >= 2 )
level_simplex = level - 1;
//
Vector x_simplex(2 * n);
level_simplex, A_simplex, b_simplex, c_simplex, maxitr, x_simplex
);
for(size_t j = 0; j < n; j++)
xout[j] = x_simplex[2 * j] - x_simplex[2 * j + 1];
if( level > 0 )
} // END_CPPAD_NAMESPACE