Beispiel #1
0
        /// <summary>
        /// A method that reads the cities from the current file
        /// </summary>
        private void ReadFile()
        {
            BestTripCitySeries.Points.Clear();
            SelectedTripCitySeries.Points.Clear();
            Cities.Clear();

            // Makes sure the file is valid
            if (CurrentFile != null && !CurrentFile.Exists)
            {
                MessageBox.Show("There is no valid file selected", "No Valid File",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            StreamReader reader = new StreamReader(CurrentFile.FullName);

            // Skip the first four lines
            for (int x = 0; x < 4; x++)
            {
                reader.ReadLine();
            }

            // Get the number of destinations
            var temp      = reader.ReadLine().Split(' ');
            int cityCount = int.Parse(temp[1]);

            // Skip two more lines
            for (int y = 0; y < 2; y++)
            {
                reader.ReadLine();
            }

            // Read the data for each city
            for (int z = 0; z < cityCount; z++)
            {
                temp = reader.ReadLine().Split(' ');
                var city = new City(int.Parse(temp[0]),
                                    double.Parse(temp[1]),
                                    double.Parse(temp[2]));
                // Add the city to the list
                Cities.Add(city);

                // Add the city to the graph
                BestTripCitySeries.Points.Add(new ScatterPoint(city.XPosition, city.YPosition));
                SelectedTripCitySeries.Points.Add(new ScatterPoint(city.XPosition, city.YPosition));
            }

            BestPathInfo.InvalidatePlot(true);
            SelectedPathInfo.InvalidatePlot(true);

            CSolver.OrderData(Cities);
        }
Beispiel #2
0
 /// <summary>
 /// A method called by the UI to start generating the paths
 /// </summary>
 public void StartGeneration()
 {
     TripCollection.Clear();
     Task.Run(() => { CSolver.GetShortestPath(); });
 }