Changeset 4722 for trunk/sources/HeuristicLab.Problems.Knapsack
- Timestamp:
- 11/06/10 01:56:04 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources
- Property svn:mergeinfo changed
/branches/CloningRefactoring (added) merged: 4656-4693,4696-4697,4711-4714,4718-4719
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs
r4513 r4722 21 21 22 22 using System.Linq; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Data; … … 35 36 [Item("BestKnapsackSolutionAnalyzer", "An operator for analyzing the best solution for a Knapsack problem.")] 36 37 [StorableClass] 37 class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {38 public class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 38 39 public LookupParameter<BoolValue> MaximizationParameter { 39 40 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } … … 67 68 } 68 69 70 [StorableConstructor] 71 protected BestKnapsackSolutionAnalyzer(bool deserializing) : base(deserializing) { } 72 protected BestKnapsackSolutionAnalyzer(BestKnapsackSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 69 73 public BestKnapsackSolutionAnalyzer() 70 74 : base() { … … 80 84 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution.")); 81 85 Parameters.Add(new LookupParameter<BinaryVector>("BestKnownSolution", "The best known solution.")); 86 } 87 88 public override IDeepCloneable Clone(Cloner cloner) { 89 return new BestKnapsackSolutionAnalyzer(this, cloner); 82 90 } 83 91 -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Evaluators/KnapsackEvaluator.cs
r4513 r4722 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Data; … … 68 69 } 69 70 71 [StorableConstructor] 72 protected KnapsackEvaluator(bool deserializing) : base(deserializing) { } 73 protected KnapsackEvaluator(KnapsackEvaluator original, Cloner cloner) : base(original, cloner) { } 70 74 public KnapsackEvaluator() 71 75 : base() { … … 79 83 Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items.")); 80 84 Parameters.Add(new LookupParameter<DoubleValue>("Penalty", "The penalty value for each unit of overweight.")); 85 } 86 87 public override IDeepCloneable Clone(Cloner cloner) { 88 return new KnapsackEvaluator(this, cloner); 81 89 } 82 90 -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r4513 r4722 141 141 [StorableConstructor] 142 142 private KnapsackProblem(bool deserializing) : base(deserializing) { } 143 private KnapsackProblem(KnapsackProblem original, Cloner cloner) 144 : base(original, cloner) { 145 this.operators = original.operators.Select(x => (IOperator)cloner.Clone(x)).ToList(); 146 AttachEventHandlers(); 147 } 148 public override IDeepCloneable Clone(Cloner cloner) { 149 return new KnapsackProblem(this, cloner); 150 } 143 151 public KnapsackProblem() 144 152 : base() { … … 167 175 } 168 176 169 public override IDeepCloneable Clone(Cloner cloner) {170 KnapsackProblem clone = (KnapsackProblem)base.Clone(cloner);171 clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();172 clone.AttachEventHandlers();173 return clone;174 }175 176 177 #region Events 177 178 public event EventHandler SolutionCreatorChanged; … … 257 258 #region Helpers 258 259 [StorableHook(HookType.AfterDeserialization)] 259 private void AfterDeserialization Hook() {260 private void AfterDeserialization() { 260 261 // BackwardsCompatibility3.3 261 262 #region Backwards compatible code (remove with 3.4) -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackSolution.cs
r4513 r4722 109 109 } 110 110 111 [StorableConstructor] 112 protected KnapsackSolution(bool deserializing) : base(deserializing) { } 113 protected KnapsackSolution(KnapsackSolution original, Cloner cloner) 114 : base(original, cloner) { 115 this.binaryVector = cloner.Clone(original.binaryVector); 116 this.quality = cloner.Clone(original.quality); 117 this.capacity = cloner.Clone(original.capacity); 118 this.weights = cloner.Clone(original.weights); 119 this.values = cloner.Clone(original.values); 120 Initialize(); 121 } 122 public override IDeepCloneable Clone(Cloner cloner) { 123 return new KnapsackSolution(this, cloner); 124 } 111 125 public KnapsackSolution() : base() { } 112 126 public KnapsackSolution(BinaryVector binaryVector, DoubleValue quality, IntValue capacity, IntArray weights, IntArray values) … … 119 133 Initialize(); 120 134 } 121 [StorableConstructor]122 private KnapsackSolution(bool deserializing) : base(deserializing) { }123 135 124 136 [StorableHook(HookType.AfterDeserialization)] 137 private void AfterDeserialization() { 138 Initialize(); 139 } 140 125 141 private void Initialize() { 126 142 if (binaryVector != null) RegisterBinaryVectorEvents(); … … 131 147 } 132 148 133 public override IDeepCloneable Clone(Cloner cloner) {134 KnapsackSolution clone = new KnapsackSolution();135 cloner.RegisterClonedObject(this, clone);136 clone.binaryVector = (BinaryVector)cloner.Clone(binaryVector);137 clone.quality = (DoubleValue)cloner.Clone(quality);138 clone.capacity = (IntValue)cloner.Clone(capacity);139 clone.weights = (IntArray)cloner.Clone(weights);140 clone.values = (IntArray)cloner.Clone(values);141 clone.Initialize();142 return clone;143 }144 145 149 #region Events 146 150 public event EventHandler BinaryVectorChanged; -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators/KnapsackMoveEvaluator.cs
r4068 r4722 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 57 58 } 58 59 60 [StorableConstructor] 61 protected KnapsackMoveEvaluator(bool deserializing) : base(deserializing) { } 62 protected KnapsackMoveEvaluator(KnapsackMoveEvaluator original, Cloner cloner) : base(original, cloner) { } 59 63 protected KnapsackMoveEvaluator() 60 64 : base() { -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators/KnapsackOneBitflipMoveEvaluator.cs
r4068 r4722 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 37 38 } 38 39 40 [StorableConstructor] 41 protected KnapsackOneBitflipMoveEvaluator(bool deserializing) : base(deserializing) { } 42 protected KnapsackOneBitflipMoveEvaluator(KnapsackOneBitflipMoveEvaluator original, Cloner cloner) : base(original, cloner) { } 39 43 public KnapsackOneBitflipMoveEvaluator() 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 KnapsackOneBitflipMoveEvaluator(this, cloner); 42 50 } 43 51
Note: See TracChangeset
for help on using the changeset viewer.