[14893] | 1 | using HeuristicLab.Common;
|
---|
| 2 | using HeuristicLab.Core;
|
---|
| 3 | using HeuristicLab.Data;
|
---|
| 4 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 5 | using HeuristicLab.Optimization;
|
---|
| 6 | using HeuristicLab.Parameters;
|
---|
| 7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 8 |
|
---|
| 9 | namespace HeuristicLab.Algorithms.SAPBA.Strategies {
|
---|
| 10 | public class GenerationalStrategy : StrategyBase {
|
---|
| 11 | public const string NoGenerationsParameterName = "Number of generations";
|
---|
| 12 | public IFixedValueParameter<IntValue> NoGenerationsParameter => Parameters[NoGenerationsParameterName] as IFixedValueParameter<IntValue>;
|
---|
| 13 | public IntValue NoGenerations => NoGenerationsParameter.Value;
|
---|
| 14 | [Storable]
|
---|
| 15 | public int Generations;
|
---|
| 16 |
|
---|
| 17 | #region Constructors
|
---|
| 18 | private GenerationalStrategy(GenerationalStrategy original, Cloner cloner) : base(original, cloner) {
|
---|
| 19 | Generations = original.Generations;
|
---|
| 20 | }
|
---|
| 21 | public GenerationalStrategy() {
|
---|
| 22 | Parameters.Add(new FixedValueParameter<IntValue>(NoGenerationsParameterName, "The number of generations before a new model is constructed", new IntValue(3)));
|
---|
| 23 | }
|
---|
| 24 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 25 | return new GenerationalStrategy(this, cloner);
|
---|
| 26 | }
|
---|
| 27 | #endregion
|
---|
| 28 |
|
---|
| 29 | public override double Evaluate(RealVector r, IRandom random) {
|
---|
| 30 | return EstimateSample(r, random).Item2;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | protected override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, ResultCollection globalResults, IRandom random) {
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | protected override void ProcessPopulation(Individual[] individuals, double[] qualities, IRandom random) {
|
---|
| 37 | if (RegressionSolution != null && Generations < NoGenerations.Value) Generations++;
|
---|
| 38 | else {
|
---|
[14894] | 39 | foreach (var indi in individuals) EvaluateSample(indi.RealVector(), random);
|
---|
[14893] | 40 | BuildRegressionSolution(random);
|
---|
| 41 | Generations = 0;
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | protected override void Initialize() {
|
---|
| 46 | Generations = 0;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | }
|
---|