1 | using HEAL.Attic;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Optimization;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HeuristicLab.Problems.DataAnalysis;
|
---|
8 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
9 | using System;
|
---|
10 | using System.Collections.Generic;
|
---|
11 | using System.Linq;
|
---|
12 | using System.Text;
|
---|
13 | using System.Threading.Tasks;
|
---|
14 |
|
---|
15 | namespace HeuristicLab.Algorithms.OESRALPS.Analyzers
|
---|
16 | {
|
---|
17 | [Item("OffspringSelectionSlidingWindowAnalyzer", "An operator that analyzes the offspring selection pressure and moves a sliding window if the threshold is exceeded.")]
|
---|
18 | [StorableType("75E112AA-95B2-4BA4-8544-CF2025A65822")]
|
---|
19 | public abstract class OffspringSelectionSlidingWindowAnalyzer<T, U> : SlidingWindowAnalyzer<T, U>
|
---|
20 | where T : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<U>
|
---|
21 | where U : class, IDataAnalysisProblemData
|
---|
22 | {
|
---|
23 | private const string SelectionPressureParameterName = "SelectionPressure";
|
---|
24 | private const string SelectionPressureThresholdParameterName = "SelectionPressureThreshold";
|
---|
25 |
|
---|
26 | #region parameter properties
|
---|
27 | public IScopeTreeLookupParameter<DoubleValue> SelectionPressureParameter {
|
---|
28 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters[SelectionPressureParameterName]; }
|
---|
29 | }
|
---|
30 | public IFixedValueParameter<DoubleValue> SelectionPressureThresholdParameter {
|
---|
31 | get { return (IFixedValueParameter<DoubleValue>)Parameters[SelectionPressureThresholdParameterName]; }
|
---|
32 | }
|
---|
33 | #endregion
|
---|
34 |
|
---|
35 | #region properties
|
---|
36 | public DoubleValue SelectionPressureThreshold {
|
---|
37 | get { return SelectionPressureThresholdParameter.Value; }
|
---|
38 | }
|
---|
39 | public ItemArray<DoubleValue> SelectionPressure {
|
---|
40 | get { return SelectionPressureParameter.ActualValue; }
|
---|
41 | }
|
---|
42 | #endregion
|
---|
43 |
|
---|
44 | [StorableConstructor]
|
---|
45 | protected OffspringSelectionSlidingWindowAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
46 | protected OffspringSelectionSlidingWindowAnalyzer(OffspringSelectionSlidingWindowAnalyzer<T, U> original, Cloner cloner) : base(original, cloner) { }
|
---|
47 | public OffspringSelectionSlidingWindowAnalyzer()
|
---|
48 | {
|
---|
49 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(SelectionPressureParameterName, "Offspring selection pressure."));
|
---|
50 | Parameters.Add(new FixedValueParameter<DoubleValue>(SelectionPressureThresholdParameterName, "Offspring selection pressure threshold.", new DoubleValue(20)));
|
---|
51 | }
|
---|
52 |
|
---|
53 | public override IOperation Apply()
|
---|
54 | {
|
---|
55 | if (TrainingPartitionParameter.ActualValue == null
|
---|
56 | || IsSelectionPressureThresholdExceeded())
|
---|
57 | return OnMoveWindow();
|
---|
58 |
|
---|
59 | return base.Apply();
|
---|
60 | }
|
---|
61 |
|
---|
62 | private bool IsSelectionPressureThresholdExceeded()
|
---|
63 | {
|
---|
64 | // Selection pressure on each layer higher
|
---|
65 | // TODO consider maximum Selection Pressure
|
---|
66 | var AgeLimits =
|
---|
67 | AgingScheme
|
---|
68 | .Linear
|
---|
69 | .CalculateAgeLimits((int)SelectionPressureThreshold.Value, SelectionPressure.Count());
|
---|
70 |
|
---|
71 | // TODO think of a suitable strategy,
|
---|
72 | // leave out first layer or check only last iterations before moving to next layer
|
---|
73 | for (int i = 0; i < SelectionPressure.Count(); i++)
|
---|
74 | {
|
---|
75 | if (SelectionPressure[i].Value > AgeLimits[i])
|
---|
76 | return true;
|
---|
77 | }
|
---|
78 |
|
---|
79 | return false;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|