Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4681


Ignore:
Timestamp:
10/29/10 19:40:07 (12 years ago)
Author:
gkronber
Message:

Refactored cloning in HeuristicLab.Problems.OneMax. #922

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  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Common;
    3031
    3132namespace HeuristicLab.Problems.OneMax {
     
    3536  [Item("BestOneMaxSolutionAnalyzer", "An operator for analyzing the best solution for a OneMax problem.")]
    3637  [StorableClass]
    37   class BestOneMaxSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
     38  public class BestOneMaxSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    3839    public LookupParameter<BoolValue> MaximizationParameter {
    3940      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    5556    }
    5657
     58    [StorableConstructor]
     59    protected BestOneMaxSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     60    protected BestOneMaxSolutionAnalyzer(BestOneMaxSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    5761    public BestOneMaxSolutionAnalyzer()
    5862      : base() {
     
    6367      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the Onemax solution should be stored."));
    6468      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);
    6573    }
    6674
  • branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/Evaluators/OneMaxEvaluator.cs

    r4068 r4681  
    2626using HeuristicLab.Parameters;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Common;
    2829
    2930namespace HeuristicLab.Problems.OneMax {
     
    4243    }
    4344
     45    [StorableConstructor]
     46    protected OneMaxEvaluator(bool deserializing) : base(deserializing) { }
     47    protected OneMaxEvaluator(OneMaxEvaluator original, Cloner cloner) : base(original, cloner) { }
    4448    public OneMaxEvaluator()
    4549      : base() {
    4650      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the OneMax solution."));
    4751      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);
    4856    }
    4957
  • branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/MoveEvaluators/OneMaxMoveEvaluator.cs

    r4068 r4681  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Common;
    2930
    3031namespace HeuristicLab.Problems.OneMax {
     
    4546    }
    4647
     48    [StorableConstructor]
     49    protected OneMaxMoveEvaluator(bool deserializing) : base(deserializing) { }
     50    protected OneMaxMoveEvaluator(OneMaxMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
    4751    protected OneMaxMoveEvaluator()
    4852      : base() {
  • branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/MoveEvaluators/OneMaxOneBitflipMoveEvaluator.cs

    r4068 r4681  
    2525using HeuristicLab.Parameters;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Common;
    2728
    2829namespace HeuristicLab.Problems.OneMax {
     
    3738    }
    3839
     40    [StorableConstructor]
     41    protected OneMaxOneBitflipMoveEvaluator(bool deserializing) : base(deserializing) { }
     42    protected OneMaxOneBitflipMoveEvaluator(OneMaxOneBitflipMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
    3943    public OneMaxOneBitflipMoveEvaluator()
    4044      : base() {
    4145      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);
    4250    }
    4351
  • branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/OneMaxSolution.cs

    r4068 r4681  
    3434  [Item("OneMaxSolution", "Represents a OneMax solution.")]
    3535  [StorableClass]
    36   public class OneMaxSolution : Item {
     36  public sealed class OneMaxSolution : Item {
    3737    public override Image ItemImage {
    3838      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Image; }
     
    6767    }
    6868
     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    }
    6977    public OneMaxSolution() : base() { }
    7078    public OneMaxSolution(BinaryVector binaryVector, DoubleValue quality)
     
    7482      Initialize();
    7583    }
    76     [StorableConstructor]
    77     private OneMaxSolution(bool deserializing) : base(deserializing) { }
    7884
    7985    [StorableHook(HookType.AfterDeserialization)]
     86    private void AfterDeserialization() {
     87      Initialize();
     88    }
     89
    8090    private void Initialize() {
    8191      if (binaryVector != null) RegisterBinaryVectorEvents();
    8292      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;
    9293    }
    9394
  • branches/CloningRefactoring/HeuristicLab.Problems.OneMax/3.3/OnemaxProblem.cs

    r4419 r4681  
    112112    [StorableConstructor]
    113113    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    }
    114119    public OneMaxProblem()
    115120      : base() {
     
    133138
    134139    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);
    139141    }
    140142
     
    200202    #region Helpers
    201203    [StorableHook(HookType.AfterDeserialization)]
    202     private void AfterDeserializationHook() {
     204    private void AfterDeserialization() {
    203205      // BackwardsCompatibility3.3
    204206      #region Backwards compatible code (remove with 3.4)
Note: See TracChangeset for help on using the changeset viewer.