protected void UpdateEdges()
        {
            sceneComponents.AcceptEdge(edgeComponent => {
                AbstractGraphEdge edge      = edgeComponent.GetGraphEdge();
                AbstractGraphNode startNode = edge.GetStartGraphNode();
                AbstractGraphNode endNode   = edge.GetEndGraphNode();

                sceneComponents.GetNodeComponent(startNode.GetId()).ConnectedRb.Add(sceneComponents.GetNodeComponent(endNode.GetId()).Rb);
                sceneComponents.GetNodeComponent(endNode.GetId()).ConnectedRb.Add(sceneComponents.GetNodeComponent(startNode.GetId()).Rb);

                edgeComponent.UpdateGeometry(
                    sceneComponents.GetNodeComponent(startNode.GetId()).GetVisualComponent().transform.position,
                    sceneComponents.GetNodeComponent(endNode.GetId()).GetVisualComponent().transform.position);
            });

            float MostEdgesNodeCount = 0;

            foreach (var n in sceneComponents.nodeComponents)
            {
                if (n.ConnectedRb.Count > MostEdgesNodeCount)
                {
                    MostEdgesNodeCount = n.ConnectedRb.Count;
                }
            }
            foreach (var n in sceneComponents.nodeComponents)
            {
                if (n.ConnectedRb.Count == MostEdgesNodeCount)
                {
                    n.SetPosition(Vector3.zero);
                }
            }
        }
Exemplo n.º 2
0
 public SimpleGraphEdge(long id, AbstractGraphNode startNode, AbstractGraphNode endNode, string rtype)
 {
     this.id        = id;
     this.startNode = startNode;
     this.endNode   = endNode;
     this.rtype     = rtype;
 }
        public override void GenerateGraph(Graph graph)
        {
            AbstractGraphNode root     = graph.NewNode();
            AbstractGraphNode lastNode = GenerateCircleSegment(graph, root, 0);

            graph.NewEdge(lastNode, root);
        }
 public SimpleGraphEdge(long id, string name, AbstractGraphNode startNode, AbstractGraphNode endNode)
 {
     this.id        = id;
     this.startNode = startNode;
     this.endNode   = endNode;
     this.name      = name;
 }
Exemplo n.º 5
0
 public List <AbstractGraphEdge> FindEdges(long nodeId)
 {
     return(AllGraphEdges.FindAll(edge => {
         AbstractGraphNode startNode = edge.GetStartGraphNode();
         AbstractGraphNode endNode = edge.GetEndGraphNode();
         return startNode.GetId() == nodeId || endNode.GetId() == nodeId;
     }));
 }
        void CreateSuburb(Graph graph, AbstractGraphNode Canberra, int numFines)
        {
            AbstractGraphNode Suburb = graph.NewNode(true);

            graph.NewEdge(Canberra, Suburb);
            graph.NewEdge(Suburb, Canberra);
            GenerateDescedants(3, graph, Suburb, numFines);
        }
Exemplo n.º 7
0
        public override AbstractGraphEdge NewEdge(AbstractGraphNode from, AbstractGraphNode to, string rtype)
        {
            SimpleGraphEdge newEdge = new SimpleGraphEdge(AllGraphEdges.Count, from, to, rtype);

            AllGraphEdges.Add(newEdge);
            NotifyBackendEdgeCreated(newEdge);
            return(newEdge);
        }
 void GenerateDescedants(int level, Graph graph, AbstractGraphNode startNode, int numNodes)
 {
     for (int index = 0; index < numNodes; index++)
     {
         AbstractGraphNode descedantNode = graph.NewNode(false);
         graph.NewEdge(startNode, descedantNode);
         graph.NewEdge(descedantNode, startNode);
     }
 }
        public override void GenerateGraph(Graph graph)
        {
            AbstractGraphNode Canberra = graph.NewNode(false); // root node
            List <Dictionary <string, object> > cameraFinesdata = CSVReader.Read("cameraFines");

            for (var i = 0; i < cameraFinesdata.Count; i++)
            {
                CreateSuburb(graph, Canberra, (int)cameraFinesdata[i]["id"]);
            }
        }
Exemplo n.º 10
0
        public List <AbstractGraphEdge> FindEdges(long startOrEndNodeId, long endOrStartNodeId)
        {
            return(AllGraphEdges.FindAll(edge => {
                AbstractGraphNode startNode = edge.GetStartGraphNode();
                AbstractGraphNode endNode = edge.GetEndGraphNode();

                return (startNode.GetId() == startOrEndNodeId && endNode.GetId() == endOrStartNodeId) ||
                (startNode.GetId() == endOrStartNodeId && endNode.GetId() == startOrEndNodeId);
            }));
        }
