Changeset 17544 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveStepTrapProblem.cs
- Timestamp:
- 05/18/20 18:55:08 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveStepTrapProblem.cs
r17226 r17544 22 22 #endregion 23 23 24 using System; 24 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; … … 34 35 [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 230)] 35 36 public class DeceptiveStepTrapProblem : DeceptiveTrapProblem { 36 [StorableConstructor] 37 protected DeceptiveStepTrapProblem(StorableConstructorFlag _) : base(_) { } 38 protected DeceptiveStepTrapProblem(DeceptiveStepTrapProblem original, Cloner cloner) 39 : base(original, cloner) { 40 RegisterParameterEvents(); 41 } 42 public override IDeepCloneable Clone(Cloner cloner) { 43 return new DeceptiveStepTrapProblem(this, cloner); 44 } 45 46 private const string StepSizeParameterName = "Step Size"; 47 48 public IFixedValueParameter<IntValue> StepSizeParameter { 49 get { return (IFixedValueParameter<IntValue>)Parameters[StepSizeParameterName]; } 50 } 37 [Storable] private int offset = -1; 38 [Storable] public IFixedValueParameter<IntValue> StepSizeParameter { get; private set; } 51 39 52 40 public int StepSize { … … 56 44 57 45 public DeceptiveStepTrapProblem() : base() { 58 Parameters.Add(new FixedValueParameter<IntValue>(StepSizeParameterName, "", new IntValue(2))); 46 Parameters.Add(StepSizeParameter = new FixedValueParameter<IntValue>("Step Size", "", new IntValue(2))); 47 offset = (TrapSize - StepSize) % StepSize; 48 59 49 RegisterParameterEvents(); 60 50 } 51 52 protected override int TrapMaximum { 53 get { return (offset + TrapSize) / StepSize; } 54 } 55 56 protected override int Score(BinaryVector individual, int trapIndex, int trapSize) { 57 int partial = base.Score(individual, trapIndex, trapSize); 58 // introduce plateaus using integer division 59 return (offset + partial) / StepSize; 60 } 61 62 [StorableConstructor] 63 protected DeceptiveStepTrapProblem(StorableConstructorFlag _) : base(_) { } 61 64 62 65 [StorableHook(HookType.AfterDeserialization)] … … 64 67 RegisterParameterEvents(); 65 68 } 69 protected DeceptiveStepTrapProblem(DeceptiveStepTrapProblem original, Cloner cloner) 70 : base(original, cloner) { 71 offset = original.offset; 72 StepSizeParameter = cloner.Clone(original.StepSizeParameter); 73 74 RegisterParameterEvents(); 75 } 76 public override IDeepCloneable Clone(Cloner cloner) { 77 return new DeceptiveStepTrapProblem(this, cloner); 78 } 66 79 67 80 private void RegisterParameterEvents() { 68 TrapSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; }; 69 StepSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; }; 81 StepSizeParameter.Value.ValueChanged += StepSizeOnChanged; 70 82 } 71 83 72 73 private int offset = -1; 74 private int Offset { 75 get { 76 if (offset == -1) offset = (TrapSize - StepSize) % StepSize; 77 return offset; 78 } 84 protected override void TrapSizeOnChanged(object sender, EventArgs e) { 85 base.TrapSizeOnChanged(sender, e); 86 offset = (TrapSize - StepSize) % StepSize; 79 87 } 80 88 81 protected override int TrapMaximum { 82 get { return (Offset + TrapSize) / StepSize; } 83 } 84 85 protected override int Score(BinaryVector individual, int trapIndex, int trapSize) { 86 int partial = base.Score(individual, trapIndex, trapSize); 87 // introduce plateaus using integer division 88 return (Offset + partial) / StepSize; 89 private void StepSizeOnChanged(object sender, EventArgs e) { 90 offset = (TrapSize - StepSize) % StepSize; 89 91 } 90 92 }
Note: See TracChangeset
for help on using the changeset viewer.