| 141 | */ |
| 142 | |
| 143 | int optimize( CBiteRnd& rnd ) |
| 144 | { |
| 145 | int i; |
| 146 | |
| 147 | if( DoInitEvals ) |
| 148 | { |
| 149 | y[ CurPopPos ] = eval( rnd, x[ CurPopPos ]); |
| 150 | |
| 151 | if( y[ CurPopPos ] < y[ xlo ]) |
| 152 | { |
| 153 | xlo = CurPopPos; |
| 154 | } |
| 155 | |
| 156 | CurPopPos++; |
| 157 | |
| 158 | if( CurPopPos == M ) |
| 159 | { |
| 160 | DoInitEvals = false; |
| 161 | calccent(); |
| 162 | } |
| 163 | |
| 164 | return( 0 ); |
| 165 | } |
| 166 | |
| 167 | StallCount++; |
| 168 | |
| 169 | const double sn = 0.5 * sqrt( ParamCountI ); |
| 170 | |
| 171 | static const double alpha = 1.0; // Reflection coeff. |
| 172 | const double gamma = 1.5 + sn; // Expansion coeff. |
| 173 | const double rho = -0.75 + sn; // Contraction coeff. |
| 174 | const double sigma = 1.0 - sn; // Reduction coeff. |
| 175 | |
| 176 | double* const xH = x[ xhi ]; // Highest cost parameter vector. |
| 177 | |
| 178 | switch( State ) |
| 179 | { |
| 180 | case stReflection: |
| 181 | { |
| 182 | for( i = 0; i < N; i++ ) |
| 183 | { |
| 184 | x1[ i ] = x0[ i ] + alpha * ( x0[ i ] - xH[ i ]); |
| 185 | } |
| 186 | |
| 187 | y1 = eval( rnd, x1 ); |
| 188 | |
| 189 | if( y1 > y[ xlo ] && y1 < y[ xhi2 ]) |
| 190 | { |
| 191 | copy( x1, y1 ); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | if( y1 < y[ xlo ]) |
| 196 | { |
| 197 | State = stExpansion; |
| 198 | StallCount--; |
| 199 | } |
| 200 | else |
nothing calls this directly
no outgoing calls
no test coverage detected