Changeset 4681
- Timestamp:
- 10/29/10 19:40:07 (14 years ago)
- Location:
- branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/Analyzers/BestOneMaxSolutionAnalyzer.cs
r4068 r4681 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Common; 30 31 31 32 namespace HeuristicLab.Problems.OneMax { … … 35 36 [Item("BestOneMaxSolutionAnalyzer", "An operator for analyzing the best solution for a OneMax problem.")] 36 37 [StorableClass] 37 class BestOneMaxSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {38 public class BestOneMaxSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 38 39 public LookupParameter<BoolValue> MaximizationParameter { 39 40 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } … … 55 56 } 56 57 58 [StorableConstructor] 59 protected BestOneMaxSolutionAnalyzer(bool deserializing) : base(deserializing) { } 60 protected BestOneMaxSolutionAnalyzer(BestOneMaxSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 57 61 public BestOneMaxSolutionAnalyzer() 58 62 : base() { … … 63 67 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the Onemax solution should be stored.")); 64 68 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution.")); 69 } 70 71 public override IDeepCloneable Clone(Cloner cloner) { 72 return new BestOneMaxSolutionAnalyzer(this, cloner); 65 73 } 66 74 -
branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/Evaluators/OneMaxEvaluator.cs
r4068 r4681 26 26 using HeuristicLab.Parameters; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Common; 28 29 29 30 namespace HeuristicLab.Problems.OneMax { … … 42 43 } 43 44 45 [StorableConstructor] 46 protected OneMaxEvaluator(bool deserializing) : base(deserializing) { } 47 protected OneMaxEvaluator(OneMaxEvaluator original, Cloner cloner) : base(original, cloner) { } 44 48 public OneMaxEvaluator() 45 49 : base() { 46 50 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the OneMax solution.")); 47 51 Parameters.Add(new LookupParameter<BinaryVector>("BinaryVector", "The OneMax solution given in path representation which should be evaluated.")); 52 } 53 54 public override IDeepCloneable Clone(Cloner cloner) { 55 return new OneMaxEvaluator(this, cloner); 48 56 } 49 57 -
branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/MoveEvaluators/OneMaxMoveEvaluator.cs
r4068 r4681 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Common; 29 30 30 31 namespace HeuristicLab.Problems.OneMax { … … 45 46 } 46 47 48 [StorableConstructor] 49 protected OneMaxMoveEvaluator(bool deserializing) : base(deserializing) { } 50 protected OneMaxMoveEvaluator(OneMaxMoveEvaluator original, Cloner cloner) : base(original, cloner) { } 47 51 protected OneMaxMoveEvaluator() 48 52 : base() { -
branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/MoveEvaluators/OneMaxOneBitflipMoveEvaluator.cs
r4068 r4681 25 25 using HeuristicLab.Parameters; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Common; 27 28 28 29 namespace HeuristicLab.Problems.OneMax { … … 37 38 } 38 39 40 [StorableConstructor] 41 protected OneMaxOneBitflipMoveEvaluator(bool deserializing) : base(deserializing) { } 42 protected OneMaxOneBitflipMoveEvaluator(OneMaxOneBitflipMoveEvaluator original, Cloner cloner) : base(original, cloner) { } 39 43 public OneMaxOneBitflipMoveEvaluator() 40 44 : base() { 41 45 Parameters.Add(new LookupParameter<OneBitflipMove>("OneBitflipMove", "The move to evaluate.")); 46 } 47 48 public override IDeepCloneable Clone(Cloner cloner) { 49 return new OneMaxOneBitflipMoveEvaluator(this, cloner); 42 50 } 43 51 -
branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/OneMaxSolution.cs
r4068 r4681 34 34 [Item("OneMaxSolution", "Represents a OneMax solution.")] 35 35 [StorableClass] 36 public class OneMaxSolution : Item {36 public sealed class OneMaxSolution : Item { 37 37 public override Image ItemImage { 38 38 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Image; } … … 67 67 } 68 68 69 [StorableConstructor] 70 private OneMaxSolution(bool deserializing) : base(deserializing) { } 71 private OneMaxSolution(OneMaxSolution original, Cloner cloner) 72 : base(original, cloner) { 73 binaryVector = cloner.Clone(original.binaryVector); 74 quality = cloner.Clone(original.quality); 75 Initialize(); 76 } 69 77 public OneMaxSolution() : base() { } 70 78 public OneMaxSolution(BinaryVector binaryVector, DoubleValue quality) … … 74 82 Initialize(); 75 83 } 76 [StorableConstructor]77 private OneMaxSolution(bool deserializing) : base(deserializing) { }78 84 79 85 [StorableHook(HookType.AfterDeserialization)] 86 private void AfterDeserialization() { 87 Initialize(); 88 } 89 80 90 private void Initialize() { 81 91 if (binaryVector != null) RegisterBinaryVectorEvents(); 82 92 if (quality != null) RegisterQualityEvents(); 83 }84 85 public override IDeepCloneable Clone(Cloner cloner) {86 OneMaxSolution clone = new OneMaxSolution();87 cloner.RegisterClonedObject(this, clone);88 clone.binaryVector = (BinaryVector)cloner.Clone(binaryVector);89 clone.quality = (DoubleValue)cloner.Clone(quality);90 clone.Initialize();91 return clone;92 93 } 93 94 -
branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/OnemaxProblem.cs
r4419 r4681 112 112 [StorableConstructor] 113 113 private OneMaxProblem(bool deserializing) : base(deserializing) { } 114 private OneMaxProblem(OneMaxProblem original, Cloner cloner) 115 : base(original, cloner) { 116 operators = original.operators.Select(x => (IOperator)cloner.Clone(x)).ToList(); 117 AttachEventHandlers(); 118 } 114 119 public OneMaxProblem() 115 120 : base() { … … 133 138 134 139 public override IDeepCloneable Clone(Cloner cloner) { 135 OneMaxProblem clone = (OneMaxProblem)base.Clone(cloner); 136 clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList(); 137 clone.AttachEventHandlers(); 138 return clone; 140 return new OneMaxProblem(this, cloner); 139 141 } 140 142 … … 200 202 #region Helpers 201 203 [StorableHook(HookType.AfterDeserialization)] 202 private void AfterDeserialization Hook() {204 private void AfterDeserialization() { 203 205 // BackwardsCompatibility3.3 204 206 #region Backwards compatible code (remove with 3.4)
Note: See TracChangeset
for help on using the changeset viewer.