#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Analysis; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Algorithms.ALPS { [Item("LayerCreator", "An operator which creates a new layer by cloning the oldest one and setting the variables accordingly.")] [StorableClass] public sealed class LayerCreator : SingleSuccessorOperator { /*private static readonly ISet SavedVariables = new HashSet{ "LocalRandom", "Layer", "LayerEvaluatedSolutions", "NumSubScopes" };*/ private ILookupParameter OpenLayersParameter { get { return (ILookupParameter)Parameters["OpenLayers"]; } } [StorableConstructor] private LayerCreator(bool deserializing) : base(deserializing) { } private LayerCreator(LayerCreator original, Cloner cloner) : base(original, cloner) { } public LayerCreator() : base() { Parameters.Add(new LookupParameter("OpenLayers")); } public override IDeepCloneable Clone(Cloner cloner) { return new LayerCreator(this, cloner); } public override IOperation Apply() { var scopes = ExecutionContext.Scope.SubScopes; if (scopes.Count < 1) throw new ArgumentException("At least one sub-scope must exist."); var lastSubScope = scopes.Last(); var clone = (IScope)lastSubScope.Clone(new Cloner()); int number; if (int.TryParse(clone.Name, out number)) clone.Name = (number + 1).ToString(); scopes.Add(clone); clone.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value); foreach (var solution in clone.SubScopes) ((IntValue)solution.Variables["Age"].Value).Value -= 1; // Decrement age, because MainOperator is goint to increment it //foreach (var variable in clone.Variables.Where(v => !SavedVariables.Contains(v.Name))) // variable.Value = null; //HACK: delete old values from quality table /*var rows = ((DataTable)clone.Variables["Qualities"].Value).Rows; var last = rows.Last(); rows.Clear(); rows.Add(last);*/ return base.Apply(); } } }