Exemple #1
0
        public static void AddCrossing(eTrack track1, eTrack track2, double length, double pos1, double pos2)
        {
            string id1 = DataContainer.IDGenerator("Connection");
            string id2 = DataContainer.IDGenerator("Connection");
            string id3 = DataContainer.IDGenerator("Connection");
            string id4 = DataContainer.IDGenerator("Connection");

            tConnectionData switchtotrack1 = new tConnectionData()
            {
                id = id1, @ref = id2
            };
            tSwitchConnectionData track1toswitch = new tSwitchConnectionData()
            {
                id = id2, @ref = id1
            };
            tConnectionData switchtotrack2 = new tConnectionData()
            {
                id = id3, @ref = id4
            };
            tSwitchConnectionData track2toswitch = new tSwitchConnectionData()
            {
                id = id4, @ref = id3
            };

            eTrack track = new eTrack()
            {
                id = DataContainer.IDGenerator("track")
            };

            track.trackTopology.trackBegin.pos  = 0;
            track.trackTopology.trackEnd.pos    = (decimal)length;
            track.trackTopology.trackBegin.Item = switchtotrack1;
            track.trackTopology.trackEnd.Item   = switchtotrack2;
            DataContainer.model.infrastructure.tracks.Add(track);

            eSwitch switch1 = new eSwitch()
            {
                pos = (decimal)pos1, id = DataContainer.IDGenerator("Switch")
            };

            switch1.connection.Add(track1toswitch);
            track1.trackTopology.connections.Add(switch1);
            eSwitch switch2 = new eSwitch()
            {
                pos = (decimal)pos2, id = DataContainer.IDGenerator("Switch")
            };

            switch1.connection.Add(track2toswitch);
            track2.trackTopology.connections.Add(switch2);
        }
Exemple #2
0
        public static void ConnectEnd(eTrack track1, eTrack track2)
        {
            string id1 = DataContainer.IDGenerator("connection");
            string id2 = DataContainer.IDGenerator("connection");

            tConnectionData connection1 = new tConnectionData()
            {
                id = id1, @ref = id2
            };
            tConnectionData connection2 = new tConnectionData()
            {
                id = id2, @ref = id1
            };

            track1.trackTopology.trackEnd.Item   = connection1;
            track2.trackTopology.trackBegin.Item = connection2;
        }
Exemple #3
0
        private static eSwitch FindConnections(eSwitch tempswitch)
        {
            Point  switchlocation = new Point(tempswitch.geoCoord.coord[0], tempswitch.geoCoord.coord[1]);
            eTrack hostline       = null;
            eTrack track2         = null;
            bool   trackend       = false;

            while (track2 == null)
            {
                eTrack besttrack = null;
                double bestdist  = 999999999999;

                foreach (eTrack track in DataContainer.model.infrastructure.tracks)
                {
                    double dist = GetDistance(switchlocation, new Point(track.trackTopology.trackBegin.geoCoord.coord[0], track.trackTopology.trackBegin.geoCoord.coord[1]));
                    if (dist < bestdist)
                    {
                        bestdist = dist; besttrack = track; trackend = false;
                    }
                    dist = GetDistance(switchlocation, new Point(track.trackTopology.trackEnd.geoCoord.coord[0], track.trackTopology.trackEnd.geoCoord.coord[1]));
                    if (dist < bestdist)
                    {
                        bestdist = dist; besttrack = track; trackend = true;
                    }
                }
                track2 = besttrack;
            }
            while (hostline == null)
            {
                eTrack besttrack = null;
                double bestdist  = 99999999999;

                foreach (eTrack track in DataContainer.model.infrastructure.tracks)
                {
                    if (track == track2)
                    {
                        continue;
                    }
                    List <Point> pointlist = NodeList(track);
                    for (int i = 0; i < pointlist.Count - 1; i++)
                    {
                        double dist = GetDistance(pointlist[i], pointlist[i + 1], switchlocation);
                        if (dist < bestdist)
                        {
                            bestdist = dist; besttrack = track;
                        }
                    }
                }
                hostline = besttrack;
            }

            tConnectionData conn1 = new tConnectionData();

            DataContainer.IDGenerator(conn1);
            tSwitchConnectionData conn2 = new tSwitchConnectionData();

            DataContainer.IDGenerator(conn2);
            conn1.@ref = conn2.id; conn2.@ref = conn1.id;
            if (trackend == true)
            {
                track2.trackTopology.trackEnd.Item = conn1;
            }
            else
            {
                track2.trackTopology.trackBegin.Item = conn1;
            }
            tempswitch.connection.Add(conn2);
            hostline.trackTopology.connections.Add(tempswitch);
            string[] orientation = GetOrientation(hostline, track2, tempswitch);
            tempswitch.connection[0].orientation = orientation[0];
            tempswitch.connection[0].course      = orientation[1];

            return(tempswitch);
        }