Exemplo n.º 11
0
        private AbstractGraphNode GenerateCircleSegment(Graph graph, AbstractGraphNode startNode, int segmentIndex)
        {
            if (segmentIndex > NODES)
            {
                return(startNode);
            }
            AbstractGraphNode neighborNode = graph.NewNode();

            graph.NewEdge(startNode, neighborNode);
            return(GenerateCircleSegment(graph, neighborNode, segmentIndex + 1));
        }
        void GenerateDescedants(int level, Graph graph, AbstractGraphNode startNode)
        {
            if (level > MAX_LEVEL)
            {
                return;
            }
            for (int index = 0; index < Math.Exp(level); index++)
            {
                AbstractGraphNode descedantNode = graph.NewNode();
                graph.NewEdge(startNode, descedantNode);

                GenerateDescedants(level + 1, graph, descedantNode);
            }
        }
Exemplo n.º 13
0
        public override void GenerateGraph(Graph graph)
        {
            AbstractGraphNode firstNode  = graph.NewNode();
            AbstractGraphNode secondNode = graph.NewNode();
            AbstractGraphNode thirdNode  = graph.NewNode();

            graph.NewEdge(firstNode, secondNode);
            graph.NewEdge(secondNode, firstNode);
            graph.NewEdge(firstNode, secondNode);
            graph.NewEdge(firstNode, secondNode);
            graph.NewEdge(firstNode, secondNode);
            graph.NewEdge(firstNode, secondNode);
            graph.NewEdge(firstNode, secondNode);

            graph.NewEdge(secondNode, thirdNode);
        }
Exemplo n.º 14
0
        private void DrawGraphNode(AbstractGraphNode node)
        {
            if (graphSceneComponents.HasNodeComponent(node))
            {
                return;
            }

            NodeComponent nodeComponent = new NodeComponent(node, graphScenePrefabs.InstantiateNode());

            graphSceneComponents.AddNodeComponent(nodeComponent);

            node.Accept(edge => {
                AbstractGraphNode endNode = edge.GetEndGraphNode();
                DrawGraphNode(endNode);
                DrawGraphEdge(edge);
            });
        }
Exemplo n.º 15
0
        private void DrawGraphEdge(AbstractGraphEdge edge)
        {
            if (graphSceneComponents.HasEdgeComponent(edge))
            {
                return;
            }
            EdgeComponent edgeComponent = new EdgeComponent(edge, graphScenePrefabs.InstantiateEdge());

            graphSceneComponents.AddEdgeComponent(edgeComponent);

            NodeComponent startNode = graphSceneComponents.GetNodeComponent(edgeComponent.GetGraphEdge().GetStartGraphNode().GetId());
            NodeComponent endNode   = graphSceneComponents.GetNodeComponent(edgeComponent.GetGraphEdge().GetEndGraphNode().GetId());

            if (endNode == null)
            {
                return;
            }

            SpringJoint spring = endNode.GetVisualComponent().GetComponent <SpringJoint> ();

            spring.connectedBody = startNode.GetVisualComponent().GetComponent <Rigidbody> ();

            // checking if there is any other edge connecting the same nodes
            long sameNodeConnections = 0;

            graphSceneComponents.AcceptEdge(existingEdgeComponent => {
                AbstractGraphEdge existingEdge      = existingEdgeComponent.GetGraphEdge();
                AbstractGraphNode existingStartNode = existingEdge.GetStartGraphNode();
                AbstractGraphNode existingEndNode   = existingEdge.GetEndGraphNode();
                if (
                    existingStartNode.GetId() == startNode.GetGraphNode().GetId() && existingEndNode.GetId() == endNode.GetGraphNode().GetId() ||
                    existingStartNode.GetId() == endNode.GetGraphNode().GetId() && existingEndNode.GetId() == startNode.GetGraphNode().GetId()
                    )
                {
                    sameNodeConnections = sameNodeConnections + 1;
                }
            });
            if (sameNodeConnections > 1)
            {
                edgeComponent.MultiEdge = true;
            }
        }
