#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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 HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence; namespace HeuristicLab.Operators { /// /// An operator which increments an integer variable. /// [Item("IntCounter", "An operator which increments an integer variable.")] [StorableType("000de522-3c36-47d5-b508-a557283c314f")] public sealed class IntCounter : SingleSuccessorOperator { public LookupParameter ValueParameter { get { return (LookupParameter)Parameters["Value"]; } } public ValueLookupParameter IncrementParameter { get { return (ValueLookupParameter)Parameters["Increment"]; } } public IntValue Increment { get { return IncrementParameter.Value; } set { IncrementParameter.Value = value; } } [StorableConstructor] private IntCounter(StorableConstructorFlag deserializing) : base(deserializing) { } private IntCounter(IntCounter original, Cloner cloner) : base(original, cloner) { } public IntCounter() : base() { Parameters.Add(new LookupParameter("Value", "The value which should be incremented.")); Parameters.Add(new ValueLookupParameter("Increment", "The increment which is added to the value.", new IntValue(1))); } public override IDeepCloneable Clone(Cloner cloner) { return new IntCounter(this, cloner); } public override IOperation Apply() { if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new IntValue(); ValueParameter.ActualValue.Value += IncrementParameter.ActualValue.Value; return base.Apply(); } } }