Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/13/08 15:01:08 (17 years ago)
Author:
gkronber
Message:

used Debug.Assert to enable tree-validity checks only in debug builds

Location:
trunk/sources/HeuristicLab.StructureIdentification/Manipulation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs

    r202 r238  
    3030using HeuristicLab.Constraints;
    3131using HeuristicLab.Functions;
     32using System.Diagnostics;
    3233
    3334namespace HeuristicLab.StructureIdentification {
     
    8586          // updating the variable is not necessary because it stays the same
    8687        }
    87         if(!gardener.IsValidTree(root)) throw new InvalidProgramException();
     88        Debug.Assert(gardener.IsValidTree(root));
    8889        // size and height stays the same when changing a terminal so no need to update the variables
    8990        // schedule an operation to initialize the new terminal
     
    119120        treeHeight.Data = gardener.GetTreeHeight(root); // must recalculate height because we can't know wether the manipulated branch was the deepest branch
    120121        // check if whole tree is ok
    121         if(!gardener.IsValidTree(root))
    122           throw new InvalidProgramException();
     122        Debug.Assert(gardener.IsValidTree(root));
    123123        // return a composite operation that initializes all created sub-trees
    124124        return gardener.CreateInitializationOperation(uninitializedBranches, scope);
  • TabularUnified trunk/sources/HeuristicLab.StructureIdentification/Manipulation/CutOutNodeManipulation.cs

    r163 r238  
    2828using System;
    2929using HeuristicLab.Functions;
     30using System.Diagnostics;
    3031
    3132namespace HeuristicLab.StructureIdentification {
     
    7778          // update the variable
    7879          scope.GetVariable(scope.TranslateName("FunctionTree")).Value = root;
    79           if (!gardener.IsValidTree(root)) {
    80             throw new InvalidProgramException();
    81           }
     80          Debug.Assert(gardener.IsValidTree(root));
    8281          // we reused a sub-tree so we don't have to schedule initialization operations
    8382          return null;
     
    9089          // update the variable
    9190          scope.GetVariable(scope.TranslateName("FunctionTree")).Value = newTree;
    92           if (!gardener.IsValidTree(newTree)) {
    93             throw new InvalidProgramException();
    94           }
     91          Debug.Assert(gardener.IsValidTree(newTree));
    9592          // schedule an operation to initialize the whole tree
    9693          return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newTree), scope);
     
    108105        parent.RemoveSubTree(childIndex);
    109106        parent.InsertSubTree(childIndex, selectedChild);
    110         if (!gardener.IsValidTree(root)) {
    111           throw new InvalidProgramException();
    112         }
     107        Debug.Assert(gardener.IsValidTree(root));
    113108        // update the size and height of our tree
    114109        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root);
     
    129124        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root);
    130125        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));
    134127        // schedule an initialization operation for the new function-tree
    135128        return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(newFunctionTree), scope);
  • TabularUnified trunk/sources/HeuristicLab.StructureIdentification/Manipulation/DeleteSubTreeManipulation.cs

    r179 r238  
    2727using HeuristicLab.Random;
    2828using HeuristicLab.Functions;
     29using System.Diagnostics;
    2930
    3031namespace HeuristicLab.StructureIdentification {
     
    6162        IFunctionTree newTree = gardener.CreateBalancedRandomTree(1, 1);
    6263        // check if the tree is ok
    63         if(!gardener.IsValidTree(newTree)) {
    64           throw new InvalidOperationException();
    65         }
     64        Debug.Assert(gardener.IsValidTree(newTree));
    6665        // update sizes to match the new tree
    6766        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(newTree);
     
    8685        // 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)
    8786
    88         if(!gardener.IsValidTree(root)) {
    89           throw new InvalidOperationException();
    90         }
     87        Debug.Assert(gardener.IsValidTree(root));
    9188        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root);
    9289        GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root);
     
    9996        IFunctionTree newFunctionTree = gardener.CreateRandomTree(allowedFunctions, 1, 1);
    10097        parent.InsertSubTree(childIndex, newFunctionTree);
    101         if(!gardener.IsValidTree(root)) {
    102           throw new InvalidProgramException();
    103         }
     98        Debug.Assert(gardener.IsValidTree(root));
    10499        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root);
    105100        GetVariableValue<IntData>("TreeHeight", scope, true).Data = gardener.GetTreeHeight(root);
  • TabularUnified trunk/sources/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs

    r163 r238  
    2828using HeuristicLab.Random;
    2929using HeuristicLab.Functions;
     30using System.Diagnostics;
    3031
    3132namespace HeuristicLab.StructureIdentification {
     
    6162        // => create a new random tree
    6263        IFunctionTree newTree = gardener.CreateRandomTree(gardener.AllFunctions, maxTreeSize, maxTreeHeight);
    63         if(!gardener.IsValidTree(newTree)) {
    64           throw new InvalidProgramException();
    65         }
     64        Debug.Assert(gardener.IsValidTree(newTree));
    6665
    6766        // update the variables in the scope with the new values
     
    9493        parent.InsertSubTree(childIndex, newTree);
    9594
    96         if(!gardener.IsValidTree(root)) {
    97           throw new InvalidProgramException();
    98         }
    99 
     95        Debug.Assert(gardener.IsValidTree(root));
    10096        // update the values of treeSize and treeHeight
    10197        GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(root);
Note: See TracChangeset for help on using the changeset viewer.