using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HeuristicLab.Problems.ProgramSynthesis.Operators { [StorableClass] [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.")] public class RemovePopulationGraphFromResultsOperator : SingleSuccessorOperator { public const string ResultCollectionParameterName = "Results"; public ILookupParameter ResultCollectionParameter { get { return (ILookupParameter)Parameters[ResultCollectionParameterName]; } } [StorableConstructor] protected RemovePopulationGraphFromResultsOperator(bool deserializing) : base(deserializing) { } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { if (!Parameters.ContainsKey(ResultCollectionParameterName)) Parameters.Add(new LookupParameter(ResultCollectionParameterName)); } public RemovePopulationGraphFromResultsOperator() { Parameters.Add(new LookupParameter(ResultCollectionParameterName)); } public RemovePopulationGraphFromResultsOperator(RemovePopulationGraphFromResultsOperator original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new RemovePopulationGraphFromResultsOperator(this, cloner); } public override IOperation Apply() { var results = ResultCollectionParameter.ActualValue; if (results.ContainsKey("PopulationGraph")) results.Remove("PopulationGraph"); return base.Apply(); } } }