Пример #1
0
 /// <summary>
 ///     Function to set simulation speed to normal (wall speed)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void _btnGlobalTimeWallSpeed_Click(object sender, EventArgs e)
 {
     _environment.StopTick();
     _environment.SetInterval(_environment.GetInterval() * 10);
     _btnGlobalTimeWallSpeed.Enabled = false;
     _environment.StartTick();
 }
Пример #2
0
        public CTCOffice(ISimulationEnvironment env, ITrackController redTC, ITrackController greenTC)
        {
            _populateTrackMutex = new Mutex(false);
            _updateTrackMutex   = new Mutex(false);
            _loadTrackMutex     = new Mutex(false);
            _rate      = 100; //num of ticks
            _tickCount = 0;
            _rate      = env.GetInterval();
            _env       = env;
            _primaryTrackControllerGreen = greenTC;
            _primaryTrackControllerRed   = redTC;

            _env.TrackModel.TrackChangedEvent += new EventHandler <EventArgs>(TrackModel_TrackChangedEvent);

            _messages = new List <string>();

            //subscribe to Environment Tick
            _env.Tick += _env_Tick;

            //create new resource wrapper
            _res = new ResourceWrapper();

            //create new operator object
            _op = new Operator();
            //set credentials
            _op.SetAuth("root", "admin");

            //create queues
            _requestsOut = new Queue <IRequest>();
            _requestsIn  = new Queue <IRequest>();

            //create queue events
            RequestQueueIn  += CTCOffice_RequestQueueIn;
            RequestQueueOut += CTCOffice_RequestQueueOut;

            //create queue processing flags / mutex
            _processingOutRequests = false;
            _processingInRequests  = false;

            _redLoaded   = false;
            _greenLoaded = false;

            _containedTrainAndBlock = new List <TrainAndBlock>();

            if (_env.TrackModel == null)
            {
                _env.SendLogEntry("CTCOffice: NULL Reference to TrackModel");
            }
        }//Constructor
Пример #3
0
        public CTCOffice(ISimulationEnvironment env, ITrackController redTC, ITrackController greenTC)
        {
            _populateTrackMutex = new Mutex(false);
            _updateTrackMutex = new Mutex(false);
            _loadTrackMutex = new Mutex(false);
            _rate = 100; //num of ticks
            _tickCount = 0;
            _rate = env.GetInterval();
            _env = env;
            _primaryTrackControllerGreen = greenTC;
            _primaryTrackControllerRed = redTC;

            _env.TrackModel.TrackChangedEvent += new EventHandler<EventArgs>(TrackModel_TrackChangedEvent);

            _messages = new List<string>();

            //subscribe to Environment Tick
            _env.Tick += _env_Tick;

            //create new resource wrapper
            _res = new ResourceWrapper();

            //create new operator object
            _op = new Operator();
            //set credentials
            _op.SetAuth("root", "admin");

            //create queues
            _requestsOut = new Queue<IRequest>();
            _requestsIn = new Queue<IRequest>();

            //create queue events
            RequestQueueIn += CTCOffice_RequestQueueIn;
            RequestQueueOut += CTCOffice_RequestQueueOut;

            //create queue processing flags / mutex
            _processingOutRequests = false;
            _processingInRequests = false;

            _redLoaded = false;
            _greenLoaded = false;

            _containedTrainAndBlock = new List<TrainAndBlock>();

            if (_env.TrackModel == null)
            {
                _env.SendLogEntry("CTCOffice: NULL Reference to TrackModel");
            }
        }
