Prev Next Index-> contents reference index search external Up-> CppAD ADFun abs_normal simplex_method simplex_method.cpp 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 simplex_method-> simplex_method.cpp simplex_method.hpp simplex_method.cpp Headings-> Problem Source

$\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}} }$
abs_normal simplex_method: Example and Test

Problem
Our original problem is $$\R{minimize} \; | u - 1| \; \R{w.r.t} \; u \in \B{R}$$ We reformulate this as the following problem $$\begin{array}{rlr} \R{minimize} & v & \R{w.r.t} \; (u,v) \in \B{R}^2 \\ \R{subject \; to} & u - 1 \leq v \\ & 1 - u \leq v \end{array}$$ We know that the value of $v$ at the solution is greater than or equal zero. Hence we can reformulate this problem as $$\begin{array}{rlr} \R{minimize} & v & \R{w.r.t} \; ( u_- , u_+ , v) \in \B{R}_+^3 \\ \R{subject \; to} & u_+ - u_- - 1 \leq v \\ & 1 - u_+ + u_- \leq v \end{array}$$ This is equivalent to $$\begin{array}{rlr} \R{minimize} & (0, 0, 1) \cdot ( u_+, u_- , v)^T & \R{w.r.t} \; (u,v) \in \B{R}_+^3 \\ \R{subject \; to} & \left( \begin{array}{ccc} +1 & -1 & -1 \\ -1 & +1 & +1 \end{array} \right) \left( \begin{array}{c} u_+ \\ u_- \\ v \end{array} \right) + \left( \begin{array}{c} -1 \\ 1 \end{array} \right) \leq 0 \end{array}$$ which is in the form expected by simplex_method .

Source

# include <limits>
# include "simplex_method.hpp"

bool simplex_method(void)
{     bool ok = true;
double eps99 = 99.0 * std::numeric_limits<double>::epsilon();
//
size_t n = 3;
size_t m = 2;
vector A(m * n), b(m), c(n), xout(n);
A[ 0 * n + 0 ] =  1.0; // A(0,0)
A[ 0 * n + 1 ] = -1.0; // A(0,1)
A[ 0 * n + 2 ] = -1.0; // A(0,2)
//
A[ 1 * n + 0 ] = -1.0; // A(1,0)
A[ 1 * n + 1 ] = +1.0; // A(1,1)
A[ 1 * n + 2 ] = -1.0; // A(1,2)
//
b[0]           = -1.0;
b[1]           =  1.0;
//
c[0]           =  0.0;
c[1]           =  0.0;
c[2]           =  1.0;
//
size_t maxitr  = 10;
size_t level   = 0;
//
ok &= CppAD::simplex_method(level, A, b, c,  maxitr, xout);
//
// check optimal value for u
ok &= std::fabs( xout[0] - 1.0 ) < eps99;
//
// check optimal value for v
ok &= std::fabs( xout[1] ) < eps99;
//
return ok;
}

Input File: example/abs_normal/simplex_method.cpp