source: trunk/ADOL-C/examples/additional_examples/timing/sfunc_rosenbrock.cpp @ 171

Last change on this file since 171 was 171, checked in by kulshres, 9 years ago

Squashed merge branch 'master' of 'gitclone' into svn

  • 'master' of 'gitclone': (84 commits) adjust example makefiles and include paths get rid of the symlink in the src subdirectory

details of the commits:
commit c9e4bc332d2363f737fc2e8a8fcfc2e43ddb9d15
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:43:47 2010 +0200

adjust example makefiles and include paths

include paths in example sources were wrong for some time now
simplify makefile rules too, there is really no need for checking SPARSE
adjust include paths in makefiles.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e6e1963e41e097fd5b4a79cd1611c12f6868dc94
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:41:25 2010 +0200

get rid of the symlink in the src subdirectory

windows doesn't like symlinks and make infinite depth directories
we now create a symlink for build in the directory parallel to src
adjust all makefiles.am accordingly for build

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     sfunc_rosenbrock.cpp
4 Revision: $Id: sfunc_rosenbrock.cpp 171 2010-10-04 13:57:19Z kulshres $
5 Contents: function module containing  Rosenbrock's function
6
7   Each << function module >> contains:
8         
9     (1) const char* const controlFileName
10     (2) int indepDim;
11     (3) void initProblemParameters( void )
12     (4) void initIndependents( double* indeps )
13     (5) double originalScalarFunction( double* indeps )
14     (6) double tapingScalarFunction( int tag, double* indeps )   
15 
16 Copyright (c) Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz,
17               Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel
18 
19 This file is part of ADOL-C. This software is provided as open source.
20 Any use, reproduction, or distribution of the software constitutes
21 recipient's acceptance of the terms of the accompanying license file.
22 
23---------------------------------------------------------------------------*/
24#define _SFUNC_ROSENBROCK_C_
25
26
27/****************************************************************************/
28/*                                                                 INCLUDES */
29#include <adolc/adolc.h>
30
31#include <cmath>
32
33
34/****************************************************************************/
35/*                                                         GLOBAL VARIABLES */
36
37/*--------------------------------------------------------------------------*/
38/*                                                        Control file name */
39const char* controlFileName = "rosenbrockexam.ctrl";
40
41/*--------------------------------------------------------------------------*/
42/*                                                               Dimensions */
43int indepDim;
44
45/*--------------------------------------------------------------------------*/
46/*                                       Other problem dependent parameters */
47
48
49/****************************************************************************/
50/*                                                  INIT PROBLEM PARAMETERS */
51void initProblemParameters( void ) {
52    fprintf(stdout,"ROSENBROCKs FUNCTION (ADOL-C Example)\n\n");
53    if (indepDim <= 0) {
54        fprintf(stdout,"    number of independent variables = ? ");
55        fscanf(stdin,"%d",&indepDim);
56        fprintf(stdout,"\n");
57    }
58}
59
60
61/****************************************************************************/
62/*                                                        INITIALIZE INDEPs */
63void initIndependents( double* indeps ) {
64    int i;
65    for (i=0; i<indepDim; i++)
66        indeps[i] = 600.0*(i+1.0)/(2.0+i);
67}
68
69
70/****************************************************************************/
71/*                                                 ORIGINAL SCALAR FUNCTION */
72
73/*--------------------------------------------------------------------------*/
74/*                                                       Griewanks function */
75double rosenbrock( int dim, double* indeps ) {
76    int i;
77    double Val1,
78    Val2,
79    tmp;
80
81    tmp = 0.0;
82    for (i = 0; i < dim-1; i++) {
83        Val1 = 10.0*(indeps[i+1]-indeps[i]*indeps[i]);
84        Val2 = indeps[i]-1.0;
85        tmp  += Val1*Val1 + Val2*Val2;
86    }
87
88    return tmp;
89}
90
91/*--------------------------------------------------------------------------*/
92/*                                                   The interface function */
93double originalScalarFunction( double* indeps ) {
94    return rosenbrock(indepDim, indeps);
95}
96
97
98/****************************************************************************/
99/*                                                   TAPING SCALAR FUNCTION */
100
101/*--------------------------------------------------------------------------*/
102/*                                                active Griewnaks function */
103adouble activeRosenbrock( int dim, adouble* indeps ) {
104    int i;
105    adouble Val1,
106    Val2,
107    tmp;
108
109    tmp = 0.0;
110    for (i = 0; i < dim-1; i++) {
111        Val1 = 10.0*(indeps[i+1]-indeps[i]*indeps[i]);
112        Val2 = indeps[i]-1.0;
113        tmp  += Val1*Val1 + Val2*Val2;
114    }
115
116    return tmp;
117}
118
119/*--------------------------------------------------------------------------*/
120/*                                                   The interface function */
121double tapingScalarFunction( int tag, double* indeps ) {
122    int i;
123    trace_on(tag);
124    adouble* activeIndeps = new adouble[indepDim];
125    adouble* aIP = activeIndeps;
126    double*  iP  = indeps;
127    for (i=0; i<indepDim; i++)
128        *aIP++ <<= *iP++;
129    adouble ares = activeRosenbrock(indepDim, activeIndeps);
130    double res = 0;
131    ares >>= res;
132    trace_off();
133    return res;
134}
135
136#undef _SFUNC_ROSENBROCK_C_
137
138
139
140
141
Note: See TracBrowser for help on using the repository browser.