Free cookie consent management tool by TermsFeed Policy Generator

Changeset 145


Ignore:
Timestamp:
04/21/08 20:57:45 (17 years ago)
Author:
gkronber
Message:

more fixes after major refactoring step (ticket #112)

Location:
branches/FunctionsAndStructIdRefactoring
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.Constraints/SubOperatorsConstraintAnalyser.cs

    r2 r145  
    9191    private static bool InSet(IOperator op, ICollection<IOperator> set) {
    9292      foreach(IOperator element in set) {
    93         if(((StringData)element.GetVariable("TypeId").Value).Data ==
     93        if(element==op ||
     94          ((StringData)element.GetVariable("TypeId").Value).Data ==
    9495          ((StringData)op.GetVariable("TypeId").Value).Data) {
    9596          return true;
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionBase.cs

    r142 r145  
    5858
    5959    public override IList<IOperator> SubOperators {
    60       get { throw new NotSupportedException(); }
     60      get { return new List<IOperator>(); }
    6161    }
    6262
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionTree.cs

    r142 r145  
    7777    public override XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    7878      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     79      node.AppendChild(PersistenceManager.Persist("Function", function, document, persistedObjects));
    7980      XmlNode subTreesNode = document.CreateNode(XmlNodeType.Element, "SubTrees", null);
    8081      for(int i = 0; i < subTrees.Count; i++)
     
    9091    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    9192      base.Populate(node, restoredObjects);
     93      function = (IFunction)PersistenceManager.Restore(node.SelectSingleNode("Function"), restoredObjects);
    9294      XmlNode subTreesNode = node.SelectSingleNode("SubTrees");
    9395      for(int i = 0; i < subTreesNode.ChildNodes.Count; i++)
     
    106108        clone.AddVariable((IVariable)variable.Clone(clonedObjects));
    107109      }
     110      clone.function = function;
    108111      return clone;
    109112    }
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/RandomTreeCreator.cs

    r143 r145  
    4141      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    4242      AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));
    43       AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IFunctionTree), VariableKind.In));
    44       AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    45       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));
    4646    }
    4747
     
    6767      int actualTreeHeight = gardener.GetTreeHeight(root);
    6868
    69       scope.AddVariable(new HeuristicLab.Core.Variable("OperatorTree", root));
    70       scope.AddVariable(new HeuristicLab.Core.Variable("TreeSize", new IntData(actualTreeSize)));
    71       scope.AddVariable(new HeuristicLab.Core.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)));
    7272
    7373      if(!gardener.IsValidTree(root)) { throw new InvalidProgramException(); }
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.StructureIdentification/TreeGardener.cs

    r143 r145  
    325325
    326326    internal bool IsValidTree(IFunctionTree tree) {
    327       if (!tree.Function.IsValid())
    328         return false;
    329       foreach (IFunctionTree subTree in tree.SubTrees) {
    330         if (!subTree.Function.IsValid())
    331           return false;
    332       }
    333 
     327      foreach(IConstraint constraint in tree.Function.Constraints) {
     328        if(constraint is NumberOfSubOperatorsConstraint) {
     329          int max = ((NumberOfSubOperatorsConstraint)constraint).MaxOperators.Data;
     330          int min = ((NumberOfSubOperatorsConstraint)constraint).MinOperators.Data;
     331          if(tree.SubTrees.Count < min || tree.SubTrees.Count > max) return false;
     332        }
     333      }
     334      foreach(IFunctionTree subTree in tree.SubTrees) {
     335        if(!IsValidTree(subTree)) return false;
     336      }
    334337      return true;
    335338    }
Note: See TracChangeset for help on using the changeset viewer.