Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Optimization/3.3/Termination/MultiTerminator.cs @ 17590

Last change on this file since 17590 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.1 KB
RevLine 
[12303]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[12303]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;
[12414]23using System.Collections.Generic;
[12303]24using System.Drawing;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Parameters;
[17097]31using HEAL.Attic;
[12303]32
[12529]33namespace HeuristicLab.Optimization {
[12402]34  [Item("MultiTerminator", "A multi operator, containing termination criteria.")]
[17097]35  [StorableType("E03CCB0D-C76C-4DBC-94C5-8FED50E25D26")]
[12402]36  public sealed class MultiTerminator : CheckedMultiOperator<ITerminator>, ITerminator {
[12303]37    public static new Image StaticItemImage {
[12405]38      get { return HeuristicLab.Common.Resources.VSImageLibrary.FlagRed; }
[12303]39    }
[15217]40   
[12303]41    public ILookupParameter<BoolValue> TerminateParameter {
42      get { return (ILookupParameter<BoolValue>)Parameters["Terminate"]; }
43    }
44
45    [StorableConstructor]
[17097]46    private MultiTerminator(StorableConstructorFlag _) : base(_) { }
[12402]47    private MultiTerminator(MultiTerminator original, Cloner cloner) : base(original, cloner) { }
48    public override IDeepCloneable Clone(Cloner cloner) { return new MultiTerminator(this, cloner); }
[12303]49
[12402]50    public MultiTerminator()
[12303]51      : base() {
52      Parameters.Add(new LookupParameter<BoolValue>("Terminate", "The parameter which will be set to determine if execution should be terminated or should continue."));
53    }
54
55    public override IOperation InstrumentedApply() {
56      if (!Operators.CheckedItems.Any()) throw new InvalidOperationException(Name + ": Please add at least one termination criterion.");
57
58      var next = new OperationCollection(base.InstrumentedApply());
59      foreach (var item in Operators.CheckedItems)
60        next.Add(ExecutionContext.CreateOperation(item.Value));
61      return next;
62    }
[12414]63
64    public override void CollectParameterValues(IDictionary<string, IItem> values) {
65      foreach (var opParam in OperatorParameters) {
66        var op = opParam.Value;
67        var @checked = Operators.ItemChecked(op);
68        if (!@checked) continue;
69        var children = GetCollectedValues(opParam);
70        foreach (var c in children) {
71          if (String.IsNullOrEmpty(c.Key))
72            values.Add(opParam.Name, new StringValue(opParam.Value.ToString()));
73          else values.Add(opParam.Name + "." + c.Key, c.Value);
74        }
75      }
76    }
[12303]77  }
78}
Note: See TracBrowser for help on using the repository browser.