Ignore:
Timestamp:
03/10/15 10:00:41 (7 years ago)
Author:
pfleck
Message:

#2350 Changed SteadyStateMatingPoolCreator to only select individuals young enough for the current layer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/SteadyStateMatingPoolCreator.cs

    r12159 r12171  
    3535      get { return (ILookupParameter<IScope>)Parameters["WorkingScope"]; }
    3636    }
     37    private ILookupParameter<IScope> LayersParameter {
     38      get { return (ILookupParameter<IScope>)Parameters["Layers"]; }
     39    }
    3740    private ILookupParameter<IntValue> LayerParameter {
    3841      get { return (ILookupParameter<IntValue>)Parameters["Layer"]; }
     42    }
     43    private ILookupParameter<IntArray> AgeLimitsParameter {
     44      get { return (ILookupParameter<IntArray>)Parameters["AgeLimits"]; }
     45    }
     46    private ILookupParameter<IntValue> NumberOfLayersParameter {
     47      get { return (ILookupParameter<IntValue>)Parameters["NumberOfLayers"]; }
     48    }
     49    private ILookupParameter<IntValue> EvaluatedSolutionsParameter {
     50      get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     51    }
     52    private ILookupParameter<IntValue> PopulationSizeParameter {
     53      get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; }
    3954    }
    4055
     
    5065      : base() {
    5166      Parameters.Add(new LookupParameter<IScope>("WorkingScope"));
     67      Parameters.Add(new LookupParameter<IScope>("Layers"));
    5268      Parameters.Add(new LookupParameter<IntValue>("Layer"));
     69      Parameters.Add(new LookupParameter<IntArray>("AgeLimits"));
     70      Parameters.Add(new LookupParameter<IntValue>("NumberOfLayers"));
     71      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
     72      Parameters.Add(new LookupParameter<IntValue>("PopulationSize"));
     73
    5374    }
    5475
     
    5677      int layerNumber = LayerParameter.ActualValue.Value;
    5778      var workingScope = WorkingScopeParameter.ActualValue;
     79      var layers = LayersParameter.ActualValue;
     80      var ageLimits = AgeLimitsParameter.ActualValue;
     81      int numberOfLayers = NumberOfLayersParameter.ActualValue.Value;
     82      int evaluations = EvaluatedSolutionsParameter.ActualValue.Value;
     83      int popSize = PopulationSizeParameter.ActualValue.Value;
    5884
    59       var currentLayer = ExecutionContext.Scope;
    60       foreach (var individual in currentLayer.SubScopes) {
    61         workingScope.SubScopes.Add((IScope)individual.Clone());
     85      var currentLayer = layers.SubScopes[layerNumber].SubScopes;
     86      var prevLayer = layerNumber > 0 ? layers.SubScopes[layerNumber - 1].SubScopes : Enumerable.Empty<IScope>();
     87
     88      var ageLimit = layerNumber < numberOfLayers - 1 ? ageLimits[layerNumber] : int.MaxValue;
     89
     90      var matingPool =
     91        from individual in currentLayer.Union(prevLayer)
     92        let evalsCreated = ((IntValue)individual.Variables["EvalsCreated"].Value).Value
     93        let age = (evaluations - evalsCreated) / popSize
     94        where age < ageLimit
     95        select (IScope)individual.Clone();
     96
     97      foreach (var individual in matingPool) {
     98        workingScope.SubScopes.Add(individual);
    6299      }
    63 
    64       if (layerNumber > 0) {
    65         var layers = currentLayer.Parent;
    66         var prevLayer = layers.SubScopes[layerNumber - 1];
    67 
    68         foreach (var individual in prevLayer.SubScopes) {
    69           workingScope.SubScopes.Add((IScope)individual.Clone());
    70         }
    71       }
    72 
    73100      return base.Apply();
    74101    }
Note: See TracChangeset for help on using the changeset viewer.