- Timestamp:
- 06/04/20 18:16:58 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Creators/RandomPermutationCreator.cs
r17226 r17587 48 48 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 49 49 } 50 public IValueParameter< PermutationType> PermutationTypeParameter {51 get { return (IValueParameter< PermutationType>)Parameters["PermutationType"]; }50 public IValueParameter<EnumValue<PermutationTypes>> PermutationTypeParameter { 51 get { return (IValueParameter<EnumValue<PermutationTypes>>)Parameters["PermutationType"]; } 52 52 } 53 53 … … 65 65 Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the new random permutation.")); 66 66 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The new random permutation.")); 67 Parameters.Add(new ValueParameter< PermutationType>("PermutationType", "The type of the permutation.", new PermutationType(PermutationTypes.RelativeUndirected)));67 Parameters.Add(new ValueParameter<EnumValue<PermutationTypes>>("PermutationType", "The type of the permutation.", new EnumValue<PermutationTypes>(PermutationTypes.RelativeUndirected))); 68 68 } 69 69 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj
r16948 r17587 207 207 <Compile Include="PermutationCrossover.cs" /> 208 208 <Compile Include="Permutation.cs" /> 209 <Compile Include="PermutationType.cs" />210 209 <Compile Include="PermutationTypes.cs" /> 211 210 <Compile Include="Plugin.cs" /> -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Interfaces/IPermutationCreator.cs
r17226 r17587 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Optimization; 25 using HEAL.Attic;26 26 27 27 namespace HeuristicLab.Encodings.PermutationEncoding { … … 32 32 public interface IPermutationCreator : IPermutationSolutionOperator, ISolutionCreator<Permutation> { 33 33 IValueLookupParameter<IntValue> LengthParameter { get; } 34 IValueParameter< PermutationType> PermutationTypeParameter { get; }34 IValueParameter<EnumValue<PermutationTypes>> PermutationTypeParameter { get; } 35 35 } 36 36 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationEncoding.cs
r17567 r17587 34 34 [Item("PermutationEncoding", "Describes a permutation encoding.")] 35 35 [StorableType("E30E7507-44BA-4021-8F56-C3FC5569A6FE")] 36 public sealed class PermutationEncoding : Encoding<Permutation> {36 public sealed class PermutationEncoding : VectorEncoding<Permutation> { 37 37 #region encoding parameters 38 [Storable] 39 private IFixedValueParameter<IntValue> lengthParameter; 40 public IFixedValueParameter<IntValue> LengthParameter { 41 get { return lengthParameter; } 38 [Storable] public IValueParameter<EnumValue<PermutationTypes>> PermutationTypeParameter { get; private set; } 39 public PermutationTypes Type { 40 get { return PermutationTypeParameter.Value.Value; } 42 41 set { 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 if (lengthParameter == value) return; 46 47 if (lengthParameter != null) Parameters.Remove(lengthParameter); 48 lengthParameter = value; 49 Parameters.Add(lengthParameter); 50 OnLengthParameterChanged(); 51 } 52 } 53 54 [Storable] 55 private IFixedValueParameter<PermutationType> permutationTypeParameter; 56 public IFixedValueParameter<PermutationType> PermutationTypeParameter { 57 get { return permutationTypeParameter; } 58 set { 59 if (value == null) throw new ArgumentNullException("Permutation type parameter must not be null."); 60 if (value.Value == null) throw new ArgumentNullException("Permutation type parameter value must not be null."); 61 if (permutationTypeParameter == value) return; 62 63 if (permutationTypeParameter != null) Parameters.Remove(permutationTypeParameter); 64 permutationTypeParameter = value; 65 Parameters.Add(permutationTypeParameter); 66 OnPermutationTypeParameterChanged(); 42 if (Type == value) return; 43 PermutationTypeParameter.Value.Value = value; 67 44 } 68 45 } 69 46 #endregion 70 71 public int Length {72 get { return LengthParameter.Value.Value; }73 set { LengthParameter.Value.Value = value; }74 }75 76 public PermutationTypes Type {77 get { return PermutationTypeParameter.Value.Value; }78 set { PermutationTypeParameter.Value.Value = value; }79 }80 47 81 48 [StorableConstructor] … … 83 50 [StorableHook(HookType.AfterDeserialization)] 84 51 private void AfterDeserialization() { 52 DiscoverOperators(); 85 53 RegisterParameterEvents(); 86 DiscoverOperators();87 54 } 88 55 … … 90 57 private PermutationEncoding(PermutationEncoding original, Cloner cloner) 91 58 : base(original, cloner) { 92 lengthParameter = cloner.Clone(original.lengthParameter); 93 permutationTypeParameter = cloner.Clone(original.permutationTypeParameter); 59 PermutationTypeParameter = cloner.Clone(original.PermutationTypeParameter); 94 60 RegisterParameterEvents(); 95 61 } … … 100 66 public PermutationEncoding(int length) : this("Permutation", length, PermutationTypes.Absolute) { } 101 67 public PermutationEncoding(string name, int length, PermutationTypes type) 102 : base(name) { 103 lengthParameter = new FixedValueParameter<IntValue>(Name + ".Length", new IntValue(length)); 104 permutationTypeParameter = new FixedValueParameter<PermutationType>(Name + ".Type", new PermutationType(type)); 105 Parameters.Add(lengthParameter); 106 Parameters.Add(permutationTypeParameter); 68 : base(name, length) { 69 PermutationTypeParameter = new ValueParameter<EnumValue<PermutationTypes>>(Name + ".Type", new EnumValue<PermutationTypes>(type)); 70 Parameters.Add(PermutationTypeParameter); 107 71 108 72 SolutionCreator = new RandomPermutationCreator(); 73 DiscoverOperators(); 109 74 RegisterParameterEvents(); 110 DiscoverOperators();111 }112 113 private void OnLengthParameterChanged() {114 RegisterLengthParameterEvents();115 ConfigureOperators(Operators);116 }117 118 private void OnPermutationTypeParameterChanged() {119 RegisterPermutationTypeParameterEvents();120 ConfigureOperators(Operators);121 75 } 122 76 123 77 private void RegisterParameterEvents() { 124 RegisterLengthParameterEvents(); 125 RegisterPermutationTypeParameterEvents(); 126 } 127 private void RegisterLengthParameterEvents() { 128 LengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators); 129 } 130 private void RegisterPermutationTypeParameterEvents() { 131 PermutationTypeParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators); 78 EnumValueParameterChangeHandler<PermutationTypes>.Create(PermutationTypeParameter, () => { 79 ConfigureOperators(Operators); 80 OnTypeChanged(); 81 }); 132 82 } 133 83 … … 239 189 } 240 190 #endregion 191 192 public event EventHandler TypeChanged; 193 private void OnTypeChanged() { 194 TypeChanged?.Invoke(this, EventArgs.Empty); 195 } 241 196 } 242 197 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationMultiObjectiveProblem.cs
r17544 r17587 22 22 #endregion 23 23 24 using System;25 24 using System.Linq; 26 25 using HEAL.Attic; … … 36 35 public abstract class PermutationMultiObjectiveProblem : MultiObjectiveProblem<PermutationEncoding, Permutation> { 37 36 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 38 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;37 [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; } 39 38 40 39 public int Dimension { 41 40 get { return DimensionRefParameter.Value.Value; } 42 41 set { DimensionRefParameter.Value.Value = value; } 42 } 43 44 public PermutationTypes Type { 45 get { return PermutationTypeRefParameter.Value.Value; } 46 set { PermutationTypeRefParameter.Value.Value = value; } 43 47 } 44 48 … … 53 57 : base(original, cloner) { 54 58 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 59 PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter); 55 60 RegisterEventHandlers(); 56 61 } … … 60 65 EncodingParameter.ReadOnly = true; 61 66 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter)); 67 Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter)); 62 68 63 69 Operators.Add(new HammingSimilarityCalculator()); … … 89 95 90 96 private void RegisterEventHandlers() { 91 DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged; 92 } 93 94 private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) { 95 DimensionOnChanged(); 97 IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged); 98 EnumValueParameterChangeHandler<PermutationTypes>.Create(PermutationTypeRefParameter, TypeOnChanged); 96 99 } 97 100 98 101 protected virtual void DimensionOnChanged() { } 102 103 protected virtual void TypeOnChanged() { } 99 104 } 100 105 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationProblem.cs
r17544 r17587 22 22 #endregion 23 23 24 using System;25 24 using System.Linq; 26 25 using HEAL.Attic; … … 37 36 public abstract class PermutationProblem : SingleObjectiveProblem<PermutationEncoding, Permutation> { 38 37 [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; } 39 public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;38 [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; } 40 39 41 40 public int Dimension { 42 41 get { return DimensionRefParameter.Value.Value; } 43 42 set { DimensionRefParameter.Value.Value = value; } 43 } 44 45 public PermutationTypes Type { 46 get { return PermutationTypeRefParameter.Value.Value; } 47 set { PermutationTypeRefParameter.Value.Value = value; } 44 48 } 45 49 … … 54 58 : base(original, cloner) { 55 59 DimensionRefParameter = cloner.Clone(original.DimensionRefParameter); 60 PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter); 56 61 RegisterEventHandlers(); 57 62 } … … 61 66 EncodingParameter.ReadOnly = true; 62 67 Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter)); 63 68 Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter)); 64 69 Operators.Add(new HammingSimilarityCalculator()); 65 70 Operators.Add(new QualitySimilarityCalculator()); … … 89 94 90 95 private void RegisterEventHandlers() { 91 DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged; 92 } 93 94 private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) { 95 DimensionOnChanged(); 96 IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged); 97 EnumValueParameterChangeHandler<PermutationTypes>.Create(PermutationTypeRefParameter, TypeOnChanged); 96 98 } 97 99 98 100 protected virtual void DimensionOnChanged() { } 101 102 protected virtual void TypeOnChanged() { } 99 103 } 100 104 }
Note: See TracChangeset
for help on using the changeset viewer.