Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/07/11 12:49:03 (13 years ago)
Author:
mkommend
Message:

#1479: Merged trunk changes into branch.

Location:
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r6337 r6377  
    182182                                where s.InitialFrequency > 0.0
    183183                                where s.Fixed || parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1
    184                                 //where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength
     184                                where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength
    185185                                select s)
    186186                               .ToList();
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6337 r6377  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Collections;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    155156
    156157      foreach (GroupSymbol group in symbols.Values.OfType<GroupSymbol>())
    157         group.symbols.Remove(symbol);
     158        group.SymbolsCollection.Remove(symbol);
    158159
    159160      ClearCaches();
     
    451452      symbol.NameChanged += new EventHandler(Symbol_NameChanged);
    452453      symbol.Changed += new EventHandler(Symbol_Changed);
     454      var groupSymbol = symbol as GroupSymbol;
     455      if (groupSymbol != null) RegisterGroupSymbolEvents(groupSymbol);
    453456    }
    454457    private void DeregisterSymbolEvents(ISymbol symbol) {
     
    456459      symbol.NameChanged -= new EventHandler(Symbol_NameChanged);
    457460      symbol.Changed -= new EventHandler(Symbol_Changed);
     461      var groupSymbol = symbol as GroupSymbol;
     462      if (groupSymbol != null) DeregisterGroupSymbolEvents(groupSymbol);
     463    }
     464
     465    private void RegisterGroupSymbolEvents(GroupSymbol groupSymbol) {
     466      groupSymbol.SymbolsCollection.ItemsAdded += new Collections.CollectionItemsChangedEventHandler<ISymbol>(GroupSymbol_ItemsAdded);
     467      groupSymbol.SymbolsCollection.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<ISymbol>(GroupSymbol_ItemsRemoved);
     468      groupSymbol.SymbolsCollection.CollectionReset += new Collections.CollectionItemsChangedEventHandler<ISymbol>(GroupSymbol_CollectionReset);
     469    }
     470    private void DeregisterGroupSymbolEvents(GroupSymbol groupSymbol) {
     471      groupSymbol.SymbolsCollection.ItemsAdded -= new Collections.CollectionItemsChangedEventHandler<ISymbol>(GroupSymbol_ItemsAdded);
     472      groupSymbol.SymbolsCollection.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<ISymbol>(GroupSymbol_ItemsRemoved);
     473      groupSymbol.SymbolsCollection.CollectionReset -= new Collections.CollectionItemsChangedEventHandler<ISymbol>(GroupSymbol_CollectionReset);
    458474    }
    459475
     
    506522    }
    507523
     524    private void GroupSymbol_ItemsAdded(object sender, CollectionItemsChangedEventArgs<ISymbol> e) {
     525      suppressEvents = true;
     526      foreach (ISymbol symbol in e.Items)
     527        if (!ContainsSymbol(symbol))
     528          AddSymbol(symbol);
     529      suppressEvents = false;
     530      OnChanged();
     531    }
     532    private void GroupSymbol_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<ISymbol> e) {
     533      suppressEvents = true;
     534      foreach (ISymbol symbol in e.Items)
     535        if (ContainsSymbol(symbol))
     536          RemoveSymbol(symbol);
     537      suppressEvents = false;
     538      OnChanged();
     539    }
     540    private void GroupSymbol_CollectionReset(object sender, CollectionItemsChangedEventArgs<ISymbol> e) {
     541      suppressEvents = true;
     542      foreach (ISymbol symbol in e.Items)
     543        if (!ContainsSymbol(symbol))
     544          AddSymbol(symbol);
     545      foreach (ISymbol symbol in e.OldItems)
     546        if (ContainsSymbol(symbol))
     547          RemoveSymbol(symbol);
     548      suppressEvents = false;
     549      OnChanged();
     550    }
     551
    508552    public event EventHandler Changed;
    509553    protected virtual void OnChanged() {
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs

    r5809 r6377  
    186186
    187187    public override string ToString() {
    188       return Symbol.Name;
     188      if (Symbol != null) return Symbol.Name;
     189      return "SymbolicExpressionTreeNode";
    189190    }
    190191
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/GroupSymbol.cs

    r6337 r6377  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HeuristicLab.Collections;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    2728namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    28   public sealed class GroupSymbol : Symbol, IReadOnlySymbol {
    29     internal List<ISymbol> symbols;
    30 
     29  public sealed class GroupSymbol : Symbol {
     30    private ObservableSet<ISymbol> symbols;
     31    public IObservableSet<ISymbol> SymbolsCollection {
     32      get { return symbols; }
     33    }
    3134    [Storable]
    3235    public IEnumerable<ISymbol> Symbols {
     
    3942        if (value != Enabled) {
    4043          base.Enabled = value;
    41           symbols.ForEach(s => s.Enabled = value);
     44          foreach (ISymbol symbol in symbols)
     45            symbol.Enabled = value;
    4246        }
    4347      }
     
    4852    private GroupSymbol(GroupSymbol original, Cloner cloner)
    4953      : base(original, cloner) {
    50       symbols = original.Symbols.Select(s => cloner.Clone(s)).ToList();
     54      symbols = new ObservableSet<ISymbol>(original.Symbols.Select(s => cloner.Clone(s)));
    5155    }
    5256    public override IDeepCloneable Clone(Cloner cloner) {
     
    5458    }
    5559
     60    public GroupSymbol() : this("Group Symbol", Enumerable.Empty<ISymbol>()) { }
    5661    public GroupSymbol(string name, IEnumerable<ISymbol> symbols)
    5762      : base(name, "A symbol which groups other symbols") {
    58       this.symbols = new List<ISymbol>(symbols);
     63      this.symbols = new ObservableSet<ISymbol>(symbols);
    5964      InitialFrequency = 0.0;
    6065    }
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Grammars.cs

    r5809 r6377  
    2727namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._4.Tests {
    2828  public static class Grammars {
     29
     30    [StorableClass]
    2931    private class Addition : Symbol {
     32      [StorableConstructor]
     33      protected Addition(bool deserializing) : base(deserializing) { }
    3034      protected Addition(Addition original, Cloner cloner) : base(original, cloner) { }
    3135      public Addition() : base("Addition", "") { }
     
    3438      }
    3539    }
     40
     41    [StorableClass]
    3642    private class Subtraction : Symbol {
     43      [StorableConstructor]
     44      protected Subtraction(bool deserializing) : base(deserializing) { }
    3745      protected Subtraction(Subtraction original, Cloner cloner) : base(original, cloner) { }
    3846      public Subtraction() : base("Subtraction", "") { }
     
    4149      }
    4250    }
     51
     52    [StorableClass]
    4353    private class Multiplication : Symbol {
     54      [StorableConstructor]
     55      protected Multiplication(bool deserializing) : base(deserializing) { }
    4456      protected Multiplication(Multiplication original, Cloner cloner) : base(original, cloner) { }
    4557      public Multiplication() : base("Multiplication", "") { }
     
    4860      }
    4961    }
     62
     63    [StorableClass]
    5064    private class Division : Symbol {
     65      [StorableConstructor]
     66      protected Division(bool deserializing) : base(deserializing) { }
    5167      protected Division(Division original, Cloner cloner) : base(original, cloner) { }
    5268      public Division() : base("Division", "") { }
     
    5571      }
    5672    }
     73
     74    [StorableClass]
    5775    private class Terminal : Symbol {
     76      [StorableConstructor]
     77      protected Terminal(bool deserializing) : base(deserializing) { }
    5878      protected Terminal(Terminal original, Cloner cloner) : base(original, cloner) { }
    5979      public Terminal() : base("Terminal", "") { }
     
    6787    }
    6888
     89    [StorableClass]
    6990    private class TerminalNode : SymbolicExpressionTreeTerminalNode {
    7091      public override bool HasLocalParameters { get { return true; } }
     
    94115    }
    95116
     117    [StorableClass]
    96118    private class SimpleArithmeticGrammar : SymbolicExpressionGrammar {
     119      [StorableConstructor]
     120      protected SimpleArithmeticGrammar(bool deserializing) : base(deserializing) { }
    97121      protected SimpleArithmeticGrammar(SimpleArithmeticGrammar original, Cloner cloner) : base(original, cloner) { }
    98122      public SimpleArithmeticGrammar()
Note: See TracChangeset for help on using the changeset viewer.