Пример #4
0
        private const int _maxCapacity = 222;                      // 74 seated, 148 standing

        #endregion

        #region Constructors

        /// <summary>
        /// This constructor is used when passenger, crew, and temperature information is not given.
        /// It adds no passengers or crew and sets the temperature equal to 32 degrees Celcius.
        /// </summary>
        /// <param name="trainID">The ID to give to the train.</param>
        /// <param name="startingBlock">The starting block of the train.</param>
        /// <param name="environment">The environment being used by the entire simulation.</param>
        public Train(int trainID, IBlock startingBlock, ISimulationEnvironment environment)
        {
            _environment       = environment;
            _environment.Tick += _environment_Tick;

            _trainID          = trainID;
            _totalMass        = calculateMass();
            _informationLog   = "";
            _informationCount = 0;
            _lightsOn         = false;
            _doorsOpen        = false;
            _temperature      = 32;

            _currentAcceleration = 0;
            _currentVelocity     = 0;
            _currentPosition     = 0;

            _numPassengers = 0;
            _numCrew       = 0;

            _brakeFailure        = false;
            _engineFailure       = false;
            _signalPickupFailure = false;

            _emergencyBrakePulled = false;

            _positionWarningGiven     = false;
            _velocityWarningGiven     = false;
            _accelerationWarningGiven = false;
            _decelerationWarningGiven = false;

            _currentBlock    = startingBlock;
            _previousBlockID = 0;
            _currentBlockID  = _currentBlock.BlockID;
            _blockLength     = _currentBlock.BlockSize;
            _trackCircuitID  = _currentBlock.TrackCirID;

            _trackModel      = environment.TrackModel;
            _trainController = new TrainController.TrainController(_environment, this);

            // set allTrains equal to list contained in environment
            allTrains = environment.AllTrains;

            _timeInterval = (environment.GetInterval() / 1000.0);

            appendInformationLog("Created on block " + _currentBlockID + ".");
        }
Пример #5
0
        /// <summary>
        ///     Updates the movement of the train. Accounts for slope and changes the block if necessary.
        /// </summary>
        public void updateMovement()
        {
            _timeInterval = (_environment.GetInterval() / 1000.0); // milliseconds to seconds

            // can't accelerate or decelerate if engine has failed
            if (_engineFailure)
            {
                _currentAcceleration = 0;
            }

            if (_emergencyBrakePulled)
            {
                _currentAcceleration = _emergencyBrakeDeceleration;
            }

            // acceleration changes due to elevation
            double absGrade = Math.Abs(_currentBlock.Grade);
            double angle    = Math.Atan(absGrade);

            if (_currentBlock.Grade > 0) // up hill
            {
                _currentAcceleration = _currentAcceleration - (_accelerationGravity * Math.Sin(angle));
            }
            else if (_currentBlock.Grade < 0) // down hill
            {
                _currentAcceleration = _currentAcceleration + (_accelerationGravity * Math.Sin(angle));
            }

            appendInformationLog("Acceleration set to " + Math.Round(_currentAcceleration, 3) + " m/s^2.");

            // stops acceleration due to slope when emergency brake is on
            if ((_currentAcceleration > 0) && (_emergencyBrakePulled))
            {
                _currentAcceleration = 0;
            }

            // check if the acceleration is greater than the physical limit
            if (_currentAcceleration > _physicalAccelerationLimit)
            {
                _currentAcceleration = _physicalAccelerationLimit;

                if (!_accelerationWarningGiven)
                {
                    appendInformationLog("WARNING: Acceleration exceeded physical limit.");
                    _accelerationWarningGiven = true;
                }
            }
            else
            {
                _accelerationWarningGiven = false;
            }

            // check if the deceleration is greater than the physical limit and emergency brake isn't toggled
            if (_currentAcceleration < _physicalDecelerationLimit && !_emergencyBrakePulled)
            {
                _currentAcceleration = _physicalDecelerationLimit;

                if (!_decelerationWarningGiven)
                {
                    appendInformationLog("WARNING: Deceleration exceeded physical limit.");
                    _decelerationWarningGiven = true;
                }
            }
            else
            {
                _decelerationWarningGiven = false;
            }

            _currentVelocity = _currentVelocity + (_currentAcceleration * _timeInterval);

            // check if velocity is less than zero or greater than the limit
            if (_currentVelocity < 0)
            {
                _currentVelocity     = 0;
                _currentAcceleration = 0;

                if (!_velocityWarningGiven)
                {
                    appendInformationLog("WARNING: Velocity less than zero. Train stopped.");
                    _velocityWarningGiven = true;
                }
            }
            else if (_currentVelocity > _physicalVelocityLimit)
            {
                _currentVelocity     = _physicalVelocityLimit;
                _currentAcceleration = 0;

                // check if velocity warning already given
                if (!_velocityWarningGiven)
                {
                    appendInformationLog("WARNING: Velocity exceeded physical limit.");
                    _velocityWarningGiven = true;
                }
            }
            else
            {
                _velocityWarningGiven = false;
            }

            _currentPosition = _currentPosition + (_currentVelocity * _timeInterval);

            // Handles edge of block, only going forward
            if (_currentPosition >= _blockLength)
            {
                // get next block ID based on the previous ID
                int    nextBlockID = _currentBlock.nextBlockIndex(_previousBlockID);
                IBlock nextBlock   = _trackModel.requestBlockInfo(nextBlockID, _currentBlock.Line);

                if (nextBlock != null)
                {
                    _previousBlockID = _currentBlockID;       // previous block is now current block
                    _currentBlock    = nextBlock;
                    _currentBlockID  = _currentBlock.BlockID; // update the current block to be the next block

                    // update the current position of the train
                    _currentPosition = _currentPosition - _blockLength;
                    _blockLength     = _currentBlock.BlockSize;

                    appendInformationLog("Moved to block " + _currentBlockID + ".");
                }
                else // cannot find block
                {
                    _currentPosition     = _blockLength;
                    _currentVelocity     = 0;
                    _currentAcceleration = 0;

                    // check if already given warning
                    if (!_positionWarningGiven)
                    {
                        appendInformationLog("WARNING: Cannot find the next block.");
                        _positionWarningGiven = true;
                    }
                    else
                    {
                        _positionWarningGiven = false;
                    }
                }
            }


            // TODO: added implementation
            if (_trackCircuitID != _currentBlock.TrackCirID)
            {
                _trackCircuitID = _currentBlock.TrackCirID;
            }
        }
