Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/11/20 13:36:02 (5 years ago)
Author:
bburlacu
Message:

#1772: Merge trunk changes and fix all errors and compilation warnings.

Location:
branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SymbolicExpressionGrammarBase.cs

    r16130 r17434  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    2929namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    3434  /// in the sub-trees of a symbol (can be specified for each sub-tree index separately).
    3535  /// </summary>
    36   [StorableClass]
     36  [StorableType("E76C087C-4E10-488A-86D0-295A4265DA53")]
    3737  public abstract class SymbolicExpressionGrammarBase : NamedItem, ISymbolicExpressionGrammarBase {
    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
     
    8081
    8182    [StorableConstructor]
    82     protected SymbolicExpressionGrammarBase(bool deserializing)
    83       : base(deserializing) {
     83    protected SymbolicExpressionGrammarBase(StorableConstructorFlag _) : base(_) {
    8484
    8585      symbols = new Dictionary<string, ISymbol>();
     
    8989
    9090      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;
    91105    }
    92106
Note: See TracChangeset for help on using the changeset viewer.