Esempio n. 1
0
        /// <summary>
        /// Constructor for the bus. 
        /// </summary>
        /// <param name="busID">ID of the bus</param>
        /// <param name="Routes">All the routes the bus can drive on. Is multiple routes when complex</param>
        /// <param name="uSpeed">Update speed</param>
        /// <param name="startDecending">Direction of the route. True = Last to first stop.</param>
        /// <param name="startingMinSpeed">Initial minimum speed of the bus</param>
        /// <param name="startingMaxSpeed">Initial maximum speed of the bus</param>
        /// <param name="randomize">True if the bus should have a random position on the route initially.</param>
        public Bus(int busID, List<BusRoute> Routes, int uSpeed, bool startDecending, int startingMinSpeed, int startingMaxSpeed, bool randomize)
        {
            
            routes = Routes;
            bID = busID;
            updateSpeed = uSpeed;
            //If complex, pick a route on random.
            initialRoute = Routes[SimulationConfig.rand.Next(0, routes.Count)];
            shouldRandomize = randomize;
            //If the bus should travel from first to last stop initially, flip the route.
            if (startDecending)
            {
                initialRoute.TurnAround();
            }
            //Update the current route and direction of the bus on the MySQL database.
            UpdateBusDB();

            maxSpeed = startingMaxSpeed;
            minSpeed = startingMinSpeed;
            
            //Set floating point for the bus thread to be "." instead of ",".
            gpsPosCalcThread = new Thread(new ThreadStart(gpsCalc));
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)gpsPosCalcThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";
            gpsPosCalcThread.CurrentCulture = customCulture;
            //Set the intial position of the bus on the route.
            SetInitialPos();
        }
Esempio n. 2
0
        public Bus(int busID, List<BusRoute> Routes, int uSpeed, bool startDecending, int startingMinSpeed, int startingMaxSpeed, bool randomize)
        {
            routes = Routes;
            bID = busID;
            updateSpeed = uSpeed;
            initialRoute = Routes[SimulationConfig.rand.Next(0, routes.Count)];
            shouldRandomize = randomize;
            if (startDecending)
            {
                initialRoute.TurnAround();
            }
            UpdateBusDB();

            maxSpeed = startingMaxSpeed;
            minSpeed = startingMinSpeed;

            gpsPosCalcThread = new Thread(new ThreadStart(gpsCalc));
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)gpsPosCalcThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";
            gpsPosCalcThread.CurrentCulture = customCulture;
            SetInitialPos();
        }
Esempio n. 3
0
        private void UpdateBus()
        {
            if (routes.Count == 1)
            {
                initialRoute.TurnAround();
                indexCounter = 0;
            }
            else
            {
                List<BusRoute> possibleRoutes;
                string oldRouteStop= initialRoute.stops[initialRoute.stops.Count - 1];
                string atStop = initialRoute.stops[initialRoute.stops.Count - 1];
                possibleRoutes = routes.FindAll(R => (R.stops[R.stops.Count - 1] == atStop) || R.stops[0] == atStop);

                if (possibleRoutes.Count == 1)
                {
                    initialRoute.TurnAround();
                }

                else
                {
                    possibleRoutes.Remove(initialRoute);
                    if (possibleRoutes.Count == 1)
                        initialRoute = possibleRoutes[0];
                    else
                        initialRoute = possibleRoutes[SimulationConfig.rand.Next(0, possibleRoutes.Count)];
                    if (initialRoute.stops[0] != atStop)
                    {
                        initialRoute.TurnAround();
                    }

                }
                indexCounter = 0;

            }
            UpdateBusDB();
        }
Esempio n. 4
0
        /// <summary>
        /// Update the route and direction the bus is driving here.
        /// </summary>
        private void UpdateBus()
        {
            //If simple route, simply flip the route, and reset the counter.
            if (routes.Count == 1)
            {
                initialRoute.TurnAround();
                indexCounter = 0;
            }
            //Otherwise pick a route on random from the list, where it cant be this route, unless its the only one possible.
            else
            {
                List<BusRoute> possibleRoutes;
                //The name of the stop, the bus is at at the moment.
                string atStop = initialRoute.stops[initialRoute.stops.Count - 1];
                //Find all possible routes where this stop is either of final stations.
                possibleRoutes = routes.FindAll(R => (R.stops[R.stops.Count - 1] == atStop) || R.stops[0] == atStop);

                //If only one remains it can only be the current route, and so reverse it
                if (possibleRoutes.Count == 1)
                {
                    initialRoute.TurnAround();
                }

                else
                {
                    //Otherwise remove the old route, and pick a new one.
                    possibleRoutes.Remove(initialRoute);
                    //If only one remains pick this.
                    if (possibleRoutes.Count == 1)
                        initialRoute = possibleRoutes[0];
                    //Otherwise pick one at random.
                    else
                        initialRoute = possibleRoutes[SimulationConfig.rand.Next(0, possibleRoutes.Count)];
                    //If the first stop on the route is not the same as the stop the bus is at, flip the route.
                    if (initialRoute.stops[0] != atStop)
                    {
                        initialRoute.TurnAround();
                    }   

                }
                indexCounter = 0;   
               
            }
            //Update the configurations of the bus on the database.
            UpdateBusDB();
        }