Exemplo n.º 1
0
        public static double CalculateDistance(DataPoint dataPoint1, DataPoint dataPoint2)
        {
            ConsumerFlight flight1 = dataPoint1.Flight;
            ConsumerFlight flight2 = dataPoint2.Flight;

            return(Math.Sqrt(Math.Pow(Math.Abs(flight1.Price - flight2.Price), 2) + Math.Pow(Math.Abs(flight1.PointToPointDistance - flight2.PointToPointDistance), 2)));
        }
Exemplo n.º 2
0
        public override bool Equals(Object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            ConsumerFlight consumerFLight = (ConsumerFlight)obj;

            return(FlightId == consumerFLight.FlightId);
        }
Exemplo n.º 3
0
        public static IList <DataPoint> LoadData(string fileName)
        {
            var dataPoints = new List <DataPoint>();
            int errorCount = 0;

            using (var flightDataStream = File.OpenText(fileName))
            {
                string line;
                while ((line = flightDataStream.ReadLine()) != null)
                {
                    var dataArray = Regex.Split(line, ",");
                    if (dataArray.Length != 9)
                    {
                        errorCount++;
                    }
                    else
                    {
                        var currentFlight = new ConsumerFlight
                        {
                            FlightId             = Int32.Parse(dataArray[0]),
                            SourceAirportId      = Int32.Parse(dataArray[1]),
                            SourceLongitude      = Double.Parse(dataArray[2]),
                            SourceLatitude       = Double.Parse(dataArray[3]),
                            DestinationAirportId = Int32.Parse(dataArray[4]),
                            DestinationLongitude = Double.Parse(dataArray[5]),
                            DestinationLatitude  = Double.Parse(dataArray[6]),
                            PointToPointDistance = Double.Parse(dataArray[7]),
                            Price = Double.Parse(dataArray[8])
                        };

                        DataPoint dataPoint = new DataPoint {
                            Flight = currentFlight, Visited = false, InCluster = false
                        };

                        dataPoints.Add(dataPoint);
                    }
                }
            }
            Console.WriteLine("Error Count loading flights: " + errorCount);
            return(dataPoints);
        }