1 | using HeuristicLab.Encodings.MoveVectorEncoding.Interfaces;
|
---|
2 | using HeuristicLab.Operators;
|
---|
3 | using HeuristicLab.Optimization;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Common;
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 | using HeuristicLab.Parameters;
|
---|
9 | using HeuristicLab.Data.MoveVectorData;
|
---|
10 | using System.Collections.Generic;
|
---|
11 | using HeuristicLab.Data.MoveVectorData.Interfaces;
|
---|
12 | using System;
|
---|
13 | using HeuristicLab.PluginInfrastructure;
|
---|
14 | using System.Linq;
|
---|
15 |
|
---|
16 | namespace HeuristicLab.Encodings.MoveVectorEncoding
|
---|
17 | {
|
---|
18 | [Item("MoveVectorCreator", "A base class for operators creating Move Vectors.")]
|
---|
19 | [StorableClass]
|
---|
20 | public abstract class MoveVectorCreator : InstrumentedOperator, IMoveVectorCreator, IStochasticOperator
|
---|
21 | {
|
---|
22 | #region Parameter Properties
|
---|
23 | public ILookupParameter<IRandom> RandomParameter
|
---|
24 | {
|
---|
25 | get { return (LookupParameter<IRandom>)Parameters["Random"]; }
|
---|
26 | }
|
---|
27 | public ILookupParameter<MoveVector> MoveVectorParameter
|
---|
28 | {
|
---|
29 | get { return (ILookupParameter<MoveVector>)Parameters["MoveVector"]; }
|
---|
30 | }
|
---|
31 | public IValueLookupParameter<IntValue> LengthParameter
|
---|
32 | {
|
---|
33 | get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; }
|
---|
34 | }
|
---|
35 | public IValueLookupParameter<IntMatrix> BoundsParameter
|
---|
36 | {
|
---|
37 | get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
|
---|
38 | }
|
---|
39 | #endregion
|
---|
40 |
|
---|
41 | #region Properties
|
---|
42 | [Storable]
|
---|
43 | private IList<Type> moveTypes;
|
---|
44 | public IList<Type> MoveTypes
|
---|
45 | {
|
---|
46 | get
|
---|
47 | {
|
---|
48 | if(moveTypes == null) moveTypes = ApplicationManager.Manager.GetTypes(typeof(IMove)).ToList();
|
---|
49 | return moveTypes;
|
---|
50 | }
|
---|
51 | set
|
---|
52 | {
|
---|
53 | moveTypes = value;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | #endregion
|
---|
57 |
|
---|
58 | #region Cloning
|
---|
59 | [StorableConstructor]
|
---|
60 | protected MoveVectorCreator(bool deserializing) : base(deserializing) { }
|
---|
61 | protected MoveVectorCreator(MoveVectorCreator original, Cloner cloner) : base(original, cloner) { }
|
---|
62 | [StorableHook(HookType.AfterDeserialization)]
|
---|
63 | private void AfterDeserialization()
|
---|
64 | {
|
---|
65 | }
|
---|
66 | #endregion
|
---|
67 |
|
---|
68 | protected MoveVectorCreator(): base() {
|
---|
69 | Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
|
---|
70 | Parameters.Add(new LookupParameter<MoveVector>("MoveVector", "The move vector which should be manipulated."));
|
---|
71 | Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the vector."));
|
---|
72 | Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
|
---|
73 | }
|
---|
74 |
|
---|
75 | public override IOperation InstrumentedApply()
|
---|
76 | {
|
---|
77 | MoveVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue, BoundsParameter.ActualValue);
|
---|
78 | return base.InstrumentedApply();
|
---|
79 | }
|
---|
80 |
|
---|
81 | public abstract MoveVector Create(IRandom random, IntValue length, IntMatrix bounds);
|
---|
82 | }
|
---|
83 | }
|
---|