Exemple #1
0
        /*
         *  Reads how the distribution of passenger arrival rates over time per station.
         */
        private void ReadPassDensity(int dir, string filename)
        {
            List <int>    times = new List <int>();
            List <double> rates = new List <double>();

            StreamReader file = new StreamReader(FOLDER + filename);

            file.ReadLine(); //get rid of comment line;
            string line;

            string[] words;
            while ((line = file.ReadLine()) != null)
            {
                if (line.Length == 0)
                {
                    continue;
                }
                words = line.Split(',');
                times.Add(Time.ConvertFromString(words[0]) - StartTime);
                rates.Add(double.Parse(words[2], System.Globalization.NumberStyles.Float));
            }
            if (dir == 0)
            {
                PassDens_0 = new TimeDistr(times.ToArray(), rates.ToArray());
            }
            if (dir == 1)
            {
                PassDens_1 = new TimeDistr(times.ToArray(), rates.ToArray());
            }
        }
Exemple #2
0
        /*
         *  Reads the scheduled times of how many trams leave per hour.
         */
        private void ReadSchedule(string line)
        {
            int start = 0;
            int end   = 0;

            for (int i = 0; i < line.Length; i++)
            {
                if (line[i] == '/')
                {
                    break;
                }
                if (line[i] == '{')
                {
                    start = i + 1;
                }
                if (line[i] == '}')
                {
                    end = i - 1;
                }
            }

            string datastring = line.Substring(start, end - start + 1);

            string[] pairs = datastring.Split(';');
            int[]    times = new int[pairs.Length];
            double[] rates = new double[pairs.Length];
            string[] pair;

            for (int i = 0; i < pairs.Length; i++)
            {
                pair     = pairs[i].Split(',');
                times[i] = Time.ConvertFromString(pair[0]) - StartTime;
                double trams = Double.Parse(pair[1]);

                rates[i] = trams;
            }

            TramSchedule = new TimeDistr(times, rates);
        }
Exemple #3
0
        /*
         *  Reads the passenger arrival distribution over time file.
         *  Note: see note at ReadExitDistr
         */
        private void ReadStationDistr(string filename)
        {
            if (EXPLICIT)
            {
                Console.WriteLine("Reading distribution data");
                if (WAIT)
                {
                    Console.ReadLine();
                }
            }
            TimeDistr[]  stationdistrs = new TimeDistr[Stations.Length];
            StreamReader data          = new StreamReader(FOLDER + filename);
            string       line          = data.ReadLine(); //read time data on these lines;

            string[] words = line.Split(',');
            int[]    times = new int[words.Length - 1];
            for (int i = 0; i < times.Length; i++)
            {
                times[i] = Time.ConvertFromString(words[i + 1]) - StartTime;
            }
            while ((line = data.ReadLine()) != null)
            {
                if (line.Length == 0)
                {
                    continue;
                }
                //find the right station.
                words = splitLine(line, ',');
                int pos = -1;
                for (int i = 0; i < Stations.Length; i++)
                {
                    if (Stations[i] == words[0])
                    {
                        pos = i;
                        break;
                    }
                }
                if (pos == -1)
                {
                    Console.WriteLine("Error in StationRates: found station not in Stations list. Check spelling.");
                    Console.ReadLine(); Environment.Exit(1);
                }

                double[] rates = new double[times.Length];
                //read distribution data
                for (int i = 1; i < words.Length; i++)   //NOTE: stating at i = 1 because first word is the station name
                {
                    rates[i - 1] = Double.Parse(words[i]);
                }
                stationdistrs[pos] = new TimeDistr(times, rates);
            }
            for (int i = 0; i < stationdistrs.Length; i++)
            {
                if (stationdistrs[i] == null)
                {
                    Console.WriteLine("Data missing from StationRates from station " + Stations[i] + ". Check files.");
                    Console.ReadLine(); Environment.Exit(1);
                }
            }
            PassInrates = stationdistrs;
        }
Exemple #4
0
        /*
         *  Function which reads all parameters given in initfile.ini. Passes on density fiels to their respective functions.
         */
        private void ReadParams(StreamReader initfile)
        {
            string line;

            while ((line = initfile.ReadLine()) != "END_PARAMS")
            {
                if (line.Length == 0)
                {
                    continue;
                }
                string[] words = splitLine(line);
                switch (words[0])
                {
                case "start_time":
                    StartTime = Time.ConvertFromString(words[1]);
                    break;

                case "end_time":
                    EndTime = Time.ConvertFromString(words[1]) - StartTime;
                    break;

                case "runs":
                    Runs = Int32.Parse(words[1]);
                    break;

                case "trams":
                    NoTrams = Int32.Parse(words[1]);
                    break;

                case "trams_hour":
                    ReadSchedule(line);
                    break;

                case "seed":
                    SEED = Int32.Parse(words[1]);
                    break;

                case "pass_0":
                    PassDir0 = Int32.Parse(words[1]);
                    break;

                case "pass_1":
                    PassDir1 = Int32.Parse(words[1]);
                    break;

                case "dir0_density":
                    ReadPassDensity(0, words[1]);
                    break;

                case "dir1_density":
                    ReadPassDensity(1, words[1]);
                    break;

                case "maxpasstram":
                    MaxPassTram = Int32.Parse(words[1]);
                    break;

                case "batchname":
                    BATCHNAME = words[1];
                    break;

                case "perstationleeway":
                    PerStationLeeway = Int32.Parse(words[1]);
                    break;

                default:
                    Console.WriteLine("Parameter " + words[0] + " not recognized. Error found, quitting.");
                    Console.ReadLine(); Environment.Exit(1);
                    break;
                }
            }
        }