Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12171 for branches/ALPS


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

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

Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3
Files:
2 edited

Legend:

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

    r12162 r12171  
    7979      var incrementNextInit = new IntCounter() { Name = "Incr. NextInit" };
    8080      var checkInitFinished = new Comparator() { Name = "DoInit = NextInit >= PopulationSize" };
    81       var createWorkingScope = new BestSelector();
    82       var workingScopeProcessor = new SubScopesProcessor() { Name = "Working Scope Processor" };
     81      var workingScopeProcessor = new NamedSubScopeProcessor() { Name = "WorkingScope Processor" };
    8382      var createRandomIndividual = new SolutionsCreator() { Name = "Create random Individual" };
    8483      var initializeAgeProcessor = new UniformSubScopesProcessor();
    8584      var initializeAge = new Assigner() { Name = "Initialize Age" };
     85      var removeEmptySubscope = new SubScopesRemover() { Name = "Remove empty subscope (from solutioncreator)" };
    8686      var selectRandomTargetIndex = new RandomIntAssigner();
    8787      var matingPoolCreator = new SteadyStateMatingPoolCreator() { Name = "Create MatingPool" };
     
    9292      var mainOperator = new AlpsSsGeneticAlgorithmMainOperator();
    9393      var reactivateInit = new Assigner() { Name = "DoInit = true" };
    94       var resetNextIndex = new Assigner() { Name = "NextInit = 1" };
     94      var resetNextInit = new Assigner() { Name = "NextInit = 1" };
    9595      var resetTargetIndex = new Assigner() { Name = "TargetIndex = 0" };
    96       var clearMatingPool = new SubScopesRemover() { Name = "Clear WorkingScope" };
    9796      var tryMoveUp = new AlpsSsMover() { Name = "Try Move Up" };
    9897      var incrementEvaluations = new IntCounter() { Name = "incr. EvaluatedSolutions" };
     
    121120
    122121      randomScopeProcessor.Operator = isLayerZeroComperator;
     122      // TODO move to old individuals
    123123      randomScopeProcessor.Successor = incrIterations;
    124124
     
    150150      checkInitFinished.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
    151151      checkInitFinished.ResultParameter.ActualName = "DoInit";
    152       checkInitFinished.Successor = createWorkingScope;
    153 
    154       createWorkingScope.NumberOfSelectedSubScopesParameter.Value = new IntValue(0);
    155       createWorkingScope.CopySelected = new BoolValue(false);
    156       createWorkingScope.Successor = workingScopeProcessor;
    157 
    158       workingScopeProcessor.Operators.Add(createRandomIndividual);
    159       workingScopeProcessor.Operators.Add(new EmptyOperator());
     152      checkInitFinished.Successor = workingScopeProcessor;
     153
     154      workingScopeProcessor.Operator = createRandomIndividual;
     155      workingScopeProcessor.TargetScopeParameter.ActualName = "WorkingScope";
    160156
    161157      createRandomIndividual.NumberOfSolutions = new IntValue(1);
     
    163159
    164160      initializeAgeProcessor.Operator = initializeAge;
     161      initializeAgeProcessor.Successor = removeEmptySubscope;
    165162
    166163      initializeAge.LeftSideParameter.ActualName = "EvalsCreated";
     
    192189      validParentsBranch.FalseBranch = reactivateInit;
    193190
    194       reactivateInit.Successor = resetNextIndex;
     191      reactivateInit.Successor = resetNextInit;
    195192      reactivateInit.LeftSideParameter.ActualName = "DoInit";
    196193      reactivateInit.RightSideParameter.Value = new BoolValue(true);
    197194
    198       resetNextIndex.Successor = resetTargetIndex;
    199       resetNextIndex.LeftSideParameter.ActualName = "NextIndex";
    200       resetNextIndex.RightSideParameter.Value = new IntValue(1);
    201 
    202       resetTargetIndex.Successor = clearMatingPool;
     195      resetNextInit.Successor = resetTargetIndex;
     196      resetNextInit.LeftSideParameter.ActualName = "NextInit";
     197      resetNextInit.RightSideParameter.Value = new IntValue(1);
     198
    203199      resetTargetIndex.LeftSideParameter.ActualName = "TargetIndex";
    204200      resetTargetIndex.RightSideParameter.Value = new IntValue(0);
    205 
    206       clearMatingPool.Successor = createRandomIndividual;
     201      resetTargetIndex.Successor = createRandomIndividual;
    207202
    208203      tryMoveUp.Successor = incrementEvaluations;
  • 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.