1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Operators;
|
---|
4 | using HeuristicLab.Optimization;
|
---|
5 | using HeuristicLab.Parameters;
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using System;
|
---|
8 | using System.Collections.Generic;
|
---|
9 | using System.Linq;
|
---|
10 | using System.Text;
|
---|
11 | using System.Threading.Tasks;
|
---|
12 |
|
---|
13 | namespace 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 | }
|
---|