- Timestamp:
- 07/02/10 11:38:04 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/DefaultSymbolicExpressionGrammar.cs
r3541 r3993 63 63 } 64 64 set { 65 allowedChildSymbols = new Dictionary<string, List< HashSet<string>>>();65 allowedChildSymbols = new Dictionary<string, List<List<string>>>(); 66 66 foreach (var pair in value) { 67 allowedChildSymbols[pair.Key] = new List< HashSet<string>>();67 allowedChildSymbols[pair.Key] = new List<List<string>>(); 68 68 foreach (var entry in pair.Value) { 69 var hashSet = new HashSet<string>();69 var hashSet = new List<string>(); 70 70 foreach (string child in entry) { 71 71 hashSet.Add(child); … … 85 85 private Dictionary<string, int> minSubTreeCount; 86 86 private Dictionary<string, int> maxSubTreeCount; 87 private Dictionary<string, List< HashSet<string>>> allowedChildSymbols;87 private Dictionary<string, List<List<string>>> allowedChildSymbols; 88 88 private Dictionary<string, Symbol> allSymbols; 89 89 [Storable] … … 92 92 public DefaultSymbolicExpressionGrammar() 93 93 : base() { 94 Clear();95 }96 97 public void Clear() {98 94 minSubTreeCount = new Dictionary<string, int>(); 99 95 maxSubTreeCount = new Dictionary<string, int>(); 100 allowedChildSymbols = new Dictionary<string, List< HashSet<string>>>();96 allowedChildSymbols = new Dictionary<string, List<List<string>>>(); 101 97 allSymbols = new Dictionary<string, Symbol>(); 98 102 99 cachedMinExpressionLength = new Dictionary<string, int>(); 103 100 cachedMaxExpressionLength = new Dictionary<string, int>(); … … 110 107 } 111 108 109 //copy constructor for cloning 110 protected DefaultSymbolicExpressionGrammar(DefaultSymbolicExpressionGrammar copy) :base() { 111 this.minSubTreeCount = new Dictionary<string, int>(copy.minSubTreeCount); 112 this.maxSubTreeCount = new Dictionary<string, int>(copy.maxSubTreeCount); 113 114 this.startSymbol = copy.startSymbol; 115 this.allowedChildSymbols = new Dictionary<string, List<List<string>>>(); 116 foreach (var entry in copy.allowedChildSymbols) { 117 this.allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count); 118 foreach (var set in entry.Value) { 119 this.allowedChildSymbols[entry.Key].Add(new List<string>(set)); 120 } 121 } 122 this.allSymbols = new Dictionary<string, Symbol>(copy.allSymbols); 123 124 cachedMinExpressionLength = new Dictionary<string, int>(); 125 cachedMaxExpressionLength = new Dictionary<string, int>(); 126 cachedMinExpressionDepth = new Dictionary<string, int>(); 127 } 128 129 [StorableConstructor] 130 protected DefaultSymbolicExpressionGrammar(bool deserializing) 131 : base(deserializing) { 132 cachedMinExpressionLength = new Dictionary<string, int>(); 133 cachedMaxExpressionLength = new Dictionary<string, int>(); 134 cachedMinExpressionDepth = new Dictionary<string, int>(); 135 } 136 137 public void Clear() { 138 minSubTreeCount.Clear(); 139 maxSubTreeCount.Clear(); 140 allowedChildSymbols.Clear(); 141 allSymbols.Clear(); 142 143 cachedMaxExpressionLength.Clear(); 144 cachedMinExpressionLength.Clear(); 145 cachedMinExpressionDepth.Clear(); 146 147 startSymbol = new StartSymbol(); 148 AddSymbol(startSymbol); 149 SetMinSubtreeCount(startSymbol, 1); 150 SetMaxSubtreeCount(startSymbol, 1); 151 } 152 112 153 #region ISymbolicExpressionGrammar Members 113 154 … … 117 158 } 118 159 119 120 160 public void AddSymbol(Symbol symbol) { 121 161 if (ContainsSymbol(symbol)) throw new ArgumentException("Symbol " + symbol + " is already defined."); 122 162 allSymbols.Add(symbol.Name, symbol); 123 allowedChildSymbols[symbol.Name] = new List< HashSet<string>>();163 allowedChildSymbols[symbol.Name] = new List<List<string>>(); 124 164 ClearCaches(); 125 165 } … … 211 251 maxSubTreeCount[symbol.Name] = nSubTrees; 212 252 while (allowedChildSymbols[symbol.Name].Count <= nSubTrees) 213 allowedChildSymbols[symbol.Name].Add(new HashSet<string>());253 allowedChildSymbols[symbol.Name].Add(new List<string>()); 214 254 while (allowedChildSymbols[symbol.Name].Count > nSubTrees) { 215 255 allowedChildSymbols[symbol.Name].RemoveAt(allowedChildSymbols[symbol.Name].Count - 1); … … 243 283 244 284 public override IDeepCloneable Clone(Cloner cloner) { 245 DefaultSymbolicExpressionGrammar clone = (DefaultSymbolicExpressionGrammar)base.Clone(cloner); 246 clone.maxSubTreeCount = new Dictionary<string, int>(maxSubTreeCount); 247 clone.minSubTreeCount = new Dictionary<string, int>(minSubTreeCount); 248 clone.startSymbol = startSymbol; 249 clone.allowedChildSymbols = new Dictionary<string, List<HashSet<string>>>(); 250 foreach (var entry in allowedChildSymbols) { 251 clone.allowedChildSymbols[entry.Key] = new List<HashSet<string>>(); 252 foreach (var set in entry.Value) { 253 clone.allowedChildSymbols[entry.Key].Add(new HashSet<string>(set)); 254 } 255 } 256 clone.allSymbols = new Dictionary<string, Symbol>(allSymbols); 285 DefaultSymbolicExpressionGrammar clone = new DefaultSymbolicExpressionGrammar(this); 286 cloner.RegisterClonedObject(this, clone); 257 287 return clone; 258 288 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs
r3990 r3993 72 72 private Defun defunSymbol; 73 73 74 public GlobalSymbolicExpressionGrammar() : base() { } // empty constructor for cloning 74 75 75 76 76 public GlobalSymbolicExpressionGrammar(ISymbolicExpressionGrammar mainBranchGrammar ) … … 79 79 maxFunctionDefinitions = 3; 80 80 Initialize(mainBranchGrammar); 81 } 82 83 //copy constructor for cloning 84 protected GlobalSymbolicExpressionGrammar(GlobalSymbolicExpressionGrammar copy) 85 : base(copy) { 86 this.maxFunctionArguments = copy.maxFunctionArguments; 87 this.minFunctionArguments = copy.minFunctionArguments; 88 this.maxFunctionDefinitions = copy.maxFunctionDefinitions; 89 this.minFunctionDefinitions = copy.minFunctionDefinitions; 90 } 91 92 [StorableConstructor] 93 protected GlobalSymbolicExpressionGrammar(bool deserializing) 94 : base(deserializing) { 81 95 } 82 96 … … 142 156 143 157 public override IDeepCloneable Clone(Cloner cloner) { 144 GlobalSymbolicExpressionGrammar clone = (GlobalSymbolicExpressionGrammar)base.Clone(cloner); 145 clone.defunSymbol = defunSymbol; 146 clone.maxFunctionArguments = maxFunctionArguments; 147 clone.maxFunctionDefinitions = maxFunctionDefinitions; 148 clone.minFunctionArguments = minFunctionArguments; 149 clone.minFunctionDefinitions = minFunctionDefinitions; 158 GlobalSymbolicExpressionGrammar clone = new GlobalSymbolicExpressionGrammar(this); 159 cloner.RegisterClonedObject(this, clone); 150 160 return clone; 151 161 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Argument.cs
r3824 r3993 28 28 /// </summary> 29 29 [StorableClass] 30 [Item( "Argument", "Symbol that represents a function argument.")]30 [Item(Argument.ArgumentName, Argument.ArgumentDescription)] 31 31 public sealed class Argument : ReadOnlySymbol { 32 public const string ArgumentName = "Argument"; 33 public const string ArgumentDescription = "Symbol that represents a function argument."; 32 34 [Storable] 33 35 private int argumentIndex; … … 36 38 } 37 39 40 public override bool CanChangeDescription { 41 get { return false; } 42 } 43 44 [StorableConstructor] 38 45 private Argument() : base() { } 39 46 40 47 public Argument(int argumentIndex) 41 : base( ) {48 : base("ARG" + argumentIndex, Argument.ArgumentDescription) { 42 49 this.argumentIndex = argumentIndex; 43 50 this.name = "ARG" + argumentIndex; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Defun.cs
r3983 r3993 28 28 /// </summary> 29 29 [StorableClass] 30 [Item( "Defun", "Symbol that represents a function defining node.")]30 [Item(Defun.DefunName, Defun.DefunDescription)] 31 31 public sealed class Defun : ReadOnlySymbol { 32 public Defun() : base() { } 32 public const string DefunName = "Defun"; 33 public const string DefunDescription = "Symbol that represents a function defining node."; 34 35 public Defun() : base(Defun.DefunName, Defun.DefunDescription) { } 36 [StorableConstructor] 37 protected Defun(bool deserializing) : base(deserializing) { } 33 38 34 39 public override SymbolicExpressionTreeNode CreateTreeNode() { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunction.cs
r3824 r3993 29 29 /// </summary> 30 30 [StorableClass] 31 [Item( "InvokeFunction", "Symbol that the invokation of another function.")]31 [Item(InvokeFunction.InvokeFunctionName, InvokeFunction.InvokeFunctionDescription)] 32 32 public sealed class InvokeFunction : ReadOnlySymbol { 33 public const string InvokeFunctionName = "InvokeFunction"; 34 public const string InvokeFunctionDescription = "Symbol that the invokation of another function."; 33 35 public override bool CanChangeName { 34 36 get { … … 46 48 } 47 49 48 private InvokeFunction() : base() { }49 50 [StorableConstructor] 51 private InvokeFunction(bool deserializing) : base(deserializing) { } 50 52 public InvokeFunction(string functionName) 51 : base( ) {53 : base("Invoke: " + functionName, InvokeFunction.InvokeFunctionDescription) { 52 54 this.FunctionName = functionName; 53 this.name = "Invoke: " + functionName;54 55 } 55 56 -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ProgramRootSymbol.cs
r3824 r3993 25 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 26 26 [StorableClass] 27 [Item( "ProgramRootSymbol", "Special symbol that represents the program root node of a symbolic expression tree.")]27 [Item(ProgramRootSymbol.ProgramRootSymbolName, ProgramRootSymbol.ProgramRootSymbolDescription)] 28 28 public sealed class ProgramRootSymbol : ReadOnlySymbol { 29 public const string ProgramRootSymbolName = "ProgramRootSymbol"; 30 public const string ProgramRootSymbolDescription = "Special symbol that represents the program root node of a symbolic expression tree."; 31 32 public ProgramRootSymbol() : base(ProgramRootSymbol.ProgramRootSymbolName, ProgramRootSymbol.ProgramRootSymbolDescription) { } 33 [StorableConstructor] 34 private ProgramRootSymbol(bool deserializing) : base(deserializing) { } 35 29 36 public override SymbolicExpressionTreeNode CreateTreeNode() { 30 37 return new SymbolicExpressionTreeTopLevelNode(this); -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ReadOnlySymbol.cs
r3824 r3993 50 50 } 51 51 52 protected ReadOnlySymbol() 53 : base() { 54 this.name = ItemName; 55 this.description = ItemDescription; 56 initialFrequency = 1.0; 57 } 52 protected ReadOnlySymbol() : base() { } 53 protected ReadOnlySymbol(string name, string description) : base(name, description) { } 54 [StorableConstructor] 55 protected ReadOnlySymbol(bool deserializing) : base(deserializing) { } 58 56 } 59 57 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Symbol.cs
r3824 r3993 54 54 protected Symbol() 55 55 : base() { 56 this.name = ItemName;57 this.description = ItemDescription;58 56 initialFrequency = 1.0; 59 57 } 58 59 protected Symbol(string name, string description) 60 : base(name, description) { 61 initialFrequency = 1.0; 62 } 63 64 [StorableConstructor] 65 protected Symbol(bool deserializing) : base(deserializing) { } 60 66 61 67 public virtual SymbolicExpressionTreeNode CreateTreeNode() {
Note: See TracChangeset
for help on using the changeset viewer.