Exemplo n.º 1
0
        private List <int> GenerateTripIdList()
        {
            var stopTimesPath =
                Path.Combine(_baseDirectoryPath, @"Data Files\stop_times.txt"); // files from google transit (GTFS file)

            if (!File.Exists(stopTimesPath))
            {
                Console.WriteLine(this + " Error! File stop_times.txt does not exist!");
                return(null);
            }
            else
            {
                FileDataReader fdr           = new FileDataReader();
                var            stopTimesData = fdr.ImportData(stopTimesPath, ',', true);
                var            tripsIdList   = new List <int>();
                foreach (var singleData in stopTimesData)
                {
                    if (!tripsIdList.Contains(int.Parse(singleData[0])))
                    {
                        tripsIdList.Add(
                            int.Parse(singleData[0])); //adds the trip_id if it doesn't exist yet in trips_id_list
                    }
                }
                return(tripsIdList);
            }
        }
Exemplo n.º 2
0
        private List <string[]> GenerateListData(string path)
        {
            List <string[]> listData = null;

            if (!File.Exists(path))
            {
                Console.WriteLine(this + " Error! File at " + path + " does not exist!");
            }
            else
            {
                FileDataReader fdr = new FileDataReader();
                listData = fdr.ImportData(path, ',', true);
            }

            return(listData);
        }
Exemplo n.º 3
0
        private void Load()
        {
            var watch = Stopwatch.StartNew();

            Console.WriteLine(this + "Loading all the necessary data...");
            Console.WriteLine(this + "Urban routes only:" + _urbanOnly);
            _baseDirectoryPath = Directory
                                 .GetParent(Directory.GetParent(Directory.GetParent(Environment.CurrentDirectory).FullName).FullName)
                                 .FullName;
            var stopsPath     = Path.Combine(_baseDirectoryPath, @"Data Files\stops.txt");  //files from google transit (GTFS file)
            var routesPath    = Path.Combine(_baseDirectoryPath, @"Data Files\routes.txt"); //files from google transit (GTFS file)
            var demandsPath   = Path.Combine(_baseDirectoryPath, @"Data Files\demands.csv");
            var stopTimesPath =
                Path.Combine(_baseDirectoryPath, @"Data Files\stop_times.txt"); // files from google transit (GTFS file)
            string tripsPath     = Path.Combine(_baseDirectoryPath, @"Data Files\trips.txt");
            var    tripStopsPath =
                Path.Combine(_baseDirectoryPath, @"Data Files\trip_stops.txt"); //file generated from stop_times.txt and stop.txt
            var routesData = GenerateListData(routesPath);

            LoadRoutes(routesData);
            var tripsData = GenerateListData(tripsPath);

            LoadTrips(tripsData);
            var stopsData = GenerateListData(stopsPath);

            LoadStops(stopsData);
            var demandsData               = GenerateListData(demandsPath);
            var stopTimesDataList         = GenerateListData(stopTimesPath);
            FileDataExporter dataExporter = new FileDataExporter();

            if (!File.Exists(tripStopsPath)
                ) //if the file doesn't exists, generate the dictionary required to sort the stops in ascending order then export to txt, then reads from the txt the next time the program is executed (to save computational time)
            {
                var tripsStopTupleDictionary = GenerateTripStopTuplesDictionary(stopTimesDataList);
                dataExporter.ExportTripStops(tripsStopTupleDictionary, tripStopsPath);
            }
            FileDataReader fdr           = new FileDataReader();
            var            tripsStopData = fdr.ImportData(tripStopsPath, ',', true);

            LoadStopsIntoTrips(tripsStopData);
            LoadTripStartTimes(tripsStopData);
            AssignUrbanStops();
            //dataExporter.ExportStops(Stops, Path.Combine(Environment.CurrentDirectory, @"stops.txt"));
            //dataExporter.ExportTrips(Routes, Path.Combine(Environment.CurrentDirectory, @"trips.txt"));
            //dataExporter.ExportTripStopSequence(Routes, Path.Combine(Environment.CurrentDirectory, @"trip_stops.txt"));
            //dataExporter.ExportTripStartTimes(Routes, Path.Combine(Environment.CurrentDirectory, @"trip_start_times.txt"));
            if (_urbanOnly)
            {
                Routes = Routes.FindAll(r => r.UrbanRoute);              // only urban routes
                Trips  = Trips.FindAll(t => t.Route.UrbanRoute == true); // only urban trips
                Stops  = Stops.FindAll(s => s.IsUrban);                  //only urban stops
            }

            LoadStopDemands(demandsData);
            RemoveDuplicateTrips();
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine(this + "All the necessary data was successfully generated in " + elapsedMs * 0.001 + " seconds.");
            string str;

            str = _urbanOnly ? "Urban " : "";
            Console.WriteLine(this + "Total of " + str + "Routes:" + Routes.Count);
            Console.WriteLine(this + "Total of " + str + "Route Trips:" + Routes.Sum(r => r.Trips.Count));
            Console.WriteLine(this + "Total of " + str + "Stops:" + Stops.Count);
        }