Пример #1
0
        public void GenerateNode_ExampleNode_Succeed()
        {
            //arrange
            GraphSystem graphSystem = new GraphSystem();

            //act
            graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty);

            //assert
            Assert.AreEqual(1, graphSystem.graph.Nodes.Count);
        }
Пример #2
0
 public PlayerSystem(SimulationConfiguration configuration,
                     IEntityFactoryProvider entityFactoryProvider,
                     GraphSystem graphSystem,
                     MovementSystem movementSystem,
                     [InjectOptional] List <IPlayerSystemBehaviour> playerSystemBehaviours)
 {
     _configuration           = configuration;
     _entityFactoryProvider   = entityFactoryProvider;
     _graphSystem             = graphSystem;
     _movementSystem          = movementSystem;
     _playterSystemBehaviours = playerSystemBehaviours;
     _playerEntityMapping     = new Dictionary <int, int>();
 }
Пример #3
0
        void changeEdgeValues(IEnumerable <Tuple <List <int>, float> > edgeIds, GraphSystem gs)
        {
            var graph = gs.GetGraph();

            foreach (var tuple in edgeIds)
            {
                foreach (int id in tuple.Item1)
                {
                    graph.Edges[id].Value = tuple.Item2;
                    // to keep track of edge values without the need to get the graph from GraphSystem:
                    this.Edges[id].Value = tuple.Item2;
                }
            }
            gs.UpdateGraph(graph);
        }
Пример #4
0
        public void CreateConnection_Connection_Succeed()
        {
            //arrange
            GraphSystem graphSystem = new GraphSystem();

            graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty);
            graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty);
            Node       node1      = graphSystem.graph.Nodes[0];
            Node       node2      = graphSystem.graph.Nodes[1];
            Connection connection = new ExampleConnection();

            //act
            graphSystem.graph.AddConnection(node1, node2, connection);

            //assert
            Assert.AreEqual(connection, graphSystem.graph.GetDirectedConnection(node1, node2));
        }
Пример #5
0
        void highlight(GraphSystem graphSystem)
        {
            List <int> highPlus  = new List <int>();
            List <int> highMinus = new List <int>();

            foreach (ProteinNode node in Nodes)
            {
                if (node.Active)
                {
                    highPlus.Add(GetIdByName(node.Name));
                }
                else if (node.Blocked)
                {
                    highMinus.Add(GetIdByName(node.Name));
                }
            }
            graphSystem.HighlightNodes(highPlus, HighlightNodesColorPos);
            graphSystem.HighlightNodes(highMinus, HighlightNodesColorNeg);
        }
Пример #6
0
        public void GetConnections_ConnectionList_Success()
        {
            //arrange
            GraphSystem graphSystem = new GraphSystem();

            graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty);
            graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty);
            graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty);
            graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty);
            graphSystem.Create <ExampleNode>(NodeCreationInfo.Empty);
            Node       node1 = graphSystem.graph.Nodes[0];
            Node       node2 = graphSystem.graph.Nodes[1];
            Node       node3 = graphSystem.graph.Nodes[2];
            Node       node4 = graphSystem.graph.Nodes[3];
            Node       node5 = graphSystem.graph.Nodes[4];
            Connection c1, c2, c3, c4;

            c1 = new ExampleConnection();
            c2 = new ExampleConnection();
            c3 = new ExampleConnection();
            c4 = new ExampleConnection();
            graphSystem.graph.AddConnection(node1, node2, c1);
            graphSystem.graph.AddConnection(node1, node3, c2);
            graphSystem.graph.AddConnection(node1, node4, c3);
            graphSystem.graph.AddConnection(node1, node5, c4);


            //act
            List <(Connection, Node)> connectionList = new List <(Connection, Node)>();

            connectionList.Add((c1, node2));
            connectionList.Add((c2, node3));
            connectionList.Add((c3, node4));
            connectionList.Add((c4, node5));

            List <(Connection, Node)> getConnectionsList = graphSystem.graph.GetOutgoingConnections(node1);

            //assert
            CollectionAssert.AreEquivalent(connectionList, getConnectionsList);
        }
Пример #7
0
        void changeNodeStates(IEnumerable <int> blockNodes, IEnumerable <int> activateNodes, GraphSystem gs)
        {
            DeactivateAll();
            UnblockAll();

            foreach (var i in activateNodes)
            {
                GetProtein(i).Activate();
            }
            foreach (var i in blockNodes)
            {
                GetProtein(i).Deactivate();
                GetProtein(i).Blocked = true;
            }
        }
Пример #8
0
        public void Propagate(GraphSystem graphSystem, float time)
        {
            List <Tuple <int, SignalType> > updatedSignals
                = new List <Tuple <int, SignalType> >();

            graphSystem.DehighlightNodes();


            List <int> activateNodes = new List <int>();
            List <int> blockNodes    = new List <int>();

            List <int> activateEdges = new List <int>();
            List <int> blockEdges    = new List <int>();

            List <int> decoupleEdges = new List <int>();
            List <int> coupleEdges   = new List <int>();

            // activate input proteins:
            foreach (int i in inputs)
            {
                GetProtein(i).Activate();
            }


            highlight(graphSystem);
            foreach (ProteinNode prot in Nodes)
            {
                if (prot.Active)
                {
                    var outInteractions = GetOutcomingInteractions(prot.Name);
                    foreach (var tuple in outInteractions)
                    {
                        var outInteraction   = tuple.Item1;
                        int outInteractionId = tuple.Item2;

                        ProteinNode nextProt = GetProtein(outInteraction.End2);
                        if (outInteraction.Type == "-")
                        {
                            // uncomment to add blocking sparks:
                            //				graphSystem.AddSpark(outInteraction.End1, outInteraction.End2, time, HighlightNodesColorNeg);
                            blockNodes.Add(outInteraction.End2);
                            blockEdges.Add(outInteractionId);
                        }
                        else if (outInteraction.Type == "+")
                        {
                            graphSystem.AddSpark(outInteraction.End1, outInteraction.End2, time, HighlightNodesColorPos);
                            activateNodes.Add(outInteraction.End2);

                            foreach (var t in GetInteractions(prot.Name, nextProt.Name))
                            {
                                activateEdges.Add(t.Item2);
                            }
                        }
                        else if (outInteraction.Type == "b")
                        {
                            if (outInteraction.Value > decoupleStrength)
                            {
                                decoupleEdges.Add(outInteractionId);
                            }
                            else
                            {
                                coupleEdges.Add(outInteractionId);
                            }
                        }
                    }
                }
            }

            // launch new sparks:
            graphSystem.RefreshSparks();

            // activate and block nodes:
            changeNodeStates(blockNodes, activateNodes, graphSystem);


            // couple and decouple nodes:
            List <Tuple <List <int>, float> > edgeLists = new List <Tuple <List <int>, float> >();

            edgeLists.Add(new Tuple <List <int>, float>(coupleEdges, coupleStrength));
            edgeLists.Add(new Tuple <List <int>, float>(decoupleEdges, decoupleStrength));
            changeEdgeValues(edgeLists, graphSystem);

            // paint edges:
            graphSystem.PaintAllEdges(EdgeNeutralColor);
            graphSystem.PaintEdges(activateEdges, EdgePosColor);
            graphSystem.PaintEdges(blockEdges, EdgeNegColor);
        }