Changeset 442
- Timestamp:
- 08/04/08 23:06:15 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs
r437 r442 34 34 namespace HeuristicLab.StructureIdentification { 35 35 public class SizeFairCrossOver : OperatorBase { 36 36 private const int MAX_RECOMBINATION_TRIES = 20; 37 37 public override string Description { 38 38 get { … … 95 95 child.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeHeight"), new IntData(newTreeHeight))); 96 96 97 // check if the new tree is valid and if the size of is still in the allowed bounds 98 Debug.Assert(gardener.IsValidTree(newTree) && 99 newTreeHeight <= maxTreeHeight && newTreeSize <= maxTreeSize); 97 // check if the new tree is valid and if the height of is still in the allowed bounds (we are not so strict for the max-size) 98 Debug.Assert(gardener.IsValidTree(newTree) && newTreeHeight <= maxTreeHeight); 100 99 return gardener.CreateInitializationOperation(newBranches, child); 101 100 } … … 114 113 return CombineTerminals(gardener, tree0, tree1, random, maxTreeHeight, out newBranches); 115 114 } else { 115 newBranches = new List<IFunctionTree>(); 116 116 117 // we are going to insert tree1 into tree0 at a random place so we have to make sure that tree0 is not a terminal 117 118 // in case both trees are higher than 1 we swap the trees with probability 50% … … 155 156 } 156 157 } 158 int tries = 0; 157 159 while(possibleChildIndices.Count == 0) { 160 if(tries++ > MAX_RECOMBINATION_TRIES) { 161 if(random.Next() > 0.5) return root1; 162 else return root0; 163 } 158 164 // we couln't find a possible configuration given the current tree0 and tree1 159 165 // possible reasons for this are: … … 189 195 tree0.RemoveSubTree(selectedIndex); 190 196 tree0.InsertSubTree(selectedIndex, tree1); 191 192 // no new operators where needed193 newBranches = new List<IFunctionTree>();194 197 return root0; 195 198 }
Note: See TracChangeset
for help on using the changeset viewer.