Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10639 for trunk


Ignore:
Timestamp:
03/19/14 16:47:51 (11 years ago)
Author:
mkommend
Message:

#2172: Added parameter to configure if parents should be used instead of lucky losers to fill the actual generation.

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithmMainLoop.cs

    r9592 r10639  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2829using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Selection;
    3032
    3133namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
     
    265267      mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
    266268      mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
     269      foreach (var offspringSelector in mainOperator.OperatorGraph.Operators.OfType<OffspringSelector>())
     270        offspringSelector.FillPopulationWithParents = true;
    267271
    268272      islandAnalyzer2.Name = "Island Analyzer (placeholder)";
  • trunk/sources/HeuristicLab.Selection/3.3/OffspringSelector.cs

    r9456 r10639  
    5757    }
    5858
     59    public FixedValueParameter<BoolValue> FillPopulationWithParentsParameter {
     60      get { return (FixedValueParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
     61    }
     62
    5963    public IOperator OffspringCreator {
    6064      get { return OffspringCreatorParameter.Value; }
     
    6266    }
    6367
     68    public bool FillPopulationWithParents {
     69      get { return FillPopulationWithParentsParameter.Value.Value; }
     70      set { FillPopulationWithParentsParameter.Value.Value = value; }
     71    }
     72
    6473    [StorableConstructor]
    6574    protected OffspringSelector(bool deserializing) : base(deserializing) { }
     75    [StorableHook(HookType.AfterDeserialization)]
     76    private void AfterDeserialization() {
     77      // BackwardsCompatibility3.3
     78      #region Backwards compatible code, remove with 3.4
     79      if (!Parameters.ContainsKey("FillPopulationWithParents"))
     80        Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individuals instead of lucky losers.", new BoolValue(false)));
     81      #endregion
     82    }
     83
    6684    protected OffspringSelector(OffspringSelector original, Cloner cloner) : base(original, cloner) { }
    6785    public override IDeepCloneable Clone(Cloner cloner) {
     
    7896      Parameters.Add(new ScopeTreeLookupParameter<BoolValue>("SuccessfulOffspring", "True if the offspring was more successful than its parents.", 2));
    7997      Parameters.Add(new OperatorParameter("OffspringCreator", "The operator used to create new offspring."));
     98      Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individuals instead of lucky losers.", new BoolValue(false)));
    8099    }
    81100
     
    133152          successfulOffspringAdded++;
    134153        } else if (worseOffspringNeeded > 0 || tmpSelPress >= maxSelPress) {
    135           IScope currentOffspring = offspring.SubScopes[i];
    136           offspring.SubScopes.Remove(currentOffspring);
    137           i--;
     154          IScope currentOffspring;
     155          if (!FillPopulationWithParents || worseOffspringNeeded > 0) {
     156            currentOffspring = offspring.SubScopes[i];
     157            offspring.SubScopes.Remove(currentOffspring);
     158            i--;
     159            worseOffspringNeeded--;
     160          } else {
     161            currentOffspring = parents.SubScopes[i];
     162          }
    138163          population.Add(currentOffspring);
    139           worseOffspringNeeded--;
    140164        }
    141165        tmpSelPress += tmpSelPressInc;
Note: See TracChangeset for help on using the changeset viewer.