/** @file algorithmicDiffTest.cpp
*
* @author Gus Gassmann, Jun Ma, Kipp Martin,
* @version 1.0, 26/06/2008
* @since OS1.1
*
* \remarks
* Copyright (C) 2008, Gus Gassmann, Jun Ma, Kipp Martin,
* Dalhousie University, 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 software is licensed under the Common 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
* 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
*
*/
#include
#include
#include
#include
#include
#include
#include
// CoinHelperFunctions
#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 "OSInstance.h"
#include "OSExpressionTree.h"
#include "OSnLNode.h"
#include "OSDataStructures.h"
#include
#include