Пример #6
0
        /// <summary>
        /// This constructor is used when passenger, crew, and temperature information is not given.
        /// It adds no passengers or crew and sets the temperature equal to 32 degrees Celcius.
        /// </summary>
        /// <param name="trainID">The ID to give to the train.</param>
        /// <param name="startingBlock">The starting block of the train.</param>
        /// <param name="environment">The environment being used by the entire simulation.</param>
        public Train(int trainID, IBlock startingBlock, ISimulationEnvironment environment)
        {
            _environment = environment;
            _environment.Tick += _environment_Tick;

            _trainID = trainID;
            _totalMass = calculateMass();
            _informationLog = "";
            _informationCount = 0;
            _lightsOn = false;
            _doorsOpen = false;
            _temperature = 32;

            _currentAcceleration = 0;
            _currentVelocity = 0;
            _currentPosition = 0;

            _numPassengers = 0;
            _numCrew = 0;

            _brakeFailure = false;
            _engineFailure = false;
            _signalPickupFailure = false;

            _emergencyBrakePulled = false;

            _positionWarningGiven = false;
            _velocityWarningGiven = false;
            _accelerationWarningGiven = false;
            _decelerationWarningGiven = false;

            _currentBlock = startingBlock;
            _previousBlockID = 0;
            _currentBlockID = _currentBlock.BlockID;
            _blockLength = _currentBlock.BlockSize;
            _trackCircuitID = _currentBlock.TrackCirID;

            _trackModel = environment.TrackModel;
            _trainController = new TrainController.TrainController(_environment, this);

            // set allTrains equal to list contained in environment
            allTrains = environment.AllTrains;

            _timeInterval = (environment.GetInterval() / 1000.0);

            appendInformationLog("Created on block " + _currentBlockID + ".");
        }