Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7489


Ignore:
Timestamp:
02/20/12 13:53:31 (13 years ago)
Author:
mkommend
Message:

#1682: Improved DepthConstrainedCrossover and removed readonly attribute from the operators collection in the MultiCrossover.

Location:
branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs

    r7481 r7489  
    106106      var checkedItemList = new CheckedItemList<ISymbolicExpressionTreeCrossover>();
    107107      checkedItemList.AddRange(list.OrderBy(op => op.Name));
    108       Operators = checkedItemList.AsReadOnly();
     108      Operators = checkedItemList;
    109109      Operators_ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeCrossover>>(Operators.CheckedItems));
    110110    }
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs

    r7481 r7489  
    3737    private enum Ranges { HighLevel, Standard, LowLevel };
    3838    private const string DepthRangeParameterName = "DepthRange";
     39
    3940    #region Parameter properties
    40 
    4141    public ConstrainedValueParameter<StringValue> DepthRangeParameter {
    4242      get { return (ConstrainedValueParameter<StringValue>)Parameters[DepthRangeParameterName]; }
     
    6060      DepthRangeParameter.ValidValues.Add(new StringValue(Enum.GetName(typeof(Ranges), Ranges.Standard)));
    6161      DepthRangeParameter.ValidValues.Add(new StringValue(Enum.GetName(typeof(Ranges), Ranges.LowLevel)));
    62       Name = "DepthConstrainedCrossover";
    6362    }
    6463    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicDataAnalysisExpressionDepthConstrainedCrossover<T>(this, cloner); }
     
    108107        depthRange.End = depthRange.Start;
    109108
    110       var crossoverPoints0 = (from node in GetNodesAtDepth(parent0.Root, depthRange) select new CutPoint(node.Parent, node)).ToList();
     109      var crossoverPoints0 = (from node in GetNodesAtDepth(parent0, depthRange) select new CutPoint(node.Parent, node)).ToList();
    111110
    112111      if (crossoverPoints0.Count == 0)
     
    118117      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
    119118
    120       var allowedBranches = (from s in GetNodesAtDepth(parent1.Root, depthRange)
     119      var allowedBranches = (from s in GetNodesAtDepth(parent1, depthRange)
    121120                             where
    122121                               crossoverPoint0.IsMatchingPointType(s) &&
     
    130129    }
    131130
    132     private static IEnumerable<ISymbolicExpressionTreeNode> GetNodesAtDepth(ISymbolicExpressionTreeNode root, IntRange range) {
    133       var list = new List<Tuple<ISymbolicExpressionTreeNode, int>> { new Tuple<ISymbolicExpressionTreeNode, int>(root, 0) };
    134       int offset = 0;
    135       int level = 0;
    136       while (level < range.End) {
    137         ++level;
    138         int count = list.Count;
    139         for (int i = offset; i != count; ++i) {
    140           if (list[i].Item1.Subtrees.Any())
    141             list.AddRange(from s in list[i].Item1.Subtrees select new Tuple<ISymbolicExpressionTreeNode, int>(s, level));
    142         }
    143         offset = count;
    144       }
    145       // taking advantage of the fact that the list is already sorted by level
    146       for (int i = list.Count - 1; i >= 0; --i) {
    147         if (list[i].Item2 >= range.Start)
    148           yield return list[i].Item1;
    149         else break;
    150       }
     131    private static IEnumerable<ISymbolicExpressionTreeNode> GetNodesAtDepth(ISymbolicExpressionTree tree, IntRange depthRange) {
     132      var treeDepth = tree.Root.GetDepth();
     133      return from node in tree.Root.IterateNodesPostfix()
     134             let depth = treeDepth - node.GetDepth()
     135             where depthRange.Start <= depth
     136             where depth <= depthRange.End
     137             select node;
     138
     139      //var list = new List<Tuple<ISymbolicExpressionTreeNode, int>> { new Tuple<ISymbolicExpressionTreeNode, int>(root, 0) };
     140      //int offset = 0;
     141      //int level = 0;
     142      //while (level < range.End) {
     143      //  ++level;
     144      //  int count = list.Count;
     145      //  for (int i = offset; i != count; ++i) {
     146      //    if (list[i].Item1.Subtrees.Any())
     147      //      list.AddRange(from s in list[i].Item1.Subtrees select new Tuple<ISymbolicExpressionTreeNode, int>(s, level));
     148      //  }
     149      //  offset = count;
     150      //}
     151      //// taking advantage of the fact that the list is already sorted by level
     152      //for (int i = list.Count - 1; i >= 0; --i) {
     153      //  if (list[i].Item2 >= range.Start)
     154      //    yield return list[i].Item1;
     155      //  else break;
     156      //}
    151157    }
    152158
Note: See TracChangeset for help on using the changeset viewer.