Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Operators/CleanupOperator.cs @ 9082

Last change on this file since 9082 was 9082, checked in by bburlacu, 11 years ago

#1772: Renamed and refactored genealogy graph components. Added SymbolGraph and FPGraph (frequent pattern graph). Added evolvability and genetic operator average improvement analyzer.

File size: 6.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using CloneMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItem>;
30using GeneticExchangeMapType = HeuristicLab.Core.ItemList<HeuristicLab.Core.IItem>;
31using TraceMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItemList<HeuristicLab.Core.IItem>>;
32
33namespace HeuristicLab.EvolutionaryTracking {
34  /// <summary>
35  /// An operator which performs some cleanup at the end of the main loop.
36  /// </summary>
37  [Item("CleanupOperator", "This operator should be the last to run in the main loop and clean up the tracking-related data structures.")]
38  [StorableClass]
39  public sealed class CleanupOperator : SingleSuccessorOperator {
40    #region Parameter Names
41    private const string GlobalTraceMapParameterName = "GlobalTraceMap";
42    private const string GlobalCloneMapParameterName = "GlobalCloneMap";
43    private const string GlobalFragmentMapParameterName = "GlobalFragmentMap";
44    private const string GlobalGeneticExchangeMapParameterName = "GlobalGeneticExchangeMap";
45    private const string PopulationGraphParameterName = "PopulationGraph";
46    private const string GenerationsParameterName = "Generations";
47    private const string MaximumGenerationsParameterName = "MaximumGenerations";
48    private const string ResultsParameterName = "Results";
49    private const string DeleteGenealogyGraphParameterName = "DeleteGenealogyGraph";
50    #endregion
51
52    #region Parameter Properties
53    public LookupParameter<TraceMapType> GlobalTraceMapParameter {
54      get { return (LookupParameter<TraceMapType>)Parameters[GlobalTraceMapParameterName]; }
55    }
56    public LookupParameter<CloneMapType> GlobalCloneMapParameter {
57      get { return (LookupParameter<CloneMapType>)Parameters[GlobalCloneMapParameterName]; }
58    }
59    public LookupParameter<CloneMapType> GlobalFragmentMapParameter {
60      get { return (LookupParameter<CloneMapType>)Parameters[GlobalFragmentMapParameterName]; }
61    }
62    public LookupParameter<GeneticExchangeMapType> GlobalGeneticExchangeMapParameter {
63      get { return (LookupParameter<GeneticExchangeMapType>)Parameters[GlobalGeneticExchangeMapParameterName]; }
64    }
65    public LookupParameter<IntValue> GenerationsParameter {
66      get { return (LookupParameter<IntValue>)Parameters[GenerationsParameterName]; }
67    }
68    public LookupParameter<IntValue> MaximumGenerationsParameter {
69      get { return (LookupParameter<IntValue>)Parameters[MaximumGenerationsParameterName]; }
70    }
71    public LookupParameter<ResultCollection> ResultsParameter {
72      get { return (LookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
73    }
74    public ValueParameter<BoolValue> DeleteGenealogyGraphParameter {
75      get { return (ValueParameter<BoolValue>)Parameters[DeleteGenealogyGraphParameterName]; }
76    }
77    #endregion
78
79    #region Properties
80    public CloneMapType GlobalCloneMap {
81      get { return GlobalCloneMapParameter.ActualValue; }
82    }
83    public TraceMapType GlobalTraceMap {
84      get { return GlobalTraceMapParameter.ActualValue; }
85    }
86    public CloneMapType GlobalFragmentMap {
87      get { return GlobalFragmentMapParameter.ActualValue; }
88    }
89    public GeneticExchangeMapType GlobalGeneticExchangeMap {
90      get { return GlobalGeneticExchangeMapParameter.ActualValue; }
91    }
92    public IntValue Generations {
93      get { return GenerationsParameter.ActualValue; }
94    }
95    public IntValue MaximumGenerations {
96      get { return MaximumGenerationsParameter.ActualValue; }
97    }
98    public ResultCollection Results {
99      get { return ResultsParameter.ActualValue; }
100    }
101    #endregion
102
103    [StorableHook(HookType.AfterDeserialization)]
104    private void AfterDeserialization() {
105      if (!Parameters.ContainsKey(GlobalGeneticExchangeMapParameterName))
106        Parameters.Add(new LookupParameter<GeneticExchangeMapType>(GlobalGeneticExchangeMapParameterName));
107    }
108
109    [StorableConstructor]
110    private CleanupOperator(bool deserializing) : base(deserializing) { }
111    private CleanupOperator(SingleSuccessorOperator original, Cloner cloner) : base(original, cloner) { }
112    public override IDeepCloneable Clone(Cloner cloner) { return new CleanupOperator(this, cloner); }
113
114    public CleanupOperator()
115      : base() {
116      Parameters.Add(new LookupParameter<TraceMapType>(GlobalTraceMapParameterName));
117      Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName));
118      Parameters.Add(new LookupParameter<CloneMapType>(GlobalFragmentMapParameterName));
119      Parameters.Add(new LookupParameter<GeneticExchangeMapType>(GlobalGeneticExchangeMapParameterName));
120      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName));
121      Parameters.Add(new LookupParameter<IntValue>(MaximumGenerationsParameterName));
122      Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
123    }
124
125    public override IOperation Apply() {
126      if (GlobalCloneMap != null) GlobalCloneMap.Clear();
127      if (GlobalFragmentMap != null) GlobalFragmentMap.Clear();
128      if (GlobalTraceMap != null) GlobalTraceMap.Clear();
129      if (GlobalGeneticExchangeMap != null) GlobalGeneticExchangeMap.Clear();
130
131      // if we are at the end of the run, then we clear the genealogy graph (to save memory)
132      if (Generations.Value == MaximumGenerations.Value)
133        if (Results.ContainsKey(PopulationGraphParameterName)) {
134          var graph = (SymbolicExpressionTreeGenealogyGraph)Results[PopulationGraphParameterName].Value;
135          Results.Remove(PopulationGraphParameterName);
136          graph.Dispose();
137        }
138
139      return base.Apply();
140    }
141  }
142}
Note: See TracBrowser for help on using the repository browser.