#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.Drawing; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Termination { [Item("MultiTerminationCriterion", "A multi operator, containing termination criteria.")] [StorableClass] public sealed class MultiTerminationCriterion : CheckedMultiOperator, ITerminationCriterion { public static new Image StaticItemImage { get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; } } public override Image ItemImage { get { if (Breakpoint) return HeuristicLab.Common.Resources.VSImageLibrary.BreakpointActive; else return base.ItemImage; } } public ILookupParameter TerminateParameter { get { return (ILookupParameter)Parameters["Terminate"]; } } [StorableConstructor] private MultiTerminationCriterion(bool deserializing) : base(deserializing) { } private MultiTerminationCriterion(MultiTerminationCriterion original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new MultiTerminationCriterion(this, cloner); } public MultiTerminationCriterion() : base() { Parameters.Add(new LookupParameter("Terminate", "The parameter which will be set to determine if execution should be terminated or should continue.")); } public override IOperation InstrumentedApply() { if (!Operators.CheckedItems.Any()) throw new InvalidOperationException(Name + ": Please add at least one termination criterion."); var next = new OperationCollection(base.InstrumentedApply()); foreach (var item in Operators.CheckedItems) next.Add(ExecutionContext.CreateOperation(item.Value)); return next; } } }