Changeset 11588 for branches/ProgrammableProblem
- Timestamp:
- 11/26/14 16:09:14 (10 years ago)
- Location:
- branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/BinaryEncoding.cs
r11587 r11588 36 36 public sealed class BinaryEncoding : Encoding<IBinaryVectorCreator> { 37 37 #region Encoding Parameters 38 [Storable]39 38 private IFixedValueParameter<IntValue> lengthParameter; 40 39 public IFixedValueParameter<IntValue> LengthParameter { … … 42 41 set { 43 42 if (value == null) throw new ArgumentNullException("Length parameter must not be null."); 43 if (value.Value == null) throw new ArgumentNullException("Length parameter value must not be null."); 44 44 if (lengthParameter == value) return; 45 46 if (lengthParameter != null) Parameters.Remove(lengthParameter); 45 47 lengthParameter = value; 48 Parameters.Add(lengthParameter); 46 49 OnLengthParameterChanged(); 47 50 } 48 }49 public override IEnumerable<IValueParameter> Parameters {50 get { return new IValueParameter[] { LengthParameter }; }51 51 } 52 52 #endregion … … 72 72 public BinaryEncoding(string name, int length) 73 73 : base(name) { 74 lengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));74 LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length)); 75 75 SolutionCreator = new RandomBinaryVectorCreator(); 76 76 RegisterParameterEvents(); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/Encoding.cs
r11587 r11588 31 31 [Item("Encoding", "Base class for describing different encodings.")] 32 32 [StorableClass] 33 public abstract class Encoding<T> : NamedItem, IEncoding33 public abstract class Encoding<T> : ParameterizedNamedItem, IEncoding 34 34 where T : class,ISolutionCreator { 35 35 public override sealed bool CanChangeName { 36 36 get { return false; } 37 37 } 38 39 public abstract IEnumerable<IValueParameter> Parameters { get; }40 38 41 39 protected HashSet<IOperator> encodingOperators = new HashSet<IOperator>(new TypeEqualityComparer<IOperator>()); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/IntegerEncoding.cs
r11587 r11588 28 28 using HeuristicLab.Encodings.IntegerVectorEncoding; 29 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 using HeuristicLab.PluginInfrastructure; … … 36 37 public class IntegerEncoding : Encoding<IIntegerVectorCreator> { 37 38 #region Encoding Parameters 38 [Storable]39 39 private IFixedValueParameter<IntValue> lengthParameter; 40 40 public IFixedValueParameter<IntValue> LengthParameter { … … 42 42 set { 43 43 if (value == null) throw new ArgumentNullException("Length parameter must not be null."); 44 if (value.Value == null) throw new ArgumentNullException("Length parameter value must not be null."); 44 45 if (lengthParameter == value) return; 46 47 if (lengthParameter != null) Parameters.Remove(lengthParameter); 45 48 lengthParameter = value; 49 Parameters.Add(lengthParameter); 46 50 OnLengthParameterChanged(); 47 51 } 48 52 } 49 53 50 [Storable]51 54 private IValueParameter<IntMatrix> boundsParameter; 52 55 public IValueParameter<IntMatrix> BoundsParameter { … … 55 58 if (value == null) throw new ArgumentNullException("Bounds parameter must not be null."); 56 59 if (boundsParameter == value) return; 60 61 if (boundsParameter != null) Parameters.Remove(boundsParameter); 57 62 boundsParameter = value; 63 Parameters.Add(boundsParameter); 58 64 OnBoundsParameterChanged(); 59 65 } 60 }61 62 public override IEnumerable<IValueParameter> Parameters {63 get { return new IValueParameter[] { LengthParameter, BoundsParameter }; }64 66 } 65 67 #endregion … … 95 97 if (step.HasValue && step.Value <= 0) throw new ArgumentException("step must be greater than zero or null", "step"); 96 98 97 Length = length; 98 Bounds = new IntMatrix(1, step.HasValue ? 3 : 2); 99 Bounds[0, 0] = min; 100 Bounds[0, 1] = max; 101 if (step.HasValue) Bounds[0, 2] = step.Value; 99 var bounds = new IntMatrix(1, step.HasValue ? 3 : 2); 100 bounds[0, 0] = min; 101 bounds[0, 1] = max; 102 if (step.HasValue) bounds[0, 2] = step.Value; 103 104 LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length)); 105 BoundsParameter = new ValueParameter<IntMatrix>(Name + "Bounds", bounds); 102 106 103 107 SolutionCreator = new UniformRandomIntegerVectorCreator(); … … 112 116 if (min.Zip(max, (mi, ma) => mi >= ma).Any(x => x)) throw new ArgumentException("min must be less than max in each dimension", "min"); 113 117 114 Length = length; 115 Bounds = new IntMatrix(min.Count, step != null ? 3 : 2); 118 var bounds = new IntMatrix(min.Count, step != null ? 3 : 2); 116 119 for (int i = 0; i < min.Count; i++) { 117 Bounds[i, 0] = min[i]; 118 Bounds[i, 1] = max[i]; 119 if (step != null) Bounds[i, 2] = step[i]; 120 } 120 bounds[i, 0] = min[i]; 121 bounds[i, 1] = max[i]; 122 if (step != null) bounds[i, 2] = step[i]; 123 } 124 125 LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length)); 126 BoundsParameter = new ValueParameter<IntMatrix>(Name + "Bounds", bounds); 121 127 122 128 SolutionCreator = new UniformRandomIntegerVectorCreator(); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/MultiEncoding.cs
r11587 r11588 35 35 36 36 private readonly List<IEncoding> encodings; 37 38 37 [Storable] 39 38 public IEnumerable<IEncoding> Encodings { … … 42 41 } 43 42 44 public override IEnumerable<IValueParameter> Parameters {45 get { return Encodings.SelectMany(e => e.Parameters); }46 }47 43 48 44 [StorableConstructor] … … 71 67 encodings.Add(encoding); 72 68 69 Parameters.AddRange(encoding.Parameters); 70 73 71 foreach (var @operator in Operators.OfType<IMultiEncodingOperator>()) { 74 72 @operator.AddEncoding(encoding); … … 79 77 public bool Remove(IEncoding encoding) { 80 78 var success = encodings.Remove(encoding); 79 Parameters.RemoveRange(encoding.Parameters); 81 80 foreach (var @operator in Operators.OfType<IMultiEncodingOperator>()) { 82 81 @operator.RemoveEncoding(encoding); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/PermutationEncoding.cs
r11587 r11588 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.PermutationEncoding; 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 31 using HeuristicLab.PluginInfrastructure; … … 35 36 public sealed class PermutationEncoding : Encoding<IPermutationCreator> { 36 37 #region encoding parameters 37 [Storable]38 38 private IFixedValueParameter<IntValue> lengthParameter; 39 39 public IFixedValueParameter<IntValue> LengthParameter { … … 41 41 set { 42 42 if (value == null) throw new ArgumentNullException("Length parameter must not be null."); 43 if (value.Value == null) throw new ArgumentNullException("Length parameter value must not be null."); 43 44 if (lengthParameter == value) return; 45 46 if (lengthParameter != null) Parameters.Remove(lengthParameter); 44 47 lengthParameter = value; 48 Parameters.Add(lengthParameter); 45 49 OnLengthParameterChanged(); 46 50 } 47 51 } 48 52 49 [Storable]50 53 private IFixedValueParameter<PermutationType> permutationTypeParameter; 51 54 public IFixedValueParameter<PermutationType> PermutationTypeParameter { … … 53 56 set { 54 57 if (value == null) throw new ArgumentNullException("Permutation type parameter must not be null."); 58 if (value.Value == null) throw new ArgumentNullException("Permutation type parameter value must not be null."); 55 59 if (permutationTypeParameter == value) return; 60 61 if (permutationTypeParameter != null) Parameters.Remove(permutationTypeParameter); 56 62 permutationTypeParameter = value; 63 Parameters.Add(permutationTypeParameter); 57 64 OnPermutationTypeParameterChanged(); 58 65 } 59 }60 61 public override IEnumerable<IValueParameter> Parameters {62 get { return new IValueParameter[] { LengthParameter, PermutationTypeParameter }; }63 66 } 64 67 #endregion … … 92 95 public PermutationEncoding(string name, int length, PermutationTypes type) 93 96 : base(name) { 94 Length = length;95 Type = type;97 LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length)); 98 PermutationTypeParameter = new FixedValueParameter<PermutationType>(Name + "Type", new PermutationType(type)); 96 99 97 100 SolutionCreator = new RandomPermutationCreator(); … … 101 104 102 105 private void OnLengthParameterChanged() { 103 Register ParameterEvents();106 RegisterLengthParameterEvents(); 104 107 ConfigureOperators(Operators); 105 108 } 106 109 107 110 private void OnPermutationTypeParameterChanged() { 108 RegisterP arameterEvents();111 RegisterPermutationTypeParameterEvents(); 109 112 ConfigureOperators(Operators); 110 113 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/RealEncoding.cs
r11587 r11588 37 37 public sealed class RealEncoding : Encoding<IRealVectorCreator> { 38 38 #region Encoding Parameters 39 [Storable]40 39 private IFixedValueParameter<IntValue> lengthParameter; 41 40 public IFixedValueParameter<IntValue> LengthParameter { … … 43 42 set { 44 43 if (value == null) throw new ArgumentNullException("Length parameter must not be null."); 44 if (value.Value == null) throw new ArgumentNullException("Length parameter value must not be null."); 45 45 if (lengthParameter == value) return; 46 47 if (lengthParameter != null) Parameters.Remove(lengthParameter); 46 48 lengthParameter = value; 49 Parameters.Add(lengthParameter); 47 50 OnLengthParameterChanged(); 48 51 } 49 52 } 50 53 51 [Storable]52 54 private IValueParameter<DoubleMatrix> boundsParameter; 53 55 public IValueParameter<DoubleMatrix> BoundsParameter { … … 56 58 if (value == null) throw new ArgumentNullException("Bounds parameter must not be null."); 57 59 if (boundsParameter == value) return; 60 61 if (boundsParameter != null) Parameters.Remove(boundsParameter); 58 62 boundsParameter = value; 63 Parameters.Add(boundsParameter); 59 64 OnBoundsParameterChanged(); 60 65 } 61 }62 63 public override IEnumerable<IValueParameter> Parameters {64 get { return new IValueParameter[] { LengthParameter, BoundsParameter }; }65 66 } 66 67 #endregion … … 99 100 bounds[0, 1] = max; 100 101 101 lengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));102 boundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds);102 LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length)); 103 BoundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds); 103 104 104 105 SolutionCreator = new UniformRandomRealVectorCreator(); … … 118 119 bounds[i, 1] = max[i]; 119 120 } 120 lengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));121 boundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds);121 LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length)); 122 BoundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds); 122 123 123 124 SolutionCreator = new UniformRandomRealVectorCreator(); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IEncoding.cs
r11587 r11588 26 26 27 27 namespace HeuristicLab.Problems.Programmable { 28 public interface IEncoding : I NamedItem {28 public interface IEncoding : IParameterizedNamedItem { 29 29 ISolutionCreator SolutionCreator { get; set; } 30 30 31 IEnumerable<IValueParameter> Parameters { get; }32 31 IEnumerable<IOperator> Operators { get; } 33 32 //event EventHandler ParameterConfigurationChanged;
Note: See TracChangeset
for help on using the changeset viewer.