Changeset 430
- Timestamp:
- 08/03/08 23:14:08 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Constraints/AllSubOperatorsTypeConstraintView.cs
r2 r430 87 87 #endregion 88 88 89 #region Drag Events 90 89 #region Drag Events 91 90 private void listView_DragDrop(object sender, DragEventArgs e) { 92 91 if(e.Effect != DragDropEffects.None) { … … 105 104 } 106 105 107 108 106 private void listView_DragEnter(object sender, DragEventArgs e) { 109 107 this.FindForm().BringToFront(); … … 117 115 } 118 116 } 119 120 117 121 118 private void listView_DragOver(object sender, DragEventArgs e) { -
trunk/sources/HeuristicLab.Constraints/SubOperatorsConstraintAnalyser.cs
r155 r430 91 91 private static bool InSet(IOperator op, ICollection<IOperator> set) { 92 92 foreach(IOperator element in set) { 93 if(element==op || 94 ((StringData)element.GetVariable("TypeId").Value).Data == 95 ((StringData)op.GetVariable("TypeId").Value).Data) { 93 if(element == op) 96 94 return true; 97 }98 95 } 99 100 96 return false; 101 97 } … … 132 128 } 133 129 } 134 130 135 131 public override void Visit(OrConstraint constraint) { 136 132 base.Visit(constraint); -
trunk/sources/HeuristicLab.Constraints/SubOperatorsTypeConstraint.cs
r2 r430 55 55 // check if already in the list of allowed functions 56 56 foreach(IOperator existingOp in subOperators) { 57 if (IsOperatorTypeEqual(existingOp, op)) {57 if(existingOp == op) { 58 58 return; 59 59 } … … 66 66 IOperator matchingOperator = null; 67 67 foreach(IOperator existingOp in subOperators) { 68 if( IsOperatorTypeEqual(existingOp, op)) {68 if(existingOp == op) { 69 69 matchingOperator = existingOp; 70 70 break; … … 72 72 } 73 73 74 if 74 if(matchingOperator != null) { 75 75 subOperators.Remove(matchingOperator); 76 76 } … … 79 79 public override bool Check(IItem data) { 80 80 IOperator op = data as IOperator; 81 if 81 if(data == null) return false; 82 82 83 83 if(op.SubOperators.Count <= subOperatorIndex.Data) { 84 84 return false; 85 85 } 86 87 return subOperators.Exists(delegate(IOperator curOp) { return IsOperatorTypeEqual(curOp, op.SubOperators[subOperatorIndex.Data]); });86 87 return subOperators.Exists(delegate(IOperator curOp) { return curOp == op.SubOperators[subOperatorIndex.Data]; }); 88 88 } 89 89 … … 108 108 109 109 #region persistence 110 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {110 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 111 111 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 112 112 XmlNode indexNode = PersistenceManager.Persist("SubOperatorIndex", subOperatorIndex, document, persistedObjects); … … 121 121 } 122 122 123 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {123 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 124 124 base.Populate(node, restoredObjects); 125 125 subOperatorIndex = (IntData)PersistenceManager.Restore(node.SelectSingleNode("SubOperatorIndex"), restoredObjects); … … 131 131 #endregion persistence 132 132 133 134 private bool IsOperatorTypeEqual(IOperator f, IOperator g) {135 return ((StringData)f.GetVariable("TypeId").Value).Data == ((StringData)g.GetVariable("TypeId").Value).Data;136 }137 133 } 138 134 } -
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.