weight_generation.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 //
43 // PUBLIC MEMBER FUNCTIONS:
44 //
45 
46 
48 
49 }
50 
52 
53 }
54 
56 
57 }
58 
60 
61  if( this != &arg ){
62 
63  }
64  return *this;
65 }
66 
67 
69  const int &pnts ,
70  const DVector &weightsLB,
71  const DVector &weightsUB,
72  DMatrix &Weights ,
73  DVector &formers ) const{
74 
75  DVector weight(m);
76  weight.setZero();
77 
78  const int layer = m-1;
79 
80  int lastone = -1 ;
81  int currentone = -1 ;
82  double step = 1.0/(pnts-1.0);
83 
84  const int n = 0;
85 
86  WeightGeneration child;
87  return child.generateWeights( n, weight, Weights, weightsLB, weightsUB, formers, layer, lastone, currentone, step );
88 }
89 
90 
91 
92 
93 //
94 // PROTECTED MEMBER FUNCTIONS:
95 //
96 
97 
99  DVector &weight ,
100  DMatrix &Weights ,
101  const DVector &weightsLB ,
102  const DVector &weightsUB ,
103  DVector &formers ,
104  const int &layer ,
105  int &lastOne ,
106  int &currentOne,
107  double &step
108  ) const{
109 
110 
111  int run1, run2;
112 
113  if( n == layer ){
114 
115  //printf("case1: n = %d layer = %d \n", n, layer );
116 
117  double weight_test = 1.0;
118  for( run1 = 0; run1 < (int) weight.getDim()-1; run1++ )
119  weight_test -= weight(run1);
120 
121  if( ( weight_test >= weightsLB(layer) - 100.0*EPS ) &&
122  ( weight_test <= weightsUB(layer) + 100.0*EPS ) ){
123 
124  if( currentOne >= 0 ){
125 
126  DVector tmp( formers.getDim()+1 );
127 
128  for( run1 = 0; run1 < (int) formers.getDim(); run1++ )
129  tmp(run1) = formers(run1);
130 
131  tmp(formers.getDim()) = lastOne;
132  formers = tmp;
133  lastOne = currentOne;
134  currentOne = -1;
135  }
136  else{
137 
138  DVector tmp( formers.getDim()+1 );
139 
140  for( run1 = 0; run1 < (int) formers.getDim(); run1++ )
141  tmp(run1) = formers(run1);
142 
143  tmp(formers.getDim()) = Weights.getNumCols();
144  formers = tmp;
145  }
146 
147  weight(n) = weight_test;
148 
149  DMatrix tmp( weight.getDim(), Weights.getNumCols()+1 );
150 
151  for( run1 = 0; run1 < (int) Weights.getNumRows(); run1++ ){
152  for( run2 = 0; run2 < (int) Weights.getNumCols(); run2++ )
153  tmp(run1,run2) = Weights(run1,run2);
154  }
155 
156  for( run2 = 0; run2 < (int) weight.getDim(); run2++ )
157  tmp(run2,Weights.getNumCols()) = weight(run2);
158 
159  Weights = tmp;
160  }
161  }
162  else{
163 
164  //printf("case2: n = %d layer = %d \n", n, layer );
165 
166  double weight_test = weightsLB(n);
167 
168  while( weight_test <= weightsUB(n) + 100.0*EPS ){
169 
170  if( n == layer-2 ) currentOne = Weights.getNumCols()+1;
171 
172  weight(n) = weight_test;
173 
174  WeightGeneration child;
175  child.generateWeights( n+1, weight, Weights, weightsLB, weightsUB, formers, layer, lastOne, currentOne, step );
176 
177  weight_test += (weightsUB(n)-weightsLB(n))*step;
178  }
179  }
180 
181  return SUCCESSFUL_RETURN;
182 }
183 
184 
185 
187 
188 // end of file.
returnValue generateWeights(const int &n, DVector &weight, DMatrix &Weights, const DVector &weightsLB, const DVector &weightsUB, DVector &formers, const int &layer, int &lastOne, int &currentOne, double &step) const
BEGIN_NAMESPACE_ACADO const double EPS
Generates weights for solving OCPs having multiple objectives.
Allows to pass back messages to the calling function.
#define CLOSE_NAMESPACE_ACADO
unsigned getDim() const
Definition: vector.hpp:172
Derived & setZero(Index size)
unsigned getNumRows() const
Definition: matrix.hpp:185
returnValue getWeights(const int &m, const int &pnts, const DVector &weightsLB, const DVector &weightsUB, DMatrix &Weights, DVector &formers) const
unsigned getNumCols() const
Definition: matrix.hpp:189
#define BEGIN_NAMESPACE_ACADO
WeightGeneration & operator=(const WeightGeneration &arg)


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