Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/25/11 10:50:21 (14 years ago)
Author:
mkommend
Message:

#1479: Created branch for grammar editing.

Location:
branches/GP.Grammar.Editor
Files:
1 edited
1 copied

Legend:

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

    r6233 r6284  
    9393      cachedMinExpressionDepth = new Dictionary<string, int>();
    9494
    95 
    9695      symbols = original.symbols.ToDictionary(x => x.Key, y => (ISymbol)cloner.Clone(y.Value));
    9796      symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>(original.symbolSubtreeCount);
     
    128127      symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0));
    129128      ClearCaches();
     129      OnChanged();
    130130    }
    131131
     
    133133      symbol.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
    134134      symbol.NameChanged += new EventHandler(Symbol_NameChanged);
     135      symbol.Changed += new EventHandler(Symbol_Changed);
    135136    }
    136137    private void DeregisterSymbolEvents(ISymbol symbol) {
    137138      symbol.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
    138139      symbol.NameChanged -= new EventHandler(Symbol_NameChanged);
     140      symbol.Changed -= new EventHandler(Symbol_Changed);
    139141    }
    140142
     
    179181
    180182      ClearCaches();
     183      OnChanged();
     184    }
     185
     186    private void Symbol_Changed(object sende, EventArgs e) {
     187      ClearCaches();
     188      OnChanged();
    181189    }
    182190
     
    200208      DeregisterSymbolEvents(symbol);
    201209      ClearCaches();
     210      OnChanged();
    202211    }
    203212
     
    217226      childSymbols.Add(child.Name);
    218227      ClearCaches();
     228      OnChanged();
    219229    }
    220230
     
    231241      childSymbols.Add(child.Name);
    232242      ClearCaches();
     243      OnChanged();
    233244    }
    234245
     
    236247      List<string> childSymbols;
    237248      if (allowedChildSymbols.TryGetValue(child.Name, out childSymbols)) {
    238         if (allowedChildSymbols[parent.Name].Remove(child.Name))
     249        if (allowedChildSymbols[parent.Name].Remove(child.Name)) {
    239250          ClearCaches();
     251          OnChanged();
     252        }
    240253      }
    241254    }
     
    245258      List<string> childSymbols;
    246259      if (allowedChildSymbolsPerIndex.TryGetValue(key, out childSymbols)) {
    247         if (allowedChildSymbolsPerIndex[key].Remove(child.Name))
     260        if (allowedChildSymbolsPerIndex[key].Remove(child.Name)) {
    248261          ClearCaches();
     262          OnChanged();
     263        }
    249264      }
    250265    }
     
    258273      symbolSubtreeCount[symbol.Name] = Tuple.Create(minimumSubtreeCount, maximumSubtreeCount);
    259274      ClearCaches();
     275      OnChanged();
    260276    }
    261277    #endregion
     
    304320        result = result.Union(temp);
    305321
    306       return result.Select(x => GetSymbol(x));
     322      return result.Select(x => GetSymbol(x)).Where(s => !s.InitialFrequency.IsAlmost(0.0));
    307323    }
    308324
     
    313329      return symbolSubtreeCount[symbol.Name].Item2;
    314330    }
    315 
    316331
    317332    private void ClearCaches() {
     
    369384      return temp;
    370385    }
     386
     387    public event EventHandler Changed;
     388    protected virtual void OnChanged() {
     389      var handler = Changed;
     390      if (handler != null) Changed(this, EventArgs.Empty);
     391    }
    371392    #endregion
    372393  }
Note: See TracChangeset for help on using the changeset viewer.