Changeset 12550


Ignore:
Timestamp:
06/30/15 12:43:44 (4 years ago)
Author:
pfleck
Message:

#2375

  • Renamed SelectionPressureAnalyzer for layers.
  • Moved updating of terminators to concrete ALPS implementation instead of abstract base class.
Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS.OffspringSelection/3.3
Files:
2 edited

Legend:

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

    r12331 r12550  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
     
    6364      get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
    6465    }
    65     private IValueParameter<IntValue> MaximumGenerationsParameter {
    66       get { return (IValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
     66    private IFixedValueParameter<IntValue> MaximumGenerationsParameter {
     67      get { return (IFixedValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
    6768    }
    6869    private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
     
    7879      get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
    7980    }
    80     private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
    81       get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
     81    private IFixedValueParameter<DoubleValue> MaximumSelectionPressureParameter {
     82      get { return (IFixedValueParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
    8283    }
    8384    private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
     
    8788      get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
    8889    }
    89     private ValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
    90       get { return (ValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
     90    private IValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
     91      get { return (IValueParameter<IntValue>)Parameters["MaximumEvaluatedSolutions"]; }
    9192    }
    9293    private IFixedValueParameter<BoolValue> FillPopulationWithParentsParameter {
     
    124125      set { ReevaluateElitesParameter.Value.Value = value; }
    125126    }
    126     public IntValue MaximumGenerations {
    127       get { return MaximumGenerationsParameter.Value; }
    128       set { MaximumGenerationsParameter.Value = value; }
     127    public int MaximumGenerations {
     128      get { return MaximumGenerationsParameter.Value.Value; }
     129      set { MaximumGenerationsParameter.Value.Value = value; }
    129130    }
    130131    public DoubleValue SuccessRatio {
     
    144145      set { ComparisonFactorModifierParameter.Value = value; }
    145146    }
    146     public DoubleValue MaximumSelectionPressure {
    147       get { return MaximumSelectionPressureParameter.Value; }
    148       set { MaximumSelectionPressureParameter.Value = value; }
     147    public double MaximumSelectionPressure {
     148      get { return MaximumSelectionPressureParameter.Value.Value; }
     149      set { MaximumSelectionPressureParameter.Value.Value = value; }
    149150    }
    150151    public BoolValue OffspringSelectionBeforeMutation {
     
    156157      set { SelectedParentsParameter.Value = value; }
    157158    }
    158     public IntValue MaximumEvaluatedSolutions {
    159       get { return MaximumEvaluatedSolutionsParameter.Value; }
    160       set { MaximumEvaluatedSolutionsParameter.Value = value; }
    161     }
    162159    public bool FillPopulationWithParents {
    163160      get { return FillPopulationWithParentsParameter.Value.Value; }
     
    171168
    172169    [Storable]
    173     private ValueAnalyzer selectionPressureAnalyzer;
     170    private ValueAnalyzer layerSelectionPressureAnalyzer;
    174171    [Storable]
    175172    private SuccessfulOffspringAnalyzer successfulOffspringAnalyzer;
     173
     174    [Storable]
     175    private ComparisonTerminator<IntValue> generationsTerminator;
     176    //[Storable]private ComparisonTerminator<DoubleValue> selectionPressureTerminator;
    176177
    177178    [StorableConstructor]
     
    180181    private AlpsOffspringSelectionGeneticAlgorithm(AlpsOffspringSelectionGeneticAlgorithm original, Cloner cloner)
    181182      : base(original, cloner) {
    182       selectionPressureAnalyzer = cloner.Clone(original.selectionPressureAnalyzer);
     183      layerSelectionPressureAnalyzer = cloner.Clone(original.layerSelectionPressureAnalyzer);
    183184      successfulOffspringAnalyzer = cloner.Clone(original.successfulOffspringAnalyzer);
     185      generationsTerminator = cloner.Clone(original.generationsTerminator);
     186      //selectionPressureTerminator = cloner.Clone(original.selectionPressureTerminator);
    184187      Initialize();
    185188    }
     
    197200      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    198201      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 });
    199       Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     202      Parameters.Add(new FixedValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    200203      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
    201204      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
    202205      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
    203206      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
    204       Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
     207      Parameters.Add(new FixedValueParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
    205208      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.", new BoolValue(false)));
    206209      Parameters.Add(new ValueLookupParameter<IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems.", new IntValue(200)));
    207       Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
    208210      Parameters.Add(new FixedValueParameter<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.", new BoolValue(false)) { Hidden = true });
    209211
     
    285287      ParameterizeComparisonFactorModifiers();
    286288
    287       selectionPressureAnalyzer = new ValueAnalyzer();
     289      layerSelectionPressureAnalyzer = new ValueAnalyzer();
    288290      successfulOffspringAnalyzer = new SuccessfulOffspringAnalyzer();
    289       selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
    290       selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
    291       selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
    292       selectionPressureAnalyzer.ValueParameter.Depth = 0;
    293       selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
    294       successfulOffspringAnalyzer.ResultsParameter.ActualName = "Results";
     291      layerSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
     292      //layerSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
     293      layerSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
     294      layerSelectionPressureAnalyzer.ValueParameter.Depth = 0;
     295      layerSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
     296      //successfulOffspringAnalyzer.ResultsParameter.ActualName = "Results";
    295297      successfulOffspringAnalyzer.GenerationsParameter.ActualName = "Generations";
    296298      successfulOffspringAnalyzer.SuccessfulOffspringFlagParameter.Value.Value = "SuccessfulOffspring";
    297299      successfulOffspringAnalyzer.DepthParameter.Value = new IntValue(1);
     300
     301      generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, MaximumGenerationsParameter) { Name = "Generations" };
     302      //selectionPressureTerminator = new ComparisonTerminator<DoubleValue>("SelectionPressure", ComparisonType.Less, MaximumSelectionPressureParameter) { Name = "Selection Pressure" };
     303
     304      UpdateAnalyzers();
     305      UpdateTerminators();
    298306
    299307      Initialize();
     
    309317      UpdateCrossovers();
    310318      UpdateMutators();
     319      UpdateAnalyzers();
     320      UpdateTerminators();
    311321    }
    312322    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
     
    325335      UpdateCrossovers();
    326336      UpdateMutators();
     337      UpdateAnalyzers();
     338      UpdateTerminators();
    327339    }
    328340    protected override void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     
    396408
    397409    #region Updates
     410    private void UpdateTerminators() {
     411      var newTerminators = new Dictionary<ITerminator, bool> {
     412        {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)},
     413        //{selectionPressureTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(selectionPressureTerminator)},
     414        {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)},
     415        {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) },
     416        {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)}
     417      };
     418      if (Problem != null) {
     419        foreach (var terminator in Problem.Operators.OfType<ITerminator>())
     420          newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator));
     421      }
     422
     423      Terminators.Operators.Clear();
     424
     425      foreach (var newTerminator in newTerminators)
     426        Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
     427    }
    398428    private void UpdateCrossovers() {
    399429      var oldCrossover = CrossoverParameter.Value;
     
    427457      }
    428458    }
     459    private void UpdateAnalyzers() {
     460      LayerAnalyzer.Operators.Add(layerSelectionPressureAnalyzer, layerSelectionPressureAnalyzer.EnabledByDefault);
     461      layerSelectionPressureAnalyzer.ValueParameter.Depth = 0; // Correct Depth because the depth of layer-analyzers is automatically set to 1
     462      LayerAnalyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault);
     463    }
    429464    #endregion
    430465  }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS.OffspringSelection/3.3/AlpsOffspringSelectionGeneticAlgorithmMainLoop.cs

    r12348 r12550  
    113113      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
    114114      var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
    115       var generationsComparator = new Comparator() { Name = "Generations >= MaximumGenerations" };
    116       var terminateBranch = new ConditionalBranch() { Name = "Terminate?" };
     115      var termination = new TerminationOperator();
    117116
    118117      OperatorGraph.InitialOperator = variableCreator;
     
    190189
    191190      analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
    192       analyzerPlaceholder.Successor = generationsComparator;
    193 
    194       generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
    195       generationsComparator.LeftSideParameter.ActualName = "Generations";
    196       generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
    197       generationsComparator.ResultParameter.ActualName = "TerminateGenerations";
    198       generationsComparator.Successor = terminateBranch;
    199 
    200       terminateBranch.ConditionParameter.ActualName = "TerminateGenerations";
    201       terminateBranch.FalseBranch = matingPoolPreProcessor;
     191      analyzerPlaceholder.Successor = termination;
     192
     193      termination.ContinueBranch = matingPoolPreProcessor;
    202194    }
    203195
Note: See TracChangeset for help on using the changeset viewer.