Changeset 430 for trunk/sources/HeuristicLab.StructureIdentification
- Timestamp:
- 08/03/08 23:14:08 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.StructureIdentification
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/GPOperatorGroup.cs
r429 r430 41 41 var localVariableInfos = op.VariableInfos.Where(f => f.Local); 42 42 43 // add a new typeid if necessary44 if(op.GetVariable(GPOperatorLibrary.TYPE_ID) == null) {45 op.AddVariable(new Variable(GPOperatorLibrary.TYPE_ID, new StringData(Guid.NewGuid().ToString())));46 }47 48 43 if(op.GetVariable(GPOperatorLibrary.MIN_TREE_HEIGHT) == null) { 49 44 op.AddVariable(new Variable(GPOperatorLibrary.MIN_TREE_HEIGHT, new IntData(-1))); … … 62 57 63 58 64 private Dictionary< string, int> minTreeHeight = new Dictionary<string, int>();65 private Dictionary< string, int> minTreeSize = new Dictionary<string, int>();59 private Dictionary<IOperator, int> minTreeHeight = new Dictionary<IOperator, int>(); 60 private Dictionary<IOperator, int> minTreeSize = new Dictionary<IOperator, int>(); 66 61 private SubOperatorsConstraintAnalyser constraintAnalyser = new SubOperatorsConstraintAnalyser(); 67 62 … … 101 96 102 97 private int RecalculateMinimalTreeSize(IOperator op) { 103 string typeId = GetTypeId(op);104 98 // check for memoized value 105 if(minTreeSize.ContainsKey( typeId)) {106 return minTreeSize[ typeId];99 if(minTreeSize.ContainsKey(op)) { 100 return minTreeSize[op]; 107 101 } 108 102 … … 112 106 // no suboperators possible => minimalTreeSize == 1 (the current node) 113 107 if(minArity == 0 && maxArity == 0) { 114 minTreeSize[ typeId] = 1;108 minTreeSize[op] = 1; 115 109 return 1; 116 110 } … … 121 115 122 116 // mark the currently processed operator to prevent infinite recursions and stack overflow 123 minTreeSize[ typeId] = 9999;117 minTreeSize[op] = 9999; 124 118 for(int i = 0; i < minArity; i++) { 125 119 // calculate the minTreeSize of all allowed sub-operators … … 136 130 } 137 131 138 minTreeSize[ typeId] = subTreeSizeSum + 1;132 minTreeSize[op] = subTreeSizeSum + 1; 139 133 return subTreeSizeSum + 1; 140 134 } … … 142 136 143 137 private int RecalculateMinimalTreeHeight(IOperator op) { 144 string typeId = GetTypeId(op);145 138 // check for memoized value 146 if(minTreeHeight.ContainsKey( typeId)) {147 return minTreeHeight[ typeId];139 if(minTreeHeight.ContainsKey(op)) { 140 return minTreeHeight[op]; 148 141 } 149 142 … … 153 146 // no suboperators possible => minimalTreeHeight == 1 154 147 if(minArity == 0 && maxArity == 0) { 155 minTreeHeight[ typeId] = 1;148 minTreeHeight[op] = 1; 156 149 return 1; 157 150 } … … 162 155 163 156 // mark the currently processed operator to prevent infinite recursions leading to stack overflow 164 minTreeHeight[ typeId] = 9999;157 minTreeHeight[op] = 9999; 165 158 for(int i = 0; i < minArity; i++) { 166 159 // calculate the minTreeHeight of all possible sub-operators. … … 182 175 } 183 176 184 minTreeHeight[ typeId] = maxSubTreeHeight + 1;177 minTreeHeight[op] = maxSubTreeHeight + 1; 185 178 return maxSubTreeHeight + 1; 186 179 } … … 200 193 } 201 194 202 private string GetTypeId(IOperator op) {203 return ((StringData)op.GetVariable(GPOperatorLibrary.TYPE_ID).Value).Data;204 }205 206 195 public override void AddSubGroup(IOperatorGroup group) { 207 196 throw new NotSupportedException(); … … 210 199 public override void RemoveOperator(IOperator op) { 211 200 base.RemoveOperator(op); 212 op.RemoveVariable(GPOperatorLibrary.TYPE_ID);213 201 op.RemoveVariable(GPOperatorLibrary.MIN_TREE_SIZE); 214 202 op.RemoveVariable(GPOperatorLibrary.MIN_TREE_HEIGHT); -
trunk/sources/HeuristicLab.StructureIdentification/GPOperatorLibrary.cs
r428 r430 30 30 public class GPOperatorLibrary : ItemBase, IOperatorLibrary, IEditable { 31 31 // constants for variable names 32 internal const string TYPE_ID = "TypeId";33 32 internal const string MIN_TREE_HEIGHT = "MinTreeHeight"; 34 33 internal const string MIN_TREE_SIZE = "MinTreeSize";
Note: See TracChangeset
for help on using the changeset viewer.