Exemple #4
0
        private static eOperatingPeriod CreateOperatingPeriod(List <DateTime> dates)
        {
            eOperatingPeriod opperiod = new eOperatingPeriod();

            DataContainer.IDGenerator(opperiod);
            DateTime         startdate = DateTime.MaxValue;
            DateTime         enddate   = DateTime.MinValue;
            List <DayOfWeek> dayindex  = Enum.GetValues(typeof(DayOfWeek)).Cast <DayOfWeek>().ToList();

            int[] days = new int[7] {
                0, 0, 0, 0, 0, 0, 0
            };
            foreach (DateTime date in dates)
            {
                if (date < startdate)
                {
                    startdate = date;
                }
                if (date > enddate)
                {
                    enddate = date;
                }
                //days[dayindex.IndexOf(date.DayOfWeek)]++;
            }
            //var missing = startdate.Range(enddate).Except(dates);
            //var exclude = new List<DateTime>();
            //foreach (DateTime missingdate in missing)
            //{
            //    if (days[dayindex.IndexOf(missingdate.DayOfWeek)] == 0)
            //    {
            //        exclude.Add(missingdate);
            //    }
            //}
            //missing = missing.Except(exclude);
            //string operatingcode = "";
            //foreach (int c in days)
            //{
            //    if (c > 0) { operatingcode += "1"; }
            //    else { operatingcode += "0"; }
            //}
            //eOperatingDay opday = new eOperatingDay() { startDate = startdate, endDate = enddate, operatingCode = operatingcode };
            //opperiod.operatingDay.Add(opday);
            //foreach (DateTime missingdate in missing)
            //{
            //    tSpecialService specialservice = new tSpecialService() { type = tSpecialServiceType.exclude, singleDate = missingdate };
            //    opperiod.specialService.Add(specialservice);
            //}
            DateTime tempdate = startdate;
            int      j        = 0;
            string   bitmask  = "";

            for (int i = 0; i < ((enddate - startdate).TotalDays + 1); i++)
            {
                if (dates[j] == tempdate)
                {
                    bitmask += "1"; j++;
                }
                else
                {
                    bitmask += "0";
                }
                tempdate = tempdate.AddDays(1);
            }
            opperiod.bitMask   = bitmask;
            opperiod.startDate = startdate;
            opperiod.endDate   = enddate;

            return(opperiod);
        }
