1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Encodings.BinaryVectorEncoding;
|
---|
25 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
26 | using HeuristicLab.Encodings.ParameterVectorEncoding;
|
---|
27 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
28 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
29 | using HeuristicLab.Operators;
|
---|
30 | using HeuristicLab.Optimization;
|
---|
31 | using HeuristicLab.Parameters;
|
---|
32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Problems.Programmable {
|
---|
35 | [Item("ParameterVector Crossover", "Applies different crossovers to cross a parameter vector.")]
|
---|
36 | [StorableClass]
|
---|
37 | public class ParameterVectorCrossover : InstrumentedOperator, ICrossover {
|
---|
38 |
|
---|
39 | public ILookupParameter<ParameterVector> ChildParameter {
|
---|
40 | get { return (ILookupParameter<ParameterVector>)Parameters["Child"]; }
|
---|
41 | }
|
---|
42 | public IScopeTreeLookupParameter<ParameterVector> ParentsParameter {
|
---|
43 | get { return (IScopeTreeLookupParameter<ParameterVector>)Parameters["Parents"]; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public ILookupParameter<BinaryVector> BinaryVectorParameter {
|
---|
47 | get { return (ILookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public ILookupParameter<IntegerVector> IntegerVectorParameter {
|
---|
51 | get { return (ILookupParameter<IntegerVector>)Parameters["IntegerVector"]; }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public ILookupParameter<RealVector> RealVectorParameter {
|
---|
55 | get { return (ILookupParameter<RealVector>)Parameters["RealVector"]; }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public ILookupParameter<Permutation> PermutationParameter {
|
---|
59 | get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
|
---|
60 | }
|
---|
61 |
|
---|
62 | [StorableConstructor]
|
---|
63 | protected ParameterVectorCrossover(bool deserializing) : base(deserializing) { }
|
---|
64 | protected ParameterVectorCrossover(ParameterVectorCrossover original, Cloner cloner)
|
---|
65 | : base(original, cloner) { }
|
---|
66 | public ParameterVectorCrossover() {
|
---|
67 | Parameters.Add(new LookupParameter<ParameterVector>("Child", "The parameter vector of the child.", "ParameterVector"));
|
---|
68 | Parameters.Add(new ScopeTreeLookupParameter<ParameterVector>("Parents", "The parameter vector of the parents.", "ParameterVector"));
|
---|
69 | Parameters.Add(new LookupParameter<BinaryVector>("BinaryVector", "The binary vector that links into the parameter vector."));
|
---|
70 | Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The integer vector that links into the parameter vector."));
|
---|
71 | Parameters.Add(new LookupParameter<RealVector>("RealVector", "The real vector that links into the parameter vector."));
|
---|
72 | Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation that links into the parameter vector."));
|
---|
73 | }
|
---|
74 |
|
---|
75 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
76 | return new ParameterVectorCrossover(this, cloner);
|
---|
77 | }
|
---|
78 |
|
---|
79 | public override IOperation InstrumentedApply() {
|
---|
80 | var child = (ParameterVector)ParentsParameter.ActualValue[0].Clone();
|
---|
81 | child.BooleanParameters = BinaryVectorParameter.ActualValue;
|
---|
82 | child.IntegerParameters = IntegerVectorParameter.ActualValue;
|
---|
83 | child.RealParameters = RealVectorParameter.ActualValue;
|
---|
84 | child.PermutationParameter = PermutationParameter.ActualValue;
|
---|
85 | ChildParameter.ActualValue = child;
|
---|
86 | return base.InstrumentedApply();
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|