Beispiel #1
0
        private void UpdateDensityAndSpeed(ITrafficLight trafficLight, ITrafficData oldTrafficData,
                                           ITrafficData trafficData, double seconds)
        {
            /*if (Math.Abs(trafficData.TrafficDensity) < Epsilon)
             * {
             *  return;
             * }*/

            if (trafficLight.State == TrafficLightState.Red)
            {
                var hours      = seconds / 3600.0;
                var length     = trafficData.TrafficSpeed * 1000.0 * hours;
                var nofCars    = length / 100.0 * 25 * trafficData.TrafficDensity;
                var newDensity = oldTrafficData.TrafficDensity + nofCars / 25.0;

                /*if (newDensity > 1)
                 * {
                 *  newDensity = 1;
                 * }*/
                trafficData.TrafficDensity = newDensity;
                trafficData.TrafficSpeed   = 0.0;
            }
            else
            {
                var hours      = seconds / 3600.0;
                var length     = trafficData.TrafficSpeed * 1000.0 * hours;
                var nofCars    = length / 100.0 * 25 * trafficData.TrafficDensity;
                var newDensity = oldTrafficData.TrafficDensity - nofCars / 25.0;
                if (newDensity < trafficData.TrafficDensity)
                {
                    newDensity = trafficData.TrafficDensity;
                }
                trafficData.TrafficDensity = newDensity;
            }
        }
Beispiel #2
0
        private double GetNofCars(ITrafficData trafficData, double seconds)
        {
            var hours   = seconds / 3600.0;
            var length  = trafficData.TrafficSpeed * 1000.0 * hours;
            var nofCars = length / 100.0 * 25 * trafficData.TrafficDensity;

            return(nofCars);
        }
Beispiel #3
0
        private double GetTrafficDataMark(ITrafficLight trafficLight, ITrafficData trafficData)
        {
            if (trafficLight.State == TrafficLightState.Green)
            {
                return(trafficData.TrafficDensity + 1 / trafficData.TrafficSpeed);
            }

            return(0.0);
        }
Beispiel #4
0
        private double GetMarkFromTrafficData(ITrafficLight trafficLight, ITrafficData trafficData)
        {
            /*           if (trafficLight.State == TrafficLightState.Green)
             * {
             *  if (Math.Abs(trafficData.TrafficSpeed) > 0.0001)
             *  {
             *      return trafficData.TrafficDensity + 1 / trafficData.TrafficSpeed;
             *  }
             *  else {
             *      return trafficData.TrafficDensity;
             *  }
             * }
             *
             * return 0.0;*/

            if (Math.Abs(trafficData.TrafficSpeed) > 0.0001)
            {
                return(trafficData.TrafficDensity + 1 / trafficData.TrafficSpeed);
            }
            return(trafficData.TrafficDensity);
        }
Beispiel #5
0
        private void AddCrossroadTrafficData(ILocation prev, ILocation crossroadLocation, ILocation next,
                                             ICrossroad crossroad, ITrafficFlow trafficFlow)
        {
            var fromLeft  = false;
            var fromUp    = false;
            var fromRight = false;
            var fromDown  = false;

            if (prev.Column < crossroadLocation.Column)
            {
                fromLeft = true;
            }
            else if (prev.Row < crossroadLocation.Row)
            {
                fromUp = true;
            }
            else if (prev.Column > crossroadLocation.Column)
            {
                fromRight = true;
            }
            else if (prev.Row > crossroadLocation.Row)
            {
                fromDown = true;
            }

            var toLeft  = false;
            var toUp    = false;
            var toRight = false;
            var toDown  = false;

            if (next.Column < crossroadLocation.Column)
            {
                toLeft = true;
            }
            else if (next.Row < crossroadLocation.Row)
            {
                toUp = true;
            }
            else if (next.Column > crossroadLocation.Column)
            {
                toRight = true;
            }
            else if (next.Row > crossroadLocation.Row)
            {
                toDown = true;
            }

            ITrafficData trafficData = null;

            if (fromLeft && toUp)
            {
                trafficData = crossroad.LeftToUpTrafficData;
            }
            else if (fromLeft && toRight)
            {
                trafficData = crossroad.LeftToRightTrafficData;
            }
            else if (fromLeft && toDown)
            {
                trafficData = crossroad.LeftToDownTrafficData;
            }
            else if (fromUp && toLeft)
            {
                trafficData = crossroad.UpToLeftTrafficData;
            }
            else if (fromUp && toDown)
            {
                trafficData = crossroad.UpToDownTrafficData;
            }
            else if (fromUp && toRight)
            {
                trafficData = crossroad.UpToRightTrafficData;
            }
            else if (fromRight && toUp)
            {
                trafficData = crossroad.RightToUpTrafficData;
            }
            else if (fromRight && toLeft)
            {
                trafficData = crossroad.RightToLeftTrafficData;
            }
            else if (fromRight && toDown)
            {
                trafficData = crossroad.RightToDownTrafficData;
            }
            else if (fromDown && toLeft)
            {
                trafficData = crossroad.DownToLeftTrafficData;
            }
            else if (fromDown && toUp)
            {
                trafficData = crossroad.DownToUpTrafficData;
            }
            else if (fromDown && toRight)
            {
                trafficData = crossroad.DownToRightTrafficData;
            }

            trafficData.TrafficDensity += trafficFlow.TrafficDensity;

            /*if (trafficData.TrafficDensity > 1.0)
             * {
             *  trafficData.TrafficDensity = 1.0;
             * }*/
            trafficData.TrafficSpeed *= trafficData.NofPassingTrafficFlows;
            trafficData.TrafficSpeed += trafficFlow.TrafficSpeed;
            trafficData.NofPassingTrafficFlows++;
            trafficData.TrafficSpeed /= trafficData.NofPassingTrafficFlows;
        }