Free cookie consent management tool by TermsFeed Policy Generator

Changeset 442


Ignore:
Timestamp:
08/04/08 23:06:15 (16 years ago)
Author:
gkronber
Message:

stop trying to cross trees that are not compatible with each other after a maximal number of tries (20).
Also weakened the final size-constraint check because trees generated with initial operators could be slightly larger than the size limit.
(ticket #225)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs

    r437 r442  
    3434namespace HeuristicLab.StructureIdentification {
    3535  public class SizeFairCrossOver : OperatorBase {
    36 
     36    private const int MAX_RECOMBINATION_TRIES = 20;
    3737    public override string Description {
    3838      get {
     
    9595      child.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeHeight"), new IntData(newTreeHeight)));
    9696
    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);
    10099      return gardener.CreateInitializationOperation(newBranches, child);
    101100    }
     
    114113        return CombineTerminals(gardener, tree0, tree1, random, maxTreeHeight, out newBranches);
    115114      } else {
     115        newBranches = new List<IFunctionTree>();
     116
    116117        // we are going to insert tree1 into tree0 at a random place so we have to make sure that tree0 is not a terminal
    117118        // in case both trees are higher than 1 we swap the trees with probability 50%
     
    155156          }
    156157        }
     158        int tries = 0;
    157159        while(possibleChildIndices.Count == 0) {
     160          if(tries++ > MAX_RECOMBINATION_TRIES) {
     161            if(random.Next() > 0.5) return root1;
     162            else return root0;
     163          }
    158164          // we couln't find a possible configuration given the current tree0 and tree1
    159165          // possible reasons for this are:
     
    189195        tree0.RemoveSubTree(selectedIndex);
    190196        tree0.InsertSubTree(selectedIndex, tree1);
    191 
    192         // no new operators where needed
    193         newBranches = new List<IFunctionTree>();
    194197        return root0;
    195198      }
Note: See TracChangeset for help on using the changeset viewer.