2017-10-28 22 views
1

가 나는 결과 교차 에지를 포함, mr.Andy 발간 파블로 link[18 페이지]왜 방사형 트리 레이아웃 드로잉 알고리즘이 교차 모서리를 만들고 있습니까?

문제가있어서, 알고리즘 드로잉 반경 레이아웃을 구현하고있다. 용납 할 수없는 일입니다. 나는 약간의 해결책, 유사한 문제 link을 발견했다. 그러나 나는이 알고리즘으로 그들을 구현할 수 없었다. (나는 해결책에 대한 전체 접근법을 바꾸어야했다.) 또한 앤디 파블로 (Andy Pavlo)의 알고리즘이이 문제를 해결할 수 있어야합니다. 알고리즘의 결과를 볼 때 여기에는 교차 된 가장자리가 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 내가 놓친 게 있니? 미리 감사드립니다.

알고리즘의 Mr.Pavlo 의사 코드 enter image description here

알고리즘의 내 구현

 public void RadialPositions(Tree<string> rootedTree, Node<string> vertex, double alfa, double beta, 
     List<RadialPoint<string>> outputGraph) 
    { 
     //check if vertex is root of rootedTree 
     if (vertex.IsRoot) 
     { 
      vertex.Point.X = 0; 
      vertex.Point.Y = 0; 
      outputGraph.Add(new RadialPoint<string> 
      { 
       Node = vertex, 
       Point = new Point 
       { 
        X = 0, 
        Y = 0 
       }, 
       ParentPoint = null 
      }); 

     } 
     //Depth of vertex starting from 0 
     int depthOfVertex = vertex.Depth; 
     double theta = alfa; 
     double radius = Constants.CircleRadius + (Constants.Delta * depthOfVertex); 

     //Leaves number in the subtree rooted at v 
     int leavesNumber = BFS.BreatFirstSearch(vertex); 
     foreach (var child in vertex.Children) 
     { 
      //Leaves number in the subtree rooted at child 
      int lambda = BFS.BreatFirstSearch(child); 
      double mi = theta + ((double)lambda/leavesNumber * (beta - alfa)); 

      double x = radius * Math.Cos((theta + mi)/2.0); 
      double y = radius * Math.Sin((theta + mi)/2.0); 

      //setting x and y 
      child.Point.X = x; 
      child.Point.Y = y; 

      outputGraph.Add(new RadialPoint<string> 
      { 
       Node = child, 
       Point = new Point 
       { 
        X = x, 
        Y = y, 
        Radius = radius 
       }, 
       ParentPoint = vertex.Point 

      }); 

      if (child.Children.Count > 0) 
      { 
       child.Point.Y = y; 
       child.Point.X = x; 
       RadialPositions(rootedTree, child, theta, mi, outputGraph); 
      } 
      theta = mi; 
     } 

    } 

지고 잎에 대한 BFS 알고리즘

public static int BreatFirstSearch<T>(Node<T> root) 
    { 
     var visited = new List<Node<T>>(); 
     var queue = new Queue<Node<T>>(); 
     int leaves = 0; 

     visited.Add(root); 
     queue.Enqueue(root); 

     while (queue.Count != 0) 
     { 
      var current = queue.Dequeue(); 
      if (current.Children.Count == 0) 
       leaves++; 
      foreach (var node in current.Children) 
      { 
       if (!visited.Contains(node)) 
       { 
        visited.Add(node); 
        queue.Enqueue(node); 
       } 
      } 
     } 

     return leaves; 
    } 

초기 호출

 var outputPoints = new List<RadialPoint<string>>(); 
     alg.RadialPositions(tree, tree.Root,0, 360, outputPoints); 

mr.Pavlo 결과 enter image description here

이 가

간단한 샘플에 내 결과가 enter image description here

답변

2

Math.CosSin 입력 각도가 라디안 될 것으로 기대가 아니라도. 초기 메서드 호출에서 상한 한도 (beta)는 360이 아니라 2 * Math.PI이어야합니다. 이렇게하면 계산 한 모든 각도가 라디안이 아닌 각도로 표시됩니다.

+0

백만의 감사는 완벽하게 작동합니다. 이것은 전혀 발생하지 않았습니다. – Arsiwaldi