Exemplo n.º 16
0
        public void Update(float time)
        {
            graphSceneComponents.AcceptEdge(edgeComponent => {
                AbstractGraphEdge edge      = edgeComponent.GetGraphEdge();
                AbstractGraphNode startNode = edge.GetStartGraphNode();
                AbstractGraphNode endNode   = edge.GetEndGraphNode();

                NodeComponent startNodeComponent = graphSceneComponents.GetNodeComponent(startNode.GetId());
                NodeComponent endNodeComponent   = graphSceneComponents.GetNodeComponent(endNode.GetId());

                // ---- distance function start
                float distance = 1F / startNode.GetDegree();
                distance      *= 100;
                distance      *= 4;

                SpringJoint springJoint = endNodeComponent.GetVisualComponent().GetComponent <SpringJoint>();
                springJoint.maxDistance = distance;
                springJoint.minDistance = distance;

                SphereCollider collider = endNodeComponent.GetVisualComponent().GetComponent <SphereCollider>();
                collider.radius         = distance * 0.3F;

                endNodeComponent.GetVisualComponent().GetComponent <Rigidbody>().mass = 5;
                // ---- distance function end

                // magic
                Rigidbody body     = endNodeComponent.GetVisualComponent().GetComponent <Rigidbody>();
                body.inertiaTensor = new Vector3(0.01F, 0.01F, 0.01F);

                edgeComponent.UpdateGeometry(
                    startNodeComponent.GetVisualComponent().transform.position,
                    endNodeComponent.GetVisualComponent().transform.position);
            });



            // graphLayout.DoLayout (time);
        }
Exemplo n.º 17
0
 public GameObject InstantiateNode(AbstractGraphNode nodePointer)
 {
     if (nodePointer.GetSuburb() == true)
     {
         GameObject node = Instantiate(SuburbPrefab);
         node.transform.SetParent(transform);
         return(node);
     }
     else
     {
         if (nodePointer.GetId() == 0)
         {
             GameObject node = Instantiate(RootPrefab);
             node.transform.SetParent(transform);
             return(node);
         }
         else
         {
             GameObject node = Instantiate(NodePrefab);
             node.transform.SetParent(transform);
             return(node);
         }
     }
 }
 public AbstractGraphEdge NewEdge(AbstractGraphNode from, AbstractGraphNode to, string rtype)
 {
     return(graphBackend.NewEdge(from, to, rtype));
 }
 public NodeComponent(AbstractGraphNode graphNode, GameObject visualComponent) : base(visualComponent)
 {
     this.graphNode = graphNode;
     InitializeNodeComponent();
 }
Exemplo n.º 20
0
 public void GraphNodeCreated(AbstractGraphNode graphNode)
 {
     DrawGraphNode(graphNode);
 }
        public override void GenerateGraph(Graph graph)
        {
            AbstractGraphNode root = graph.NewNode();

            GenerateDescedants(1, graph, root);
        }
Exemplo n.º 22
0
 public abstract AbstractGraphEdge NewEdge(AbstractGraphNode from, AbstractGraphNode to);
 public void GraphBackendNodeCreated(AbstractGraphNode graphNode)
 {
     loadedNodes.Add(graphNode);
     listeners.NotifyNodeCreated(graphNode);
 }
Exemplo n.º 24
0
 public abstract AbstractGraphEdge NewEdge(AbstractGraphNode from, AbstractGraphNode to, string rtype);
Exemplo n.º 25
0
 public void NotifyBackendNodeCreated(AbstractGraphNode graphNode)
 {
     listeners.NotifyGraphBackendCreated(graphNode);
 }
 public abstract bool IsAdjacent(AbstractGraphNode graphNode);
Exemplo n.º 27
0
 public bool HasNodeComponent(AbstractGraphNode graphNode)
 {
     return(nodeComponents.Exists(nodeComponent => {
         return nodeComponent.GetGraphNode().GetId() == graphNode.GetId();
     }));
 }
Exemplo n.º 28
0
 public override bool IsAdjacent(AbstractGraphNode graphNode)
 {
     return(graphBackend.FindEdges(id, graphNode.GetId()).Count > 0);
 }
Exemplo n.º 29
0
 public void NotifyNodeCreated(AbstractGraphNode graphNode)
 {
     listeners.ForEach(listener => {
         listener.GraphNodeCreated(graphNode);
     });
 }
Exemplo n.º 30
0
 public AbstractGraphEdge NewEdge(AbstractGraphNode from, AbstractGraphNode to)
 {
     return(graphBackend.NewEdge(from, to));
 }