Esempio n. 1
0
 public static Graph MakeHub(int childrenCount)
 {
     Graph graph = new Graph();
     graph.AddNode(new BaseNode());
     graph.AddChildren( childrenCount, 0 );
     return graph;
 }
Esempio n. 2
0
        public static Graph MakeString(int nodeCount)
        {
            Graph graph = new Graph();

            graph.AddNode(new BaseNode());
            for (int i = 1; i < nodeCount; ++i)
            {
                graph.AddNode(new BaseNode());
                graph.AddEdge(graph.NodeCount - 2, graph.NodeCount - 1);
            }
            return graph;
        }
Esempio n. 3
0
 void setBuffers(Graph graph)
 {
     foreach (BaseNode n in graph.Nodes)
     {
         if (n is SpatialNode)
         {
             addNode(n.GetSize(), n.GetColor(), ((SpatialNode)n).Position);
         }
         else
         {
             addNode(n.GetSize(), n.GetColor());
         }
     }
     foreach (var e in graph.Edges)
     {
         addEdge(e.End1, e.End2, e.Length, e.Value);
     }
     setBuffers();
 }
Esempio n. 4
0
 public void UpdateGraph(Graph graph)
 {
     nodeList.Clear();
     edgeList.Clear();
     edgeIndexLists.Clear();
     setBuffers(graph);
 }
Esempio n. 5
0
 public Graph GetGraph()
 {
     if (lay.CurrentStateBuffer != null)
     {
         Particle3d[] particleArray = new Particle3d[lay.ParticleCount];
         lay.CurrentStateBuffer.GetData(particleArray);
         Graph graph = new Graph();
         foreach (var p in particleArray)
         {
             graph.AddNode(new SpatialNode(p.Position, p.Size, new Color(p.Color)));
         }
         foreach (var l in edgeList)
         {
             graph.AddEdge(new Graph.Edge((int)l.par1, (int)l.par2, l.length, l.strength));
         }
         return graph;
     }
     return new Graph();
 }
Esempio n. 6
0
 public void AddGraph(Graph graph)
 {
     lay.ResetState();
     nodeList.Clear();
     edgeList.Clear();
     edgeIndexLists.Clear();
     referenceNodeIndex = 0;
     setBuffers( graph );
 }
Esempio n. 7
0
        public static Graph MakeTree(int nodeCount, int arity)
        {
            Graph graph = new Graph();

            graph.AddNode(new BaseNode());
            graph.AddChildren(arity, graph.NodeCount - 1);

            Queue<int> latestIndex = new Queue<int>();
            for (int i = 0; i < arity; ++i)
            {
                latestIndex.Enqueue(graph.NodeCount - 1 - i);
            }

            while (graph.NodeCount < nodeCount)
            {
                if (latestIndex.Count <= 0)
                {
                    break;
                }
                int parentIndex = latestIndex.Peek();

                if (graph.adjacencyList[parentIndex].Count > arity)
                {
                    latestIndex.Dequeue();
                    continue;
                }
                graph.AddChildren(1, parentIndex);
                latestIndex.Enqueue(graph.NodeCount - 1);
            }
            return graph;
        }