Esempio n. 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());
            }
        }
        public Station(string name, TimeDistr inrate, TimeDistr outrate, TimeDistr indens, int pass,
                       double driveavg, double drivevar, string datafolder, Simulation sim)
        {
            if (Simulation.EXPLICIT)
            {
                Console.WriteLine("Initialising station " + name);
                if (Simulation.WAIT)
                {
                    Console.ReadLine();
                }
            }
            Name           = name;
            Spaces         = new Tram[1];
            lastpassupdate = 0;
            PassWaiting    = 0;
            lastDeparture  = 0;
            TotalIn        = 0;
            TotalOut       = 0;
            DriveAvg       = driveavg;
            DriveVar       = drivevar;
            Sim            = sim;


            //reformulate distributions for incoming passengers to something sensible
            int[]    times      = indens.getTimes();
            double[] passengers = new double[times.Length];
            for (int i = 0; i < passengers.Length; i++)
            {
//                if (Simulation.EXPLICIT) Console.WriteLine("Calculating passengers at time " + times[i].ToString());
                passengers[i] = Convert.ToDouble(pass) * inrate.getRate(times[i]) * indens.getRate(times[i]);
//                if (Simulation.EXPLICIT) Console.WriteLine("Passengers from time " + times[i].ToString() + " : " + passengers[i].ToString());
            }
            PassArrival = new TimeDistr(times, passengers);

            PassArrival.WriteToFile(datafolder + Name + "PassDistr.csv");

            PassOut = outrate;

            logPassengersWaiting = new StreamWriter(datafolder + Name + "PassWaiting.csv");
            logPassengersWaiting.WriteLine("Time , Passengers waiting, passengers in tram");
            logInterDepartureTime = new StreamWriter(datafolder + Name + "IntDepTime.csv");
            logInterDepartureTime.WriteLine("Time , time since last Departure");
            logTramsWaiting = new StreamWriter(datafolder + Name + "TramsWaiting.csv");
            logTramsWaiting.WriteLine("Time , trams waiting , trams at station");
            logWaitingtime = new StreamWriter(datafolder + Name + "WaitingTime.csv");
            logWaitingtime.WriteLine("Time , passengers already waiting , time last departure , new passengers , time since last passenger update , passengers waiting after loading");
            logDwelltime = new StreamWriter(datafolder + name + "Dwelltime.csv");
            logDwelltime.WriteLine("Time , dwelltime of departing tram");
        }
