- Timestamp:
- 06/08/11 10:42:57 (13 years ago)
- Location:
- branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs
r5983 r6387 126 126 string symbolName; 127 127 if (aggregateDifferentNumberOfSubtrees) symbolName = node.Symbol.Name; 128 else symbolName = node.Symbol.Name + "-" + node.Subtree sCount;128 else symbolName = node.Symbol.Name + "-" + node.SubtreeCount; 129 129 if (symbolFrequencies.ContainsKey(symbolName)) symbolFrequencies[symbolName] += 1; 130 130 else symbolFrequencies.Add(symbolName, 1); -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeCompiler.cs
r5809 r6387 62 62 foreach (var node in branch.IterateNodesPrefix()) { 63 63 Instruction instr = new Instruction(); 64 int subtreesCount = node.Subtree sCount;64 int subtreesCount = node.SubtreeCount; 65 65 if (subtreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)"); 66 66 instr.nArguments = (byte)subtreesCount; -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r6284 r6387 133 133 if (newChild == null) { 134 134 // make sure that one subtree can be removed and that only the last subtree is removed 135 return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.Subtree sCount &&136 cutPoint.ChildIndex == parent.Subtree sCount - 1;135 return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount && 136 cutPoint.ChildIndex == parent.SubtreeCount - 1; 137 137 } else { 138 138 // check syntax constraints of direct parent - child relation … … 146 146 result && 147 147 parent.Grammar.ContainsSymbol(n.Symbol) && 148 n.Subtree sCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) &&149 n.Subtree sCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol);148 n.SubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) && 149 n.SubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol); 150 150 }); 151 151 return result; … … 169 169 } 170 170 // add one additional extension point if the number of sub trees for the symbol is not full 171 if (n.Subtree sCount < n.Grammar.GetMaximumSubtreeCount(n.Symbol)) {171 if (n.SubtreeCount < n.Grammar.GetMaximumSubtreeCount(n.Symbol)) { 172 172 // empty extension point 173 internalCrossoverPoints.Add(new CutPoint(n, n.Subtree sCount));173 internalCrossoverPoints.Add(new CutPoint(n, n.SubtreeCount)); 174 174 } 175 175 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbol.cs
r6296 r6387 30 30 bool Fixed { get; set; } 31 31 32 int MinimumArity { get; } 33 int MaximumArity { get; } 34 32 35 event EventHandler Changed; 33 36 } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs
r5809 r6387 39 39 40 40 IEnumerable<ISymbolicExpressionTreeNode> Subtrees { get; } 41 int Subtree sCount { get; }41 int SubtreeCount { get; } 42 42 ISymbolicExpressionTreeNode GetSubtree(int index); 43 43 int IndexOfSubtree(ISymbolicExpressionTreeNode tree); -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs
r6377 r6387 143 143 private void AddSymbolToDictionaries(ISymbol symbol) { 144 144 symbols.Add(symbol.Name, symbol); 145 symbolSubtreeCount.Add(symbol.Name, Tuple.Create( 0, 0));145 symbolSubtreeCount.Add(symbol.Name, Tuple.Create(symbol.MinimumArity, symbol.MaximumArity)); 146 146 RegisterSymbolEvents(symbol); 147 147 } … … 315 315 protected void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) { 316 316 var groupSymbol = symbol as GroupSymbol; 317 if (groupSymbol != null) 318 foreach (ISymbol s in groupSymbol.Flatten().Where(s => !(s is GroupSymbol))) 317 if (groupSymbol != null) { 318 var symbols = groupSymbol.Flatten().Where(s => !(s is GroupSymbol)); 319 if (symbols.Any(s => s.MinimumArity > minimumSubtreeCount)) throw new ArgumentException("Invalid minimum subtree count " + minimumSubtreeCount + " for " + symbol); 320 if (symbols.Any(s => s.MaximumArity < maximumSubtreeCount)) throw new ArgumentException("Invalid minimum subtree count " + minimumSubtreeCount + " for " + symbol); 321 foreach (ISymbol s in symbols) 319 322 SetSubTreeCountInDictionaries(s, minimumSubtreeCount, maximumSubtreeCount); 320 else 323 } else { 324 if (symbol.MinimumArity > minimumSubtreeCount) throw new ArgumentException("Invalid minimum subtree count " + minimumSubtreeCount + " for " + symbol); 325 if (symbol.MaximumArity < maximumSubtreeCount) throw new ArgumentException("Invalid minimum subtree count " + minimumSubtreeCount + " for " + symbol); 321 326 SetSubTreeCountInDictionaries(symbol, minimumSubtreeCount, maximumSubtreeCount); 327 } 322 328 323 329 ClearCaches(); -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r6377 r6387 126 126 public virtual void ShakeLocalParameters(IRandom random, double shakingFactor) { } 127 127 128 public int Subtree sCount {128 public int SubtreeCount { 129 129 get { 130 130 if (subtrees == null) return 0; -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Argument.cs
r6233 r6387 32 32 public const string ArgumentName = "Argument"; 33 33 public const string ArgumentDescription = "Symbol that represents a function argument."; 34 private const int minimumArity = 0; 35 private const int maximumArity = 0; 36 37 public override int MinimumArity { 38 get { return minimumArity; } 39 } 40 public override int MaximumArity { 41 get { return maximumArity; } 42 } 43 34 44 [Storable] 35 45 private int argumentIndex; -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Defun.cs
r5809 r6387 32 32 public const string DefunName = "Defun"; 33 33 public const string DefunDescription = "Symbol that represents a function defining node."; 34 private const int minimumArity = 1; 35 private const int maximumArity = 1; 36 37 public override int MinimumArity { 38 get { return minimumArity; } 39 } 40 public override int MaximumArity { 41 get { return maximumArity; } 42 } 34 43 35 44 [StorableConstructor] -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/GroupSymbol.cs
r6377 r6387 28 28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 29 29 public sealed class GroupSymbol : Symbol { 30 private const int minimumArity = 0; 31 private const int maximumArity = 0; 32 33 public override int MinimumArity { 34 get { return minimumArity; } 35 } 36 public override int MaximumArity { 37 get { return maximumArity; } 38 } 39 30 40 private ObservableSet<ISymbol> symbols; 31 41 public IObservableSet<ISymbol> SymbolsCollection { -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/InvokeFunction.cs
r6233 r6387 32 32 public const string InvokeFunctionName = "InvokeFunction"; 33 33 public const string InvokeFunctionDescription = "Symbol that the invocation of another function."; 34 private const int minimumArity = 0; 35 private const int maximumArity = byte.MaxValue; 36 37 public override int MinimumArity { 38 get { return minimumArity; } 39 } 40 public override int MaximumArity { 41 get { return maximumArity; } 42 } 34 43 35 44 [Storable] -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/ProgramRootSymbol.cs
r5809 r6387 29 29 public const string ProgramRootSymbolName = "ProgramRootSymbol"; 30 30 public const string ProgramRootSymbolDescription = "Special symbol that represents the program root node of a symbolic expression tree."; 31 private const int minimumArity = 1; 32 private const int maximumArity = byte.MaxValue; 33 34 public override int MinimumArity { 35 get { return minimumArity; } 36 } 37 public override int MaximumArity { 38 get { return maximumArity; } 39 } 31 40 32 41 [StorableConstructor] -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/StartSymbol.cs
r5809 r6387 29 29 public const string StartSymbolName = "StartSymbol"; 30 30 public const string StartSymbolDescription = "Special symbol that represents the starting node of the result producing branch of a symbolic expression tree."; 31 private const int minimumArity = 1; 32 private const int maximumArity = 1; 33 34 public override int MinimumArity { 35 get { return minimumArity; } 36 } 37 public override int MaximumArity { 38 get { return maximumArity; } 39 } 31 40 32 41 [StorableConstructor] 33 private StartSymbol(bool deserializing) : base(deserializing) { } 42 private StartSymbol(bool deserializing) 43 : base(deserializing) { 44 } 34 45 private StartSymbol(StartSymbol original, Cloner cloner) : base(original, cloner) { } 35 46 public StartSymbol() : base(StartSymbol.StartSymbolName, StartSymbol.StartSymbolDescription) { } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Symbol.cs
r6299 r6387 73 73 get { return false; } 74 74 } 75 76 public abstract int MinimumArity { get; } 77 public abstract int MaximumArity { get; } 75 78 #endregion 76 79 -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Grammars.cs
r6377 r6387 27 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._4.Tests { 28 28 public static class Grammars { 29 30 29 [StorableClass] 31 30 private class Addition : Symbol { 31 private const int minimumArity = 1; 32 private const int maximumArity = byte.MaxValue; 33 34 public override int MinimumArity { 35 get { return minimumArity; } 36 } 37 public override int MaximumArity { 38 get { return maximumArity; } 39 } 40 32 41 [StorableConstructor] 33 42 protected Addition(bool deserializing) : base(deserializing) { } … … 41 50 [StorableClass] 42 51 private class Subtraction : Symbol { 52 private const int minimumArity = 1; 53 private const int maximumArity = byte.MaxValue; 54 55 public override int MinimumArity { 56 get { return minimumArity; } 57 } 58 public override int MaximumArity { 59 get { return maximumArity; } 60 } 61 43 62 [StorableConstructor] 44 63 protected Subtraction(bool deserializing) : base(deserializing) { } … … 52 71 [StorableClass] 53 72 private class Multiplication : Symbol { 73 private const int minimumArity = 1; 74 private const int maximumArity = byte.MaxValue; 75 76 public override int MinimumArity { 77 get { return minimumArity; } 78 } 79 public override int MaximumArity { 80 get { return maximumArity; } 81 } 82 54 83 [StorableConstructor] 55 84 protected Multiplication(bool deserializing) : base(deserializing) { } … … 63 92 [StorableClass] 64 93 private class Division : Symbol { 94 private const int minimumArity = 1; 95 private const int maximumArity = byte.MaxValue; 96 97 public override int MinimumArity { 98 get { return minimumArity; } 99 } 100 public override int MaximumArity { 101 get { return maximumArity; } 102 } 103 65 104 [StorableConstructor] 66 105 protected Division(bool deserializing) : base(deserializing) { } … … 74 113 [StorableClass] 75 114 private class Terminal : Symbol { 115 private const int minimumArity = 0; 116 private const int maximumArity = 0; 117 118 public override int MinimumArity { 119 get { return minimumArity; } 120 } 121 public override int MaximumArity { 122 get { return maximumArity; } 123 } 124 76 125 [StorableConstructor] 77 126 protected Terminal(bool deserializing) : base(deserializing) { } -
branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Util.cs
r5809 r6387 122 122 123 123 foreach (var argTreenode in defunTreeNode.IterateNodesPrefix().OfType<ArgumentTreeNode>()) { 124 Assert.IsTrue(argTreenode.Subtree sCount == 0);124 Assert.IsTrue(argTreenode.SubtreeCount == 0); 125 125 Assert.IsTrue(((Argument)argTreenode.Symbol).ArgumentIndex < arity); 126 126 }
Note: See TracChangeset
for help on using the changeset viewer.