Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Manipulators/MultiLLEManipulator.cs @ 17243

Last change on this file since 17243 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.8 KB
RevLine 
[12286]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[12286]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.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Collections;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
[16565]31using HEAL.Attic;
[12286]32using HeuristicLab.PluginInfrastructure;
33
34namespace HeuristicLab.Encodings.LinearLinkageEncoding {
35  [Item("Multi LLE Manipulator", "Randomly selects and applies one of its manipulators every time it is called.")]
[16565]36  [StorableType("7D22C9F6-BD21-4A21-BF8E-5F176D2260E1")]
[12286]37  public class MultiLinearLinkageManipulator : StochasticMultiBranch<ILinearLinkageManipulator>, ILinearLinkageManipulator, IStochasticOperator {
38    public override bool CanChangeName {
39      get { return false; }
40    }
41    protected override bool CreateChildOperation {
42      get { return true; }
43    }
44
45    public ILookupParameter<LinearLinkage> LLEParameter {
46      get { return (ILookupParameter<LinearLinkage>)Parameters["LLE"]; }
47    }
48
49    [StorableConstructor]
[16565]50    protected MultiLinearLinkageManipulator(StorableConstructorFlag _) : base(_) { }
[12286]51    protected MultiLinearLinkageManipulator(MultiLinearLinkageManipulator original, Cloner cloner) : base(original, cloner) { }
52    public MultiLinearLinkageManipulator()
53      : base() {
54      Parameters.Add(new LookupParameter<LinearLinkage>("LLE", "The encoding vector that is to be manipulated."));
[12701]55      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ILinearLinkageManipulator), typeof(LinearLinkageEncoding).Assembly)) {
[12286]56        if (!typeof(MultiOperator<ILinearLinkageManipulator>).IsAssignableFrom(type))
57          Operators.Add((ILinearLinkageManipulator)Activator.CreateInstance(type), true);
58      }
[12701]59      SelectedOperatorParameter.ActualName = "SelectedManipulationOperator";
[12286]60    }
61
62    public override IDeepCloneable Clone(Cloner cloner) {
63      return new MultiLinearLinkageManipulator(this, cloner);
64    }
65
66    protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ILinearLinkageManipulator>> e) {
67      base.Operators_ItemsReplaced(sender, e);
68      ParameterizeManipulators(e.Items);
69    }
70
71    protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ILinearLinkageManipulator>> e) {
72      base.Operators_ItemsAdded(sender, e);
73      ParameterizeManipulators(e.Items);
74    }
75
76    private void ParameterizeManipulators(IEnumerable<IndexedItem<ILinearLinkageManipulator>> manipulators) {
77      foreach (var m in manipulators.Select(x => x.Value)) {
78        m.LLEParameter.ActualName = LLEParameter.Name;
79        var stOp = m as IStochasticOperator;
80        if (stOp != null) stOp.RandomParameter.ActualName = RandomParameter.Name;
81      }
82    }
83
84    public override IOperation InstrumentedApply() {
85      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one LLE manipulator to choose from.");
86      return base.InstrumentedApply();
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.