Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs

    r2 r23  
    3838      AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In));
    3939      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    40       AddVariableInfo(new VariableInfo("BalanceTrees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));
     40      AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));
    4141      AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In));
    4242      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
     
    4949      MersenneTwister random = GetVariableValue<MersenneTwister>("Random", scope, true);
    5050      GPOperatorLibrary library = GetVariableValue<GPOperatorLibrary>("OperatorLibrary", scope, true);
    51       bool balanceTrees = GetVariableValue<BoolData>("BalanceTrees", scope, true).Data;
     51      double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data;
    5252      IntData treeSize = GetVariableValue<IntData>("TreeSize", scope, false);
    5353      IntData treeHeight = GetVariableValue<IntData>("TreeHeight", scope, false);
     
    8787      } else {
    8888        List<IOperator> uninitializedOperators;
    89         IOperator newFunction = ChangeFunctionType(parent, selectedChild, selectedChildIndex, gardener, random, balanceTrees, out uninitializedOperators);
     89        IOperator newFunction = ChangeFunctionType(parent, selectedChild, selectedChildIndex, gardener, random, balancedTreesRate, out uninitializedOperators);
    9090
    9191        if (parent == null) {
     
    139139
    140140    private IOperator ChangeFunctionType(IOperator parent, IOperator child, int childIndex, TreeGardener gardener, MersenneTwister random,
    141       bool balanceTrees, out List<IOperator> uninitializedOperators) {
     141      double balancedTreesRate, out List<IOperator> uninitializedOperators) {
    142142      // since there are suboperators, we have to check which
    143143      // and how many of the existing suboperators we can reuse
     
    197197          availableSubOperators.Remove(selectedSubOperator); // the operator shouldn't be available for the following slots
    198198        } else {
    199           IOperator freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, balanceTrees);
     199          IOperator freshOperatorTree;
     200          if(random.NextDouble() <= balancedTreesRate) {
     201            freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, true);
     202          } else {
     203            freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, false);
     204          }
    200205          freshSubTrees.AddRange(gardener.GetAllOperators(freshOperatorTree));
    201206
Note: See TracChangeset for help on using the changeset viewer.