Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/06/10 01:56:04 (13 years ago)
Author:
swagner
Message:

Merged cloning refactoring branch back into trunk (#922)

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/DefaultSymbolicExpressionGrammar.cs

    r4262 r4722  
    8888    private Symbol startSymbol;
    8989
     90    [StorableConstructor]
     91    protected DefaultSymbolicExpressionGrammar(bool deserializing)
     92      : base(deserializing) {
     93      cachedMinExpressionLength = new Dictionary<string, int>();
     94      cachedMaxExpressionLength = new Dictionary<string, int>();
     95      cachedMinExpressionDepth = new Dictionary<string, int>();
     96    }
     97    // cloning ctor
     98    protected DefaultSymbolicExpressionGrammar(DefaultSymbolicExpressionGrammar original, Cloner cloner)
     99      : base(original, cloner) {
     100      this.cachedMinExpressionLength = new Dictionary<string, int>();
     101      this.cachedMaxExpressionLength = new Dictionary<string, int>();
     102      this.cachedMinExpressionDepth = new Dictionary<string, int>();
     103      minSubTreeCount = new Dictionary<string, int>(original.minSubTreeCount);
     104      maxSubTreeCount = new Dictionary<string, int>(original.maxSubTreeCount);
     105
     106      allSymbols = new Dictionary<string, Symbol>();
     107      foreach (Symbol symbol in original.allSymbols.Values.Select(s => cloner.Clone(s)))
     108        allSymbols.Add(symbol.Name, symbol);
     109
     110      startSymbol = cloner.Clone<Symbol>(original.startSymbol);
     111      allowedChildSymbols = new Dictionary<string, List<List<string>>>();
     112      foreach (var entry in original.allowedChildSymbols) {
     113        allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count);
     114        foreach (var set in entry.Value) {
     115          allowedChildSymbols[entry.Key].Add(new List<string>(set));
     116        }
     117      }
     118    }
    90119    protected DefaultSymbolicExpressionGrammar()
    91120      : base() {
     
    136165    }
    137166
    138     [StorableConstructor]
    139     protected DefaultSymbolicExpressionGrammar(bool deserializing)
    140       : base(deserializing) {
    141       cachedMinExpressionLength = new Dictionary<string, int>();
    142       cachedMaxExpressionLength = new Dictionary<string, int>();
    143       cachedMinExpressionDepth = new Dictionary<string, int>();
    144     }
    145 
    146167    public void Clear() {
    147168      minSubTreeCount.Clear();
     
    289310    }
    290311
    291     public override IDeepCloneable Clone(Cloner cloner) {
    292       DefaultSymbolicExpressionGrammar clone = (DefaultSymbolicExpressionGrammar)base.Clone(cloner);
    293 
    294       clone.minSubTreeCount = new Dictionary<string, int>(this.minSubTreeCount);
    295       clone.maxSubTreeCount = new Dictionary<string, int>(this.maxSubTreeCount);
    296 
    297       clone.allSymbols = new Dictionary<string, Symbol>();
    298       foreach (Symbol symbol in this.allSymbols.Values.Select(s => cloner.Clone(s)))
    299         clone.allSymbols.Add(symbol.Name, symbol);
    300 
    301       clone.startSymbol = (Symbol)cloner.Clone(this.startSymbol);
    302       clone.allowedChildSymbols = new Dictionary<string, List<List<string>>>();
    303       foreach (var entry in this.allowedChildSymbols) {
    304         clone.allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count);
     312    protected void InitializeShallowClone(DefaultSymbolicExpressionGrammar original) {
     313      minSubTreeCount = new Dictionary<string, int>(original.minSubTreeCount);
     314      maxSubTreeCount = new Dictionary<string, int>(original.maxSubTreeCount);
     315
     316      allSymbols = new Dictionary<string, Symbol>(original.allSymbols);
     317      startSymbol = original.startSymbol;
     318      allowedChildSymbols = new Dictionary<string, List<List<string>>>(original.allowedChildSymbols.Count);
     319      foreach (var entry in original.allowedChildSymbols) {
     320        allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count);
    305321        foreach (var set in entry.Value) {
    306           clone.allowedChildSymbols[entry.Key].Add(new List<string>(set));
    307         }
    308       }
    309 
    310       return clone;
    311     }
    312 
    313     protected void InitializeShallowClone(DefaultSymbolicExpressionGrammar clone) {
    314       clone.minSubTreeCount = new Dictionary<string, int>(this.minSubTreeCount);
    315       clone.maxSubTreeCount = new Dictionary<string, int>(this.maxSubTreeCount);
    316 
    317       clone.allSymbols = new Dictionary<string, Symbol>(this.allSymbols);
    318       clone.startSymbol = this.startSymbol;
    319       clone.allowedChildSymbols = new Dictionary<string, List<List<string>>>(this.allowedChildSymbols.Count);
    320       foreach (var entry in this.allowedChildSymbols) {
    321         clone.allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count);
    322         foreach (var set in entry.Value) {
    323           clone.allowedChildSymbols[entry.Key].Add(new List<string>(set));
     322          allowedChildSymbols[entry.Key].Add(new List<string>(set));
    324323        }
    325324      }
Note: See TracChangeset for help on using the changeset viewer.