Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13095


Ignore:
Timestamp:
10/30/15 17:10:35 (9 years ago)
Author:
pfleck
Message:

#2269

  • Added the possibility of continuous reseeding (percentage based reseeding of layer 0).
  • Restructured operator graph.
  • Deleted LayerUpdator (replaced by LayerOpener`)
  • Deleted LayerSorter.
  • Moved preparing of GeneticAlgorithmMainLoop to AlpsGeneticAlgorithmMainOperator.
Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
Files:
3 added
2 deleted
4 edited

Legend:

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

    r13046 r13095  
    114114      get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; }
    115115    }
     116    private IValueParameter<BoolValue> ContinuousReseedingParameter {
     117      get { return (IValueParameter<BoolValue>)Parameters["ContinuousReseeding"]; }
     118    }
    116119
    117120    private IValueParameter<MultiTerminator> TerminatorParameter {
     
    195198      get { return MatingPoolRangeParameter.Value; }
    196199      set { MatingPoolRangeParameter.Value = value; }
     200    }
     201    public BoolValue ContinuousReseeding {
     202      get { return ContinuousReseedingParameter.Value; }
     203      set { ContinuousReseedingParameter.Value = value; }
    197204    }
    198205
     
    296303
    297304      Parameters.Add(new ValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true });
     305      Parameters.Add(new ValueParameter<BoolValue>("ContinuousReseeding", "Instead of replacing the lowest layer every AgeGap generations replace 1/AgeGap individuals every generation", new BoolValue(false)) { Hidden = true });
    298306
    299307      Parameters.Add(new ValueParameter<MultiTerminator>("Terminator", "The termination criteria which sould be checked.", new MultiTerminator()));
     
    546554      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    547555      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    548       MainLoop.LayerUpdator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    549       MainLoop.LayerUpdator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    550556    }
    551557    private void ParameterizeMainLoop() {
     
    555561      MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    556562      MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    557       MainLoop.LayerUpdator.SolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
    558563    }
    559564    private void ParameterizeAnalyzers() {
     
    614619      int numberOfLayers = NumberOfLayers.Value;
    615620      AgeLimits = scheme.CalculateAgeLimits(ageGap, numberOfLayers);
     621      AgeLimits[AgeLimits.Length - 1] = int.MaxValue; // last layer infinite age limit
    616622    }
    617623
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs

    r13046 r13095  
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    32 using HeuristicLab.Selection;
    3332
    3433namespace HeuristicLab.Algorithms.ALPS {
     
    6160      get { return OperatorGraph.Iterate().OfType<EldersEmigrator>().First(); }
    6261    }
    63     public LayerUpdator LayerUpdator {
    64       get { return OperatorGraph.Iterate().OfType<LayerUpdator>().First(); }
    65     }
    6662
    6763    [StorableConstructor]
     
    9086      var matingPoolProcessor = new UniformSubScopesProcessor();
    9187      var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
    92       var mainOperator = CreatePreparedGeneticAlgorithmMainLoop();
     88      var mainOperator = AlpsGeneticAlgorithmMainOperator.Create();
    9389      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
    9490      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
    9591      var eldersEmigrator = new EldersEmigrator() { Name = "Emigrate Elders" };
    96       var layerUpdator = new LayerUpdator(mainOperator) { Name = "Update Layers" };
     92      var layerOpener = new LayerOpener() { Name = "Open new Layer" };
     93      var layerReseeder = new LayerReseeder() { Name = "Reseed Layer Zero" };
    9794      var layerAnalyzerProcessor = new UniformSubScopesProcessor();
    9895      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
     
    146143      evaluatedSolutionsReducer.Successor = eldersEmigrator;
    147144
    148       eldersEmigrator.Successor = layerUpdator;
     145      eldersEmigrator.Successor = layerOpener;
    149146
    150       layerUpdator.Successor = layerAnalyzerProcessor;
     147      layerOpener.Successor = layerReseeder;
     148
     149      layerReseeder.Successor = layerAnalyzerProcessor;
    151150
    152151      layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder;
     
    160159      termination.ContinueBranch = matingPoolCreator;
    161160    }
    162 
    163     private GeneticAlgorithmMainLoop CreatePreparedGeneticAlgorithmMainLoop() {
    164       var mainLoop = new GeneticAlgorithmMainLoop();
    165 
    166       var oldInitialOp = mainLoop.OperatorGraph.InitialOperator;
    167       var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector");
    168       var crossover = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Crossover");
    169       var subScopesCounter = mainLoop.OperatorGraph.Iterate().OfType<SubScopesCounter>().First();
    170       var elitesMerger = mainLoop.OperatorGraph.Iterate().OfType<MergingReducer>().First();
    171 
    172       // Operator starts with calculating number of selected scopes base on plus/comma-selection replacement scheme
    173       var numberOfSubScopesBranch = new ConditionalBranch() { Name = "PlusSelection?" };
    174       var numberOfSelectedSubScopesPlusCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = PopulationSize * 2" };
    175       var numberOfSelectedSubScopesCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = (PopulationSize - Elites) * 2" };
    176       var replacementBranch = new ConditionalBranch() { Name = "PlusSelection?" };
    177 
    178       // Set new initial operator
    179       mainLoop.OperatorGraph.InitialOperator = numberOfSubScopesBranch;
    180 
    181       numberOfSubScopesBranch.ConditionParameter.ActualName = "PlusSelection";
    182       numberOfSubScopesBranch.TrueBranch = numberOfSelectedSubScopesPlusCalculator;
    183       numberOfSubScopesBranch.FalseBranch = numberOfSelectedSubScopesCalculator;
    184       numberOfSubScopesBranch.Successor = selector;
    185 
    186       numberOfSelectedSubScopesPlusCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
    187       numberOfSelectedSubScopesPlusCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";
    188       numberOfSelectedSubScopesPlusCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 2 * toint");
    189 
    190       numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
    191       numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Elites"));
    192       numberOfSelectedSubScopesCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";
    193       numberOfSelectedSubScopesCalculator.ExpressionParameter.Value = new StringValue("PopulationSize Elites - 2 * toint");
    194 
    195       // Use Elitism or Plus-Selection as replacement strategy
    196       var selectedProcessor = (SubScopesProcessor)selector.Successor;
    197       var elitismReplacement = selectedProcessor.Successor;
    198       selectedProcessor.Successor = replacementBranch;
    199       replacementBranch.ConditionParameter.ActualName = "PlusSelection";
    200       replacementBranch.FalseBranch = elitismReplacement;
    201 
    202       // Plus selection replacement
    203       var replacementMergingReducer = new MergingReducer();
    204       var replacementBestSelector = new BestSelector();
    205       var replacementRightReducer = new RightReducer();
    206       replacementBranch.TrueBranch = replacementMergingReducer;
    207 
    208       replacementMergingReducer.Successor = replacementBestSelector;
    209 
    210       replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = "PopulationSize";
    211       replacementBestSelector.CopySelected = new BoolValue(false);
    212       replacementBestSelector.Successor = replacementRightReducer;
    213 
    214       replacementRightReducer.Successor = null;
    215 
    216       // Increment ages of all individuals after replacement
    217       var incrementAgeProcessor = new UniformSubScopesProcessor();
    218       var ageIncrementor = new DoubleCounter() { Name = "Increment Age" };
    219       replacementBranch.Successor = incrementAgeProcessor;
    220       incrementAgeProcessor.Operator = ageIncrementor;
    221       incrementAgeProcessor.Successor = null;
    222       ageIncrementor.ValueParameter.ActualName = "Age";
    223       ageIncrementor.Increment = new DoubleValue(1.0);
    224 
    225       // Insert AgeCalculator between crossover and its successor
    226       var crossoverSuccessor = crossover.Successor;
    227       var ageCalculator = new WeightingReducer() { Name = "Calculate Age" };
    228       crossover.Successor = ageCalculator;
    229 
    230       ageCalculator.ParameterToReduce.ActualName = "Age";
    231       ageCalculator.TargetParameter.ActualName = "Age";
    232       ageCalculator.WeightParameter.ActualName = "AgeInheritance";
    233       ageCalculator.Successor = crossoverSuccessor;
    234 
    235       // When counting the evaluated solutions, write in LayerEvaluatedSolutions
    236       subScopesCounter.ValueParameter.ActualName = "LayerEvaluatedSolutions";
    237       subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
    238 
    239       // Instead of generational loop after merging of elites, stop
    240       elitesMerger.Successor = null;
    241 
    242       // Parameterize
    243       foreach (var stochasticOperator in mainLoop.OperatorGraph.Iterate().OfType<IStochasticOperator>())
    244         stochasticOperator.RandomParameter.ActualName = "LocalRandom";
    245       foreach (var stochasticBranch in mainLoop.OperatorGraph.Iterate().OfType<StochasticBranch>())
    246         stochasticBranch.RandomParameter.ActualName = "LocalRandom";
    247 
    248       // Remove unused operators
    249       var usedOperators = mainLoop.OperatorGraph.Iterate();
    250       var unusedOperators = mainLoop.OperatorGraph.Operators.Except(usedOperators);
    251       foreach (var op in unusedOperators.ToList())
    252         mainLoop.OperatorGraph.Operators.Remove(op);
    253 
    254       return mainLoop;
    255     }
    256161  }
    257162}
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj

    r13079 r13095  
    132132  </ItemGroup>
    133133  <ItemGroup>
     134    <Compile Include="AlpsGeneticAlgorithmMainOperator.cs" />
     135    <Compile Include="LayerOpener.cs" />
     136    <Compile Include="LayerReseeder.cs" />
    134137    <Compile Include="WeightingReducer.cs" />
    135138    <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" />
     
    142145    <Compile Include="EldersSelector.cs" />
    143146    <Compile Include="LayerCreator.cs" />
    144     <Compile Include="LayerSorter.cs" />
    145     <Compile Include="LayerUpdator.cs" />
    146147    <Compile Include="MatingPoolCreator.cs" />
    147148    <Compile Include="Plugin.cs" />
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerCreator.cs

    r13046 r13095  
    3838      get { return (ILookupParameter<IntValue>)Parameters["OpenLayers"]; }
    3939    }
     40    public OperatorParameter NewLayerOperatorParameter {
     41      get { return (OperatorParameter)Parameters["NewLayerOperator"]; }
     42    }
     43
     44    public IOperator NewLayerOperator {
     45      get { return NewLayerOperatorParameter.Value; }
     46      set { NewLayerOperatorParameter.Value = value; }
     47    }
    4048
    4149    [StorableConstructor]
     
    4856      : base() {
    4957      Parameters.Add(new LookupParameter<IntValue>("OpenLayers"));
     58      Parameters.Add(new OperatorParameter("NewLayerOperator"));
    5059    }
    5160
     
    5564
    5665    public override IOperation Apply() {
    57       var scopes = ExecutionContext.Scope.SubScopes;
    58       if (scopes.Count < 1)
    59         throw new ArgumentException("At least one sub-scope must exist.");
     66      var layersScope = ExecutionContext.Scope.SubScopes;
     67      if (layersScope.Count < 1)
     68        throw new ArgumentException("At least one layer must exist.");
    6069
    61       var lastSubScope = scopes.Last();
    62       var clone = (IScope)lastSubScope.Clone(new Cloner());
     70      var newLayer = (IScope)layersScope.Last().Clone();
    6371
    6472      int number;
    65       if (int.TryParse(clone.Name, out number))
    66         clone.Name = (number + 1).ToString();
     73      if (int.TryParse(newLayer.Name, out number))
     74        newLayer.Name = (number + 1).ToString();
    6775
    68       scopes.Add(clone);
     76      layersScope.Add(newLayer);
    6977
    70       // Set new layernumber
    71       clone.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value);
     78      // Set new layer number
     79      newLayer.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value);
    7280
    7381      // Decrement ages, because MainOperator is goint to increment it
    74       foreach (var solution in clone.SubScopes)
     82      foreach (var solution in newLayer.SubScopes)
    7583        ((DoubleValue)solution.Variables["Age"].Value).Value -= 1;
    7684
    7785      // Reset existing values in the results to NaN to symbolize that no layer existed during that duration
    78       var results = (ResultCollection)clone.Variables["LayerResults"].Value;
     86      var results = (ResultCollection)newLayer.Variables["LayerResults"].Value;
    7987      ResetResults(results);
    8088
    81       return base.Apply();
     89      var next = new OperationCollection(base.Apply());
     90      next.Insert(0, ExecutionContext.CreateChildOperation(NewLayerOperator, newLayer));
     91      return next;
    8292    }
    8393
Note: See TracChangeset for help on using the changeset viewer.