Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00034 #include <acado/optimization_algorithm/weight_generation.hpp>
00035 
00036 
00037 
00038 BEGIN_NAMESPACE_ACADO
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 WeightGeneration::WeightGeneration(){
00048 
00049 }
00050 
00051 WeightGeneration::WeightGeneration( const WeightGeneration& arg ){
00052 
00053 }
00054 
00055 WeightGeneration::~WeightGeneration( ){
00056 
00057 }
00058 
00059 WeightGeneration& WeightGeneration::operator=( const WeightGeneration& arg ){
00060 
00061     if( this != &arg ){
00062 
00063     }
00064     return *this;
00065 }
00066 
00067 
00068 returnValue WeightGeneration::getWeights( const int    &m        ,
00069                                           const int    &pnts     ,
00070                                           const DVector &weightsLB,
00071                                           const DVector &weightsUB,
00072                                           DMatrix       &Weights  ,
00073                                           DVector       &formers    ) const{
00074 
00075     DVector weight(m);
00076     weight.setZero();
00077 
00078     const int layer = m-1;
00079 
00080     int lastone     = -1            ;
00081     int currentone  = -1            ;
00082     double    step        = 1.0/(pnts-1.0);
00083 
00084     const int n = 0;
00085 
00086     WeightGeneration child;
00087     return child.generateWeights( n, weight, Weights, weightsLB, weightsUB, formers, layer, lastone, currentone, step );
00088 }
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 returnValue WeightGeneration::generateWeights( const  int    &n         ,
00099                                                DVector        &weight    ,
00100                                                DMatrix        &Weights   ,
00101                                                const  DVector &weightsLB ,
00102                                                const  DVector &weightsUB ,
00103                                                DVector        &formers   ,
00104                                                const int     &layer     ,
00105                                                int           &lastOne   ,
00106                                                int           ¤tOne,
00107                                                double        &step
00108                                              ) const{
00109 
00110 
00111    int run1, run2;
00112 
00113     if( n == layer ){
00114 
00115         
00116 
00117         double weight_test = 1.0;
00118         for( run1 = 0; run1 < (int) weight.getDim()-1; run1++ )
00119             weight_test -= weight(run1);
00120 
00121         if( ( weight_test >= weightsLB(layer) - 100.0*EPS ) &&
00122             ( weight_test <= weightsUB(layer) + 100.0*EPS )    ){
00123 
00124             if( currentOne >= 0 ){
00125 
00126                 DVector tmp( formers.getDim()+1 );
00127 
00128                 for( run1 = 0; run1 < (int) formers.getDim(); run1++ )
00129                     tmp(run1) = formers(run1);
00130 
00131                 tmp(formers.getDim()) = lastOne;
00132                 formers = tmp;
00133                 lastOne = currentOne;
00134                 currentOne = -1;
00135             }
00136             else{
00137 
00138                 DVector tmp( formers.getDim()+1 );
00139 
00140                 for( run1 = 0; run1 < (int) formers.getDim(); run1++ )
00141                     tmp(run1) = formers(run1);
00142 
00143                 tmp(formers.getDim()) = Weights.getNumCols();
00144                 formers = tmp;
00145             }
00146 
00147              weight(n) = weight_test;
00148 
00149              DMatrix tmp( weight.getDim(), Weights.getNumCols()+1 );
00150 
00151              for( run1 = 0; run1 < (int) Weights.getNumRows(); run1++ ){
00152                  for( run2 = 0; run2 < (int) Weights.getNumCols(); run2++ )
00153                      tmp(run1,run2) = Weights(run1,run2);
00154              }
00155 
00156              for( run2 = 0; run2 < (int) weight.getDim(); run2++ )
00157                      tmp(run2,Weights.getNumCols()) = weight(run2);
00158 
00159              Weights = tmp;
00160         }
00161     }
00162     else{
00163 
00164         
00165 
00166         double weight_test = weightsLB(n);
00167 
00168         while( weight_test <= weightsUB(n) + 100.0*EPS ){
00169 
00170             if( n == layer-2 ) currentOne = Weights.getNumCols()+1;
00171 
00172             weight(n) = weight_test;
00173 
00174             WeightGeneration child;
00175             child.generateWeights( n+1, weight, Weights, weightsLB, weightsUB, formers, layer, lastOne, currentOne, step );
00176 
00177             weight_test += (weightsUB(n)-weightsLB(n))*step;
00178         }
00179     }
00180 
00181     return SUCCESSFUL_RETURN;
00182 }
00183 
00184 
00185 
00186 CLOSE_NAMESPACE_ACADO
00187 
00188