/home/coin/SVN-release/OS-1.0.0/OS/examples/algorithmicDiff/algorithmicDiffTest.cpp File Reference

#include <cstddef>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <stack>
#include <cppad/cppad.hpp>
#include <iostream>
#include "CoinHelperFunctions.hpp"
#include "OSInstance.h"
#include "OSiLWriter.h"
#include "OSParameters.h"
#include "OSnLNode.h"
#include "ErrorClass.h"
#include "FileUtil.h"
#include "OSiLReader.h"
#include "OSExpressionTree.h"
#include "OSDataStructures.h"
#include <vector>
#include <map>
#include <string>

Include dependency graph for algorithmicDiffTest.cpp:

Go to the source code of this file.

Functions

int main ()
bool CheckFunctionValues (double *conVals, double objValue, double x0, double x1, double x2, double x3, double z0, double z1, double w)
bool CheckGradientValues (SparseJacobianMatrix *sparseJac, double *objGrad, double x0, double x1, double x2, double x3, double y0, double y1, double w)
bool CheckHessianUpper (SparseHessianMatrix *sparseHessian, double x0, double x1, double x2, double x3, double z0, double z1, double w)


Detailed Description

Author:
Robert Fourer, Jun Ma, Kipp Martin,
Version:
1.0, 10/05/2005
Since:
OS1.0
Remarks:
Copyright (C) 2005, Robert Fourer, Jun Ma, Kipp Martin, Northwestern University, and the University of Chicago. All Rights Reserved. This software is licensed under the Common Public License. Please see the accompanying LICENSE file in root directory for terms.
This example illustrates the alrorithmic differentiation features of the OS library

The test problem CppADTestLag.osil:

min x0^2 + 9*x1 -- w[0]
s.t.
33 - 105 + 1.37*x1 + 2*x3 + 5*x1 <= 10 -- y[0]
ln(x0*x3) + 7*x2 >= 10 -- y[1]
Note: in the first constraint 33 is a constant term and 105
is part of the nl node
the Jacobian is:

2*x0 9 0 0
0 6.37 0 2
1/x0 0 7 1/x3

now set x0 = 1, x1 = 5, x2 = 10, x3 = 5

the Jacobian is

2 9 0 0
0 6.37 0 2
1 0 7 .2

Now form a Lagrangian with multipliers of w on the objective z0 the multiplier on the first constraint and z1 on the second the Lagrangain is then:

L = w*(x0^2 + 9*x1) + z0*(1 + 1.37*x1 + 2*x3 + 5*x1) + z1*(log(x0*x3) + 7*x2)

the partial with respect x0
L_0 = 2 * w * x0 + z1 / x0

the partial with respect x1
L_1 = w * 9 + z0*1.37 + z0*5

the partial with respect x2
L_2 = z1*7

the partial with respect x3
L_3 = z0*2 + z1/x3

in the Hessian there are only two nonzero terms
L_00 = 2 * w - z1 / ( x0 * x0 )
L_33 = - z1 / (x3 * x3)

IMPORTANT: the forwardAD and reverseAD calls ONLY apply to the nonlinear part of the problem. The 9*x1 term in the objective is not part of the AD calculation nor are any terms in <linearConstraintCoefficients> that DO NOT appear in any nl nodes, for example the 7*x3 term in constraint with index 1. Note also, that there are only three variables that appear in nl nodes, x3 does not

Definition in file algorithmicDiffTest.cpp.


Function Documentation

int main (  ) 

Definition at line 100 of file algorithmicDiffTest.cpp.

References OSInstance::bUseExpTreeForFunEval, OSInstance::calculateAllConstraintFunctionGradients(), OSInstance::calculateAllConstraintFunctionValues(), OSInstance::calculateAllObjectiveFunctionValues(), OSInstance::calculateFunctionValue(), OSInstance::calculateHessian(), OSInstance::calculateLagrangianHessian(), OSInstance::calculateObjectiveFunctionGradient(), CheckFunctionValues(), CheckGradientValues(), CheckHessianUpper(), SparseJacobianMatrix::conVals, OSInstance::forwardAD(), OSInstance::getAllNonlinearVariablesIndexMap(), OSInstance::getConstraintNumber(), FileUtil::getFileAsString(), OSInstance::getJacobianSparsityPattern(), OSInstance::getLagrangianHessianSparsityPattern(), OSInstance::getObjectiveNumber(), OSInstance::getVariableNumber(), SparseHessianMatrix::hessColIdx, SparseHessianMatrix::hessDimension, SparseHessianMatrix::hessRowIdx, SparseHessianMatrix::hessValues, SparseJacobianMatrix::indexes, OSInstance::initForAlgDiff(), osinstance, OSiLReader::readOSiL(), OSInstance::reverseAD(), SparseJacobianMatrix::starts, SparseJacobianMatrix::startSize, and SparseJacobianMatrix::values.

bool CheckFunctionValues ( double *  conVals,
double  objValue,
double  x0,
double  x1,
double  x2,
double  x3,
double  z0,
double  z1,
double  w 
)

Definition at line 660 of file algorithmicDiffTest.cpp.

Referenced by main().

bool CheckGradientValues ( SparseJacobianMatrix sparseJac,
double *  objGrad,
double  x0,
double  x1,
double  x2,
double  x3,
double  y0,
double  y1,
double  w 
)

Definition at line 677 of file algorithmicDiffTest.cpp.

References SparseJacobianMatrix::values.

Referenced by main().

bool CheckHessianUpper ( SparseHessianMatrix sparseHessian,
double  x0,
double  x1,
double  x2,
double  x3,
double  z0,
double  z1,
double  w 
)

Definition at line 704 of file algorithmicDiffTest.cpp.

References SparseHessianMatrix::hessValues.

Referenced by main().


Generated on Thu May 15 22:15:06 2008 by  doxygen 1.4.7