Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4680


Ignore:
Timestamp:
10/29/10 19:36:48 (14 years ago)
Author:
abeham
Message:

#922

  • Refactored HeuristicLab.Problems.Knapsack
Location:
branches/CloningRefactoring/HeuristicLab.Problems.Knapsack/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactoring/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs

    r4513 r4680  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Common;
    3031
    3132namespace HeuristicLab.Problems.Knapsack {
     
    3536  [Item("BestKnapsackSolutionAnalyzer", "An operator for analyzing the best solution for a Knapsack problem.")]
    3637  [StorableClass]
    37   class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
     38  public class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    3839    public LookupParameter<BoolValue> MaximizationParameter {
    3940      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    6768    }
    6869
     70    [StorableConstructor]
     71    protected BestKnapsackSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     72    protected BestKnapsackSolutionAnalyzer(BestKnapsackSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    6973    public BestKnapsackSolutionAnalyzer()
    7074      : base() {
     
    8084      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
    8185      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);
    8290    }
    8391
  • branches/CloningRefactoring/HeuristicLab.Problems.Knapsack/3.3/Evaluators/KnapsackEvaluator.cs

    r4513 r4680  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Common;
    2930
    3031namespace HeuristicLab.Problems.Knapsack {
     
    6869    }
    6970
     71    [StorableConstructor]
     72    protected KnapsackEvaluator(bool deserializing) : base(deserializing) { }
     73    protected KnapsackEvaluator(KnapsackEvaluator original, Cloner cloner) : base(original, cloner) { }
    7074    public KnapsackEvaluator()
    7175      : base() {
     
    7983      Parameters.Add(new LookupParameter<IntArray>("Values", "The values of the items."));
    8084      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);
    8189    }
    8290
  • branches/CloningRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r4513 r4680  
    141141    [StorableConstructor]
    142142    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    }
    143151    public KnapsackProblem()
    144152      : base() {
     
    167175    }
    168176
    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 
    176177    #region Events
    177178    public event EventHandler SolutionCreatorChanged;
     
    257258    #region Helpers
    258259    [StorableHook(HookType.AfterDeserialization)]
    259     private void AfterDeserializationHook() {
     260    private void AfterDeserialization() {
    260261      // BackwardsCompatibility3.3
    261262      #region Backwards compatible code (remove with 3.4)
  • branches/CloningRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackSolution.cs

    r4513 r4680  
    109109    }
    110110
     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    }
    111125    public KnapsackSolution() : base() { }
    112126    public KnapsackSolution(BinaryVector binaryVector, DoubleValue quality, IntValue capacity, IntArray weights, IntArray values)
     
    119133      Initialize();
    120134    }
    121     [StorableConstructor]
    122     private KnapsackSolution(bool deserializing) : base(deserializing) { }
    123135
    124136    [StorableHook(HookType.AfterDeserialization)]
     137    private void AfterDeserialization() {
     138      Initialize();
     139    }
     140
    125141    private void Initialize() {
    126142      if (binaryVector != null) RegisterBinaryVectorEvents();
     
    131147    }
    132148
    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 
    145149    #region Events
    146150    public event EventHandler BinaryVectorChanged;
  • branches/CloningRefactoring/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators/KnapsackMoveEvaluator.cs

    r4068 r4680  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Common;
    2930
    3031namespace HeuristicLab.Problems.Knapsack {
     
    5758    }
    5859
     60    [StorableConstructor]
     61    protected KnapsackMoveEvaluator(bool deserializing) : base(deserializing) { }
     62    protected KnapsackMoveEvaluator(KnapsackMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
    5963    protected KnapsackMoveEvaluator()
    6064      : base() {
  • branches/CloningRefactoring/HeuristicLab.Problems.Knapsack/3.3/MoveEvaluators/KnapsackOneBitflipMoveEvaluator.cs

    r4068 r4680  
    2525using HeuristicLab.Parameters;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Common;
    2728
    2829namespace HeuristicLab.Problems.Knapsack {
     
    3738    }
    3839
     40    [StorableConstructor]
     41    protected KnapsackOneBitflipMoveEvaluator(bool deserializing) : base(deserializing) { }
     42    protected KnapsackOneBitflipMoveEvaluator(KnapsackOneBitflipMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
    3943    public KnapsackOneBitflipMoveEvaluator()
    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 KnapsackOneBitflipMoveEvaluator(this, cloner);
    4250    }
    4351
Note: See TracChangeset for help on using the changeset viewer.