Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Operators/ParameterVectorCrossover.cs @ 10753

Last change on this file since 10753 was 10753, checked in by abeham, 10 years ago

#2174: The problem is now not Sim# specific anymore, but the parameters of Sim# models could be optimized using this problem. It's all about being able to program the evaluation function and parameter vector.

File size: 4.1 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Encodings.BinaryVectorEncoding;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Encodings.ParameterVectorEncoding;
27using HeuristicLab.Encodings.PermutationEncoding;
28using HeuristicLab.Encodings.RealVectorEncoding;
29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33
34namespace 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}
Note: See TracBrowser for help on using the repository browser.