/// <summary>
        /// Creates Track Circuits and Track Controllers.  Track Circuits are packaged into Track Controllers,
        /// and Track Controllers are chained off of the 2 'Primaries' (1 for each line) in the environment
        /// </summary>
        /// <param name="trackConBlockLists">Array of lists- 1 list is associated with each Track Circuit</param>
        /// <param name="redLine">A boolean value; true if we're on the red line</param>
        /// <returns>A true or false value, denoting the success of the operation</returns>
        public bool populateTCs(List <IBlock>[] trackConBlockLists, bool redLine)
        {
            if (trackConBlockLists == null)
            {
                return(false);
            }
            for (int i = 0; i < trackConBlockLists.Length; i++)
            {
                if (trackConBlockLists[i].Count != 0)//i is a TrackConID that is loaded
                {
                    TrackController.TrackCircuit tc = new TrackController.TrackCircuit(_env, trackConBlockLists[i]);
                    tc.ID = i;
                    circuits.Add(tc);
                    TrackController.TrackController TC = new TrackController.TrackController(_env, tc);

                    if (redLine)//We're red line, man
                    {
                        //If were the first track controller on this line
                        if (_env.PrimaryTrackControllerRed == null)
                        {
                            _env.PrimaryTrackControllerRed = TC;
                            TC.Previous = null;
                            TC.Next     = null;
                        }
                        else//Add track controller at end of linked list
                        {
                            ITrackController cur = _env.PrimaryTrackControllerRed;
                            while (cur.Next != null)
                            {
                                cur = cur.Next;
                            }
                            cur.Next    = TC;
                            TC.Previous = cur;
                        }
                    }
                    else//We're green line, man.
                    {
                        //If were the first track controller on this line
                        if (_env.PrimaryTrackControllerGreen == null)
                        {
                            _env.PrimaryTrackControllerGreen = TC;
                            TC.Previous = null;
                            TC.Next     = null;
                        }
                        else//Add track controller at end of linked list
                        {
                            ITrackController cur = _env.PrimaryTrackControllerGreen;
                            while (cur.Next != null)
                            {
                                cur = cur.Next;
                            }
                            cur.Next    = TC;
                            TC.Previous = cur;
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool DoTest(out int pass, out int fail, out List <string> messages)
        {
            pass     = 0;
            fail     = 0;
            messages = new List <string>();

            // Create 100 blocks for the red line
            var blocks = new List <IBlock>();

            // First block
            blocks.Add(new Block(1, StateEnum.Healthy, 100, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 2, 0, 0, "Red", 100));
            // Next 99 blocks
            for (var i = 2; i < 100; i++)
            {
                blocks.Add(new Block(i, StateEnum.Healthy, i - 1, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, i + 1, 0, 0, "Red", 100));
            }
            // Last block
            blocks.Add(new Block(100, StateEnum.Healthy, 99, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 1, 0, 0, "Red", 100));

            // Environment object
            ISimulationEnvironment environment = new global::SimulationEnvironment.SimulationEnvironment();
            // Our track circuit
            ITrackCircuit currCircuit = new TrackController.TrackCircuit(environment, blocks.Where(x => x.BlockID > 0 && x.BlockID <= 34).ToList());
            // Next track controller's circuit
            ITrackCircuit nextCircuit = new TrackController.TrackCircuit(environment, blocks.Where(x => x.BlockID > 34 && x.BlockID <= 67).ToList());
            // Previous track controller's circuit
            ITrackCircuit prevCircuit = new TrackController.TrackCircuit(environment, blocks.Where(x => x.BlockID > 67 && x.BlockID <= 100).ToList());

            ITrackController prev = new TrackController.TrackController(environment, currCircuit);
            ITrackController curr = new TrackController.TrackController(environment, currCircuit);
            ITrackController next = new TrackController.TrackController(environment, currCircuit);

            prev.Previous = null;
            prev.Next     = curr;

            curr.Previous = prev;
            curr.Next     = next;

            next.Previous = curr;
            next.Next     = null;

            environment.PrimaryTrackControllerGreen = prev;
            environment.PrimaryTrackControllerRed   = prev;
            environment.TrackModel = new DummyTrackModel(blocks);

            _env        = (global::SimulationEnvironment.SimulationEnvironment)environment;
            _startBlock = blocks[0];

            return(DoTestInternal(out pass, out fail, out messages));
        }
        public bool DoTest(out int pass, out int fail, out List<string> messages)
        {
            pass = 0;
            fail = 0;
            messages = new List<string>();

            // Create 100 blocks for the red line
            var blocks = new List<IBlock>();
            // First block
            blocks.Add(new Block(1, StateEnum.Healthy, 100, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 2, 0, 0, "Red", 100));
            // Next 99 blocks
            for (var i = 2; i < 100; i++)
                blocks.Add(new Block(i, StateEnum.Healthy, i - 1, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, i + 1, 0, 0, "Red", 100));
            // Last block
            blocks.Add(new Block(100, StateEnum.Healthy, 99, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 1, 0, 0, "Red", 100));

            // Environment object
            ISimulationEnvironment environment = new global::SimulationEnvironment.SimulationEnvironment();
            // Our track circuit
            ITrackCircuit currCircuit = new TrackController.TrackCircuit(environment, blocks.Where(x => x.BlockID > 0 && x.BlockID <= 34).ToList());
            // Next track controller's circuit
            ITrackCircuit nextCircuit = new TrackController.TrackCircuit(environment, blocks.Where(x => x.BlockID > 34 && x.BlockID <= 67).ToList());
            // Previous track controller's circuit
            ITrackCircuit prevCircuit = new TrackController.TrackCircuit(environment, blocks.Where(x => x.BlockID > 67 && x.BlockID <= 100).ToList());

            ITrackController prev = new TrackController.TrackController(environment, currCircuit);
            ITrackController curr = new TrackController.TrackController(environment, currCircuit);
            ITrackController next = new TrackController.TrackController(environment, currCircuit);

            prev.Previous = null;
            prev.Next = curr;

            curr.Previous = prev;
            curr.Next = next;

            next.Previous = curr;
            next.Next = null;

            environment.PrimaryTrackControllerGreen = prev;
            environment.PrimaryTrackControllerRed = prev;
            environment.TrackModel = new DummyTrackModel(blocks);

            _env = (global::SimulationEnvironment.SimulationEnvironment) environment;
            _startBlock = blocks[0];

            return DoTestInternal(out pass, out fail, out messages);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates Track Circuits and Track Controllers.  Track Circuits are packaged into Track Controllers, 
        /// and Track Controllers are chained off of the 2 'Primaries' (1 for each line) in the environment
        /// </summary>
        /// <param name="trackConBlockLists">Array of lists- 1 list is associated with each Track Circuit</param>
        /// <param name="redLine">A boolean value; true if we're on the red line</param>
        /// <returns>A true or false value, denoting the success of the operation</returns>
        public bool populateTCs(List<IBlock>[] trackConBlockLists, bool redLine)
        {
            if (trackConBlockLists == null)
                return false;
            for (int i = 0; i < trackConBlockLists.Length; i++)
            {
                if (trackConBlockLists[i].Count != 0)//i is a TrackConID that is loaded
                {
                    TrackController.TrackCircuit tc = new TrackController.TrackCircuit(_env,trackConBlockLists[i]);
                    tc.ID = i;
                    circuits.Add(tc);
                    TrackController.TrackController TC = new TrackController.TrackController(_env,tc);

                    if (redLine)//We're red line, man
                    {
                        //If were the first track controller on this line
                        if (_env.PrimaryTrackControllerRed == null)
                        {
                            _env.PrimaryTrackControllerRed = TC;
                            TC.Previous = null;
                            TC.Next = null;
                        }
                        else//Add track controller at end of linked list
                        {
                            ITrackController cur = _env.PrimaryTrackControllerRed;
                            while (cur.Next != null)
                                cur = cur.Next;
                            cur.Next = TC;
                            TC.Previous = cur;
                        }
                    }
                    else//We're green line, man.
                    {
                        //If were the first track controller on this line
                        if (_env.PrimaryTrackControllerGreen == null)
                        {
                            _env.PrimaryTrackControllerGreen = TC;
                            TC.Previous = null;
                            TC.Next = null;
                        }
                        else//Add track controller at end of linked list
                        {
                            ITrackController cur = _env.PrimaryTrackControllerGreen;
                            while (cur.Next != null)
                                cur = cur.Next;
                            cur.Next = TC;
                            TC.Previous = cur;
                        }
                    }

                }
            }

            return true;
        }