1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data.MoveVectorData;
|
---|
4 | using HeuristicLab.Encodings.MoveVectorEncoding.Interfaces;
|
---|
5 | using HeuristicLab.Optimization;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Encodings.MoveVectorEncoding
|
---|
10 | {
|
---|
11 | [Item("MoveVectorCrossover", "A base class for operators that perform a crossover of int-valued vectors.")]
|
---|
12 | [StorableClass]
|
---|
13 | public abstract class MoveVectorCrossover : MoveVectorOperator, IMoveVectorCrossover, IStochasticOperator
|
---|
14 | {
|
---|
15 | public override bool CanChangeName
|
---|
16 | {
|
---|
17 | get { return false; }
|
---|
18 | }
|
---|
19 | public ILookupParameter<IRandom> RandomParameter
|
---|
20 | {
|
---|
21 | get { return (LookupParameter<IRandom>)Parameters["Random"]; }
|
---|
22 | }
|
---|
23 | public ILookupParameter<ItemArray<MoveVector>> ParentsParameter
|
---|
24 | {
|
---|
25 | get { return (ScopeTreeLookupParameter<MoveVector>)Parameters["Parents"]; }
|
---|
26 | }
|
---|
27 | public ILookupParameter<MoveVector> ChildParameter
|
---|
28 | {
|
---|
29 | get { return (ILookupParameter<MoveVector>)Parameters["Child"]; }
|
---|
30 | }
|
---|
31 |
|
---|
32 | [StorableConstructor]
|
---|
33 | protected MoveVectorCrossover(bool deserializing) : base(deserializing) { }
|
---|
34 | protected MoveVectorCrossover(MoveVectorCrossover original, Cloner cloner) : base(original, cloner) { }
|
---|
35 | protected MoveVectorCrossover() : base()
|
---|
36 | {
|
---|
37 | Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators."));
|
---|
38 | Parameters.Add(new ScopeTreeLookupParameter<MoveVector>("Parents", "The parent vectors which should be crossed."));
|
---|
39 | ParentsParameter.ActualName = "IntegerVector";
|
---|
40 | Parameters.Add(new LookupParameter<MoveVector>("Child", "The child vector resulting from the crossover."));
|
---|
41 | ChildParameter.ActualName = "IntegerVector";
|
---|
42 | }
|
---|
43 |
|
---|
44 | public sealed override IOperation InstrumentedApply()
|
---|
45 | {
|
---|
46 | ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
|
---|
47 | return base.InstrumentedApply();
|
---|
48 | }
|
---|
49 |
|
---|
50 | protected abstract MoveVector Cross(IRandom random, ItemArray<MoveVector> parents);
|
---|
51 | }
|
---|
52 | }
|
---|