コード例 #1
0
ファイル: XMLStationsImport.cs プロジェクト: FPLedit/FPLedit
        public Timetable Import(Stream stream, IReducedPluginInterface pluginInterface, ILog replaceLog = null)
        {
            var xElement = XElement.Load(stream);

            var xmlEntity = new XMLEntity(xElement);
            var tt        = new Timetable(TimetableType.Linear);

            var stations = xmlEntity.Children.Where(x => x.XName == "sta") // Filters other xml elements.
                           .Select(x =>
            {
                // Fix importing linear line files wich only support old style chainage.
                var km = x.GetAttribute <string>("km");
                if (km != null)
                {
                    x.SetAttribute("kml", km);
                    x.SetAttribute("kmr", km);
                    x.RemoveAttribute("km");
                }

                return(new Station(x, tt));
            });

            foreach (var i in stations)
            {
                tt.AddStation(i, Timetable.LINEAR_ROUTE_ID);
            }

            return(tt);
        }
コード例 #2
0
ファイル: LineEditForm.xeto.cs プロジェクト: fadoe/FPLedit
        private void NewStation()
        {
            using (EditStationForm nsf = new EditStationForm(tt, route))
            {
                if (nsf.ShowModal(this) == DialogResult.Ok)
                {
                    Station sta = nsf.Station;

                    if (info.Timetable.Type == TimetableType.Network)
                    {
                        var handler = new StaPosHandler();
                        handler.SetMiddlePos(route, sta, info.Timetable);
                        var r = sta.Routes.ToList();
                        r.Add(route);
                        sta.Routes = r.ToArray();
                    }

                    tt.AddStation(sta, route);
                    UpdateStations();
                }
            }
        }
コード例 #3
0
        public void GenerateHugeTimetable()
        {
            // this should not fail
            Timetable tt      = new Timetable(TimetableType.Network);
            var       handler = new StationCanvasPositionHandler();
            Dictionary <Station, Point> stapos = new Dictionary <Station, Point>();
            var     rand    = new Random();
            Station branchS = null;

            for (int i = 0; i < 2000; i++)
            {
                var branch = rand.Next(2, 98);
                for (int j = 1; j < 100; j++)
                {
                    var sta = new Station(tt)
                    {
                        SName = $"Teststation {i},{j}"
                    };

                    if (j == branch)
                    {
                        branchS = sta;
                    }
                    for (int k = 0; k < rand.Next(10); k++)
                    {
                        sta.Tracks.Add(new Track(tt)
                        {
                            Name = "Neues Gleis " + k,
                        });
                    }

                    if (j == 1 && i > 0)
                    {
                        tt.AddRoute(branchS, sta, 0f, 1f);
                    }
                    else
                    {
                        tt.AddStation(sta, i);
                        sta.Positions.SetPosition(i, j);
                    }
                    stapos.Add(sta, new Point(j * 70, i * 70));
                }
            }
            handler.WriteStapos(tt, stapos);
        }
コード例 #4
0
ファイル: XMLStationsImport.cs プロジェクト: fadoe/FPLedit
        public Timetable Import(string filename, IInfo info, ILog replaceLog = null)
        {
            try
            {
                XElement el = XElement.Load(filename);

                XMLEntity en   = new XMLEntity(el);
                var       list = new StationsList(en);
                var       tt   = new Timetable(TimetableType.Linear);
                foreach (var i in list.Stations)
                {
                    tt.AddStation(i, 0);
                }
                return(tt);
            }
            catch (Exception ex)
            {
                var log = replaceLog ?? info.Logger;
                log.Error("XMLStationsImporter: " + ex.Message);
                return(null);
            }
        }
コード例 #5
0
        public void LinkedTrainsPerformanceTest()
        {
            var tt       = new Timetable(TimetableType.Linear);
            var stations = new Station[100];

            for (int i = 0; i < 100; i++)
            {
                var sta = new Station(tt);
                sta.SName = "Station " + i;
                sta.Positions.SetPosition(Timetable.LINEAR_ROUTE_ID, i);
                tt.AddStation(sta, Timetable.LINEAR_ROUTE_ID);
                stations[i] = sta;
            }

            var normalTrain = new Train(TrainDirection.ti, tt)
            {
                TName = "P 01"
            };

            tt.AddTrain(normalTrain);
            normalTrain.AddLinearArrDeps();
            for (int i = 0; i < 100; i++)
            {
                var ardp = normalTrain.GetArrDep(stations[i]);
                ardp.Arrival   = new TimeEntry(0, i * 30);
                ardp.Departure = new TimeEntry(0, i * 30 + 10);
            }

            var link = new TrainLink(normalTrain, 10)
            {
                TimeDifference    = new TimeEntry(0, 30),
                TimeOffset        = new TimeEntry(0, 0),
                TrainNamingScheme = new AutoTrainNameGen(normalTrain.TName, 2)
            };

            normalTrain.AddLink(link);
            LinkedTrain linkedTrain = null;

            for (int i = 0; i < link.TrainCount; i++)
            {
                linkedTrain = new LinkedTrain(link, i);
                tt.AddTrain(linkedTrain);
            }

            var sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < 100; i++)
            {
                var ardps = linkedTrain.GetArrDepsUnsorted();
            }
            sw.Stop();

            Console.WriteLine("Linked read: " + ((float)sw.ElapsedMilliseconds) / 100);

            var sw2 = new Stopwatch();

            sw2.Start();
            for (int i = 0; i < 100; i++)
            {
                var ardps = normalTrain.GetArrDepsUnsorted();
            }
            sw2.Stop();

            Console.WriteLine("Normal read: " + ((float)sw2.ElapsedMilliseconds) / 100);

            var sw3   = new Stopwatch();
            var sta3  = stations[0];
            var ardp3 = normalTrain.GetArrDep(sta3);

            sw3.Start();
            for (int i = 0; i < 100; i++)
            {
                ardp3.Arrival = new TimeEntry(0, i);
            }
            sw3.Stop();

            Console.WriteLine("Write: " + ((float)sw3.ElapsedMilliseconds) / 100);
        }