Changeset 12186


Ignore:
Timestamp:
03/11/15 09:33:08 (3 years ago)
Author:
pfleck
Message:

#2269 Added the possibility for a plus-selection replacement scheme.

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

Legend:

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

    r12120 r12186  
    6464      get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
    6565    }
     66    private IValueParameter<BoolValue> PlusSelectionParameter {
     67      get { return (IValueParameter<BoolValue>)Parameters["PlusSelection"]; }
     68    }
    6669    #endregion
    6770
     
    99102      get { return ReevaluateElitesParameter.Value.Value; }
    100103      set { ReevaluateElitesParameter.Value.Value = value; }
     104    }
     105    public bool PlusSelection {
     106      get { return PlusSelectionParameter.Value.Value; }
     107      set { PlusSelectionParameter.Value.Value = value; }
    101108    }
    102109
     
    126133      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    127134      Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
     135      Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false)) { Hidden = true });
    128136
    129137      var globalRandomCreator = new RandomCreator();
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs

    r12094 r12186  
    178178    private GeneticAlgorithmMainLoop CreatePreparedGeneticAlgorithmMainLoop() {
    179179      var mainLoop = new GeneticAlgorithmMainLoop();
    180       var numberOfSelectedSubScopesCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = (PopulationSize - Elites) * 2" };
     180
    181181      var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector");
    182182      var crossover = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Crossover");
     
    184184      var elitesMerger = mainLoop.OperatorGraph.Iterate().OfType<MergingReducer>().First();
    185185
    186       // Operator starts with numberOfSelectedSubScopesCalculator
    187       mainLoop.OperatorGraph.InitialOperator = numberOfSelectedSubScopesCalculator;
     186      // Operator starts with calculating number of selected scopes base on plus/comma-selection replacement scheme
     187      var numberOfSubScopesBranch = new ConditionalBranch() { Name = "PlusSelection?" };
     188      var numberOfSelectedSubScopesPlusCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = PopulationSize * 2" };
     189      var numberOfSelectedSubScopesCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = (PopulationSize - Elites) * 2" };
     190      var replacementBranch = new ConditionalBranch() { Name = "PlusSelection?" };
     191
     192      mainLoop.OperatorGraph.InitialOperator = numberOfSubScopesBranch;
     193
     194      numberOfSubScopesBranch.ConditionParameter.ActualName = "PlusSelection";
     195      numberOfSubScopesBranch.TrueBranch = numberOfSelectedSubScopesPlusCalculator;
     196      numberOfSubScopesBranch.FalseBranch = numberOfSelectedSubScopesCalculator;
     197      numberOfSubScopesBranch.Successor = selector;
     198
     199      numberOfSelectedSubScopesPlusCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
     200      numberOfSelectedSubScopesPlusCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";
     201      numberOfSelectedSubScopesPlusCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 2 * toint");
     202
    188203      numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
    189204      numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Elites"));
    190205      numberOfSelectedSubScopesCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";
    191206      numberOfSelectedSubScopesCalculator.ExpressionParameter.Value = new StringValue("PopulationSize Elites - 2 * toint");
    192       numberOfSelectedSubScopesCalculator.Successor = selector;
     207
     208      // Use Elitism or Plus-Selection as replacement strategy
     209      var selectedProcessor = (SubScopesProcessor)selector.Successor;
     210      var elitismReplacement = selectedProcessor.Successor;
     211      selectedProcessor.Successor = replacementBranch;
     212      replacementBranch.ConditionParameter.ActualName = "PlusSelection";
     213      replacementBranch.FalseBranch = elitismReplacement;
     214
     215      // Plus selection replacement
     216      var replacementMergingReducer = new MergingReducer();
     217      var replacementBestSelector = new BestSelector();
     218      var replacementRightReducer = new RightReducer();
     219      replacementBranch.TrueBranch = replacementMergingReducer;
     220
     221      replacementMergingReducer.Successor = replacementBestSelector;
     222
     223      replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = "PopulationSize";
     224      replacementBestSelector.CopySelected = new BoolValue(false);
     225      replacementBestSelector.Successor = replacementRightReducer;
     226
     227      replacementRightReducer.Successor = null;
     228
     229      // Increment ages of all individuals after replacement
     230      var incrementAgeProcessor = new UniformSubScopesProcessor();
     231      var ageIncrementor = new IntCounter() { Name = "Increment Age" };
     232      replacementBranch.Successor = incrementAgeProcessor;
     233      incrementAgeProcessor.Operator = ageIncrementor;
     234      incrementAgeProcessor.Successor = null;
     235      ageIncrementor.ValueParameter.ActualName = "Age";
     236      ageIncrementor.Increment = new IntValue(1);
     237      //ageIncrementor.Successor = null;
    193238
    194239      // Insert AgeCalculator between crossover and its successor
    195240      var crossoverSuccessor = crossover.Successor;
    196241      var ageCalculator = new DataReducer() { Name = "Calculate Age" };
     242      crossover.Successor = ageCalculator;
     243
    197244      ageCalculator.ParameterToReduce.ActualName = "Age";
    198245      ageCalculator.TargetParameter.ActualName = "Age";
     
    200247      ageCalculator.ReductionOperation.ActualName = "AgeInheritance";
    201248      ageCalculator.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
    202       crossover.Successor = ageCalculator;
    203249      ageCalculator.Successor = crossoverSuccessor;
    204250
     
    207253      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
    208254
    209       // Instead of generational loop after merging of elites, increment ages of all individuals
    210       var processor = new UniformSubScopesProcessor();
    211       var incrementor = new IntCounter() { Name = "Increment Age" };
    212       processor.Operator = incrementor;
    213       processor.Successor = null;
    214       incrementor.ValueParameter.ActualName = "Age";
    215       incrementor.Increment = new IntValue(1);
    216       incrementor.Successor = null;
    217       elitesMerger.Successor = processor;
     255      // Instead of generational loop after merging of elites, stop
     256      elitesMerger.Successor = null;
    218257
    219258      // Parameterize
Note: See TracChangeset for help on using the changeset viewer.