Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/22/08 18:05:14 (17 years ago)
Author:
gkronber
Message:

merged FunctionsAndStructIdRefactoring-branch (r142, r143, r144, r145, r146, r147, r148, r149, r152, r153) back into the trunk (ticket #112)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/RandomTreeCreator.cs

    r23 r155  
    2626using System;
    2727using HeuristicLab.Random;
     28using HeuristicLab.Functions;
    2829
    2930namespace HeuristicLab.StructureIdentification {
     
    4041      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    4142      AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));
    42       AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In));
    43       AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    44       AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.In));
     43      AddVariableInfo(new VariableInfo("FunctionTree", "The created tree", typeof(IFunctionTree), VariableKind.New | VariableKind.Out));
     44      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.New | VariableKind.Out));
     45      AddVariableInfo(new VariableInfo("TreeHeight", "The height of the tree", typeof(IntData), VariableKind.New | VariableKind.Out));
    4546    }
    4647
     
    5657      int treeHeight = random.Next(1, maxTreeHeight + 1);
    5758      int treeSize = random.Next(1, maxTreeSize + 1);
    58       IOperator rootOperator;
     59      IFunctionTree root;
    5960      if(random.NextDouble() <= balancedTreesRate) {
    60         rootOperator = gardener.CreateRandomTree(treeSize, treeHeight, true);
     61        root = gardener.CreateRandomTree(treeSize, treeHeight, true);
    6162      } else {
    62         rootOperator = gardener.CreateRandomTree(treeSize, treeHeight, false);
     63        root = gardener.CreateRandomTree(treeSize, treeHeight, false);
    6364      }
    6465
    65       int actualTreeSize = gardener.GetTreeSize(rootOperator);
    66       int actualTreeHeight = gardener.GetTreeHeight(rootOperator);
     66      int actualTreeSize = gardener.GetTreeSize(root);
     67      int actualTreeHeight = gardener.GetTreeHeight(root);
    6768
    68       scope.AddVariable(new Variable("OperatorTree", rootOperator));
    69       scope.AddVariable(new Variable("TreeSize", new IntData(actualTreeSize)));
    70       scope.AddVariable(new Variable("TreeHeight", new IntData(actualTreeHeight)));
     69      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FunctionTree"), root));
     70      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeSize"), new IntData(actualTreeSize)));
     71      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeHeight"), new IntData(actualTreeHeight)));
    7172
    72       if(!gardener.IsValidTree(rootOperator)) { throw new InvalidProgramException(); }
     73      if(!gardener.IsValidTree(root)) { throw new InvalidProgramException(); }
    7374
    7475      if(actualTreeSize > maxTreeSize ||
     
    7778      }
    7879
    79       return gardener.CreateInitializationOperation(gardener.GetAllOperators(rootOperator), scope);
     80      return gardener.CreateInitializationOperation(gardener.GetAllSubTrees(root), scope);
    8081    }
    8182  }
Note: See TracChangeset for help on using the changeset viewer.