Changeset 10501 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines
- Timestamp:
- 02/21/14 18:20:47 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/HeuristicLab.ReingoldTilfordTreeLayout/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs merged eligible /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs merged eligible /branches/Benchmarking/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 6917-7005 /branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 5815-6180 /branches/DataAnalysis/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 4458-4459,4462,4464 /branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 5060 /branches/HLScript/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 10331-10358 /branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 7343-7503 /branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 9271-9826 /branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 7098-8789 /branches/LogResidualEvaluator/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 10202-10483 /branches/NET40/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 5138-5162 /branches/ParallelEngine/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 6828 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 5370-5682 /branches/Trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 6829-6865 /branches/VNS/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 5594-5752 /branches/histogram/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 5959-6341 /stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/LayoutNode.cs 10032-10033
r10269 r10501 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .LayoutEngines{26 public class LayoutNode<T> : ILayoutNode<T>where T : class {27 public ILayoutNode<T> NextLeft {26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 27 public class LayoutNode<T> where T : class { 28 public LayoutNode<T> NextLeft { 28 29 get { 29 30 return Children == null ? Thread : Children.First(); 30 31 } 31 32 } 32 public ILayoutNode<T> NextRight {33 public LayoutNode<T> NextRight { 33 34 get { 34 35 return Children == null ? Thread : Children.Last(); 35 36 } 36 37 } 37 public ILayoutNode<T> LeftSibling {38 public LayoutNode<T> LeftSibling { 38 39 get { 39 40 if (Parent == null) return null; … … 41 42 } 42 43 } 43 public ILayoutNode<T> LeftmostSibling {44 public LayoutNode<T> LeftmostSibling { 44 45 get { 45 46 if (Parent == null) return null; … … 48 49 } 49 50 50 public ILayoutNode<T> Thread { get; set; }51 public ILayoutNode<T> Ancestor { get; set; }52 public ILayoutNode<T> Parent { get; set; }53 public List< ILayoutNode<T>> Children { get; set; }51 public LayoutNode<T> Thread { get; set; } 52 public LayoutNode<T> Ancestor { get; set; } 53 public LayoutNode<T> Parent { get; set; } 54 public List<LayoutNode<T>> Children { get; set; } 54 55 public float Mod { get; set; } 55 56 public float Prelim { get; set; } … … 65 66 } 66 67 67 public T Content { get; set; } 68 private T content; 69 public T Content { 70 get { return content; } 71 set { 72 if (value == null) 73 throw new ArgumentNullException("LayoutNode: Content cannot be null."); 74 content = value; 75 } 76 } 68 77 } 69 78 } -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/HeuristicLab.ReingoldTilfordTreeLayout/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs merged eligible /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs merged eligible /branches/Benchmarking/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 6917-7005 /branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 5815-6180 /branches/DataAnalysis/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 4458-4459,4462,4464 /branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 5060 /branches/HLScript/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 10331-10358 /branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 7343-7503 /branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 9271-9826 /branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 7098-8789 /branches/LogResidualEvaluator/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 10202-10483 /branches/NET40/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 5138-5162 /branches/ParallelEngine/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 6828 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 5370-5682 /branches/Trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 6829-6865 /branches/VNS/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 5594-5752 /branches/histogram/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 5959-6341 /stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs 10032-10033
r10269 r10501 7 7 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 8 8 public class ReingoldTilfordLayoutEngine<T> where T : class { 9 private readonly Dictionary<T, ILayoutNode<T>> nodes; // provides a reverse mapping T => ILayoutNode9 private readonly Dictionary<T, LayoutNode<T>> nodeMap; // provides a reverse mapping T => LayoutNode 10 10 11 11 public ReingoldTilfordLayoutEngine() { 12 node s = new Dictionary<T, ILayoutNode<T>>();13 } 14 15 public Dictionary<T, ILayoutNode<T>> Nodes { get { return nodes; } }16 17 public void AddNode(T content , ILayoutNode<T> node) {18 if (node s.ContainsKey(content)) {12 nodeMap = new Dictionary<T, LayoutNode<T>>(); 13 } 14 15 public Dictionary<T, LayoutNode<T>> NodeMap { get { return nodeMap; } } 16 17 public void AddNode(T content) { 18 if (nodeMap.ContainsKey(content)) { 19 19 throw new ArgumentException("Content already present in the dictionary."); 20 20 } 21 nodes.Add(content, node); 22 } 23 24 public ILayoutNode<T> GetNode(T content) { 25 ILayoutNode<T> ILayoutNode; 26 nodes.TryGetValue(content, out ILayoutNode); 27 return ILayoutNode; 21 var node = new LayoutNode<T> { Content = content }; 22 nodeMap.Add(content, node); 23 } 24 25 public void AddNode(LayoutNode<T> node) { 26 var content = node.Content; 27 if (nodeMap.ContainsKey(content)) { 28 throw new ArgumentException("Content already present in the dictionary."); 29 } 30 nodeMap.Add(content, node); 31 } 32 33 public void AddNodes(IEnumerable<LayoutNode<T>> nodes) { 34 foreach (var node in nodes) 35 nodeMap.Add(node.Content, node); 36 } 37 38 public LayoutNode<T> GetNode(T content) { 39 LayoutNode<T> layoutNode; 40 nodeMap.TryGetValue(content, out layoutNode); 41 return layoutNode; 28 42 } 29 43 … … 40 54 } 41 55 42 private ILayoutNode<T> root;43 public ILayoutNode<T> Root {56 private LayoutNode<T> root; 57 public LayoutNode<T> Root { 44 58 get { return root; } 45 59 set { … … 49 63 50 64 public void ResetCoordinates() { 51 foreach (var node in node s.Values) {65 foreach (var node in nodeMap.Values) { 52 66 node.X = 0; 53 67 node.Y = 0; … … 56 70 57 71 /// <summary> 58 /// Transform ILayoutNode coordinates so that all coordinates are positive and start from 0.72 /// Transform LayoutNode coordinates so that all coordinates are positive and start from 0. 59 73 /// </summary> 60 74 private void NormalizeCoordinates() { 61 var list = node s.Values.ToList();75 var list = nodeMap.Values.ToList(); 62 76 float xmin = 0, ymin = 0; 63 for (int i = 0; i !=list.Count; ++i) {77 for (int i = 0; i < list.Count; ++i) { 64 78 if (xmin > list[i].X) xmin = list[i].X; 65 79 if (ymin > list[i].Y) ymin = list[i].Y; 66 80 } 67 for (int i = 0; i !=list.Count; ++i) {81 for (int i = 0; i < list.Count; ++i) { 68 82 list[i].X -= xmin; 69 83 list[i].Y -= ymin; … … 73 87 public void Reset() { 74 88 root = null; 75 node s.Clear();89 nodeMap.Clear(); 76 90 } 77 91 78 92 public void ResetParameters() { 79 foreach (var layoutNode in node s.Values) {93 foreach (var layoutNode in nodeMap.Values) { 80 94 // reset layout-related parameters 81 95 layoutNode.Ancestor = layoutNode; … … 99 113 100 114 /// <summary> 101 /// Returns a map of coordinates for each ILayoutNode in the symbolic expression tree.115 /// Returns a map of coordinates for each LayoutNode in the symbolic expression tree. 102 116 /// </summary> 103 117 /// <returns></returns> 104 118 public Dictionary<T, PointF> GetNodeCoordinates() { 105 return node s.ToDictionary(x => x.Key, x => new PointF(x.Value.X, x.Value.Y));119 return nodeMap.ToDictionary(x => x.Key, x => new PointF(x.Value.X, x.Value.Y)); 106 120 } 107 121 … … 112 126 public RectangleF Bounds() { 113 127 float xmin, xmax, ymin, ymax; xmin = xmax = ymin = ymax = 0; 114 var list = node s.Values.ToList();115 for (int i = 0; i !=list.Count; ++i) {128 var list = nodeMap.Values.ToList(); 129 for (int i = 0; i < list.Count; ++i) { 116 130 float x = list[i].X, y = list[i].Y; 117 131 if (xmin > x) xmin = x; … … 123 137 } 124 138 125 private void FirstWalk( ILayoutNode<T> v) {126 ILayoutNode<T> w;139 private void FirstWalk(LayoutNode<T> v) { 140 LayoutNode<T> w; 127 141 if (v.IsLeaf) { 128 142 w = v.LeftSibling; … … 151 165 } 152 166 153 private void SecondWalk( ILayoutNode<T> v, float m) {167 private void SecondWalk(LayoutNode<T> v, float m) { 154 168 v.X = v.Prelim + m; 155 169 v.Y = v.Level * minVerticalSpacing; … … 160 174 } 161 175 162 private void Apportion( ILayoutNode<T> v, ref ILayoutNode<T> defaultAncestor) {176 private void Apportion(LayoutNode<T> v, ref LayoutNode<T> defaultAncestor) { 163 177 var w = v.LeftSibling; 164 178 if (w == null) return; 165 ILayoutNode<T> vip = v;166 ILayoutNode<T> vop = v;167 ILayoutNode<T> vim = w;168 ILayoutNode<T> vom = vip.LeftmostSibling;179 LayoutNode<T> vip = v; 180 LayoutNode<T> vop = v; 181 LayoutNode<T> vim = w; 182 LayoutNode<T> vom = vip.LeftmostSibling; 169 183 170 184 float sip = vip.Mod; … … 202 216 } 203 217 204 private void MoveSubtree( ILayoutNode<T> wm, ILayoutNode<T> wp, float shift) {205 int subtrees = wp.Number - wm.Number; // TODO: Investigate possible bug (if the value ever happens to be zero) - happens when the tree is actually a graph 206 if (subtrees == 0) throw new Exception( );218 private void MoveSubtree(LayoutNode<T> wm, LayoutNode<T> wp, float shift) { 219 int subtrees = wp.Number - wm.Number; // TODO: Investigate possible bug (if the value ever happens to be zero) - happens when the tree is actually a graph (but that's outside the use case of this algorithm which only works with trees) 220 if (subtrees == 0) throw new Exception("MoveSubtree failed: check if object is really a tree (no cycles)"); 207 221 wp.Change -= shift / subtrees; 208 222 wp.Shift += shift; … … 212 226 } 213 227 214 private void ExecuteShifts( ILayoutNode<T> v) {228 private void ExecuteShifts(LayoutNode<T> v) { 215 229 if (v.IsLeaf) return; 216 230 float shift = 0; … … 225 239 } 226 240 227 private ILayoutNode<T> Ancestor(ILayoutNode<T> u, ILayoutNode<T> v) {241 private LayoutNode<T> Ancestor(LayoutNode<T> u, LayoutNode<T> v) { 228 242 var ancestor = u.Ancestor; 229 243 if (ancestor == null) return null; -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/HeuristicLab.ReingoldTilfordTreeLayout/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs merged eligible /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs merged eligible /branches/Benchmarking/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 6917-7005 /branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 5815-6180 /branches/DataAnalysis/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 4458-4459,4462,4464 /branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 5060 /branches/HLScript/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 10331-10358 /branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 7343-7503 /branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 9271-9826 /branches/HeuristicLab.TimeSeries/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 7098-8789 /branches/LogResidualEvaluator/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 10202-10483 /branches/NET40/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 5138-5162 /branches/ParallelEngine/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 6828 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 5370-5682 /branches/Trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 6829-6865 /branches/VNS/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 5594-5752 /branches/histogram/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 5959-6341 /stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/LayoutEngines/SymbolicExpressionTreeLayoutAdapter.cs 10032-10033
r10456 r10501 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.LayoutEngines;25 24 26 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 27 26 // adapter class that provides some conversion methods from symbolic expression trees to layout nodes (preserving the tree structure) 28 27 public class SymbolicExpressionTreeLayoutAdapter : ILayoutAdapter<ISymbolicExpressionTreeNode> { 29 // default conversion function between ISymbolicExpressionTreeNode and ILayoutNode<ISymbolicExpressionTree>30 static ILayoutNode<ISymbolicExpressionTreeNode> DefaultConvert(ISymbolicExpressionTreeNode node) {28 // default conversion function between ISymbolicExpressionTreeNode and LayoutNode<ISymbolicExpressionTree> 29 LayoutNode<ISymbolicExpressionTreeNode> defaultConvert(ISymbolicExpressionTreeNode node) { 31 30 var layoutNode = new LayoutNode<ISymbolicExpressionTreeNode> { Content = node }; 32 31 layoutNode.Ancestor = layoutNode; … … 34 33 } 35 34 36 public IEnumerable< ILayoutNode<ISymbolicExpressionTreeNode>> Convert(ISymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, ILayoutNode<ISymbolicExpressionTreeNode>> convertFunc = null) {35 public IEnumerable<LayoutNode<ISymbolicExpressionTreeNode>> Convert(ISymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, LayoutNode<ISymbolicExpressionTreeNode>> convertFunc = null) { 37 36 return Convert(tree.Root, convertFunc); 38 37 } 39 38 // translate the symbolic expression tree structure to a layout node tree structure 40 39 // return an enumerable containing all the layout nodes 41 public IEnumerable< ILayoutNode<ISymbolicExpressionTreeNode>> Convert(ISymbolicExpressionTreeNode root, Func<ISymbolicExpressionTreeNode, ILayoutNode<ISymbolicExpressionTreeNode>> convertFunc = null) {42 var rootLayoutNode = convertFunc == null ? DefaultConvert(root) : convertFunc(root);40 public IEnumerable<LayoutNode<ISymbolicExpressionTreeNode>> Convert(ISymbolicExpressionTreeNode root, Func<ISymbolicExpressionTreeNode, LayoutNode<ISymbolicExpressionTreeNode>> convertFunc = null) { 41 var rootLayoutNode = convertFunc == null ? defaultConvert(root) : convertFunc(root); 43 42 rootLayoutNode.Ancestor = rootLayoutNode; 44 43 45 44 if (root.SubtreeCount > 0) { 46 rootLayoutNode.Children = new List< ILayoutNode<ISymbolicExpressionTreeNode>>(root.SubtreeCount);45 rootLayoutNode.Children = new List<LayoutNode<ISymbolicExpressionTreeNode>>(root.SubtreeCount); 47 46 Expand(rootLayoutNode, convertFunc); 48 47 } 49 48 50 var list = new List< ILayoutNode<ISymbolicExpressionTreeNode>> { rootLayoutNode };49 var list = new List<LayoutNode<ISymbolicExpressionTreeNode>> { rootLayoutNode }; 51 50 int i = 0; 52 51 while (i < list.Count) { 53 if (list[i].Children != null) 54 foreach (ILayoutNode<ISymbolicExpressionTreeNode> child in list[i].Children) 55 list.Add(child); 52 if (list[i].Children != null) list.AddRange(list[i].Children); 56 53 ++i; 57 54 } … … 59 56 } 60 57 61 private void Expand( ILayoutNode<ISymbolicExpressionTreeNode> layoutNode, Func<ISymbolicExpressionTreeNode, ILayoutNode<ISymbolicExpressionTreeNode>> convertFunc = null) {58 private void Expand(LayoutNode<ISymbolicExpressionTreeNode> layoutNode, Func<ISymbolicExpressionTreeNode, LayoutNode<ISymbolicExpressionTreeNode>> convertFunc = null) { 62 59 if (layoutNode.Children == null) return; 63 60 for (int i = 0; i < layoutNode.Content.SubtreeCount; ++i) { 64 61 var subtree = layoutNode.Content.GetSubtree(i); 65 var childLayoutNode = convertFunc == null ? DefaultConvert(subtree) : convertFunc(subtree);62 var childLayoutNode = convertFunc == null ? defaultConvert(subtree) : convertFunc(subtree); 66 63 childLayoutNode.Parent = layoutNode; 67 64 childLayoutNode.Number = i; 68 65 childLayoutNode.Level = layoutNode.Level + 1; 69 66 childLayoutNode.Ancestor = childLayoutNode; 70 childLayoutNode.Children = subtree.SubtreeCount > 0 ? new List< ILayoutNode<ISymbolicExpressionTreeNode>>(subtree.SubtreeCount) : null;67 childLayoutNode.Children = subtree.SubtreeCount > 0 ? new List<LayoutNode<ISymbolicExpressionTreeNode>>(subtree.SubtreeCount) : null; 71 68 layoutNode.Children.Add(childLayoutNode); 72 69 Expand(childLayoutNode, convertFunc); -
Property
svn:mergeinfo
set to
(toggle deleted branches)
Note: See TracChangeset
for help on using the changeset viewer.