Free cookie consent management tool by TermsFeed Policy Generator

source: branches/TerminationCriteria/HeuristicLab.Termination/3.3/MultiTerminator.cs @ 12402

Last change on this file since 12402 was 12402, checked in by pfleck, 9 years ago

#2027 Renamed TerminationCriterion to Terminator.

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Drawing;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Termination {
33  [Item("MultiTerminator", "A multi operator, containing termination criteria.")]
34  [StorableClass]
35  public sealed class MultiTerminator : CheckedMultiOperator<ITerminator>, ITerminator {
36    public static new Image StaticItemImage {
37      get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
38    }
39    public override Image ItemImage {
40      get {
41        if (Breakpoint) return HeuristicLab.Common.Resources.VSImageLibrary.BreakpointActive;
42        else return base.ItemImage;
43      }
44    }
45
46    public ILookupParameter<BoolValue> TerminateParameter {
47      get { return (ILookupParameter<BoolValue>)Parameters["Terminate"]; }
48    }
49
50    [StorableConstructor]
51    private MultiTerminator(bool deserializing) : base(deserializing) { }
52    private MultiTerminator(MultiTerminator original, Cloner cloner) : base(original, cloner) { }
53    public override IDeepCloneable Clone(Cloner cloner) { return new MultiTerminator(this, cloner); }
54
55    public MultiTerminator()
56      : base() {
57      Parameters.Add(new LookupParameter<BoolValue>("Terminate", "The parameter which will be set to determine if execution should be terminated or should continue."));
58    }
59
60    public override IOperation InstrumentedApply() {
61      if (!Operators.CheckedItems.Any()) throw new InvalidOperationException(Name + ": Please add at least one termination criterion.");
62
63      var next = new OperationCollection(base.InstrumentedApply());
64      foreach (var item in Operators.CheckedItems)
65        next.Add(ExecutionContext.CreateOperation(item.Value));
66      return next;
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.