Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/15 09:57:06 (9 years ago)
Author:
mkommend
Message:

#2472: Moved cloning and persistence code near the default ctor for all new GP problems.

Location:
trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs

    r13267 r13269  
    5858    }
    5959
     60    #region item cloning and persistence
     61    // persistence
     62    [StorableConstructor]
     63    private EvenParityProblem(bool deserializing) : base(deserializing) { }
     64    [StorableHook(HookType.AfterDeserialization)]
     65    private void AfterDeserialization() {
     66      RegisterEventHandlers();
     67    }
     68
     69    // cloning
     70    private EvenParityProblem(EvenParityProblem original, Cloner cloner)
     71      : base(original, cloner) {
     72      RegisterEventHandlers();
     73    }
     74    public override IDeepCloneable Clone(Cloner cloner) {
     75      return new EvenParityProblem(this, cloner);
     76    }
     77    #endregion
     78
    6079    public EvenParityProblem()
    6180      : base() {
     
    109128
    110129      switch (node.Symbol.Name) {
    111         case "AND":  return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
    112         case "OR":   return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
     130        case "AND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
     131        case "OR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
    113132        case "NAND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x & y));
    114         case "NOR":  return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x | y));
     133        case "NOR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x | y));
    115134        default: {
    116135            byte bitPos;
     
    126145    }
    127146
    128     #region item cloning and persistence
    129     // persistence
    130     [StorableConstructor]
    131     private EvenParityProblem(bool deserializing) : base(deserializing) { }
    132 
    133     [StorableHook(HookType.AfterDeserialization)]
    134     private void AfterDeserialization() {
    135       RegisterEventHandlers();
    136     }
    137 
    138     // cloning
    139     private EvenParityProblem(EvenParityProblem original, Cloner cloner)
    140       : base(original, cloner) {
    141       RegisterEventHandlers();
    142     }
    143     public override IDeepCloneable Clone(Cloner cloner) {
    144       return new EvenParityProblem(this, cloner);
    145     }
    146     #endregion
    147 
    148147    #region events
    149148    private void RegisterEventHandlers() {
  • trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs

    r13267 r13269  
    5959      get { return true; }
    6060    }
     61
     62    #region item cloning and persistence
     63    // persistence
     64    [StorableConstructor]
     65    private MultiplexerProblem(bool deserializing) : base(deserializing) { }
     66    [StorableHook(HookType.AfterDeserialization)]
     67    private void AfterDeserialization() {
     68      RegisterEventHandlers();
     69    }
     70
     71    // cloning
     72    private MultiplexerProblem(MultiplexerProblem original, Cloner cloner)
     73      : base(original, cloner) {
     74      RegisterEventHandlers();
     75    }
     76    public override IDeepCloneable Clone(Cloner cloner) {
     77      return new MultiplexerProblem(this, cloner);
     78    }
     79    #endregion
     80
    6181
    6282    public MultiplexerProblem()
     
    134154      switch (node.Symbol.Name) {
    135155        case "AND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
    136         case "OR":  return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
     156        case "OR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
    137157        case "NOT": return unaryEval(node.GetSubtree(0), (x) => !x);
    138         case "IF":  return EvalIf(node.GetSubtree(0), node.GetSubtree(1), node.GetSubtree(2), bs, addrBits);
     158        case "IF": return EvalIf(node.GetSubtree(0), node.GetSubtree(1), node.GetSubtree(2), bs, addrBits);
    139159        default: {
    140160            if (node.Symbol.Name[0] == 'a') {
     
    171191    }
    172192
    173     #region item cloning and persistence
    174     // persistence
    175     [StorableConstructor]
    176     private MultiplexerProblem(bool deserializing) : base(deserializing) { }
    177 
    178     [StorableHook(HookType.AfterDeserialization)]
    179     private void AfterDeserialization() {
    180       RegisterEventHandlers();
    181     }
    182 
    183     // cloning
    184     private MultiplexerProblem(MultiplexerProblem original, Cloner cloner)
    185       : base(original, cloner) {
    186       RegisterEventHandlers();
    187     }
    188     public override IDeepCloneable Clone(Cloner cloner) {
    189       return new MultiplexerProblem(this, cloner);
    190     }
    191     #endregion
    192 
    193193    #region events
    194194    private void RegisterEventHandlers() {
Note: See TracChangeset for help on using the changeset viewer.