Ejemplo n.º 1
0
        /// <summary>
        /// Processes all agents in a branch node.
        /// </summary>
        /// <param name="branch">Branch node to processes.</param>
        private void ProcessBranchAll(BranchNode branch)
        {
            // For every agent on the node...
            while (branch.Out.Count > 0)
            {
                // Get next agent
                Agent a = branch.Dequeue();

                // Perfrom transaction between station and agent
                InteractJunc(branch.Junction, a);

                // Get node that agent will travel to next
                GraphNode exit = branch.GetExit(a);

                // Move agent to node if available, otherwise put back onto branch
                if (exit != null)
                {
                    exit.Enqueue(a);
                }
                else
                {
                    branch.Enqueue(a);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the first available agent in a branch node.
        /// </summary>
        /// <param name="b">Index of the branch node to process.</param>
        /// <param name="state">State of the parallel loop.</param>
        /// <param name="doneTick">Whether or not the process cylce has been completed.</param>
        /// <returns>The doneTick variable.</returns>
        private long ProcessBranchSingle(int b, ParallelLoopState state, long toProcess)
        {
            // Get branch
            BranchNode branch = Branches[b];

            // If there is an agent to process
            if (branch.Out.Count > 0)
            {
                // Get agent from node
                Agent a = branch.Dequeue();

                // Perform transaction between station and agent
                InteractJunc(branch.Junction, a);

                // Get node that agent will travel to next
                GraphNode exit = branch.GetExit(a);

                // Move agent to node if available, otherwise put back onto branch
                if (exit != null)
                {
                    exit.Enqueue(a);
                }
                else
                {
                    branch.Enqueue(a);
                }

                // If there are more agents, then the tick isn't done
                if (branch.Out.Count > 0)
                {
                    toProcess++;
                }
            }

            return(toProcess++);
        }