Exemple #5
0
        public static void TimetableFromCsv(object sender, DoWorkEventArgs e)
        {
            DateTime ThresholdDate = new DateTime(2010, 1, 1);

            if (DataContainer.model == null)
            {
                DataContainer.model = new railml();
            }
            DataContainer.model.timetable = new timetable();
            Dictionary <string, int> categories = new Dictionary <string, int>();
            string           filename           = e.Argument as string;
            BackgroundWorker worker             = sender as BackgroundWorker;

            CsvDefinition def = new CsvDefinition()
            {
                FieldSeparator = ','
            };
            CsvFileReader <TimetableEntry> reader = new CsvFileReader <TimetableEntry>(filename, def);
            int              count      = 0;
            RuntimeRep       rep        = new RuntimeRep();
            List <StopDelay> stopdelays = new List <StopDelay>();
            string           traincode  = "";

            foreach (TimetableEntry entry in reader)
            {
                if (entry.TrainDate < ThresholdDate)
                {
                    count++; continue;
                }



                string category = entry.TrainOrigin + "to" + entry.TrainDestination;
                if (categories.ContainsKey(category))
                {
                    categories[category] = (int)categories[category] + 1;
                }
                else
                {
                    categories.Add(category, 1);
                    //eCategory cat = new eCategory();
                    //cat.id = category;
                    //cat.name = category;
                    //DataContainer.model.timetable.categories.Add(cat);
                    //eRostering roster = new eRostering();
                    //DataContainer.IDGenerator(roster);
                    //roster.name = category;
                    //DataContainer.model.timetable.rosterings.Add(roster);
                }

                if (entry.TrainDate != date || entry.TrainCode != traincode)
                {
                    AddStopDelays(stopdelays, traincode, date);
                    stopdelays = new List <StopDelay>();
                    if (rep.traincode != null)
                    {
                        trainvariations.AddRep(rep, date);
                    }
                    if (entry.TrainCode != traincode)
                    {
                        if (trainvariations != null)
                        {
                            string cat = categories.FirstOrDefault(x => x.Value == categories.Values.Max()).Key;
                            trainvariations.category = cat;
                            categories = new Dictionary <string, int>();
                            if (!DataContainer.model.timetable.rosterings.Any(x => x.name == cat))
                            {
                                eRostering roster = new eRostering()
                                {
                                    name  = cat,
                                    scope = "scheduled"
                                };
                                DataContainer.IDGenerator(roster);
                                DataContainer.model.timetable.rosterings.Add(roster);
                            }
                            ProcessTimetableVariations(trainvariations);
                        }
                        trainvariations           = new TrainVariations();
                        trainvariations.traincode = entry.TrainCode;
                        worker.ReportProgress(0, new string[] { traincode, count.ToString() });
                        traincode = entry.TrainCode;
                    }

                    rep             = new RuntimeRep();
                    date            = entry.TrainDate;
                    rep.traincode   = entry.TrainCode;
                    rep.destination = entry.TrainDestination;
                    rep.origin      = entry.TrainOrigin;
                }

                if (entry.LocationType == "O")
                {
                    rep.departuretime = default(DateTime).Add(entry.ScheduledDeparture.TimeOfDay);
                }
                else if (entry.LocationType == "D")
                {
                    rep.arrivaltime = default(DateTime).Add(entry.ScheduledArrival.TimeOfDay);
                }
                else if (entry.LocationType == "S")
                {
                    Stop stop = new Stop()
                    {
                        location = entry.LocationCode, arrival = entry.ScheduledArrival, departure = entry.ScheduledDeparture
                    };
                    rep.stops.Add(stop);
                    if (entry.Arrival != default(DateTime) && entry.Departure != default(DateTime))
                    {
                        StopDelay delay = new StopDelay()
                        {
                            location = entry.LocationCode, departuredelay = (entry.Departure - entry.ScheduledDeparture).TotalSeconds, arrivaldelay = (entry.Arrival - entry.ExpectedArrival).TotalSeconds
                        };
                        stopdelays.Add(delay);
                    }
                }

                //if (count > 300000) { break; }
                count++;
            }
            // Append the last trainvariation to the totalvariations list
            if (trainvariations != null)
            {
                string cat = categories.FirstOrDefault(x => x.Value == categories.Values.Max()).Key;
                trainvariations.category = cat;
                categories = new Dictionary <string, int>();
                ProcessTimetableVariations(trainvariations);
                if (!DataContainer.model.timetable.rosterings.Any(x => x.name == cat))
                {
                    eRostering roster = new eRostering()
                    {
                        name  = cat,
                        scope = "scheduled"
                    };
                    DataContainer.IDGenerator(roster);
                    DataContainer.model.timetable.rosterings.Add(roster);
                }
            }

            e.Result = unhandled;
        }
