private void btnShowTracks_Click(object sender, System.EventArgs e) { // First, instantiate the train system object, passing an input file containing the list of tracks. trainSystem = new TrainSystem(cbFilename.Text); // Loop through the tracks and spit 'em out foreach (Track track in trainSystem.mTracks) { lbTracks.Items.Add(track.Source.Name + " " + track.Target.Name + " " + track.Distance.ToString()); } }
private void btnFindSolution_Click(object sender, System.EventArgs e) { // First, instantiate the train system object, passing an input file containing the list of tracks. trainSystem = new TrainSystem(cbFilename.Text); // Variable to hold the distance between two stations int distance; // Find distance A-B-C distance = trainSystem.GetDistance("ABC"); if (distance == 0) { lbSolution.Items.Add("Output #1: No Such Route"); } else { lbSolution.Items.Add("Output #1: " + distance.ToString()); } // Find distance A-D distance = trainSystem.GetDistance("AD"); if (distance == 0) { lbSolution.Items.Add("Output #2: No Such Route"); } else { lbSolution.Items.Add("Output #2: " + distance.ToString()); } // Find distance A-D-C distance = trainSystem.GetDistance("ADC"); if (distance == 0) { lbSolution.Items.Add("Output #3: No Such Route"); } else { lbSolution.Items.Add("Output #3: " + distance.ToString()); } // Find distance A-E-B-C-D distance = trainSystem.GetDistance("AEBCD"); if (distance == 0) { lbSolution.Items.Add("Output #4: No Such Route"); } else { lbSolution.Items.Add("Output #4: " + distance.ToString()); } // Find distance A-E-D distance = trainSystem.GetDistance("AED"); if (distance == 0) { lbSolution.Items.Add("Output #5: No Such Route"); } else { lbSolution.Items.Add("Output #5: " + distance.ToString()); } // Get number of routes between C and C with less than (or equal to) 3 stops int numRoutes = trainSystem.GetAllRoutesWithMaxStops('C', 'C', 3); lbSolution.Items.Add("Output #6: " + numRoutes.ToString()); // Get number of routes between A and C with exactly 4 stops numRoutes = trainSystem.GetNumRoutesWithNStops('A', 'C', 4); lbSolution.Items.Add("Output #7: " + numRoutes.ToString()); // Get shortest route between A and C distance = trainSystem.GetShortestRoute('A', 'C'); lbSolution.Items.Add("Output #8: " + distance.ToString()); // Get shortest route from B to B distance = trainSystem.GetShortestRoute('B', 'B'); lbSolution.Items.Add("Output #9: " + distance.ToString()); // Get number of routes between C and C that have a distance less than 30 distance = trainSystem.GetAllRoutesWithMaxDistance('C', 'C', 30); lbSolution.Items.Add("Output #10: " + distance.ToString()); /* Some test cases to exercise other possibilities */ /* * // Get number of routes between A and B with less than (or equal to) 4 stops * numRoutes = trainSystem.GetAllRoutesWithMaxStops('A', 'B', 4); * lbSolution.Items.Add("Output #11: " + numRoutes.ToString()); * * // Get number of routes between A and B with exactly 7 stops * numRoutes = trainSystem.GetNumRoutesWithNStops('A', 'B', 7); * lbSolution.Items.Add("Output #12: " + numRoutes.ToString()); * * // Get shortest route between A and E * distance = trainSystem.GetShortestRoute('A', 'E'); * lbSolution.Items.Add("Output #13: " + distance.ToString()); * * // Get shortest route from A to E * distance = trainSystem.GetShortestRoute('A', 'E'); * lbSolution.Items.Add("Output #14: " + distance.ToString()); * * // Get number of routes between A and B that have a distance less than 30 * distance = trainSystem.GetAllRoutesWithMaxDistance('A', 'B', 30); * lbSolution.Items.Add("Output #15: " + distance.ToString()); */ }