using HEAL.Attic; 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.EvolutionTracking.Operators { [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.")] [StorableType("5F5FEAAD-DA7C-4C8C-A9B3-B4DE30B64C51")] public class RemovePopulationGraphFromResultsOperator : SingleSuccessorOperator { public const string ResultCollectionParameterName = "Results"; public ILookupParameter ResultCollectionParameter { get { return (ILookupParameter)Parameters[ResultCollectionParameterName]; } } [StorableConstructor] protected RemovePopulationGraphFromResultsOperator(StorableConstructorFlag _) : base(_) { } [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() { if (Parameters.ContainsKey(ResultCollectionParameterName)) { var results = ResultCollectionParameter.ActualValue; if (results.ContainsKey("PopulationGraph")) results.Remove("PopulationGraph"); } return base.Apply(); } } }