コード例 #1
0
ファイル: Program.cs プロジェクト: MathieuJsrd/SchoolProjects
        public static void shortestWayBetweenXandY(List <CStation> trainStationsList, string stationXStr, string stationYStr)
        {
            List <CStation> finalListWithAllDetails = new List <CStation>();

            //We check that the two stations exist
            if (stationExistBool(stationXStr, trainStationsList) && stationExistBool(stationYStr, trainStationsList))
            {
                //stationX and stationY exist in the list

                //Now, we have to allocate the station "string" into a station "CStation"
                CStation stationX = allocationStationIntoObjectFromString(trainStationsList, stationXStr);
                CStation stationY = allocationStationIntoObjectFromString(trainStationsList, stationYStr);
                //reset of the DijkstraCounter = 0, because X is our Starting point and where from tag remains ""
                stationX.alterDijkstraCounter(0);

                //Boucle
                while (stationX != stationY)
                {
                    //Get all the station edges of station X, then get all the main station corresponding, and change djikstra counter and where from attributes of those stations in the main station list
                    ChangingCounterAccordingToOriginStation(trainStationsList, stationX);
                    //Now, after this step, we have to remove stationX from the list
                    finalListWithAllDetails.Add(stationX);
                    trainStationsList.Remove(stationX);
                    //To continue the algo, the new station X is the station with the smallest djikstra counter
                    stationX = returnSmallestDijkstraCounter(trainStationsList);
                    //Do it again, with a new station X until station X == station Y
                }
                //We have station X == station Y
                finalListWithAllDetails.Add(stationY);

                //All the stations to go to Y are in the finalListWithAllDetails


                /*
                 * Console.WriteLine("END WHILE LOOP!!");
                 * Console.WriteLine("DISPLAY STATION X :");
                 * stationX.displayObjectWithMoreDetails();
                 * Console.WriteLine("DISPLAY STATION Y :");
                 * stationY.displayObjectWithMoreDetails();
                 *
                 * Console.WriteLine("DISPLAY OF FINAL LIST : \n" + finalListWithAllDetails.Count);
                 * foreach (CStation station in finalListWithAllDetails)
                 * {
                 *  station.displayObjectWithMoreDetails();
                 * }
                 * displayItinerary(finalListWithAllDetails);
                 */
                List <CStation> finalstationItineraryList = finalItineraryList(finalListWithAllDetails);
                displayItineraryInConsole(finalstationItineraryList);
            }
            else
            {
                Console.WriteLine("Station X or Station Y doesn't exist. Please enter right stations.");
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: MathieuJsrd/SchoolProjects
        public static CStation returnSmallestDijkstraCounter(List <CStation> trainStationsList)
        {
            CStation returnedStation = trainStationsList.ElementAt(0);

            foreach (CStation station in trainStationsList)
            {
                if (returnedStation.DijkstraCounterInt > station.DijkstraCounterInt)
                {
                    returnedStation = station;
                }
            }
            return(returnedStation);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: MathieuJsrd/SchoolProjects
        public static CStation allocationStationIntoObjectFromString(List <CStation> trainStationsList, string stationNameStr)
        {
            CStation tempStationReturned = new CStation();

            foreach (CStation station in trainStationsList)
            {
                //If the current station name "i" matches with my string => we have the right station to allocate
                if (station.NameStationStr == stationNameStr)
                {
                    tempStationReturned = station;
                    break;
                }
            }
            return(tempStationReturned);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: MathieuJsrd/SchoolProjects
        //This function aims to upload the xml data in a List<Station>
        public static List <CStation> UploadingDataFromXml(string fileNameStr)
        {
            List <CStation> listStationReturned = new List <CStation>();
            //used to stack all the station edges of one main station

            XmlTextReader reader = new XmlTextReader(fileNameStr);
            string        tempNameMainStation      = "";
            string        tempTrainLineMainStation = "";
            string        tempNameStationEdge      = "";
            string        tempTrainLineStationEdge = "";
            string        tempDuration             = "";

            while (reader.Read()) //read the first tag (here "Stations")
            {
                List <CStationEdge> stationEdgesListPerStation = new List <CStationEdge>();
                if (reader.Name == "Station")        //Next element is logically "Name"
                {
                    reader.Read();                   //skip a tag, reader = "Name" now
                    while (reader.Name != "Station") // means exit of the node
                    {
                        if (reader.Name == "Name")
                        {
                            reader.Read(); //skip a tag, name of the main station here
                                           //Allocation of the name of the main station
                            tempNameMainStation = reader.Value;
                            reader.Read();
                        }
                        if (reader.Name == "Line")
                        {
                            reader.Read(); //skip a tag, line of the main station here
                                           //Allocation of the line of the main station
                            tempTrainLineMainStation = reader.Value;
                            reader.Read();
                        }
                        if (reader.Name == "StationEdges")        //Station Edges nodes
                        {
                            reader.Read();                        //skip a tag, reader = "StationEdge" (first tag)
                            while (reader.Name != "StationEdges") //means exist of the node, no more station edges
                            {
                                if (reader.Name == "Name")
                                {
                                    reader.Read(); //skip a tag, name of the station edge here
                                                   //Allocation of the name of the station edge
                                    tempNameStationEdge = reader.Value;
                                    reader.Read();
                                }
                                if (reader.Name == "Line")
                                {
                                    reader.Read(); //skip a tag, line of the station edge here
                                                   //Allocation of the line of the station edge
                                    tempTrainLineStationEdge = reader.Value;
                                    reader.Read();
                                }
                                if (reader.Name == "Duration")
                                {
                                    reader.Read(); //skip a tag, line of the duration here
                                                   //Allocation of the line of the station edge
                                    tempDuration = reader.Value;
                                    reader.Read();

                                    //Last variable of the station edge
                                    //Creation of a StationEdge object
                                    CStationEdge tempEdge = new CStationEdge(tempNameStationEdge, tempTrainLineStationEdge, tempDuration);
                                    //tempEdge.displayObject();
                                    //Console.ReadKey();
                                    //Add to the Station Edges list
                                    stationEdgesListPerStation.Add(tempEdge);
                                }

                                reader.Read();
                            } //end of the stationEdges node
                        }
                        reader.Read(); //skip a tag
                    }//end of the main station node
                     //Creation of the current main station
                    CStation tempMainStation = new CStation(tempNameMainStation, tempTrainLineMainStation, stationEdgesListPerStation);
                    //tempMainStation.displayObject();
                    //Console.ReadKey();
                    //Add the temp main station to the final main station list !
                    listStationReturned.Add(tempMainStation);
                    //stationEdgesListPerStation.Clear(); //reset the list for the next main station
                }
            }//End of the lecture of the xml doc
            return(listStationReturned);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: MathieuJsrd/SchoolProjects
        public static bool stationExistsInListBool(List <CStation> trainStationsList, CStation stationToFind)
        {
            bool returnedBool = false;

            foreach (CStation station in trainStationsList)
            {
                if (station == stationToFind)
                {
                    returnedBool = true;
                }
            }
            return(returnedBool);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: MathieuJsrd/SchoolProjects
        public static void ChangingCounterAccordingToOriginStation(List <CStation> trainStationsList, CStation landmarkStation)
        {
            //Dans la list de station, on va retenir les main stations de la station d'origine, et changer leur counter
            //Through trainStationList, we get back all the "name" of the station edges of the origin station (landmarkStation)
            //Then, we change their djikstra counter if the duration is less than their current djikstra attribute
            string landmarkStationNameStr    = landmarkStation.NameStationStr;
            int    landmarkStationCounterInt = landmarkStation.DijkstraCounterInt;

            foreach (CStationEdge stationEdge in landmarkStation.StationEdgesList)
            {
                //For each stationEdge of the main Station, we get back its name
                string tempStationEdgeName     = "";
                string tempStationEdgeDuration = "";
                tempStationEdgeName     = stationEdge.Name;
                tempStationEdgeDuration = stationEdge.Duration;
                //Search the main station and change attributes if it's possible
                alterDjikstraCounterIfPossible(trainStationsList, tempStationEdgeName, tempStationEdgeDuration, landmarkStationNameStr, landmarkStationCounterInt);
            }
        }