Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4676


Ignore:
Timestamp:
10/29/10 19:02:32 (14 years ago)
Author:
mkommend
Message:

Refactored ArtificialAntProble (ticket #922).

Location:
branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/Analyzers/BestAntTrailAnalyzer.cs

    r4068 r4676  
    2121
    2222using System.Linq;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    6566    }
    6667
     68    [StorableConstructor]
     69    private BestAntTrailAnalyzer(bool deserializing) : base(deserializing) { }
     70    private BestAntTrailAnalyzer(BestAntTrailAnalyzer original, Cloner cloner)
     71      : base(original, cloner) {
     72    }
     73    public override IDeepCloneable Clone(Cloner cloner) {
     74      return new BestAntTrailAnalyzer(this, cloner);
     75    }
     76
    6777    public override IOperation Apply() {
    6878      ItemArray<SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/AntTrail.cs

    r4068 r4676  
    8989      Initialize();
    9090    }
     91
    9192    [StorableConstructor]
    9293    private AntTrail(bool deserializing) : base(deserializing) { }
     94    [StorableHook(HookType.AfterDeserialization)]
     95    private void AfterDeserialization() {
     96      Initialize();
     97    }
     98    private AntTrail(AntTrail original, Cloner cloner)
     99      : base(original, cloner) {
     100      expression = cloner.Clone(original.expression);
     101      world = cloner.Clone(original.world);
     102      maxTimeSteps = cloner.Clone(original.maxTimeSteps);
     103      Initialize();
     104    }
     105    public override IDeepCloneable Clone(Cloner cloner) {
     106      return new AntTrail(this, cloner);
     107    }
    93108
    94     [StorableHook(HookType.AfterDeserialization)]
    95109    private void Initialize() {
    96110      //if (expression != null) RegisterSymbolicExpressionTreeEvents();
     
    99113    }
    100114
    101     public override IDeepCloneable Clone(Cloner cloner) {
    102       AntTrail clone = new AntTrail();
    103       cloner.RegisterClonedObject(this, clone);
    104       clone.expression = (SymbolicExpressionTree)cloner.Clone(expression);
    105       clone.world = (BoolMatrix)cloner.Clone(world);
    106       clone.maxTimeSteps = (IntValue)cloner.Clone(maxTimeSteps);
    107       clone.Initialize();
    108       return clone;
    109     }
    110 
    111115    #region Events
    112116    public event EventHandler SymbolicExpressionTreeChanged;
    113117    private void OnSymbolicExpressionTreeChanged() {
    114118      var changed = SymbolicExpressionTreeChanged;
    115       if (changed != null)
    116         changed(this, EventArgs.Empty);
     119      if (changed != null) changed(this, EventArgs.Empty);
    117120    }
    118121    public event EventHandler WorldChanged;
    119122    private void OnWorldChanged() {
    120123      var changed = WorldChanged;
    121       if (changed != null)
    122         changed(this, EventArgs.Empty);
     124      if (changed != null) changed(this, EventArgs.Empty);
    123125    }
    124126    public event EventHandler MaxTimeStepsChanged;
    125127    private void OnMaxTimeStepsChanged() {
    126128      var changed = MaxTimeStepsChanged;
    127       if (changed != null)
    128         changed(this, EventArgs.Empty);
     129      if (changed != null) changed(this, EventArgs.Empty);
    129130    }
    130131
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs

    r4068 r4676  
    2222
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2526using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     
    3637    [StorableConstructor]
    3738    protected ArtificialAntExpressionGrammar(bool deserializing) : base(deserializing) { }
     39    protected ArtificialAntExpressionGrammar(ArtificialAntExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
     40    public override IDeepCloneable Clone(Cloner cloner) {
     41      return new ArtificialAntExpressionGrammar(this, cloner);
     42    }
    3843
    3944    private void Initialize() {
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs

    r4419 r4676  
    196196    [StorableConstructor]
    197197    private ArtificialAntProblem(bool deserializing) : base(deserializing) { }
     198    [StorableHook(HookType.AfterDeserialization)]
     199    private void AfterDeserialization() {
     200      // BackwardsCompatibility3.3
     201      #region Backwards compatible code (remove with 3.4)
     202      if (operators == null) InitializeOperators();
     203      #endregion
     204      AttachEventHandlers();
     205    }
     206
     207    private ArtificialAntProblem(ArtificialAntProblem original, Cloner cloner)
     208      : base(original, cloner) {
     209      operators = original.operators.Select(x => cloner.Clone(x)).ToList();
     210      AttachEventHandlers();
     211    }
     212    public override IDeepCloneable Clone(Cloner cloner) {
     213      return new ArtificialAntProblem(this, cloner);
     214    }
    198215    public ArtificialAntProblem()
    199216      : base() {
     
    222239    }
    223240
    224     public override IDeepCloneable Clone(Cloner cloner) {
    225       ArtificialAntProblem clone = (ArtificialAntProblem)base.Clone(cloner);
    226       clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
    227       clone.AttachEventHandlers();
    228       return clone;
    229     }
    230 
    231241    #region Events
    232242    public event EventHandler SolutionCreatorChanged;
     
    278288
    279289    #region Helpers
    280     [StorableHook(HookType.AfterDeserialization)]
    281     private void AfterDeserializationHook() {
    282       // BackwardsCompatibility3.3
    283       #region Backwards compatible code (remove with 3.4)
    284       if (operators == null) InitializeOperators();
    285       #endregion
    286       AttachEventHandlers();
    287     }
    288 
    289290    private void AttachEventHandlers() {
    290291      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/Evaluator.cs

    r4477 r4676  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    4748    }
    4849
     50    [StorableConstructor]
     51    protected Evaluator(bool deserializing) : base(deserializing) { }
     52    protected Evaluator(Evaluator original, Cloner cloner) : base(original, cloner) { }
     53    public override IDeepCloneable Clone(Cloner cloner) { return new Evaluator(this, cloner); }
    4954    public Evaluator()
    5055      : base() {
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/IfFoodAhead.cs

    r4477 r4676  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     
    2728  [Item("IfFoodAhead", "Represents the if-food-ahead symbol in a artificial ant expression.")]
    2829  public sealed class IfFoodAhead : Symbol {
     30    [StorableConstructor]
     31    private IfFoodAhead(bool deserializing) : base(deserializing) { }
     32    private IfFoodAhead(IfFoodAhead original, Cloner cloner) : base(original, cloner) { }
     33    public override IDeepCloneable Clone(Cloner cloner) {
     34      return new IfFoodAhead(this, cloner);
     35    }
     36
    2937    public IfFoodAhead() : base("IfFoodAhead", "Represents the if-food-ahead symbol in a artificial ant expression.") { }
    3038  }
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Left.cs

    r4477 r4676  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     
    2728  [Item("Left", "Represents the turn-left symbol in a artificial ant expression.")]
    2829  public sealed class Left : Symbol {
     30    [StorableConstructor]
     31    private Left(bool deserializing) : base(deserializing) { }
     32    private Left(Left original, Cloner cloner) : base(original, cloner) { }
     33    public override IDeepCloneable Clone(Cloner cloner) {
     34      return new Left(this, cloner);
     35    }
    2936    public Left() : base("Left", "Represents the turn-left symbol in a artificial ant expression.") { }
    3037  }
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Move.cs

    r4477 r4676  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     
    2728  [Item("Move", "Represents the move-forward symbol in a artificial ant expression.")]
    2829  public sealed class Move : Symbol {
     30    [StorableConstructor]
     31    private Move(bool deserializing) : base(deserializing) { }
     32    private Move(Move original, Cloner cloner) : base(original, cloner) { }
     33    public override IDeepCloneable Clone(Cloner cloner) {
     34      return new Move(this, cloner);
     35    }
    2936    public Move() : base("Move", "Represents the move-forward symbol in a artificial ant expression.") { }
    3037  }
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Prog2.cs

    r4477 r4676  
    2121
    2222
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     
    2829  [Item("Prog2", "Represents the sequence symbol with 2 sub-trees in a artificial ant expression.")]
    2930  public sealed class Prog2 : Symbol {
     31    [StorableConstructor]
     32    private Prog2(bool deserializing) : base(deserializing) { }
     33    private Prog2(Prog2 original, Cloner cloner) : base(original, cloner) { }
     34    public override IDeepCloneable Clone(Cloner cloner) {
     35      return new Prog2(this, cloner);
     36    }
    3037    public Prog2() : base("Prog2", "Represents the sequence symbol with 2 sub-trees in a artificial ant expression.") { }
    3138  }
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Prog3.cs

    r4477 r4676  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     
    2728  [Item("Prog3", "Represents the sequence symbol with 3 sub-trees in a artificial ant expression.")]
    2829  public sealed class Prog3 : Symbol {
     30    [StorableConstructor]
     31    private Prog3(bool deserializing) : base(deserializing) { }
     32    private Prog3(Prog3 original, Cloner cloner) : base(original, cloner) { }
     33    public override IDeepCloneable Clone(Cloner cloner) {
     34      return new Prog3(this, cloner);
     35    }
    2936    public Prog3() : base("Prog3", "Represents the sequence symbol with 3 sub-trees in a artificial ant expression.") { }
    3037  }
  • branches/CloningRefactoring/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Right.cs

    r4477 r4676  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     
    2728  [Item("Right", "Represents the turn-right symbol in a artificial ant expression.")]
    2829  public sealed class Right : Symbol {
     30    [StorableConstructor]
     31    private Right(bool deserializing) : base(deserializing) { }
     32    private Right(Right original, Cloner cloner) : base(original, cloner) { }
     33    public override IDeepCloneable Clone(Cloner cloner) {
     34      return new Right(this, cloner);
     35    }
    2936    public Right() : base("Right", "Represents the turn-right symbol in a artificial ant expression.") { }
    3037  }
Note: See TracChangeset for help on using the changeset viewer.