Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/RemovePopulationGraphFromResults.cs @ 16131

Last change on this file since 16131 was 16131, checked in by bburlacu, 6 years ago

#1772: Update project paths, add extra check in RemovePopulationGraphFromResultsOperator

File size: 2.1 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.EvolutionTracking.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      if (Parameters.ContainsKey(ResultCollectionParameterName)) {
46        var results = ResultCollectionParameter.ActualValue;
47
48        if (results.ContainsKey("PopulationGraph"))
49          results.Remove("PopulationGraph");
50      }
51
52      return base.Apply();
53    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.