/// <summary>
 /// constructor of BusStop
 /// </summary>
 public BusStop()
 {
     duration   = -1;
     distance   = 0;
     mylocation = new stopLocation();
 }
Exemple #2
0
        /// <summary>
        /// initialize a busCollection with 10 bus routs which contain at least 40 stops
        /// </summary>
        public static void initializeBusRoute(ref BusCollection myBusCollection, ref List <BusStop> myUniqueStops)
        {
            //BusCollection myBusCollection = new BusCollection();
            Random   r          = new Random();
            BusRoute myBusRoute = new BusRoute();

            BusRoute[] myRoutes = new BusRoute[Areas.Length];
            int        myRandom;

            ///////////////////////////////////////////
            ///     INITAILIZEING 40 STOPS
            //////////////////////////////////////////
            for (int i = 0; i < stopName.Length; i++)
            {
                myStops[i]             = new stopLocation();
                myStops[i].m_location  = stopName[i];
                myStops[i].m_longitude = r.Next(34, 36) + (float)(r.NextDouble() % 0.2 + 0.3);
                if (myStops[i].m_longitude < 35)
                {
                    myStops[i].m_longitude += (float)r.NextDouble();
                }
                myStops[i].m_latitude = r.Next(31, 34) + (float)(r.NextDouble() % 0.3);
                if (myStops[i].m_longitude < 33)
                {
                    myStops[i].m_longitude += (float)r.NextDouble();
                }
                do
                {
                    myStops[i].m_busStationKey = r.Next(10000000);
                } while (myBusCollection.keyExist(myStops[i].m_busStationKey));
            }
            ///////////////////////////////////////////
            ///     INITAILIZEING 10 BUS ROUTES
            //////////////////////////////////////////
            for (int i = 0; i < 10; i++)
            {
                myBusRoute = new BusRoute();

                myBusRoute = initializeBus(myBusRoute, myBusCollection, myUniqueStops);

                myBusCollection.addFirstBusRoute(myBusRoute);
            }
            ///////////////////////////////////////////
            ///     ALL STOP ARE USED CHECK
            //////////////////////////////////////////
            bool   addedNewBus = false;
            bool   foundFirst  = false;
            string last        = "";

            myBusRoute = new BusRoute();
            for (int i = 0; i < stopName.Length; i++)
            {
                if (notUseDStops[i] == 0)
                {
                    BusStop myNewStop = new BusStop();
                    myNewStop.m_mylocation.m_busStationKey = myStops[i].m_busStationKey;
                    myNewStop.m_mylocation.m_latitude      = myStops[i].m_latitude;
                    myNewStop.m_mylocation.m_location      = myStops[i].m_location;
                    myNewStop.m_mylocation.m_longitude     = myStops[i].m_longitude;
                    myNewStop.m_mylocation.m_location      = myStops[i].m_location;
                    addedNewBus = true;
                    notUseDStops[i]++;
                    myBusRoute.add(myNewStop, myBusRoute.m_Stations.Count());
                    last = myStops[i].m_location;
                    if (!foundFirst)
                    {
                        myBusRoute.m_FirstStation = last;
                        foundFirst = true;
                    }
                    if (!myBusCollection.keyExist(myStops[i].m_busStationKey))
                    {
                        myBusCollection.m_BusKeysList.Add(myStops[i].m_busStationKey);
                        myUniqueStops.Add(myNewStop);
                    }
                }
            }
            if (foundFirst)
            {
                myBusRoute.m_LastStation = last;
                myBusRoute.m_Area        = Areas[r.Next(Areas.Length)];
                do
                {
                    myBusRoute.m_BusLine = r.Next(1000);
                } while (myBusCollection.busLineExist(myBusRoute));
            }
            myBusCollection.addFirstBusRoute(myBusRoute);
            /////////////////////////////////////////////////
            //   10 STOPS ARE USED IN MORE THAN 1 BUS  LINE
            //////////////////////////////////////////////////

            BusRoute myNewRoute = new BusRoute();

            for (int i = 0; i < 10; i++)
            {
                if (notUseDStops[i] < 2)
                {
                    BusStop myNewStop = new BusStop();
                    myNewStop.m_mylocation.m_busStationKey = myStops[i].m_busStationKey;
                    myNewStop.m_mylocation.m_latitude      = myStops[i].m_latitude;
                    myNewStop.m_mylocation.m_location      = myStops[i].m_location;
                    myNewStop.m_mylocation.m_longitude     = myStops[i].m_longitude; notUseDStops[i]++;
                    myNewRoute.add(myNewStop, myNewRoute.m_Stations.Count());
                    if (!myBusCollection.keyExist(myStops[i].m_busStationKey))
                    {
                        myBusCollection.m_BusKeysList.Add(myStops[i].m_busStationKey);
                        myUniqueStops.Add(myNewStop);
                    }
                }
            }
        }