Example #1
0
        public static void Testing()
        {
            Console.Write("Enter Station Name : ");
            string  stationname = Console.ReadLine();
            Station s           = new Station();

            foreach (string a in Guide.SearchByStationName(stationname).StationCode)
            {
                Console.WriteLine(a);
                s.StationCode = SearchByStationName(a).StationCode;
            }

            Station s2 = new Station();

            Console.Write("Enter Station Code : ");
            string c = Console.ReadLine();

            foreach (char b in Guide.SearchByStationCd(c).StationName)
            {
                Console.Write(b.ToString());
            }

            Station s3 = new Station("CC9", "Jurong East");
            Station s4 = new Station("NE12", "Pasir Ris");

            Console.WriteLine();
            Console.WriteLine();
            //FindRoute(s3, s4);
            //Console.WriteLine();
            //FindRoute("NS1", "EW1"); // Find route cant do this yet
            Console.ReadKey();
        }
Example #2
0
        public static void TestGraphRoute()
        {
            bool repeat = true;

            while (repeat)
            {
                Console.Write("Please enter the boarding station code: ");
                string boardingStationCd = Console.ReadLine();
                Console.Write("Please enter the alighting station code: ");
                string alightingStationCd = Console.ReadLine();
                initTraverseDijkstra(Guide.SearchByStationCd(boardingStationCd).GraphIndex, Guide.SearchByStationCd(alightingStationCd).GraphIndex);

                Console.Write("New Route? (Y/N)");
                char response = char.Parse(Console.ReadLine().ToUpper());
                switch (response)
                {
                case 'Y':
                    repeat = true;
                    break;

                case 'N':
                    repeat = false;
                    break;
                }
            }
        }
Example #3
0
        public static void TestGraph()
        {
            string stationCd = "";

            Console.Write("Please enter a station code: ");
            stationCd = Console.ReadLine();
            Station tempStat = Guide.SearchByStationCd(stationCd);

            Console.WriteLine("Station Information:\nStation Name: {0}\nGraphIndex: {1}", tempStat.StationName, tempStat.GraphIndex);
            List <int> neighbourIdx = new List <int>();

            for (int i = 0; i < size; i++)
            {
                if (mrtGraph.isEdge(tempStat.GraphIndex, i))
                {
                    neighbourIdx.Add(i);
                    Console.WriteLine(i);
                }
            }
            Console.WriteLine("Neighbouring Stations: \nIndex|StationName\n");
            List <string> neighbourName = new List <string>();

            foreach (int index in neighbourIdx)
            {
                foreach (Line line in Guide.MRTLine)
                {
                    foreach (Station stat in line.StationList)
                    {
                        if (index == stat.GraphIndex)
                        {
                            neighbourName.Add(stat.StationName);
                            goto end_of_loop;//using goto as a subtitute for java's named loop in c#. from https://stackoverflow.com/questions/359436/c-sharp-equivalent-to-javas-continue-label
                        }
                    }
                }
                end_of_loop : { }
            }
            for (int i = 0; i < neighbourIdx.Count; i++)
            {
                Console.WriteLine("{0,5}|{1}", neighbourIdx[i], neighbourName[i]);
            }
        }
Example #4
0
        public static void TestingStationMtd()
        {
            //for testing

            Console.WriteLine("\r\n ------Testing------ \r\n");

            for (int i = 0; i < MRT[4].StationList.Count; i++)
            {
                Console.WriteLine(MRT[4].StationList[i].StationName);
                foreach (string str in MRT[4].StationList[i].StationCode)
                {
                    Console.Write("{0,5},", str);
                }
                Console.WriteLine();
            }
            Console.WriteLine(MRT[0].StationList[0].StationName);
            foreach (string str in MRT[0].StationList[0].StationCode)
            {
                Console.Write("{0,5},", str);
            }
            Console.WriteLine();

            Console.WriteLine("--------");
            Console.WriteLine(Guide.SearchByStationCd("EW4").StationName);
            Console.WriteLine("--------");
            Console.WriteLine(Guide.SearchByStationCd("EW8").StationName);
            Console.WriteLine("--------");
            Console.WriteLine(Guide.SearchByStationCd("CC1").StationName);
            Console.WriteLine("--------");

            string output = "";

            foreach (string str in Guide.SearchByStationName("Jurong East").StationCode)
            {
                output += str + " ";
            }
            Console.WriteLine(output);

            output = "";
            foreach (string str in Guide.SearchByStationName("Tanah Merah").StationCode)
            {
                output += str + " ";
            }
            Console.WriteLine(output);

            foreach (Station stat in MRT[4].StationList)
            {
                Console.WriteLine(stat.StationName);
                foreach (string str in stat.StationCode)
                {
                    Console.WriteLine(str);
                }
            }


            Console.WriteLine("DisplayingRoute");

            Station testStat = SearchByStationName("Dhoby Ghaut");

            foreach (string StationCodeStr in testStat.StationCode)
            {
                DisplayRoute(StationCodeStr);
            }

            Console.WriteLine("Display path WIP");
            FindPathV2("NS1", "EW1");
            DisplayRoute("EW2");
            Console.ReadKey();
        }