Exemple #6
0
        private static void ProcessTimetableVariations(TrainVariations variations)
        {
            eTrain train = new eTrain();

            train.id          = variations.traincode;
            train.description = variations.category;
            train.scope       = tTrainScope.primary;
            List <eTrainPart> trainparts = new List <eTrainPart>();

            for (int i = 0; i < variations.dates.Count; i++)
            {
                try
                {
                    eTrainPart trainpart = new eTrainPart()
                    {
                        id = train.id + "-" + i.ToString()
                    };

                    var operatingperiod = CreateOperatingPeriod(variations.dates[i]);
                    trainpart.operatingPeriodRef = new eOperatingPeriodRef()
                    {
                        @ref = operatingperiod.id
                    };
                    DataContainer.model.timetable.operatingPeriods.Add(operatingperiod);
                    eOcpTT departure = new eOcpTT()
                    {
                        ocpRef = DataContainer.model.infrastructure.operationControlPoints.Single(x => x.code == variations.reps[i].origin).id
                    };
                    departure.times.Add(new eArrivalDepartureTimes()
                    {
                        departure = variations.reps[i].departuretime, scope = "scheduled"
                    });
                    trainpart.ocpsTT.Add(departure);
                    foreach (Stop stop in variations.reps[i].stops)
                    {
                        eOcpTT ocp = new eOcpTT()
                        {
                            ocpRef = DataContainer.model.infrastructure.operationControlPoints.Single(x => x.code == stop.location).id
                        };
                        ocp.times.Add(new eArrivalDepartureTimes()
                        {
                            arrival = stop.arrival, departure = stop.departure, scope = "scheduled"
                        });
                        trainpart.ocpsTT.Add(ocp);
                    }
                    eOcpTT arrival = new eOcpTT()
                    {
                        ocpRef = DataContainer.model.infrastructure.operationControlPoints.Single(x => x.code == variations.reps[i].destination).id
                    };
                    arrival.times.Add(new eArrivalDepartureTimes()
                    {
                        arrival = variations.reps[i].arrivaltime, scope = "scheduled"
                    });
                    trainpart.ocpsTT.Add(arrival);
                    trainparts.Add(trainpart);

                    tBlockPart blockpart = new tBlockPart()
                    {
                        trainPartRef       = trainpart.id,
                        startOcpRef        = variations.reps[i].origin,
                        endOcpRef          = variations.reps[i].destination,
                        operatingPeriodRef = operatingperiod.id,
                        begin = variations.reps[i].departuretime,
                        end   = variations.reps[i].arrivaltime
                    };
                    DataContainer.IDGenerator(blockpart);
                    eRostering roster = DataContainer.model.timetable.rosterings.Single(e => e.name == variations.category);
                    roster.blockParts.blockPart.Add(blockpart);
                    eBlock block = new eBlock()
                    {
                        code = train.id
                    };
                    DataContainer.IDGenerator(block);
                    eBlockPartSequence seq = new eBlockPartSequence()
                    {
                        sequence = "1"
                    };
                    seq.blockPartRef.Add(new tBlockPartRef()
                    {
                        @ref = blockpart.id
                    });
                    block.blockPartSequence.Add(seq);
                    roster.blocks.Add(block);
                    tCirculation circ = new tCirculation()
                    {
                        startDate          = operatingperiod.startDate,
                        endDate            = operatingperiod.endDate,
                        operatingPeriodRef = operatingperiod.id,
                        blockRef           = block.id
                    };
                    roster.circulations.Add(circ);
                }
                catch
                {
                    unhandled++;
                }
            }

            for (int i = 0; i < trainparts.Count; i++)
            {
                eTrainPartSequence seq = new eTrainPartSequence()
                {
                    sequence = i.ToString()
                };
                seq.trainPartRef.Add(new tTrainPartRef()
                {
                    @ref = trainparts[i].id
                });
                train.trainPartSequence.Add(seq);
            }
            DataContainer.model.timetable.trains.Add(train);
            DataContainer.model.timetable.trainParts.AddRange(trainparts);
        }