Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/19 08:13:50 (6 years ago)
Author:
gkronber
Message:

#2925: merged r17007:17033 from trunk to branch

Location:
branches/2925_AutoDiffForDynamicalModels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2925_AutoDiffForDynamicalModels

  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

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

    r16953 r17035  
    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 List<Action> afterDeserializationActions = new List<Action>();
     40    private IEnumerable<ISymbol> storableSymbols;
    4141    [Storable(Name = "Symbols")]
    4242    private IEnumerable<ISymbol> StorableSymbols {
    4343      get { return symbols.Values.ToArray(); }
    44       set { afterDeserializationActions.Add(() => { foreach (var s in value) symbols.Add(s.Name, s); }); }
    45     }
    46 
     44      set { storableSymbols = value; }
     45    }
     46
     47    private IEnumerable<KeyValuePair<ISymbol, Tuple<int, int>>> storableSymbolSubtreeCount;
    4748    [Storable(Name = "SymbolSubtreeCount")]
    4849    private IEnumerable<KeyValuePair<ISymbol, Tuple<int, int>>> StorableSymbolSubtreeCount {
    4950      get { return symbolSubtreeCount.Select(x => new KeyValuePair<ISymbol, Tuple<int, int>>(GetSymbol(x.Key), x.Value)).ToArray(); }
    50       set { afterDeserializationActions.Add(() => { foreach (var pair in value) symbolSubtreeCount.Add(pair.Key.Name, pair.Value); }); }
    51     }
    52 
     51      set { storableSymbolSubtreeCount = value; }
     52    }
     53
     54    private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> storableAllowedChildSymbols;
    5355    [Storable(Name = "AllowedChildSymbols")]
    5456    private IEnumerable<KeyValuePair<ISymbol, IEnumerable<ISymbol>>> StorableAllowedChildSymbols {
    5557      get { return allowedChildSymbols.Select(x => new KeyValuePair<ISymbol, IEnumerable<ISymbol>>(GetSymbol(x.Key), x.Value.Select(GetSymbol).ToArray())).ToArray(); }
    56       set { afterDeserializationActions.Add(() => { foreach (var pair in value) allowedChildSymbols.Add(pair.Key.Name, pair.Value.Select(y => y.Name).ToList()); }); }
    57     }
    58 
     58      set { storableAllowedChildSymbols = value; }
     59    }
     60
     61    private IEnumerable<KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>> storableAllowedChildSymbolsPerIndex;
    5962    [Storable(Name = "AllowedChildSymbolsPerIndex")]
    6063    private IEnumerable<KeyValuePair<Tuple<ISymbol, int>, IEnumerable<ISymbol>>> StorableAllowedChildSymbolsPerIndex {
    6164      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(); }
    62       set {
    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         });
    67       }
     65      set { storableAllowedChildSymbolsPerIndex = value; }
    6866    }
    6967    #endregion
     
    9189
    9290      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;
    93105    }
    94106
Note: See TracChangeset for help on using the changeset viewer.