| 659 | */ |
| 660 | |
| 661 | void generateSol2( CBiteRnd& rnd ) |
| 662 | { |
| 663 | ptype* const Params = TmpParams; |
| 664 | |
| 665 | const CBitePop& ParPop = *this; |
| 666 | const int ParPopSize = ParPop.getCurPopSize(); |
| 667 | const int ParPopSize1 = ParPopSize - 1; |
| 668 | |
| 669 | const int si1 = getMinSolIndex( 1, rnd, ParPopSize ); |
| 670 | const ptype* const rp1 = ParPop.getParamsOrdered( si1 ); |
| 671 | const ptype* const rp3 = ParPop.getParamsOrdered( ParPopSize1 - si1 ); |
| 672 | |
| 673 | const int si2 = 1 + rnd.getInt( ParPopSize1 ); |
| 674 | const ptype* const rp2 = ParPop.getParamsOrdered( si2 ); |
| 675 | |
| 676 | const int si4 = rnd.getSqrInt( ParPopSize ); |
| 677 | const ptype* const rp4 = ParPop.getParamsOrdered( si4 ); |
| 678 | const ptype* const rp5 = ParPop.getParamsOrdered( ParPopSize1 - si4 ); |
| 679 | |
| 680 | // The "step in the right direction" (Differential Evolution |
| 681 | // "mutation") operation towards the best (minimal) and away from |
| 682 | // the worst (maximal) parameter vector, plus a difference of two |
| 683 | // random vectors. |
| 684 | |
| 685 | const int Mode = select( Gen2ModeSel, rnd ); |
| 686 | int i; |
| 687 | |
| 688 | if( Mode == 0 ) |
| 689 | { |
| 690 | for( i = 0; i < ParamCount; i++ ) |
| 691 | { |
| 692 | Params[ i ] = rp1[ i ] + ((( rp2[ i ] - rp3[ i ]) + |
| 693 | ( rp4[ i ] - rp5[ i ])) >> 1 ); |
| 694 | } |
| 695 | } |
| 696 | else |
| 697 | { |
| 698 | const ptype* const rp1b = ParPop.getParamsOrdered( |
| 699 | rnd.getSqrInt( ParPopSize )); |
| 700 | |
| 701 | for( i = 0; i < ParamCount; i++ ) |
| 702 | { |
| 703 | Params[ i ] = (( rp1[ i ] + rp1b[ i ]) + |
| 704 | ( rp2[ i ] - rp3[ i ]) + ( rp4[ i ] - rp5[ i ])) >> 1; |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * An alternative "Differential Evolution"-based solution generator. |
nothing calls this directly
no test coverage detected