scp_step_linesearch.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 SCPstepLinesearch::SCPstepLinesearch( UserInteraction* _userInteraction ) : SCPstep( _userInteraction )
51 {
52 }
53 
54 
56 {
57 }
58 
59 
61 {
62 }
63 
64 
66 {
67  if ( this != &rhs )
68  {
69  SCPstep::operator=( rhs );
70  }
71 
72  return *this;
73 }
74 
75 
76 
77 
79 {
80  return new SCPstepLinesearch( *this );
81 }
82 
83 
84 
86  BandedCP& cp,
87  SCPevaluation* eval
88  )
89 {
90  returnValue returnvalue;
91 
92  double alpha = 1.0;
93  double lineSearchTOL, alphaMin;
94 
95  get( LINESEARCH_TOLERANCE , lineSearchTOL );
96  get( MIN_LINESEARCH_PARAMETER, alphaMin );
97 
98 // iter.print();
99 
100  if( eval->getKKTtolerance( iter,cp ) > lineSearchTOL )
101  {
102  returnvalue = performLineSearch( iter,cp,*eval, alpha,alphaMin );
103  if( returnvalue != SUCCESSFUL_RETURN ) ACADOERROR(returnvalue);
104  }
105  else
106  {
107  returnvalue = performLineSearch( iter,cp,*eval, alpha,1.0 );
108  if( returnvalue != SUCCESSFUL_RETURN ) ACADOERROR(returnvalue);
109  }
111 
112  returnvalue = applyStep( iter,cp,alpha );
113  if( returnvalue != SUCCESSFUL_RETURN )
114  ACADOERROR( returnvalue );
115 
116 
117  return SUCCESSFUL_RETURN;
118 }
119 
120 
121 
122 
123 //
124 // PROTECTED MEMBER FUNCTIONS:
125 //
126 
127 
128 
130  BandedCP& cp,
131  SCPevaluation& eval,
132  double& alpha,
133  const double& alphaMin
134  )
135 {
136 
137  const int maxIter = 50;
138  const double kappa = 0.5;
139 
140  alpha = 1.0;
141 
142  double meritFcnValue1 = INFTY;
143  double meritFcnValue2 = INFTY;
144 
145  if ( meritFcn->evaluate( 0.0,iter,cp,eval, meritFcnValue1 ) != SUCCESSFUL_RETURN )
146  return ACADOERROR( RET_UNKNOWN_BUG );
147 
148  int run1 = 0;
149  while( run1 < maxIter ){
150  meritFcn->evaluate( alpha,iter,cp,eval, meritFcnValue2 );
151 
152 // acadoPrintf("LineSearch: T1 = %.16e T2 = %.16e alpha = %.3e \n", meritFcnValue1, meritFcnValue2, alpha );
153 
154  if( meritFcnValue2 <= meritFcnValue1 + EPS ) break;
155  if( alpha <= alphaMin+EPS ) break;
156  alpha *= kappa;
157  run1++;
158  }
159 
160  setLast( LOG_MERIT_FUNCTION_VALUE,meritFcnValue2 );
161 
162  return SUCCESSFUL_RETURN;
163 }
164 
165 
166 
167 
169 
170 // end of file.
returnValue setLast(LogName _name, int lastValue, double time=-INFTY)
virtual SCPstep * clone() const
Data class for storing generic optimization variables.
Definition: ocp_iterate.hpp:57
Implements linesearch techniques to perform a globalized step of an SCPmethod for solving NLPs...
SCPmeritFunction * meritFcn
Definition: scp_step.hpp:124
SCPstepLinesearch & operator=(const SCPstepLinesearch &rhs)
const double INFTY
BEGIN_NAMESPACE_ACADO const double EPS
virtual returnValue performStep(OCPiterate &iter, BandedCP &cp, SCPevaluation *eval)
Allows to pass back messages to the calling function.
virtual returnValue evaluate(double alpha, const OCPiterate &iter, BandedCP &cp, SCPevaluation &eval, double &result)
Base class for different ways to perform a step of an SCPmethod for solving NLPs. ...
Definition: scp_step.hpp:62
virtual returnValue applyStep(OCPiterate &iter, BandedCP &cp, double alpha) const
Definition: scp_step.cpp:116
SCPstep & operator=(const SCPstep &rhs)
Definition: scp_step.cpp:82
#define CLOSE_NAMESPACE_ACADO
returnValue performLineSearch(const OCPiterate &iter, BandedCP &cp, SCPevaluation &eval, double &alpha, const double &alphaMin)
virtual double getKKTtolerance(const OCPiterate &iter, const BandedCP &cp, double KKTmultiplierRegularisation=0.0)
Encapsulates all user interaction for setting options, logging data and plotting results.
void rhs(const real_t *x, real_t *f)
Base class for different ways to evaluate functions and derivatives within an SCPmethod for solving N...
#define BEGIN_NAMESPACE_ACADO
#define ACADOERROR(retval)
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