예제 #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);
        }
예제 #2
0
        /// <summary>
        /// A method called when a new common path is created
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnNewBestFound(object sender, BestFoundEventArgs args)
        {
            BestDistance = args.NewBest.GetDistance();
            BestPathSeries.Points.Clear();

            foreach (City stop in args.NewBest.Stops)
            {
                BestPathSeries.Points.Add(new DataPoint(stop.XPosition, stop.YPosition));
            }

            BestPathInfo.InvalidatePlot(true);
            NotifyOfPropertyChange(nameof(BestDistance));
        }