Example #5
0
        public static void initTraverseDijkstra(int sourceGraphIndex, int destinationGraphIndex)
        {
            List <int> visitedIndex;

            int[,] distanceTable;
            visitedIndex  = new List <int>();
            distanceTable = new int[size, 2];//the first column will have the distance of that node from the starting node, the second column is the index of the node that came before it.
            for (int i = 0; i < size; i++)
            {
                distanceTable[i, 0] = int.MaxValue;
                distanceTable[i, 1] = -1;
            }
            distanceTable[sourceGraphIndex, 0] = 0; //Distance from the starting station from the starting station is 0, thus setting it.
            int currentNodeIndex = sourceGraphIndex;

            //while (visitedIndex.Count < size)
            //{
            //    currentNodeIndex = TraverseDijkstra(currentNodeIndex);
            //}
            TraverseDijkstraRecursive(distanceTable, visitedIndex, currentNodeIndex);

            for (int i = 0; i < size; i++)
            {
                Console.WriteLine("{0} - Distance:{1} - Comes From:{2}", i, distanceTable[i, 0], distanceTable[i, 1]);
            }

            List <int> routeGraphIndex = new List <int>()
            {
                destinationGraphIndex
            };
            int currentIndex = destinationGraphIndex;

            while (currentIndex != sourceGraphIndex)
            {
                currentIndex = distanceTable[currentIndex, 1];
                routeGraphIndex.Add(currentIndex);
            }

            routeGraphIndex.Reverse();

            List <Station> routeStation = new List <Station>();

            foreach (int gI in routeGraphIndex)
            {
                routeStation.Add(SearchByStationGraphIndex(gI));
            }



            //int startIndex = -1;
            //int endIndex = -1;

            //string lineCd = "";
            //int lineCdIdx = -1;
            //int nextLineCdIdx = -1;
            //int nextStartIndex = -1;
            //for (int idx = 0; idx < routeStation.Count; idx++)
            //{
            //    bool matchFound = false;
            //    if (idx == 0)
            //    {
            //        if (routeStation[idx].IsInterchange)
            //        {
            //            List<string> stationLineCd = new List<string>();
            //            foreach(string statCd in routeStation[idx].StationCode)
            //            {
            //                stationLineCd.Add(statCd.Substring(0, 2));
            //            }
            //                foreach(string statCd in routeStation[1].StationCode)
            //                {
            //                    if (stationLineCd.Contains(statCd.Substring(0, 2)))
            //                    {

            //                        lineCd = statCd.Substring(0, 2);

            //                    }
            //                }
            //            lineCdIdx = Guide.GetIndexOfLine(lineCd);

            //        }
            //        else
            //        {
            //            lineCdIdx = Guide.GetIndexOfLine(routeStation[idx].StationCode[0].Substring(0, 2));
            //        }
            //        startIndex = Guide.GetStationIndexFromLine(lineCdIdx, routeStation[idx].StationName);
            //    }
            //    else if (idx == (routeStation.Count - 1))
            //    {
            //        if (routeStation[idx].IsInterchange)
            //        {
            //            List<string> stationLineCd = new List<string>();
            //            foreach (string statCd in routeStation[idx].StationCode)
            //            {
            //                stationLineCd.Add(statCd.Substring(0, 2));
            //            }
            //            foreach (string statCd in routeStation[routeStation.Count - 2].StationCode)
            //            {
            //                if (stationLineCd.Contains(statCd.Substring(0, 2)))
            //                {
            //                    lineCd = statCd.Substring(0, 2);

            //                }
            //            }
            //            lineCdIdx = Guide.GetIndexOfLine(lineCd);

            //        }
            //        else
            //        {
            //            lineCdIdx = Guide.GetIndexOfLine(routeStation[idx].StationCode[0].Substring(0, 2));
            //        }
            //        endIndex = Guide.GetStationIndexFromLine(lineCdIdx, routeStation[idx].StationName);
            //    }
            //    else
            //    {
            //        if (routeStation[idx].IsInterchange)
            //        {

            //            List<string> statLineCd = new List<string>();
            //            foreach (string statCd in routeStation[idx-1].StationCode)
            //            {
            //                statLineCd.Add(statCd.Substring(0, 2));
            //            }
            //            foreach (string statCd in routeStation[idx+1].StationCode)
            //            {
            //                bool contains = statLineCd.Contains(statCd.Substring(0, 2));
            //                if (contains)
            //                {
            //                    matchFound = true;

            //                }
            //            }
            //            if (!matchFound)
            //            {
            //                endIndex = Guide.GetStationIndexFromLine(lineCdIdx,routeStation[idx].StationName);

            //                List<string> stationLineCd = new List<string>();
            //                foreach (string statCd in routeStation[idx].StationCode)
            //                {
            //                    stationLineCd.Add(statCd.Substring(0, 2));
            //                }
            //                foreach (string statCd in routeStation[idx+1].StationCode)
            //                {
            //                    if (stationLineCd.Contains(statCd.Substring(0, 2)))
            //                    {

            //                        lineCd = statCd.Substring(0, 2);

            //                    }
            //                }
            //                nextLineCdIdx = Guide.GetIndexOfLine(lineCd);
            //                nextStartIndex = Guide.GetStationIndexFromLine(nextLineCdIdx, routeStation[idx].StationName);
            //            }

            //        }

            //    }
            //    if (matchFound)
            //    {
            //        continue;
            //    }
            //    if ((startIndex != -1) &&(endIndex != -1)&&(lineCdIdx != -1))
            //    {
            //        Guide.DisplayFindPath(lineCdIdx, startIndex, endIndex);
            //        lineCdIdx = nextLineCdIdx;
            //        startIndex = nextStartIndex;
            //        endIndex = -1;
            //    }

            //}

            List <string> routeStationCd = new List <string>();

            for (int idx = 0; idx < routeStation.Count; idx++)
            {
                string prevStatLineCd = "";
                string nextStatLineCd = "";
                if ((idx == 0) && (routeStation[idx].IsInterchange))
                {
                    List <string> stationLineCd = new List <string>();
                    foreach (string statCd in routeStation[idx].StationCode)
                    {
                        stationLineCd.Add(statCd.Substring(0, 2));
                    }
                    foreach (string statCd in routeStation[idx + 1].StationCode)
                    {
                        if (stationLineCd.Contains(statCd.Substring(0, 2)))
                        {
                            nextStatLineCd = statCd.Substring(0, 2);
                        }
                    }

                    foreach (string statCd in routeStation[idx].StationCode)
                    {
                        if (statCd.Contains(nextStatLineCd))
                        {
                            routeStationCd.Add(statCd);
                        }
                    }
                }
                else if ((idx == routeStation.Count - 1) && (routeStation[idx].IsInterchange))
                {
                    List <string> stationLineCd = new List <string>();
                    foreach (string statCd in routeStation[idx].StationCode)
                    {
                        stationLineCd.Add(statCd.Substring(0, 2));
                    }
                    foreach (string statCd in routeStation[idx - 1].StationCode)
                    {
                        if (stationLineCd.Contains(statCd.Substring(0, 2)))
                        {
                            prevStatLineCd = statCd.Substring(0, 2);
                        }
                    }

                    foreach (string statCd in routeStation[idx].StationCode)
                    {
                        if (statCd.Contains(prevStatLineCd))
                        {
                            routeStationCd.Add(statCd);
                        }
                    }
                }
                else if (routeStation[idx].IsInterchange)
                {
                    List <string> stationLineCd = new List <string>();
                    foreach (string statCd in routeStation[idx].StationCode)
                    {
                        stationLineCd.Add(statCd.Substring(0, 2));
                    }

                    foreach (string statCd in routeStation[idx - 1].StationCode)
                    {
                        if (stationLineCd.Contains(statCd.Substring(0, 2)))
                        {
                            prevStatLineCd = statCd.Substring(0, 2);
                        }
                    }

                    foreach (string statCd in routeStation[idx + 1].StationCode)
                    {
                        if (stationLineCd.Contains(statCd.Substring(0, 2)))
                        {
                            nextStatLineCd = statCd.Substring(0, 2);
                        }
                    }


                    foreach (string statCd in routeStation[idx].StationCode)
                    {
                        if (statCd.Contains(prevStatLineCd))
                        {
                            routeStationCd.Add(statCd);
                        }
                    }
                    if (!prevStatLineCd.Equals(nextStatLineCd))
                    {
                        foreach (string statCd in routeStation[idx].StationCode)
                        {
                            if (statCd.Contains(nextStatLineCd))
                            {
                                routeStationCd.Add(statCd);
                            }
                        }
                    }
                }
                else
                {
                    routeStationCd.Add(routeStation[idx].StationCode[0]);
                }
            }

            string outputRoute = string.Format("Display Route from {0} to {1} - Taking {2} stations\r\n", routeStation[0].StationName, routeStation[routeStation.Count - 1].StationName, routeStation.Count);

            outputRoute += "Start of Route\r\n";
            foreach (string statCd in routeStationCd)
            {
                outputRoute += string.Format("{0} - {1}\r\n", statCd, Guide.SearchByStationCd(statCd).StationName);
            }
            outputRoute += "End of Route";
            Console.WriteLine(outputRoute);
        }