- Timestamp:
- 11/12/14 17:52:15 (10 years ago)
- Location:
- branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/Encoding.cs
r11484 r11543 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 28 30 [Item("Encoding", "Base class for describing different encodings.")] 29 31 [StorableClass] 30 public abstract class Encoding : NamedItem {31 public override bool CanChangeName {32 public abstract class Encoding : NamedItem, IEncoding { 33 public override sealed bool CanChangeName { 32 34 get { return false; } 33 35 } … … 39 41 protected Encoding(string name) : base(name) { } 40 42 43 public virtual IEnumerable<IValueParameter> EncodingParameters { 44 get { return Enumerable.Empty<IValueParameter>(); } 45 } 41 46 42 public event EventHandler ParameterConfigurationChanged;47 //public event EventHandler ParameterConfigurationChanged; 43 48 protected virtual void OnParameterConfigurationChanged() { 44 var handler = ParameterConfigurationChanged;45 if (handler != null) handler(this, EventArgs.Empty);49 // var handler = ParameterConfigurationChanged; 50 // if (handler != null) handler(this, EventArgs.Empty); 46 51 } 47 52 } -
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 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
r11484 r11543 139 139 <Compile Include="Encodings\Individual.cs" /> 140 140 <Compile Include="Helper.cs" /> 141 <Compile Include="Interfaces\IEncoding.cs" /> 141 142 <Compile Include="Interfaces\ISingleObjectiveMoveOperator.cs" /> 142 143 <Compile Include="Interfaces\IMultiObjectiveProblemDefinition.cs" /> -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs
r11484 r11543 140 140 if (definition == null) return; 141 141 142 Encoding encoding; 143 try { 144 encoding = definition.Encoding; 145 } catch { return; } 142 Encoding encoding = definition.Encoding; 146 143 EncodingParameter.Value = encoding; 147 144 Maximization = new BoolArray(definition.Maximization); … … 220 217 var realEnc = encoding as RealEncoding; 221 218 if (realEnc != null) { 222 var l = new ValueParameter<IntValue>(realEnc.Name + "Length", realEnc.Length); 223 var b = new ValueParameter<DoubleMatrix>(realEnc.Name + "Bounds", realEnc.Bounds); 224 DynamicEncodingParameters.Add(l); 225 DynamicEncodingParameters.Add(b); 226 227 var creator = new UniformRandomRealVectorCreator(); 228 creator.RealVectorParameter.ActualName = realEnc.Name; 229 creator.LengthParameter.ActualName = l.Name; 230 creator.BoundsParameter.ActualName = b.Name; 231 return creator; 219 DynamicEncodingParameters.AddRange(realEnc.EncodingParameters); 220 return realEnc.SolutionCreator; 232 221 } 233 222 #endregion … … 458 447 .Union(ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>(), new TypeEqualityComparer<IRealVectorStdDevStrategyParameterOperator>()) 459 448 .ToList(); 460 var problemSize = ((RealEncoding)encoding).Length .Value;449 var problemSize = ((RealEncoding)encoding).Length; 461 450 var bounds = (DoubleMatrix)((RealEncoding)encoding).Bounds.Clone(); 462 451 for (var i = 0; i < bounds.Rows; i++) { -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/ProblemDefinition.cs
r11484 r11543 35 35 get { return encoding; } 36 36 protected set { 37 if (value == null) throw new ArgumentNullException("The encoding must not be null."); 37 38 if (encoding == value) return; 38 39 encoding = value; -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r11484 r11543 143 143 if (definition == null) return; 144 144 145 Encoding encoding; 146 try { 147 encoding = definition.Encoding; 148 } catch { return; } 145 Encoding encoding = definition.Encoding; 146 149 147 EncodingParameter.Value = encoding; 150 148 Maximization.Value = definition.IsMaximizationProblem; … … 225 223 var realEnc = encoding as RealEncoding; 226 224 if (realEnc != null) { 227 var l = new ValueParameter<IntValue>(realEnc.Name + "Length", realEnc.Length); 228 var b = new ValueParameter<DoubleMatrix>(realEnc.Name + "Bounds", realEnc.Bounds); 229 DynamicEncodingParameters.Add(l); 230 DynamicEncodingParameters.Add(b); 231 232 var creator = new UniformRandomRealVectorCreator(); 233 creator.RealVectorParameter.ActualName = realEnc.Name; 234 creator.LengthParameter.ActualName = l.Name; 235 creator.BoundsParameter.ActualName = b.Name; 236 return creator; 225 DynamicEncodingParameters.AddRange(realEnc.EncodingParameters); 226 return realEnc.SolutionCreator; 237 227 } 238 228 #endregion … … 463 453 .Union(ApplicationManager.Manager.GetInstances<IRealVectorStdDevStrategyParameterOperator>(), new TypeEqualityComparer<IRealVectorStdDevStrategyParameterOperator>()) 464 454 .ToList(); 465 var problemSize = ((RealEncoding)encoding).Length .Value;455 var problemSize = ((RealEncoding)encoding).Length; 466 456 var bounds = (DoubleMatrix)((RealEncoding)encoding).Bounds.Clone(); 467 457 for (var i = 0; i < bounds.Rows; i++) {
Note: See TracChangeset
for help on using the changeset viewer.