Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/RemovePopulationGraphFromResults.cs @ 17874

Last change on this file since 17874 was 17434, checked in by bburlacu, 5 years ago

#1772: Merge trunk changes and fix all errors and compilation warnings.

File size: 2.1 KB
Line 
1using HEAL.Attic;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Operators;
5using HeuristicLab.Optimization;
6using HeuristicLab.Parameters;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
12using System.Threading.Tasks;
13
14namespace HeuristicLab.EvolutionTracking.Operators {
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  [StorableType("5F5FEAAD-DA7C-4C8C-A9B3-B4DE30B64C51")]
17  public class RemovePopulationGraphFromResultsOperator : SingleSuccessorOperator {
18
19    public const string ResultCollectionParameterName = "Results";
20
21    public ILookupParameter<ResultCollection> ResultCollectionParameter {
22      get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; }
23    }
24
25    [StorableConstructor]
26    protected RemovePopulationGraphFromResultsOperator(StorableConstructorFlag _) : base(_) { }
27
28    [StorableHook(HookType.AfterDeserialization)]
29    private void AfterDeserialization() {
30      if (!Parameters.ContainsKey(ResultCollectionParameterName))
31        Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName));
32    }
33
34    public RemovePopulationGraphFromResultsOperator() {
35      Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName));
36    }
37
38    public RemovePopulationGraphFromResultsOperator(RemovePopulationGraphFromResultsOperator original, Cloner cloner) : base(original, cloner) {
39    }
40
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new RemovePopulationGraphFromResultsOperator(this, cloner);
43    }
44
45    public override IOperation Apply() {
46      if (Parameters.ContainsKey(ResultCollectionParameterName)) {
47        var results = ResultCollectionParameter.ActualValue;
48
49        if (results.ContainsKey("PopulationGraph"))
50          results.Remove("PopulationGraph");
51      }
52
53      return base.Apply();
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.