- Timestamp:
- 05/13/08 15:01:08 (17 years ago)
- Location:
- trunk/sources/HeuristicLab.StructureIdentification
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs
r202 r238 30 30 using HeuristicLab.Constraints; 31 31 using HeuristicLab.Functions; 32 using System.Diagnostics; 32 33 33 34 namespace HeuristicLab.StructureIdentification { … … 85 86 // updating the variable is not necessary because it stays the same 86 87 } 87 if(!gardener.IsValidTree(root)) throw new InvalidProgramException();88 Debug.Assert(gardener.IsValidTree(root)); 88 89 // size and height stays the same when changing a terminal so no need to update the variables 89 90 // schedule an operation to initialize the new terminal … … 119 120 treeHeight.Data = gardener.GetTreeHeight(root); // must recalculate height because we can't know wether the manipulated branch was the deepest branch 120 121 // check if whole tree is ok 121 if(!gardener.IsValidTree(root)) 122 throw new InvalidProgramException(); 122 Debug.Assert(gardener.IsValidTree(root)); 123 123 // return a composite operation that initializes all created sub-trees 124 124 return gardener.CreateInitializationOperation(uninitializedBranches, scope); -
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/CutOutNodeManipulation.cs
r163 r238 28 28 using System; 29 29 using HeuristicLab.Functions; 30 using System.Diagnostics; 30 31 31 32 namespace HeuristicLab.StructureIdentification { … … 77 78 // update the variable 78 79 scope.GetVariable(scope.TranslateName("FunctionTree")).Value = root; 79 if (!gardener.IsValidTree(root)) { 80 throw new InvalidProgramException(); 81 } 80 Debug.Assert(gardener.IsValidTree(root)); 82 81 // we reused a sub-tree so we don't have to schedule initialization operations 83 82 return null; … … 90 89 // update the variable 91 90 scope.GetVariable(scope.TranslateName("FunctionTree")).Value = newTree; 92 if (!gardener.IsValidTree(newTree)) { 93 throw new InvalidProgramException(); 94 } 91 Debug.Assert(gardener.IsValidTree(newTree)); 95 92 // schedule an operation to initialize the whole tree 96 93 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newTree), scope); … … 108 105 parent.RemoveSubTree(childIndex); 109 106 parent.InsertSubTree(childIndex, selectedChild); 110 if (!gardener.IsValidTree(root)) { 111 throw new InvalidProgramException(); 112 } 107 Debug.Assert(gardener.IsValidTree(root)); 113 108 // update the size and height of our tree 114 109 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); … … 129 124 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); 130 125 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root); 131 if (!gardener.IsValidTree(root)) { 132 throw new InvalidProgramException(); 133 } 126 Debug.Assert(gardener.IsValidTree(root)); 134 127 // schedule an initialization operation for the new function-tree 135 128 return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newFunctionTree), scope); -
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/DeleteSubTreeManipulation.cs
r179 r238 27 27 using HeuristicLab.Random; 28 28 using HeuristicLab.Functions; 29 using System.Diagnostics; 29 30 30 31 namespace HeuristicLab.StructureIdentification { … … 61 62 IFunctionTree newTree = gardener.CreateBalancedRandomTree(1, 1); 62 63 // check if the tree is ok 63 if(!gardener.IsValidTree(newTree)) { 64 throw new InvalidOperationException(); 65 } 64 Debug.Assert(gardener.IsValidTree(newTree)); 66 65 // update sizes to match the new tree 67 66 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(newTree); … … 86 85 // and find the first one that doesn't fit. At this position we insert a new randomly initialized subtree of matching type (gkronber 25.12.07) 87 86 88 if(!gardener.IsValidTree(root)) { 89 throw new InvalidOperationException(); 90 } 87 Debug.Assert(gardener.IsValidTree(root)); 91 88 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); 92 89 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root); … … 99 96 IFunctionTree newFunctionTree = gardener.CreateRandomTree(allowedFunctions, 1, 1); 100 97 parent.InsertSubTree(childIndex, newFunctionTree); 101 if(!gardener.IsValidTree(root)) { 102 throw new InvalidProgramException(); 103 } 98 Debug.Assert(gardener.IsValidTree(root)); 104 99 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); 105 100 GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root); -
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs
r163 r238 28 28 using HeuristicLab.Random; 29 29 using HeuristicLab.Functions; 30 using System.Diagnostics; 30 31 31 32 namespace HeuristicLab.StructureIdentification { … … 61 62 // => create a new random tree 62 63 IFunctionTree newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight); 63 if(!gardener.IsValidTree(newTree)) { 64 throw new InvalidProgramException(); 65 } 64 Debug.Assert(gardener.IsValidTree(newTree)); 66 65 67 66 // update the variables in the scope with the new values … … 94 93 parent.InsertSubTree(childIndex, newTree); 95 94 96 if(!gardener.IsValidTree(root)) { 97 throw new InvalidProgramException(); 98 } 99 95 Debug.Assert(gardener.IsValidTree(root)); 100 96 // update the values of treeSize and treeHeight 101 97 GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root); -
trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs
r189 r238 30 30 using HeuristicLab.Constraints; 31 31 using HeuristicLab.Functions; 32 using System.Diagnostics; 32 33 33 34 namespace HeuristicLab.StructureIdentification { … … 95 96 96 97 // check if the new tree is valid and if the size of is still in the allowed bounds 97 if(!gardener.IsValidTree(newTree) || 98 newTreeHeight > maxTreeHeight || 99 newTreeSize > maxTreeSize) { 100 throw new InvalidProgramException(); 101 } 98 Debug.Assert(gardener.IsValidTree(newTree) && 99 newTreeHeight <= maxTreeHeight && newTreeSize <= maxTreeSize); 102 100 return gardener.CreateInitializationOperation(newBranches, child); 103 101 } … … 165 163 // - go down in tree1 => the tree that is inserted becomes smaller 166 164 // - however we have to get lucky to solve the 'allowed sub-trees' problem 167 if(tree1Height == 1 || (tree0Level >0 && random.Next(2) == 0)) {165 if(tree1Height == 1 || (tree0Level > 0 && random.Next(2) == 0)) { 168 166 // go up in tree0 169 167 tree0Level--;
Note: See TracChangeset
for help on using the changeset viewer.