Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/25/15 17:50:52 (8 years ago)
Author:
pfleck
Message:

#2527 Implemented ALPS-OSGA on the base of the AlpsGeneticAlgorithm and and the OffspringSelectionGeneticAlgorithmMainOperator.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/AlpsOffspringSelectionGeneticAlgorithmMainLoop.cs

    r13326 r13402  
    3232namespace HeuristicLab.Algorithms.ALPS {
    3333
    34   [Item("AlpsGeneticAlgorithmMainLoop", "An ALPS genetic algorithm main loop operator.")]
     34  [Item("AlpsOffspringSelectionGeneticAlgorithmMainLoop", "An ALPS offspring selection genetic algorithm main loop operator.")]
    3535  [StorableClass]
    36   public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {
     36  public sealed class AlpsOffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator {
    3737    #region Parameter Properties
    3838    public IValueLookupParameter<IRandom> GlobalRandomParameter {
     
    9191      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
    9292    }
    93     public IValueLookupParameter<BoolValue> PlusSelectionParameter {
    94       get { return (IValueLookupParameter<BoolValue>)Parameters["PlusSelection"]; }
     93
     94    public IValueLookupParameter<DoubleValue> SuccessRatioParameter {
     95      get { return (IValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
     96    }
     97    public ILookupParameter<DoubleValue> ComparisonFactorParameter {
     98      get { return (ILookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
     99    }
     100    public IValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
     101      get { return (IValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
     102    }
     103    public IValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
     104      get { return (IValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
     105    }
     106    public IValueLookupParameter<BoolValue> FillPopulationWithParentsParameter {
     107      get { return (IValueLookupParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
    95108    }
    96109
     
    121134
    122135    [StorableConstructor]
    123     private AlpsGeneticAlgorithmMainLoop(bool deserializing)
     136    private AlpsOffspringSelectionGeneticAlgorithmMainLoop(bool deserializing)
    124137      : base(deserializing) { }
    125     private AlpsGeneticAlgorithmMainLoop(AlpsGeneticAlgorithmMainLoop original, Cloner cloner)
     138    private AlpsOffspringSelectionGeneticAlgorithmMainLoop(AlpsOffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner)
    126139      : base(original, cloner) { }
    127140    public override IDeepCloneable Clone(Cloner cloner) {
    128       return new AlpsGeneticAlgorithmMainLoop(this, cloner);
    129     }
    130     public AlpsGeneticAlgorithmMainLoop()
     141      return new AlpsOffspringSelectionGeneticAlgorithmMainLoop(this, cloner);
     142    }
     143    public AlpsOffspringSelectionGeneticAlgorithmMainLoop()
    131144      : base() {
    132145      Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
     
    151164      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
    152165      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
    153       Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation."));
     166
     167      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
     168      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1]."));
     169      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
     170      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation."));
     171      Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded."));
    154172
    155173      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
     
    168186      var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
    169187      var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
     188      var layerResultCollector = new ResultsCollector() { Name = "Collect layer results" };
    170189      var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
    171190      var resultsCollector = new ResultsCollector();
     
    173192      var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" };
    174193      var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
    175       var mainOperator = new AlpsGeneticAlgorithmMainOperator();
     194      var mainOperator = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
    176195      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
    177196      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
     
    195214      layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Layer", new IntValue(0)));
    196215      layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
     216      layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
     217      layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
    197218      layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
    198219
    199220      initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
    200       initLayerAnalyzerPlaceholder.Successor = null;
     221      initLayerAnalyzerPlaceholder.Successor = layerResultCollector;
     222
     223      layerResultCollector.ResultsParameter.ActualName = "LayerResults";
     224      layerResultCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Selection Pressure", "Displays the rising selection pressure during a generation.", "SelectionPressure"));
     225      layerResultCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Success Ratio", "Indicates how many successful children were already found during a generation (relative to the population size).", "CurrentSuccessRatio"));
     226      layerResultCollector.Successor = null;
    201227
    202228      initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
     
    233259      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
    234260      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
    235       mainOperator.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
     261      mainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
     262      mainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
     263      mainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
     264      mainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";
     265      mainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
     266      mainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
     267      mainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
    236268      mainOperator.AgeParameter.ActualName = AgeParameter.Name;
    237269      mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
     
    327359      var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" };
    328360      var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" };
    329       var createChildrenViaCrossover = new AlpsGeneticAlgorithmMainOperator();
     361      var createChildrenViaCrossover = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
    330362      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
    331363      var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
     
    373405      createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name;
    374406      createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name;
    375       createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.Name;
     407      createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.ActualName;
    376408      createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
    377409      createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name;
    378410      createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
    379       createChildrenViaCrossover.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
     411      createChildrenViaCrossover.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
     412      createChildrenViaCrossover.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
     413      createChildrenViaCrossover.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
     414      createChildrenViaCrossover.SelectionPressureParameter.ActualName = "SelectionPressure";
     415      createChildrenViaCrossover.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
     416      createChildrenViaCrossover.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
     417      createChildrenViaCrossover.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
    380418      createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name;
    381419      createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
Note: See TracChangeset for help on using the changeset viewer.