/home/coin/SVN-release/OS-2.4.2/examples/algorithmicDiff/OSAlgorithmicDiffTest.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 "OSErrorClass.h"
#include "OSFileUtil.h"
#include "OSiLReader.h"
#include "OSExpressionTree.h"
#include "OSDataStructures.h"
#include <vector>
#include <map>
#include <string>

Include dependency graph for OSAlgorithmicDiffTest.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, Horand Gassmann, Jun Ma, Kipp Martin
Remarks:
Copyright (C) 2005-2011, Robert Fourer, Horand Gassmann, Jun Ma, Kipp Martin, Northwestern University, Dalhousie University and the University of Chicago. All Rights Reserved. This software is licensed under the Eclipse Public License. Please see the accompanying LICENSE file in root directory for terms.
This example illustrates the algorithmic 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 Lagrangian 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 to x0
L_0 = 2 * w * x0 + z1 / x0

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

the partial with respect to x2
L_2 = z1*7

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

in the Hessian there are only two nonzero terms however the code will think there may be three since it does not know log(x0*x3) = log(x0) + log(x3)
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*x2 term in constraint with index 1. Note also, that there are only three variables that appear in nl nodes, x2 does not appear in an nl node

Definition in file OSAlgorithmicDiffTest.cpp.


Function Documentation

int main (  ) 

Definition at line 102 of file OSAlgorithmicDiffTest.cpp.

References OSInstance::bUseExpTreeForFunEval, OSInstance::calculateAllConstraintFunctionGradients(), OSInstance::calculateAllConstraintFunctionValues(), OSInstance::calculateAllObjectiveFunctionValues(), OSInstance::calculateFunctionValue(), OSInstance::calculateHessian(), OSInstance::calculateLagrangianHessian(), OSInstance::calculateObjectiveFunctionGradient(), CheckFunctionValues(), CheckGradientValues(), CheckHessianUpper(), SparseJacobianMatrix::conVals, e, ErrorClass::errormsg, f, OSInstance::forwardAD(), OSInstance::getAllNonlinearVariablesIndexMap(), OSInstance::getConstraintNumber(), FileUtil::getFileAsString(), OSInstance::getJacobianSparsityPattern(), OSInstance::getLagrangianHessianSparsityPattern(), OSInstance::getNonlinearExpressionTreeModIndexes(), OSInstance::getNumberOfNonlinearExpressionTreeModIndexes(), OSInstance::getObjectiveNumber(), OSInstance::getVariableNumber(), SparseJacobianMatrix::indexes, OSInstance::initForAlgDiff(), k, log(), m, n, OS_NEAR_EQUAL, osinstance, r, OSiLReader::readOSiL(), OSInstance::reverseAD(), SparseJacobianMatrix::starts, SparseJacobianMatrix::startSize, SparseJacobianMatrix::values, w, and x.

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

Definition at line 753 of file OSAlgorithmicDiffTest.cpp.

References log(), and OS_NEAR_EQUAL.

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 776 of file OSAlgorithmicDiffTest.cpp.

References OS_NEAR_EQUAL, and 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 811 of file OSAlgorithmicDiffTest.cpp.

References e, and SparseHessianMatrix::hessValues.

Referenced by main().


Generated on Wed Nov 30 03:09:31 2011 by  doxygen 1.4.7