1 | using System.Reflection;
|
---|
2 | using HeuristicLab.Collections;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
7 | using HeuristicLab.Operators;
|
---|
8 | using HeuristicLab.Optimization;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
11 | using HeuristicLab.PluginInfrastructure;
|
---|
12 | using System;
|
---|
13 | using System.Linq;
|
---|
14 |
|
---|
15 | namespace 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 | }
|
---|