Changeset 11543 for branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/RealEncoding.cs
- Timestamp:
- 11/12/14 17:52:15 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/RealEncoding.cs
r11484 r11543 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Text; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 29 using HeuristicLab.Encodings.RealVectorEncoding; 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Parameters; 28 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 33 … … 31 35 [Item("RealEncoding", "Describes a real vector encoding.")] 32 36 [StorableClass] 33 public class RealEncoding : Encoding { 37 public sealed class RealEncoding : Encoding { 38 34 39 [Storable] 35 private I ntValue length;36 public I ntValue Length{37 get { return length ; }40 private IFixedValueParameter<IntValue> lengthParameter; 41 public IFixedValueParameter<IntValue> LengthParameter { 42 get { return lengthParameter; } 38 43 set { 39 if (length == value) return; 40 length = value; 41 OnParameterConfigurationChanged(); 44 if(value == null) throw new ArgumentNullException("Length parameter must not be null."); 45 if (lengthParameter == value) return; 46 lengthParameter = value; 47 OnLengthParameterChanged(); 42 48 } 43 49 } 44 50 45 51 [Storable] 46 private DoubleMatrix bounds;47 public DoubleMatrix Bounds{48 get { return bounds ; }52 private IValueParameter<DoubleMatrix> boundsParameter; 53 public IValueParameter<DoubleMatrix> BoundsParameter { 54 get { return boundsParameter; } 49 55 set { 50 if (bounds == value) return; 51 bounds = value; 52 OnParameterConfigurationChanged(); 56 if (value == null) throw new ArgumentNullException("Bounds parameter must not be null."); 57 if (boundsParameter == value) return; 58 boundsParameter = value; 59 OnBoundsParameterChanged(); 53 60 } 54 61 } 55 62 63 public override IEnumerable<IValueParameter> EncodingParameters { 64 get { return base.EncodingParameters.Concat(new IValueParameter[] { LengthParameter, BoundsParameter }); } 65 } 66 67 public int Length { 68 get { return LengthParameter.Value.Value; } 69 set { LengthParameter.Value.Value = value; } 70 } 71 public DoubleMatrix Bounds { 72 get { return BoundsParameter.Value; } 73 set { BoundsParameter.Value = value; } 74 } 75 76 public ISolutionCreator SolutionCreator { 77 get { 78 var creator = new UniformRandomRealVectorCreator(); 79 creator.RealVectorParameter.ActualName = Name; 80 creator.LengthParameter.ActualName = LengthParameter.Name; 81 creator.BoundsParameter.ActualName = BoundsParameter.Name; 82 return creator; 83 } 84 } 85 56 86 [StorableConstructor] 57 pr otectedRealEncoding(bool deserializing) : base(deserializing) { }58 pr otectedRealEncoding(RealEncoding original, Cloner cloner)87 private RealEncoding(bool deserializing) : base(deserializing) { } 88 private RealEncoding(RealEncoding original, Cloner cloner) 59 89 : base(original, cloner) { 60 length = cloner.Clone(original.length);61 bounds = cloner.Clone(original.bounds);90 lengthParameter = cloner.Clone(original.lengthParameter); 91 boundsParameter = cloner.Clone(original.boundsParameter); 62 92 } 63 93 public RealEncoding(string name, int length, double min, double max) 64 94 : base(name) { 65 95 if (min >= max) throw new ArgumentException("min must be less than max", "min"); 66 this.length = new IntValue(length); 67 bounds = new DoubleMatrix(1, 2);96 97 var bounds = new DoubleMatrix(1, 2); 68 98 bounds[0, 0] = min; 69 99 bounds[0, 1] = max; 100 101 lengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length)); 102 boundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds); 70 103 } 71 104 public RealEncoding(string name, int length, IList<double> min, IList<double> max) … … 74 107 if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min"); 75 108 if (min.Zip(max, (mi, ma) => mi >= ma).Any(x => x)) throw new ArgumentException("min must be less than max in each dimension", "min"); 76 this.length = new IntValue(length); 77 bounds = new DoubleMatrix(min.Count, 2);109 110 var bounds = new DoubleMatrix(min.Count, 2); 78 111 for (int i = 0; i < min.Count; i++) { 79 112 bounds[i, 0] = min[i]; 80 113 bounds[i, 1] = max[i]; 81 114 } 82 } 115 lengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length)); 116 boundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds); 117 } 83 118 84 119 public override IDeepCloneable Clone(Cloner cloner) { … … 86 121 } 87 122 123 private void OnLengthParameterChanged() { 124 //TODO rewire parameters 125 } 126 127 private void OnBoundsParameterChanged() { 128 //TODO rewire parameters 129 } 130 131 88 132 } 89 } 133 }
Note: See TracChangeset
for help on using the changeset viewer.