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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs

    r13267 r13269  
    3939
    4040    #region parameter names
    41 
    4241    private const string ProblemDataParameterName = "ProblemData";
    43 
    4442    #endregion
    45 
    46     public event EventHandler ProblemDataChanged;
    4743
    4844    #region Parameter Properties
     
    5248      get { return (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
    5349    }
    54 
    5550    #endregion
    5651
    5752    #region Properties
    58 
    5953    public IRegressionProblemData ProblemData {
    6054      get { return ProblemDataParameter.Value; }
     
    6256    }
    6357    IDataAnalysisProblemData IDataAnalysisProblem.ProblemData { get { return ProblemData; } }
     58    #endregion
    6459
    65 
    66     #endregion
     60    public event EventHandler ProblemDataChanged;
    6761
    6862    public override bool Maximization {
    6963      get { return true; }
    7064    }
     65
     66    #region item cloning and persistence
     67    // persistence
     68    [StorableConstructor]
     69    private Problem(bool deserializing) : base(deserializing) { }
     70    [StorableHook(HookType.AfterDeserialization)]
     71    private void AfterDeserialization() {
     72      RegisterEventHandlers();
     73    }
     74
     75    // cloning
     76    private Problem(Problem original, Cloner cloner)
     77      : base(original, cloner) {
     78      RegisterEventHandlers();
     79    }
     80    public override IDeepCloneable Clone(Cloner cloner) { return new Problem(this, cloner); }
     81    #endregion
    7182
    7283    public Problem()
     
    102113      return InterpretRec(tree.Root.GetSubtree(0).GetSubtree(0), dataset, rows);
    103114    }
    104                                                                                                        
     115
    105116    private IEnumerable<double> InterpretRec(ISymbolicExpressionTreeNode node, IDataset dataset, IEnumerable<int> rows) {
    106117      Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<double, double, double>, IEnumerable<double>> binaryEval =
    107         (left, right, f) => InterpretRec(left, dataset,rows).Zip(InterpretRec(right, dataset, rows), f);
     118        (left, right, f) => InterpretRec(left, dataset, rows).Zip(InterpretRec(right, dataset, rows), f);
    108119
    109120      switch (node.Symbol.Name) {
     
    124135    }
    125136
    126     #region item cloning and persistence
    127     // persistence
    128     [StorableConstructor]
    129     private Problem(bool deserializing) : base(deserializing) { }
    130 
    131     [StorableHook(HookType.AfterDeserialization)]
    132     private void AfterDeserialization() {
    133       RegisterEventHandlers();
    134     }
    135 
    136     // cloning
    137     private Problem(Problem original, Cloner cloner)
    138       : base(original, cloner) {
    139       RegisterEventHandlers();
    140     }
    141     public override IDeepCloneable Clone(Cloner cloner) {
    142       return new Problem(this, cloner);
    143     }
    144     #endregion
    145137
    146138    #region events
    147 
    148139    private void RegisterEventHandlers() {
    149140      ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged);
     
    188179      Encoding.Grammar = g;
    189180    }
    190 
    191181    #endregion
    192182
Note: See TracChangeset for help on using the changeset viewer.