MCPcopy Create free account
hub / github.com/avaneev/biteopt / generateSol8

Method generateSol8

biteopt.h:1254–1325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1252 */
1253
1254 void generateSol8( CBiteRnd& rnd )
1255 {
1256 ptype* const Params = TmpParams;
1257
1258 const int Mode = select( Gen8ModeSel, rnd );
1259 const int NumSols = 5 + select( Gen8NumSel, rnd );
1260 const ptype* rp[ 8 ];
1261
1262 // Calculate centroid of a number of selected solutions.
1263
1264 const ptype* rp0 = getParamsOrdered( rnd.getSqrInt( CurPopSize ));
1265 rp[ 0 ] = rp0;
1266 copyParams( Params, rp0 );
1267
1268 int j;
1269 int i;
1270
1271 for( j = 1; j < NumSols; j++ )
1272 {
1273 rp0 = getParamsOrdered( rnd.getSqrInt( CurPopSize ));
1274 rp[ j ] = rp0;
1275
1276 for( i = 0; i < ParamCount; i++ )
1277 {
1278 Params[ i ] += rp0[ i ];
1279 }
1280 }
1281
1282 const double m = 1.0 / NumSols;
1283
1284 for( i = 0; i < ParamCount; i++ )
1285 {
1286 NewValues[ i ] = Params[ i ] * m; // Centroid.
1287 Params[ i ] = (ptype) NewValues[ i ];
1288 }
1289
1290 // Apply "move" operations in one of two modes.
1291
1292 if( Mode == 0 )
1293 {
1294 static const double Spans[ 4 ] = { 1.5, 2.5, 3.5, 4.5 };
1295 const double gm = Spans[ select( Gen8SpanSel[ Mode ], rnd )] *
1296 sqrt( m );
1297
1298 for( j = 0; j < NumSols; j++ )
1299 {
1300 const double r = rnd.getGaussian() * gm;
1301 rp0 = rp[ j ];
1302
1303 for( i = 0; i < ParamCount; i++ )
1304 {
1305 Params[ i ] += (ptype) (( NewValues[ i ] - rp0[ i ]) * r );
1306 }
1307 }
1308 }
1309 else
1310 {
1311 static const double Spans[ 4 ] = { 0.5, 1.5, 2.5, 3.5 };

Callers

nothing calls this directly

Calls 2

getSqrIntMethod · 0.80
getGaussianMethod · 0.80

Tested by

no test coverage detected