Changeset 16953


Ignore:
Timestamp:
05/15/19 12:17:12 (12 days ago)
Author:
gkronber
Message:

#2925: made a fix in StorableProperties of SymExprGrammarBase which is necessary because of the new HEAL.Attic-based persistence.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs

    r16662 r16953  
    3838
    3939    #region properties for separation between implementation and persistence
     40    private List<Action> afterDeserializationActions = new List<Action>();
    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      set { afterDeserializationActions.Add(() => { foreach (var s in value) symbols.Add(s.Name, s); }); }
    4445    }
    4546
     
    4748    private IEnumerable<KeyValuePair<ISymbol, Tuple<int, int>>> StorableSymbolSubtreeCount {
    4849      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      set { afterDeserializationActions.Add(() => { foreach (var pair in value) symbolSubtreeCount.Add(pair.Key.Name, pair.Value); }); }
    5051    }
    5152
     
    5354    private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> StorableAllowedChildSymbols {
    5455      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      set { afterDeserializationActions.Add(() => { foreach (var pair in value) allowedChildSymbols.Add(pair.Key.Name, pair.Value.Select(y => y.Name).ToList()); }); }
    5657    }
    5758
     
    6061      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(); }
    6162      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());
     63        afterDeserializationActions.Add(() => {
     64          foreach (var pair in value)
     65            allowedChildSymbolsPerIndex.Add(Tuple.Create(pair.Key.Item1.Name, pair.Key.Item2), pair.Value.Select(y => y.Name).ToList());
     66        });
    6467      }
    6568    }
     
    116119      suppressEvents = false;
    117120    }
     121
     122    [StorableHook(HookType.AfterDeserialization)]
     123    private void AfterDeserialization() {
     124      foreach(var a in afterDeserializationActions) {
     125        a();
     126      }
     127    }
     128
    118129
    119130    #region protected grammar manipulation methods
Note: See TracChangeset for help on using the changeset viewer.