예제 #1
0
                public Branch(JsonRoute.StopPointSequence sps, StationDictionary stationDiction, LineDictionary lineDiction) // creates branch from JSON stop point sequence
                {
                    StopSequence = new List <Stop>();
                    int        stationId;
                    int        lineId;
                    List <int> lineIds = new List <int>();

                    foreach (var station in sps.stopPoint)
                    {
                        stationId = stationDiction.GetKey(station.name, station.lat, station.lon);
                        // gets key and updates coordinates within station Dictionary

                        foreach (var line in station.lines)
                        {
                            lineId = lineDiction.GetKey(line.id);
                            if (lineId != -1)
                            {
                                lineIds.Add(lineId);
                            }
                        }

                        StopSequence.Add(new Stop(stationId, lineIds));

                        if (lineIds.Any()) // avoids error if list is empty
                        {
                            lineIds.Clear();
                        }
                    }
                }
예제 #2
0
        private static void FixPaddingtonBakerloo(StationDictionary stationDiction, LineDictionary lineDiction) // adds bakerloo line to paddington
        {
            int paddingtonId = stationDiction.GetKey("paddington");
            int bakerlooId   = lineDiction.GetKey("bakerloo");

            Line line;

            Line.Branch      branch;
            Line.Branch.Stop stop;

            for (int lineIndex = 0; lineIndex < Lines.Count(); lineIndex++)
            {
                line = Lines[lineIndex]; // alias
                for (int branchIndex = 0; branchIndex < line.Branches.Count(); branchIndex++)
                {
                    branch = line.Branches[branchIndex]; // alias
                    for (int stationindex = 0; stationindex < branch.StopSequence.Count(); stationindex++)
                    {
                        stop = branch.StopSequence[stationindex]; // alias
                        if (stop.StationId == paddingtonId)
                        {
                            if (!stop.LineIds.Contains(bakerlooId))
                            {
                                stop.LineIds.Add(bakerlooId);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
            // Constructor

            public Line(JsonRoute jRoute, StationDictionary stationDiction, LineDictionary lineDiction) // sets up line structure
            {
                foreach (var sps in jRoute.stopPointSequences)
                {
                    Branches.Add(new Branch(sps, stationDiction, lineDiction));
                }
            }
        private BaseDictionary[] InitialiseMetroNetwork()
        {
            StationDictionary stationDiction = new StationDictionary(APIHandler.GetStationList());
            LineDictionary    lineDiction    = new LineDictionary(APIHandler.GetLineList(), APIHandler.GetLineColors());

            MetroNetwork.Initialise(stationDiction, lineDiction);

            BaseDictionary[] dictionaries = new BaseDictionary[] { stationDiction, lineDiction };
            return(dictionaries);
        }
예제 #5
0
        // basic methods

        public bool TryInitialise(string line, StationDictionary stations) // reads and converts data form sourceFile
        {
            var cells = line.Split(',');

            for (int i = 0; i < cells.Count(); i++)
            {
                cells[i] = cells[i].Trim('"');
            }

            if (cells.Count() < 8)
            {
                return(false); // avoids index out of array
            }

            string start, end;

            start = cells[3];
            end   = cells[4];

            if (cells[2].Length >= 3)
            {
                if (cells[2].Substring(0, 3) == "LUL") // logic checks, can also be LUL/NR or LUL/DLR
                {
                    if (start != "Unstarted")          // more
                    {
                        if (end != "Unfinished")       // more
                        {
                            StartStn  = stations.GetKey(start);
                            EndStn    = stations.GetKey(end);
                            StartTime = Convert.ToInt16(cells[5]);
                            EndTime   = Convert.ToInt16(cells[7]);

                            if (StartStn == -1)
                            {
                                return(false);
                            }

                            if (EndStn == -1)
                            {
                                return(false);
                            }

                            if (StartStn == EndStn)
                            {
                                return(false);
                            }

                            return(true); // operation succeeded
                        }
                    }
                }
            }

            return(false); // operation failed, must repeat
        }
예제 #6
0
        // Initialisation methods

        public static void Initialise(StationDictionary stationDiction, LineDictionary lineDiction)
        {
            Lines = new List <Line>();                                    // intialise variable
            List <JsonRoute> jRoutes = APIHandler.GetRoutes(lineDiction); // makes api request for link data

            foreach (var jRoute in jRoutes)
            {
                Lines.Add(new Line(jRoute, stationDiction, lineDiction));
            }

            FixCircleLine(stationDiction, lineDiction);                     // necessary fix to inconsistency in circle line branch structure
            FixPaddingtonEdgwareRdHammersmith(stationDiction, lineDiction); // ensures these stations have consistent id's
        }
예제 #7
0
        private static void FixPaddingtonEdgwareRdHammersmith(StationDictionary stationDiction, LineDictionary lineDiction)
        {
            // paddington, edgware road and hammermsith are only stations to have duplicate id's in TFL's database
            // this procedure fixes the resulting problems of inconsistent links

            int paddingtonId  = stationDiction.GetKey("paddington");
            int edgwareRdId   = stationDiction.GetKey("edgware road");
            int hammermsithId = stationDiction.GetKey("hammersmith");

            int bakerlooId   = lineDiction.GetKey("bakerloo");
            int circleId     = lineDiction.GetKey("circle");
            int districtId   = lineDiction.GetKey("district");
            int hamCityId    = lineDiction.GetKey("hammersmith-city");
            int piccadillyId = lineDiction.GetKey("piccadilly");

            List <int> PadEdgLineIds = new List <int> {
                bakerlooId, circleId, districtId, hamCityId
            };
            List <int> HamLineIds = new List <int> {
                circleId, districtId, hamCityId, piccadillyId
            };

            Line line;

            Line.Branch      branch;
            Line.Branch.Stop stop;

            for (int lineIndex = 0; lineIndex < Lines.Count(); lineIndex++)
            {
                line = Lines[lineIndex];
                for (int branchIndex = 0; branchIndex < line.Branches.Count(); branchIndex++)
                {
                    branch = line.Branches[branchIndex];
                    for (int stationIndex = 0; stationIndex < branch.StopSequence.Count(); stationIndex++)
                    {
                        stop = branch.StopSequence[stationIndex];

                        if (stop.StationId == paddingtonId || stop.StationId == edgwareRdId)
                        {
                            CopyList <int>(stop.LineIds, PadEdgLineIds);
                        }
                        else if (stop.StationId == hammermsithId)
                        {
                            CopyList <int>(stop.LineIds, HamLineIds);
                        }
                    }
                }
            }
        }
예제 #8
0
        // constructor

        public Backend()
        {
            // instantiating variables
            List <string> tempList = new List <string>();

            Children = new List <Node>();

            // api requests
            tempList    = APIHandler.GetLineList();                                 // makes request for list of lines
            LineDiction = new LineDictionary(tempList, APIHandler.GetLineColors()); // sets up line dictionary

            tempList       = APIHandler.GetStationList();                           // makes request for station list
            StationDiction = new StationDictionary(tempList);                       // sets up station dictionary

            MetroNetwork.Initialise(StationDiction, LineDiction);                   // sets up network structure
        }
예제 #9
0
        private static void FixCircleLine(StationDictionary stationDiction, LineDictionary lineDiction) // fix to error in circle line, where paddington and edgware road are not end of branch
        {
            int circleId      = lineDiction.GetKey("circle");
            int paddingtonId  = stationDiction.GetKey("paddington");
            int edgwareRoadId = stationDiction.GetKey("edgware road");

            Line.Branch.Stop edgwareRoad = null;
            Line.Branch.Stop paddington  = null;

            Line circleLine = Lines[circleId]; // alias

            Line.Branch branch;
            int         branchLength;

            for (int i = 0; i < circleLine.Branches.Count(); i++)
            {
                branch       = circleLine.Branches[i];
                branchLength = branch.StopSequence.Count();

                if (branch.StopSequence[0].StationId == edgwareRoadId)
                {
                    edgwareRoad = branch.StopSequence[0];
                    if (branch.StopSequence[1].StationId == paddingtonId)
                    {
                        paddington = branch.StopSequence[1];
                        branch.StopSequence.RemoveAt(0);
                    }
                }

                else if (branch.StopSequence[branchLength - 1].StationId == edgwareRoadId)
                {
                    edgwareRoad = branch.StopSequence[branchLength - 1];
                    if (branch.StopSequence[branchLength - 2].StationId == paddingtonId)
                    {
                        paddington = branch.StopSequence[branchLength - 2];
                        branch.StopSequence.RemoveAt(branchLength - 1);
                    }
                }
            }

            List <Line.Branch.Stop> stops = new List <Line.Branch.Stop> {
                paddington, edgwareRoad
            };

            circleLine.Branches.Add(new Line.Branch(stops));
        }
예제 #10
0
        // MergeSort methods

        public int Sort(StationDictionary stations, BackgroundWorker backgroundWorker) // begins sorting data on request
        {
            this.bgw = backgroundWorker;
            int N = 0;

            if (SourceFile.Substring(SourceFile.LastIndexOf('.')) == ".csv")
            {
                N = FirstPass(stations);
                ListMergeSort();
                WriteFile();
            }

            else // pre sorted txt file
            {
                N = LoadPreSortedData();
            }

            return(N);
        }
        public const int Interval = 10; // group loadings into 10 minute time intervals

        //Constructor

        public MetroNetworkLoading(LineDictionary lineDiction, StationDictionary stationDiction, Canvas c)
        {
            // assigning static variables
            C = c;
            StationDiction = stationDiction;
            LineDiction    = lineDiction;

            // instantiating variables
            LineRecords = new List <LineRecord>();
            RecLocs     = new List <RecordLocation>();

            for (int i = 0; i < LineDiction.N; i++)
            {
                LineRecords.Add(new LineRecord(i)); // intialise record setup
            }

            NodeNumber = StationDiction.N;

            // displays stations
            StatDisplay = new StationDisplay(C);
        }
        // helper methods
        private void CheckCorrectValues(PathClass p, StationDictionary stationDiction, LineDictionary lineDiction, int index, int score, string stationName, string lineName = "unspecified")
        {
            int  stationId = stationDiction.GetKey(stationName);
            int  lineId    = lineDiction.GetKey(lineName);
            Node n         = p.Path.ElementAt(index);

            Assert.AreEqual(score, n.Score);

            if (stationId != -1)
            {
                Assert.AreEqual(stationId, n.StationId);
            }
            else
            {
                throw new ArgumentException(stationName + " is misspelt");
            }

            if (lineId != -1)
            {
                Assert.AreEqual(lineId, n.LineIndex);
            }
        }
예제 #13
0
        private int FirstPass(StationDictionary stations) // reads in data and converts to numerical form
        {
            StreamReader r = new StreamReader(SourceFile);
            FinalLine    f = new FinalLine();

            FileInfo fi   = new FileInfo(SourceFile);
            long     size = fi.Length; //bytes in file

            long bytesRead = 0;
            int  percent   = 0;

            string line;

            const int bytesPerChar = 1; // UTF-8

            while (!r.EndOfStream)
            {
                line = r.ReadLine();
                if (f.TryInitialise(line, stations))
                {
                    Records.AddFirst(new List <FinalLine> {
                        new FinalLine(f)
                    });
                }

                bytesRead += (line.Length + 2) * bytesPerChar; // +2 to account for return and new line

                if (percent < (bytesRead * split) / size)
                {
                    percent++;
                    bgw.ReportProgress(percent);
                }
            }

            r.Close();
            return(Records.Count());
        }
예제 #14
0
 public PreSortingTests()
 {
     sd = new StationDictionary(APIHandler.GetStationList());
 }