#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 HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Optimization { [Item("ExecutionTimeTerminator", "A termination criterion based on execution time of an algorithm.")] [StorableClass] public class ExecutionTimeTerminator : ThresholdTerminator { [Storable] private readonly IExecutable executable; [StorableConstructor] protected ExecutionTimeTerminator(bool deserializing) : base(deserializing) { } protected ExecutionTimeTerminator(ExecutionTimeTerminator original, Cloner cloner) : base(original, cloner) { executable = cloner.Clone(original.executable); } public override IDeepCloneable Clone(Cloner cloner) { return new ExecutionTimeTerminator(this, cloner); } public ExecutionTimeTerminator(IExecutable executable) : this(executable, new TimeSpanValue(new TimeSpan(0, 10, 0))) { } public ExecutionTimeTerminator(IExecutable executable, TimeSpanValue maximumExecutionTime) : base(maximumExecutionTime) { this.executable = executable; Name = "Execution Time"; } protected override bool CheckContinueCriterion() { var max = ThresholdParameter.Value.Value; return executable.ExecutionTime < max; } public override string ToString() { if (Threshold == null) return Name; else return string.Format("{0} {1} {2}", Name, "<", ThresholdParameter.Value); } } }