source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Crossover/MultiCrossover.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 7 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 1.8 KB
Line 
1using System.Reflection;
2using HeuristicLab.Collections;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Encodings.IntegerVectorEncoding;
7using HeuristicLab.Operators;
8using HeuristicLab.Optimization;
9using HeuristicLab.Parameters;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using HeuristicLab.PluginInfrastructure;
12using System;
13using System.Linq;
14
15namespace HeuristicLab.BioBoost.Operators.Mutation {
16  [StorableClass]
17  public class MultiCrossover : StochasticMultiBranch<ICrossover>, ICrossover, IStochasticOperator {
18
19    public override bool CanChangeName {
20      get { return false; }
21    }
22
23    protected override bool CreateChildOperation {
24      get { return true; }
25    }
26
27    #region Construction & Cloning
28    [StorableConstructor]
29    protected MultiCrossover(bool isDeserializing) : base(isDeserializing) {}
30    protected MultiCrossover(MultiCrossover orig, Cloner cloner) : base(orig, cloner) {}
31    public MultiCrossover() {
32      foreach (var t in ApplicationManager.Manager.GetTypes(typeof(ICrossover), Assembly.GetExecutingAssembly())) {
33        if (t == this.GetType()) continue; // avoid infinite recursion
34        ICrossover instance = null;
35        try {
36          instance = Activator.CreateInstance(t) as ICrossover;
37        } catch {}
38        if (instance != null) Operators.Add(instance);
39      }
40    }
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new MultiCrossover(this, cloner);
43    }
44    #endregion
45
46    public override IOperation InstrumentedApply() {
47        if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one crossover to choose from.");
48        return base.InstrumentedApply();
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.