- Timestamp:
- 06/07/11 12:49:03 (13 years ago)
- 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 182 182 where s.InitialFrequency > 0.0 183 183 where s.Fixed || parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1 184 //where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength184 where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength 185 185 select s) 186 186 .ToList(); -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r6337 r6377 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Collections; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 155 156 156 157 foreach (GroupSymbol group in symbols.Values.OfType<GroupSymbol>()) 157 group. symbols.Remove(symbol);158 group.SymbolsCollection.Remove(symbol); 158 159 159 160 ClearCaches(); … … 451 452 symbol.NameChanged += new EventHandler(Symbol_NameChanged); 452 453 symbol.Changed += new EventHandler(Symbol_Changed); 454 var groupSymbol = symbol as GroupSymbol; 455 if (groupSymbol != null) RegisterGroupSymbolEvents(groupSymbol); 453 456 } 454 457 private void DeregisterSymbolEvents(ISymbol symbol) { … … 456 459 symbol.NameChanged -= new EventHandler(Symbol_NameChanged); 457 460 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); 458 474 } 459 475 … … 506 522 } 507 523 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 508 552 public event EventHandler Changed; 509 553 protected virtual void OnChanged() { -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r5809 r6377 186 186 187 187 public override string ToString() { 188 return Symbol.Name; 188 if (Symbol != null) return Symbol.Name; 189 return "SymbolicExpressionTreeNode"; 189 190 } 190 191 -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/GroupSymbol.cs
r6337 r6377 22 22 using System.Collections.Generic; 23 23 using System.Linq; 24 using HeuristicLab.Collections; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 28 namespace 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 } 31 34 [Storable] 32 35 public IEnumerable<ISymbol> Symbols { … … 39 42 if (value != Enabled) { 40 43 base.Enabled = value; 41 symbols.ForEach(s => s.Enabled = value); 44 foreach (ISymbol symbol in symbols) 45 symbol.Enabled = value; 42 46 } 43 47 } … … 48 52 private GroupSymbol(GroupSymbol original, Cloner cloner) 49 53 : 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))); 51 55 } 52 56 public override IDeepCloneable Clone(Cloner cloner) { … … 54 58 } 55 59 60 public GroupSymbol() : this("Group Symbol", Enumerable.Empty<ISymbol>()) { } 56 61 public GroupSymbol(string name, IEnumerable<ISymbol> symbols) 57 62 : base(name, "A symbol which groups other symbols") { 58 this.symbols = new List<ISymbol>(symbols);63 this.symbols = new ObservableSet<ISymbol>(symbols); 59 64 InitialFrequency = 0.0; 60 65 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Grammars.cs
r5809 r6377 27 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._4.Tests { 28 28 public static class Grammars { 29 30 [StorableClass] 29 31 private class Addition : Symbol { 32 [StorableConstructor] 33 protected Addition(bool deserializing) : base(deserializing) { } 30 34 protected Addition(Addition original, Cloner cloner) : base(original, cloner) { } 31 35 public Addition() : base("Addition", "") { } … … 34 38 } 35 39 } 40 41 [StorableClass] 36 42 private class Subtraction : Symbol { 43 [StorableConstructor] 44 protected Subtraction(bool deserializing) : base(deserializing) { } 37 45 protected Subtraction(Subtraction original, Cloner cloner) : base(original, cloner) { } 38 46 public Subtraction() : base("Subtraction", "") { } … … 41 49 } 42 50 } 51 52 [StorableClass] 43 53 private class Multiplication : Symbol { 54 [StorableConstructor] 55 protected Multiplication(bool deserializing) : base(deserializing) { } 44 56 protected Multiplication(Multiplication original, Cloner cloner) : base(original, cloner) { } 45 57 public Multiplication() : base("Multiplication", "") { } … … 48 60 } 49 61 } 62 63 [StorableClass] 50 64 private class Division : Symbol { 65 [StorableConstructor] 66 protected Division(bool deserializing) : base(deserializing) { } 51 67 protected Division(Division original, Cloner cloner) : base(original, cloner) { } 52 68 public Division() : base("Division", "") { } … … 55 71 } 56 72 } 73 74 [StorableClass] 57 75 private class Terminal : Symbol { 76 [StorableConstructor] 77 protected Terminal(bool deserializing) : base(deserializing) { } 58 78 protected Terminal(Terminal original, Cloner cloner) : base(original, cloner) { } 59 79 public Terminal() : base("Terminal", "") { } … … 67 87 } 68 88 89 [StorableClass] 69 90 private class TerminalNode : SymbolicExpressionTreeTerminalNode { 70 91 public override bool HasLocalParameters { get { return true; } } … … 94 115 } 95 116 117 [StorableClass] 96 118 private class SimpleArithmeticGrammar : SymbolicExpressionGrammar { 119 [StorableConstructor] 120 protected SimpleArithmeticGrammar(bool deserializing) : base(deserializing) { } 97 121 protected SimpleArithmeticGrammar(SimpleArithmeticGrammar original, Cloner cloner) : base(original, cloner) { } 98 122 public SimpleArithmeticGrammar()
Note: See TracChangeset
for help on using the changeset viewer.