Changeset 7489
- Timestamp:
- 02/20/12 13:53:31 (13 years ago)
- 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 106 106 var checkedItemList = new CheckedItemList<ISymbolicExpressionTreeCrossover>(); 107 107 checkedItemList.AddRange(list.OrderBy(op => op.Name)); 108 Operators = checkedItemList .AsReadOnly();108 Operators = checkedItemList; 109 109 Operators_ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeCrossover>>(Operators.CheckedItems)); 110 110 } -
branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs
r7481 r7489 37 37 private enum Ranges { HighLevel, Standard, LowLevel }; 38 38 private const string DepthRangeParameterName = "DepthRange"; 39 39 40 #region Parameter properties 40 41 41 public ConstrainedValueParameter<StringValue> DepthRangeParameter { 42 42 get { return (ConstrainedValueParameter<StringValue>)Parameters[DepthRangeParameterName]; } … … 60 60 DepthRangeParameter.ValidValues.Add(new StringValue(Enum.GetName(typeof(Ranges), Ranges.Standard))); 61 61 DepthRangeParameter.ValidValues.Add(new StringValue(Enum.GetName(typeof(Ranges), Ranges.LowLevel))); 62 Name = "DepthConstrainedCrossover";63 62 } 64 63 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicDataAnalysisExpressionDepthConstrainedCrossover<T>(this, cloner); } … … 108 107 depthRange.End = depthRange.Start; 109 108 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(); 111 110 112 111 if (crossoverPoints0.Count == 0) … … 118 117 int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength(); 119 118 120 var allowedBranches = (from s in GetNodesAtDepth(parent1 .Root, depthRange)119 var allowedBranches = (from s in GetNodesAtDepth(parent1, depthRange) 121 120 where 122 121 crossoverPoint0.IsMatchingPointType(s) && … … 130 129 } 131 130 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 //} 151 157 } 152 158
Note: See TracChangeset
for help on using the changeset viewer.