Ejemplo n.º 1
0
 public SubPath(Line lineUsed, Station start, Station end)
 {
     this.lineUsed = lineUsed;
     findPath(start, end);
 }
Ejemplo n.º 2
0
 private void createPath(Station start, Station end)
 {
     if (!start.Junction && !end.Junction)
     {
         Line           startLine = start.LineBelong;
         Line           endLine   = end.LineBelong;
         List <Station> junctions = findJunction(startLine, endLine);
         for (int count = 0; count <= junctions.Count() - 1; count++)
         {
             SubPath temp = new SubPath(startLine, start, junctions[count]);
             possiblePaths.Add(temp.PathTaken);
             temp = new SubPath(endLine, junctions[count], end);
             List <Station> extendedPath = combinedLists(possiblePaths[count], temp.PathTaken);
             possiblePaths[count] = extendedPath;
         }
         completePath.AddRange(possiblePaths[indexOfSmallestList(possiblePaths)]);
     }            //if neither are junctions
     else if (start.Junction && end.Junction)
     {
         List <Line> line1 = start.getLines();
         List <Line> line2 = end.getLines();
         if (line1.Any(x => line2.Contains(x)))                      //on same line
         {
             Line    lineUsed = findCommonLine(line1, line2);
             SubPath temp     = new SubPath(lineUsed, start, end);
             completePath.AddRange(temp.PathTaken);
         }
         else
         {
             List <Station> junctions = findJunctions(line1, line2);
             for (int line1Count = 0; line1Count <= line1.Count() - 1; line1Count++)
             {
                 for (int line2Count = 0; line2Count <= line2.Count() - 1; line2Count++)
                 {
                     for (int count = 0; count <= junctions.Count() - 1; count++)
                     {
                         if (line1[line1Count].Stations.Contains(junctions[count]) && line2[line2Count].Stations.Contains(junctions[count]))
                         {
                             SubPath temp = new SubPath(line1[line1Count], start, junctions[count]);
                             possiblePaths.Add(temp.PathTaken);
                             temp = new SubPath(line2[line2Count], junctions[count], end);
                             List <Station> extendedPath = combinedLists(possiblePaths[count], temp.PathTaken);
                             possiblePaths[count] = extendedPath;
                         }
                     }
                     completePath.AddRange(possiblePaths[indexOfSmallestList(possiblePaths)]);
                 }
             }
         }
     }            //if both are junctions
     else if (!start.Junction && end.Junction)
     {
         Line           startLine = start.LineBelong;
         List <Line>    endLines  = end.getLines();
         List <Station> junctions = findJunctions(endLines, startLine);
         for (int count1 = 0; count1 <= endLines.Count() - 1; count1++)
         {
             for (int count = 0; count <= junctions.Count() - 1; count++)
             {
                 if (endLines[count1].Stations.Contains(junctions[count]) && startLine.Stations.Contains(junctions[count]))
                 {
                     SubPath temp = new SubPath(startLine, start, junctions[count]);
                     possiblePaths.Add(temp.PathTaken);
                     temp = new SubPath(endLines[count1], junctions[count], end);
                     List <Station> extendedPath = combinedLists(possiblePaths[count], temp.PathTaken);
                     possiblePaths[count] = extendedPath;
                 }
             }
         }
         completePath.AddRange(possiblePaths[indexOfSmallestList(possiblePaths)]);
     }            //if only end is a junction
     else
     {
         List <Line>    startLine = start.getLines();
         Line           endLine   = end.LineBelong;
         List <Station> junctions = findJunctions(startLine, endLine);
         for (int count1 = 0; count1 <= startLine.Count() - 1; count1++)
         {
             for (int count = 0; count <= junctions.Count() - 1; count++)
             {
                 if (startLine[count1].Stations.Contains(junctions[count]) && endLine.Stations.Contains(junctions[count]))
                 {
                     SubPath temp = new SubPath(startLine[count1], start, junctions[count]);
                     possiblePaths.Add(temp.PathTaken);
                     temp = new SubPath(endLine, junctions[count], end);
                     List <Station> extendedPath = combinedLists(possiblePaths[count], temp.PathTaken);
                     possiblePaths[count] = extendedPath;
                 }
             }
         }
         completePath.AddRange(possiblePaths[indexOfSmallestList(possiblePaths)]);
     }    //if only start is junction
 }        //create path
Ejemplo n.º 3
0
 public InputToStation(string input, List <Line> lines)
 {
     this.lines             = lines;
     this.referencedStation = findStation(input);
 }
Ejemplo n.º 4
0
 public Path(Station start, Station end)
 {
     createPath(start, end);
 }