Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis.GenealogyAnalysis/Operators/RemovePopulationGraphFromResults.cs @ 17251

Last change on this file since 17251 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

File size: 2.0 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Operators;
4using HeuristicLab.Optimization;
5using HeuristicLab.Parameters;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using System;
8using System.Collections.Generic;
9using System.Linq;
10using System.Text;
11using System.Threading.Tasks;
12
13namespace HeuristicLab.Problems.ProgramSynthesis.Operators {
14  [StorableClass]
15  [Item("RemovePopulationGraphFromResultsOperator", "In some cases the genealogy graph is necessary during the run but to save memory it should be removed from the results at the end of the run.")]
16  public class RemovePopulationGraphFromResultsOperator : SingleSuccessorOperator {
17
18    public const string ResultCollectionParameterName = "Results";
19
20    public ILookupParameter<ResultCollection> ResultCollectionParameter {
21      get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; }
22    }
23
24    [StorableConstructor]
25    protected RemovePopulationGraphFromResultsOperator(bool deserializing) : base(deserializing) { }
26
27    [StorableHook(HookType.AfterDeserialization)]
28    private void AfterDeserialization() {
29      if (!Parameters.ContainsKey(ResultCollectionParameterName))
30        Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName));
31    }
32
33    public RemovePopulationGraphFromResultsOperator() {
34      Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName));
35    }
36
37    public RemovePopulationGraphFromResultsOperator(RemovePopulationGraphFromResultsOperator original, Cloner cloner) : base(original, cloner) {
38    }
39
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new RemovePopulationGraphFromResultsOperator(this, cloner);
42    }
43
44    public override IOperation Apply() {
45      var results = ResultCollectionParameter.ActualValue;
46
47      if (results.ContainsKey("PopulationGraph"))
48        results.Remove("PopulationGraph");
49
50      return base.Apply();
51    }
52  }
53}
Note: See TracBrowser for help on using the repository browser.