Free cookie consent management tool by TermsFeed Policy Generator

Changeset 618


Ignore:
Timestamp:
10/02/08 01:13:35 (16 years ago)
Author:
gkronber
Message:
  • improved SizeFairCrossOver
  • implemented very simple and strict form of a homologous crossover operator

(ticket #108)

Location:
trunk/sources/HeuristicLab.StructureIdentification
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/HeuristicLab.StructureIdentification.csproj

    r617 r618  
    101101    <Compile Include="Properties\AssemblyInfo.cs" />
    102102    <Compile Include="RampedTreeCreator.cs" />
     103    <Compile Include="Recombination\OnePointCrossOver.cs" />
    103104    <Compile Include="Recombination\StandardCrossOver.cs" />
    104105    <Compile Include="Recombination\SizeFairCrossOver.cs" />
  • trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs

    r617 r618  
    126126        }
    127127
    128         // save the roots because later on we change tree0 and tree1 while searching a valid tree configuration
    129         IFunctionTree root0 = tree0;
    130         IFunctionTree root1 = tree1;
    131         int root0Height = tree0Height;
    132         int root1Height = tree1Height;
    133         int rootSize = tree0Size;
    134 
    135128        // select a random suboperator of the 'receiving' tree
    136         IFunctionTree crossoverPoint = gardener.GetRandomParentNode(root0);
     129        IFunctionTree crossoverPoint = gardener.GetRandomParentNode(tree0);
    137130        int removedBranchIndex;
    138131        IFunctionTree removedBranch;
     
    140133        if(crossoverPoint == null) {
    141134          removedBranchIndex = 0;
    142           removedBranch = root0;
     135          removedBranch = tree0;
    143136          allowedFunctions = gardener.GetAllowedSubFunctions(null, 0);
    144137        } else {
     
    148141        }
    149142        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);
    153146
    154147        int tries = 0;
    155148        while(insertedBranch == null) {
    156149          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;
    159152          }
    160153
    161154          // retry with a different crossoverPoint       
    162           crossoverPoint = gardener.GetRandomParentNode(root0);
     155          crossoverPoint = gardener.GetRandomParentNode(tree0);
    163156          if(crossoverPoint == null) {
    164157            removedBranchIndex = 0;
    165             removedBranch = root0;
     158            removedBranch = tree0;
    166159            allowedFunctions = gardener.GetAllowedSubFunctions(null, 0);
    167160          } else {
     
    171164          }
    172165          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);
    176169        }
    177170        if(crossoverPoint != null) {
     
    179172          crossoverPoint.RemoveSubTree(removedBranchIndex);
    180173          crossoverPoint.InsertSubTree(removedBranchIndex, insertedBranch);
    181           return root0;
     174          return tree0;
    182175        } else {
    183176          return insertedBranch;
Note: See TracChangeset for help on using the changeset viewer.