Free cookie consent management tool by TermsFeed Policy Generator

Changeset 238 for trunk


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

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

Location:
trunk/sources/HeuristicLab.StructureIdentification
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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);
  • 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);
  • 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);
  • 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);
  • trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs

    r189 r238  
    3030using HeuristicLab.Constraints;
    3131using HeuristicLab.Functions;
     32using System.Diagnostics;
    3233
    3334namespace HeuristicLab.StructureIdentification {
     
    9596
    9697      // 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);
    102100      return gardener.CreateInitializationOperation(newBranches, child);
    103101    }
     
    165163          //  - go down in tree1 => the tree that is inserted becomes smaller
    166164          //  - 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)) {
    168166            // go up in tree0
    169167            tree0Level--;
Note: See TracChangeset for help on using the changeset viewer.