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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Operators;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Termination {
|
---|
34 | [Item("MultiTerminator", "A multi operator, containing termination criteria.")]
|
---|
35 | [StorableClass]
|
---|
36 | public sealed class MultiTerminator : CheckedMultiOperator<ITerminator>, ITerminator {
|
---|
37 | public static new Image StaticItemImage {
|
---|
38 | get { return HeuristicLab.Common.Resources.VSImageLibrary.FlagRed; }
|
---|
39 | }
|
---|
40 | public override Image ItemImage {
|
---|
41 | get {
|
---|
42 | if (Breakpoint) return HeuristicLab.Common.Resources.VSImageLibrary.BreakpointActive;
|
---|
43 | else return base.ItemImage;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public ILookupParameter<BoolValue> TerminateParameter {
|
---|
48 | get { return (ILookupParameter<BoolValue>)Parameters["Terminate"]; }
|
---|
49 | }
|
---|
50 |
|
---|
51 | [StorableConstructor]
|
---|
52 | private MultiTerminator(bool deserializing) : base(deserializing) { }
|
---|
53 | private MultiTerminator(MultiTerminator original, Cloner cloner) : base(original, cloner) { }
|
---|
54 | public override IDeepCloneable Clone(Cloner cloner) { return new MultiTerminator(this, cloner); }
|
---|
55 |
|
---|
56 | public MultiTerminator()
|
---|
57 | : base() {
|
---|
58 | Parameters.Add(new LookupParameter<BoolValue>("Terminate", "The parameter which will be set to determine if execution should be terminated or should continue."));
|
---|
59 | }
|
---|
60 |
|
---|
61 | public override IOperation InstrumentedApply() {
|
---|
62 | if (!Operators.CheckedItems.Any()) throw new InvalidOperationException(Name + ": Please add at least one termination criterion.");
|
---|
63 |
|
---|
64 | var next = new OperationCollection(base.InstrumentedApply());
|
---|
65 | foreach (var item in Operators.CheckedItems)
|
---|
66 | next.Add(ExecutionContext.CreateOperation(item.Value));
|
---|
67 | return next;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public override void CollectParameterValues(IDictionary<string, IItem> values) {
|
---|
71 | foreach (var opParam in OperatorParameters) {
|
---|
72 | var op = opParam.Value;
|
---|
73 | var @checked = Operators.ItemChecked(op);
|
---|
74 | if (!@checked) continue;
|
---|
75 | var children = GetCollectedValues(opParam);
|
---|
76 | foreach (var c in children) {
|
---|
77 | if (String.IsNullOrEmpty(c.Key))
|
---|
78 | values.Add(opParam.Name, new StringValue(opParam.Value.ToString()));
|
---|
79 | else values.Add(opParam.Name + "." + c.Key, c.Value);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 | } |
---|