Changeset 12548


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

#2269 Moved updating of terminators to concrete ALPS implementation instead of abstract base class.

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

Legend:

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

    r12531 r12548  
    162162    #region Preconfigured Terminators
    163163    [Storable]
    164     private ComparisonTerminator<IntValue> evaluationsTerminator;
     164    protected ComparisonTerminator<IntValue> evaluationsTerminator;
    165165    [Storable]
    166     private SingleObjectiveQualityTerminator qualityTerminator;
     166    protected SingleObjectiveQualityTerminator qualityTerminator;
    167167    [Storable]
    168     private ExecutionTimeTerminator executionTimeTerminator;
     168    protected ExecutionTimeTerminator executionTimeTerminator;
    169169    #endregion
    170170
     
    201201      layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    202202
     203      evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" };
     204      qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" };
     205      executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5)));
     206
    203207      ParameterizeAgeLimits();
    204208      ParameterizeAgeInheritanceReduction();
     
    207211      UpdateAnalyzers();
    208212
    209       CreateTerminators();
    210213      ParameterizeTerminators();
    211       UpdateTerminators();
    212214
    213215      Initialize();
     
    231233      ParameterizeTerminators();
    232234      UpdateAnalyzers();
    233       UpdateTerminators();
    234235      Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
    235236    }
     
    262263        ParameterizeStochasticOperator(@operator);
    263264      UpdateAnalyzers();
    264       UpdateTerminators();
    265265      base.Problem_OperatorsChanged(sender, e);
    266266    }
     
    410410      }
    411411    }
    412     protected virtual void UpdateTerminators() {
    413       var newTerminators = new Dictionary<ITerminator, bool> {
    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     }
    428     protected virtual void CreateTerminators() {
    429       evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" };
    430       qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" };
    431       executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5)));
    432     }
    433412    #endregion
    434413  }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs

    r12533 r12548  
    200200      }
    201201
     202      generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" };
     203
    202204      ParameterizeSelectors();
     205
     206      UpdateTerminators();
     207
    203208      Initialize();
    204209    }
     
    213218      UpdateCrossovers();
    214219      UpdateMutators();
     220      UpdateTerminators();
    215221    }
    216222    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
     
    229235      UpdateCrossovers();
    230236      UpdateMutators();
     237      UpdateTerminators();
    231238    }
    232239    protected override void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     
    291298
    292299    #region Updates
    293     protected override void UpdateTerminators() {
     300    private void UpdateTerminators() {
    294301      var newTerminators = new Dictionary<ITerminator, bool> {
    295302        {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)},
     303        {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)},
     304        {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) },
     305        {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)}
    296306      };
    297 
    298       base.UpdateTerminators();
     307      if (Problem != null) {
     308        foreach (var terminator in Problem.Operators.OfType<ITerminator>())
     309          newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator));
     310      }
     311
     312      Terminators.Operators.Clear();
    299313
    300314      foreach (var newTerminator in newTerminators)
    301         Terminators.Operators.Insert(0, newTerminator.Key, newTerminator.Value);
    302     }
    303     protected override void CreateTerminators() {
    304       generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" };
    305       base.CreateTerminators();
     315        Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
    306316    }
    307317    private void UpdateCrossovers() {
Note: See TracChangeset for help on using the changeset viewer.