scp_merit_function.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
35 
36 
37 
39 
40 
41 //
42 // PUBLIC MEMBER FUNCTIONS:
43 //
44 
46 {
47 }
48 
49 
50 SCPmeritFunction::SCPmeritFunction( UserInteraction* _userInteraction ) : AlgorithmicBase( _userInteraction )
51 {
52 }
53 
54 
56 {
57 }
58 
59 
61 {
62 }
63 
64 
66 {
67  if ( this != &rhs )
68  {
70  }
71 
72  return *this;
73 }
74 
75 
77 {
78  return new SCPmeritFunction( *this );
79 }
80 
81 
83  const OCPiterate& iter,
84  BandedCP& cp,
85  SCPevaluation& eval,
86  double& result
87  )
88 {
89  if( fabs( alpha ) >= EPS )
90  {
91  result = INFTY;
92 
94 
95  OCPiterate iterTest = iter;
96  iterTest.applyStep( cp.deltaX,alpha );
97 
98  if ( eval.evaluate( iterTest,cp ) != SUCCESSFUL_RETURN )
99  return SUCCESSFUL_RETURN;
100  }
101 
102  result = eval.getObjectiveValue( );
103 
104 
105  const double kappa = 1.2;
106  DMatrix tmp;
107 
108 // acadoPrintf("result1 = %.16e \n", result );
109 
110 // acadoPrintf("cp.dynResiduum = \n");
111 // cp.dynResiduum.print();
112 
113 // acadoPrintf("cp.lambdaDynamic = \n");
114 // cp.lambdaDynamic.print();
115 
116  if( eval.isDynamicNLP( ) == BT_TRUE ){
117 
118  (cp.lambdaDynamic.getAbsolute()^cp.dynResiduum.getAbsolute()).getSubBlock( 0, 0, tmp, 1, 1 );
119  result += kappa*tmp(0,0);
120  }
121 
122 // acadoPrintf("result2 = %.16e \n", result );
123 //
124 // --------
125 //
126 //
127 // acadoPrintf("cp.lambdaBound = \n");
128 // (cp.lambdaBound.absolute() ).print();
129 // acadoPrintf("upperBoundRes = \n");
130 // (cp.upperBoundResiduum.negative()).print();
131 // acadoPrintf("lowerBoundRes = \n");
132 // (cp.lowerBoundResiduum.negative()).print();
133 
134 
135  (cp.lambdaBound.getAbsolute()^cp.upperBoundResiduum.getNegative()).getSubBlock( 0, 0, tmp, 1, 1 );
136  result -= kappa*tmp(0,0);
137 
138 // acadoPrintf("result3 = %.16e \n", result );
139 
140  (cp.lambdaBound.getAbsolute()^cp.lowerBoundResiduum.getPositive()).getSubBlock( 0, 0, tmp, 1, 1 );
141  result += kappa*tmp(0,0);
142 
143 // acadoPrintf("result4 = %.16e \n", result );
144 
145  // --------
146 
147  (cp.lambdaConstraint.getAbsolute()^cp.upperConstraintResiduum.getNegative()).getSubBlock( 0, 0, tmp, 1, 1 );
148  result -= kappa*tmp(0,0);
149 
150 // acadoPrintf("result5 = %.16e \n", result );
151 //
152 // acadoPrintf("cp.lambdaConstraint = \n");
153 // cp.lambdaConstraint.print();
154 //
155 // acadoPrintf("cp.lambdaConstraint = \n");
156 // cp.lowerConstraintResiduum.print();
157 
158  (cp.lambdaConstraint.getAbsolute()^cp.lowerConstraintResiduum.getPositive()).getSubBlock( 0, 0, tmp, 1, 1 );
159  result += kappa*tmp(0,0);
160 
161 // acadoPrintf("result6 = %.16e \n", result );
162 
163  return SUCCESSFUL_RETURN;
164 }
165 
166 
167 
168 
170 
171 // end of file.
Data class for storing generic optimization variables.
Definition: ocp_iterate.hpp:57
returnValue clearDynamicDiscretization()
BlockMatrix upperConstraintResiduum
Definition: banded_cp.hpp:114
const double INFTY
BlockMatrix deltaX
Definition: banded_cp.hpp:123
BEGIN_NAMESPACE_ACADO const double EPS
Allows to pass back messages to the calling function.
AlgorithmicBase & operator=(const AlgorithmicBase &rhs)
virtual returnValue evaluate(double alpha, const OCPiterate &iter, BandedCP &cp, SCPevaluation &eval, double &result)
Base class for all algorithmic modules within the ACADO Toolkit providing some basic functionality...
BlockMatrix getAbsolute() const
virtual returnValue evaluate(OCPiterate &iter, BandedCP &cp)
BlockMatrix lambdaConstraint
Definition: banded_cp.hpp:126
#define CLOSE_NAMESPACE_ACADO
BlockMatrix getNegative() const
virtual double getObjectiveValue() const
BlockMatrix lambdaDynamic
Definition: banded_cp.hpp:125
BlockMatrix lowerBoundResiduum
Definition: banded_cp.hpp:106
BooleanType isDynamicNLP() const
Allows to evaluate a merit function within an SCPmethod for solving NLPs.
returnValue applyStep(const BlockMatrix &bm, double alpha)
BlockMatrix lowerConstraintResiduum
Definition: banded_cp.hpp:113
BlockMatrix lambdaBound
Definition: banded_cp.hpp:124
BlockMatrix upperBoundResiduum
Definition: banded_cp.hpp:107
Encapsulates all user interaction for setting options, logging data and plotting results.
void rhs(const real_t *x, real_t *f)
#define BT_TRUE
Definition: acado_types.hpp:47
virtual SCPmeritFunction * clone() const
BlockMatrix dynResiduum
Definition: banded_cp.hpp:110
BlockMatrix getPositive() const
Base class for different ways to evaluate functions and derivatives within an SCPmethod for solving N...
#define BEGIN_NAMESPACE_ACADO
SCPmeritFunction & operator=(const SCPmeritFunction &rhs)
Data class for storing conic programs arising from optimal control.
Definition: banded_cp.hpp:56


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:04