[17434] | 1 | using HEAL.Attic;
|
---|
| 2 | using HeuristicLab.Common;
|
---|
[15757] | 3 | using HeuristicLab.Core;
|
---|
| 4 | using HeuristicLab.Operators;
|
---|
| 5 | using HeuristicLab.Optimization;
|
---|
| 6 | using HeuristicLab.Parameters;
|
---|
| 7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 8 | using System;
|
---|
| 9 | using System.Collections.Generic;
|
---|
| 10 | using System.Linq;
|
---|
| 11 | using System.Text;
|
---|
| 12 | using System.Threading.Tasks;
|
---|
| 13 |
|
---|
| 14 | namespace 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.")]
|
---|
[17434] | 16 | [StorableType("5F5FEAAD-DA7C-4C8C-A9B3-B4DE30B64C51")]
|
---|
[15757] | 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]
|
---|
[17434] | 26 | protected RemovePopulationGraphFromResultsOperator(StorableConstructorFlag _) : base(_) { }
|
---|
[15757] | 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() {
|
---|
[16131] | 46 | if (Parameters.ContainsKey(ResultCollectionParameterName)) {
|
---|
| 47 | var results = ResultCollectionParameter.ActualValue;
|
---|
[15757] | 48 |
|
---|
[16131] | 49 | if (results.ContainsKey("PopulationGraph"))
|
---|
| 50 | results.Remove("PopulationGraph");
|
---|
| 51 | }
|
---|
[15757] | 52 |
|
---|
| 53 | return base.Apply();
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|