Changeset 618 for trunk/sources/HeuristicLab.StructureIdentification
- Timestamp:
- 10/02/08 01:13:35 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.StructureIdentification
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/HeuristicLab.StructureIdentification.csproj
r617 r618 101 101 <Compile Include="Properties\AssemblyInfo.cs" /> 102 102 <Compile Include="RampedTreeCreator.cs" /> 103 <Compile Include="Recombination\OnePointCrossOver.cs" /> 103 104 <Compile Include="Recombination\StandardCrossOver.cs" /> 104 105 <Compile Include="Recombination\SizeFairCrossOver.cs" /> -
trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs
r617 r618 126 126 } 127 127 128 // save the roots because later on we change tree0 and tree1 while searching a valid tree configuration129 IFunctionTree root0 = tree0;130 IFunctionTree root1 = tree1;131 int root0Height = tree0Height;132 int root1Height = tree1Height;133 int rootSize = tree0Size;134 135 128 // select a random suboperator of the 'receiving' tree 136 IFunctionTree crossoverPoint = gardener.GetRandomParentNode( root0);129 IFunctionTree crossoverPoint = gardener.GetRandomParentNode(tree0); 137 130 int removedBranchIndex; 138 131 IFunctionTree removedBranch; … … 140 133 if(crossoverPoint == null) { 141 134 removedBranchIndex = 0; 142 removedBranch = root0;135 removedBranch = tree0; 143 136 allowedFunctions = gardener.GetAllowedSubFunctions(null, 0); 144 137 } else { … … 148 141 } 149 142 int removedBranchSize = removedBranch.Size; 150 int maxBranchSize = maxTreeSize - ( root0.Size - removedBranchSize);151 int maxBranchHeight = maxTreeHeight - gardener.GetBranchLevel( root0, removedBranch);152 IFunctionTree insertedBranch = GetReplacementBranch(random, gardener, allowedFunctions, root1, removedBranchSize, maxBranchSize, maxBranchHeight);143 int maxBranchSize = maxTreeSize - (tree0.Size - removedBranchSize); 144 int maxBranchHeight = maxTreeHeight - gardener.GetBranchLevel(tree0, removedBranch); 145 IFunctionTree insertedBranch = GetReplacementBranch(random, gardener, allowedFunctions, tree1, removedBranchSize, maxBranchSize, maxBranchHeight); 153 146 154 147 int tries = 0; 155 148 while(insertedBranch == null) { 156 149 if(tries++ > MAX_RECOMBINATION_TRIES) { 157 if(random.Next() > 0.5) return root1;158 else return root0;150 if(random.Next() > 0.5) return tree1; 151 else return tree0; 159 152 } 160 153 161 154 // retry with a different crossoverPoint 162 crossoverPoint = gardener.GetRandomParentNode( root0);155 crossoverPoint = gardener.GetRandomParentNode(tree0); 163 156 if(crossoverPoint == null) { 164 157 removedBranchIndex = 0; 165 removedBranch = root0;158 removedBranch = tree0; 166 159 allowedFunctions = gardener.GetAllowedSubFunctions(null, 0); 167 160 } else { … … 171 164 } 172 165 removedBranchSize = removedBranch.Size; 173 maxBranchSize = maxTreeSize - ( root0.Size - removedBranchSize);174 maxBranchHeight = maxTreeHeight - gardener.GetBranchLevel( root0, removedBranch) + 1;175 insertedBranch = GetReplacementBranch(random, gardener, allowedFunctions, root1, removedBranchSize, maxBranchSize, maxBranchHeight);166 maxBranchSize = maxTreeSize - (tree0.Size - removedBranchSize); 167 maxBranchHeight = maxTreeHeight - gardener.GetBranchLevel(tree0, removedBranch) + 1; 168 insertedBranch = GetReplacementBranch(random, gardener, allowedFunctions, tree1, removedBranchSize, maxBranchSize, maxBranchHeight); 176 169 } 177 170 if(crossoverPoint != null) { … … 179 172 crossoverPoint.RemoveSubTree(removedBranchIndex); 180 173 crossoverPoint.InsertSubTree(removedBranchIndex, insertedBranch); 181 return root0;174 return tree0; 182 175 } else { 183 176 return insertedBranch;
Note: See TracChangeset
for help on using the changeset viewer.