Esempio n. 3
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);
        }
        /*
            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());
        }
        /*
            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);
        }
        /*
            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;
            
        }
Esempio n. 7
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;
        }
        public Endstation(string name, bool depot, int maxtrams, TimeDistr inrate, TimeDistr outrate,
                          TimeDistr indens, int pass, double driveavg, double drivevar, TimeDistr schedule,
                          int timefromstrt, string datafolder, Simulation sim)
            : base(name, inrate, outrate, indens, pass, driveavg, drivevar, datafolder, sim)
        {
            if (Simulation.EXPLICIT)
            {
                Console.WriteLine("Initialising Endstation " + name);
                if (Simulation.WAIT)
                {
                    Console.ReadLine();
                }
            }
            Spaces   = new Tram[2];
            raillock = new bool[2];
            if (depot)
            {
                this.depot = new Tram[maxtrams];
            }
            Name     = name;
            Dweltime = 4 * 60;  //Parameterize this.
            //counter = 0;

            logPunctuality = new StreamWriter(datafolder + Name + "Punctuality.csv");
            logPunctuality.WriteLine("Time , Deviation from schedule");

            //create schedule
            int[]    periods   = schedule.getTimes();
            double[] intensity = schedule.getRates();

            if (Simulation.EXPLICIT)
            {
                Console.WriteLine("Creating timetable at Endstation " + name);
                if (Simulation.WAIT)
                {
                    Console.ReadLine();
                }
            }
            Queue <int> temptable = new Queue <int>();

            for (int i = 0; i < periods.Length; i++)
            {
                if ((i + 1 == periods.Length + timefromstrt) || (intensity[i] == 0.0))
                {
                    if (Simulation.EXPLICIT)
                    {
                        Console.WriteLine("Scheduled leaving of tram at " + (periods[i] + timefromstrt).ToString());
                    }
                    temptable.Enqueue(periods[i] + timefromstrt);
                    continue;
                }
                int next = periods[i] + timefromstrt;

                int intdeptime = Convert.ToInt32(3600.0 / intensity[i]);
                while (next < periods[i + 1] + timefromstrt)
                {
                    if (Simulation.EXPLICIT)
                    {
                        Console.WriteLine("Scheduled event leaving at " + next.ToString());
                    }

                    temptable.Enqueue(next);
                    next += intdeptime;
                }
            }

            timetable = temptable.ToArray();
            StreamWriter logTimeSchedule = new StreamWriter(datafolder + Name + "schedule.txt");

            foreach (int i in timetable)
            {
                logTimeSchedule.WriteLine(i.ToString());
            }

            usedtimes = new bool[timetable.Length];
            for (int i = 0; i < usedtimes.Length; i++)
            {
                usedtimes[i] = false;
            }
            logTimeSchedule.Close();
        }
        public Endstation (string name, bool depot, int maxtrams, TimeDistr inrate, TimeDistr outrate, 
                           TimeDistr indens, int pass, double driveavg, double drivevar, TimeDistr schedule,
                           int timefromstrt, string datafolder, Simulation sim ) 
                           : base(name,inrate,outrate,indens, pass, driveavg, drivevar, datafolder, sim) {
            if (Simulation.EXPLICIT) {
                Console.WriteLine("Initialising Endstation " + name);
                if (Simulation.WAIT) Console.ReadLine();
            } 
            Spaces = new Tram[2];
            raillock = new bool[2];
            if (depot) this.depot = new Tram[maxtrams];
            Name = name;
            Dweltime = 4* 60;  //Parameterize this.
            //counter = 0;

            logPunctuality = new StreamWriter(datafolder + Name + "Punctuality.csv");
            logPunctuality.WriteLine("Time , Deviation from schedule");

            //create schedule
            int[] periods = schedule.getTimes();
            double[] intensity = schedule.getRates();

            if (Simulation.EXPLICIT) {
                Console.WriteLine("Creating timetable at Endstation " + name);
                if (Simulation.WAIT) Console.ReadLine();
            } 
            Queue<int> temptable = new Queue<int>();

            for (int i = 0; i < periods.Length ; i++) {
                if ( (i+1 == periods.Length + timefromstrt) || (intensity[i] == 0.0) ){
                    if (Simulation.EXPLICIT) Console.WriteLine("Scheduled leaving of tram at " + (periods[i]+ timefromstrt).ToString() );
                    temptable.Enqueue(periods[i] + timefromstrt);
                    continue;
                }
                int next = periods[i] + timefromstrt;
                
                int intdeptime = Convert.ToInt32( 3600.0/intensity[i]);
                while (next < periods[i+1] + timefromstrt) {
                    if (Simulation.EXPLICIT) Console.WriteLine("Scheduled event leaving at " + next.ToString() );

                    temptable.Enqueue(next);
                    next += intdeptime;
                }
            }

            timetable = temptable.ToArray();
            StreamWriter logTimeSchedule = new StreamWriter(datafolder + Name + "schedule.txt");
            
            foreach (int i in timetable) {
                logTimeSchedule.WriteLine(i.ToString());
            }

            usedtimes = new bool[timetable.Length];
            for (int i = 0; i < usedtimes.Length; i++) {
                usedtimes[i] = false;
            }
            logTimeSchedule.Close();

        }
        public Station (string name, TimeDistr inrate, TimeDistr outrate, TimeDistr indens, int pass, 
                        double driveavg, double drivevar, string datafolder, Simulation sim) { 
            if (Simulation.EXPLICIT) {
                Console.WriteLine("Initialising station " + name);
                if (Simulation.WAIT) Console.ReadLine();
            } 
            Name = name;
            Spaces = new Tram[1];
            lastpassupdate = 0;
            PassWaiting = 0;
            lastDeparture = 0;
            TotalIn = 0;
            TotalOut = 0;
            DriveAvg = driveavg;
            DriveVar = drivevar;
            Sim = sim;


            //reformulate distributions for incoming passengers to something sensible
            int[] times = indens.getTimes();
            double[] passengers = new double[times.Length];
            for (int i = 0; i < passengers.Length; i++) {
//                if (Simulation.EXPLICIT) Console.WriteLine("Calculating passengers at time " + times[i].ToString());
                passengers[i] = Convert.ToDouble(pass) * inrate.getRate(times[i]) * indens.getRate(times[i]);
//                if (Simulation.EXPLICIT) Console.WriteLine("Passengers from time " + times[i].ToString() + " : " + passengers[i].ToString());
            }
            PassArrival = new TimeDistr(times, passengers);

            PassArrival.WriteToFile(datafolder+Name+"PassDistr.csv");

            PassOut = outrate;
    
            logPassengersWaiting = new StreamWriter(datafolder + Name + "PassWaiting.csv");
            logPassengersWaiting.WriteLine("Time , Passengers waiting, passengers in tram");
            logInterDepartureTime = new StreamWriter(datafolder + Name + "IntDepTime.csv");
            logInterDepartureTime.WriteLine("Time , time since last Departure");
            logTramsWaiting = new StreamWriter(datafolder + Name + "TramsWaiting.csv");
            logTramsWaiting.WriteLine("Time , trams waiting , trams at station");
            logWaitingtime = new StreamWriter(datafolder + Name + "WaitingTime.csv");
            logWaitingtime.WriteLine("Time , passengers already waiting , time last departure , new passengers , time since last passenger update , passengers waiting after loading");
            logDwelltime = new StreamWriter(datafolder + name + "Dwelltime.csv");
            logDwelltime.WriteLine("Time , dwelltime of departing tram");

        }