Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/18/19 23:03:28 (5 years ago)
Author:
mkommend
Message:

#2520: Adapted storable properties from SymbolicExpressionGrammarBase to use new temporary fields and populate the real data fields in the after deserialization hook.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs

    r16565 r17020  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    27 using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    3838
    3939    #region properties for separation between implementation and persistence
     40    private IEnumerable<ISymbol> storableSymbols;
    4041    [Storable(Name = "Symbols")]
    4142    private IEnumerable<ISymbol> StorableSymbols {
    4243      get { return symbols.Values.ToArray(); }
    43       set { foreach (var s in value) symbols.Add(s.Name, s); }
    44     }
    45 
     44      set { storableSymbols = value; }
     45    }
     46
     47    private IEnumerable<KeyValuePair<ISymbol, Tuple<int, int>>> storableSymbolSubtreeCount;
    4648    [Storable(Name = "SymbolSubtreeCount")]
    4749    private IEnumerable<KeyValuePair<ISymbol, Tuple<int, int>>> StorableSymbolSubtreeCount {
    4850      get { return symbolSubtreeCount.Select(x => new KeyValuePair<ISymbol, Tuple<int, int>>(GetSymbol(x.Key), x.Value)).ToArray(); }
    49       set { foreach (var pair in value) symbolSubtreeCount.Add(pair.Key.Name, pair.Value); }
    50     }
    51 
     51      set { storableSymbolSubtreeCount = value; }
     52    }
     53
     54    private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> storableAllowedChildSymbols;
    5255    [Storable(Name = "AllowedChildSymbols")]
    5356    private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> StorableAllowedChildSymbols {
    5457      get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(GetSymbol).ToArray())).ToArray(); }
    55       set { foreach (var pair in value) allowedChildSymbols.Add(pair.Key.Name, pair.Value.Select(y => y.Name).ToList()); }
    56     }
    57 
     58      set { storableAllowedChildSymbols = value; }
     59    }
     60
     61    private IEnumerable<KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>> storableAllowedChildSymbolsPerIndex;
    5862    [Storable(Name = "AllowedChildSymbolsPerIndex")]
    5963    private IEnumerable<KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>> StorableAllowedChildSymbolsPerIndex {
    6064      get { return allowedChildSymbolsPerIndex.Select(x => new KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>(Tuple.Create(GetSymbol(x.Key.Item1), x.Key.Item2), x.Value.Select(GetSymbol).ToArray())).ToArray(); }
    61       set {
    62         foreach (var pair in value)
    63           allowedChildSymbolsPerIndex.Add(Tuple.Create(pair.Key.Item1.Name, pair.Key.Item2), pair.Value.Select(y => y.Name).ToList());
    64       }
     65      set { storableAllowedChildSymbolsPerIndex = value; }
    6566    }
    6667    #endregion
     
    8889
    8990      suppressEvents = false;
     91    }
     92
     93    [StorableHook(HookType.AfterDeserialization)]
     94    private void AfterDeserialization() {
     95      foreach (var s in storableSymbols) symbols.Add(s.Name, s);
     96      foreach (var pair in storableSymbolSubtreeCount) symbolSubtreeCount.Add(pair.Key.Name, pair.Value);
     97      foreach (var pair in storableAllowedChildSymbols) allowedChildSymbols.Add(pair.Key.Name, pair.Value.Select(y => y.Name).ToList());
     98      foreach (var pair in storableAllowedChildSymbolsPerIndex)
     99        allowedChildSymbolsPerIndex.Add(Tuple.Create(pair.Key.Item1.Name, pair.Key.Item2), pair.Value.Select(y => y.Name).ToList());
     100
     101      storableSymbols = null;
     102      storableSymbolSubtreeCount = null;
     103      storableAllowedChildSymbols = null;
     104      storableAllowedChildSymbolsPerIndex = null;
    90105    }
    91106
Note: See TracChangeset for help on using the changeset viewer.