/// <summary> /// Get the shortest A-S-P-B way. Less than 15km /// Minimum P-B way and minimum P-S way /// Return best S-P way /// </summary> public Way GetBicycleWay() { List <SharingParking> allPoints = GetAllSP(); //TODO: GET ALL SHARING-PARKING POINTS TABLE List <Point> allParking = GetPossibleParking(); // GET ALL BICYCLE STATIONS List <Point> possibleParking = new List <Point>(); //POSSIBLE PARKING POINTS (< 1.5km). HIGH PRORITY List <SharingParking> possiblePoints = new List <SharingParking>(); //GET ALL POSSIBLE SHARING-PARKING POINTS foreach (var item in allParking) { if (RequestAPI(Location.B, item)) // Less than 1.5km { possibleParking.Add(item); } } SharingParking best = null; foreach (var item in possibleParking) { var points = allPoints.Where(x => x.Parking.Latitude == item.Latitude && x.Parking.Longitude == item.Longitude && x.Distance < maxBicycleDistance).ToList(); if (points.Count > 0) { foreach (var way in points) { if (best != null) { if (best.Distance > way.Distance) { best = way; } } else { best = way; } } } } return(best != null ? new Way() { A = best.Sharing, B = best.Parking } : null); }
//TODO Get all sharing points. Directed graph (n*(n-1))-nodes private List <SharingParking> GetAllSP() { List <SharingParking> st = new List <SharingParking>(); foreach (Route item in WayStations) { SharingParking sharingParking = new SharingParking(); var sharing = BicycleStations.FirstOrDefault(x => x.Id == item.StartPointId); var parking = BicycleStations.FirstOrDefault(x => x.Id == item.FinishPointId); sharingParking.Sharing = new Point() { Latitude = sharing.Latitude, Longitude = sharing.Longitude }; sharingParking.Parking = new Point() { Latitude = parking.Latitude, Longitude = parking.Longitude }; sharingParking.Time = item.Duration; sharingParking.Distance = item.Distance; st.Add(sharingParking); } //st = WayStations.Select(x => new SharingParking() //{ // Sharing = new Point() // { // Latitude = x.StartPoint.Latitude, // Longitude = x.FinishPoint.Longitude // }, // Parking = new Point() // { // Latitude = x.StartPoint.Latitude, // Longitude = x.FinishPoint.Longitude // }, // Distance = x.Distance, // Time = x.Duration //}).ToList(); return(st); }