Free cookie consent management tool by TermsFeed Policy Generator

source: branches/TerminationCriteria/HeuristicLab.Termination/3.3/MultiTerminationCriterion.cs @ 12349

Last change on this file since 12349 was 12303, checked in by pfleck, 10 years ago

#2027 First draft for termination criteria.

File size: 2.8 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("MultiTerminationCriterion", "A multi operator, containing termination criteria.")]
34  [StorableClass]
35  public sealed class MultiTerminationCriterion : CheckedMultiOperator<ITerminationCriterion>, ITerminationCriterion {
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 MultiTerminationCriterion(bool deserializing) : base(deserializing) { }
52    private MultiTerminationCriterion(MultiTerminationCriterion original, Cloner cloner) : base(original, cloner) { }
53    public override IDeepCloneable Clone(Cloner cloner) { return new MultiTerminationCriterion(this, cloner); }
54
55    public MultiTerminationCriterion()
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.