public void PredictEndLocation() { foreach (var driver in drivers) { RoutePrediction routePrediction = new RoutePrediction(500); foreach (TripSummary trip in trips.Where(t => t.DriverId.Equals(driver))) { routePrediction.AddTripSummary(trip); } double lat = 47.6583066666667; double lon = -122.14119; RoutePredictionResult predictionResult = routePrediction.PredictEndLocation(lat, lon, DateTime.Now); Console.WriteLine("driver: " + driver); Console.WriteLine("cluster level: " + predictionResult.ClusterLevel); foreach (var prediction in predictionResult.Predictions) { Console.Write("Lat/Lon: " + prediction.Lat + "/" + prediction.Lon); Console.Write("\tProbability: " + prediction.Probability); Console.Write("\tEndpoints: " + prediction.NrOfEndPoints); Console.Write("\tMatches T/D/W: " + prediction.NrOfTimeMatches); Console.Write("/" + prediction.NrOfDayMatches); Console.WriteLine("/" + prediction.NrOfWorkdayMatches); } Console.WriteLine(); } }
public RoutePredictionResult PredictEndLocation(double lat, double lon, DateTime time) { var prediction = new RoutePredictionResult(); // check how many start points we have within a cluster // and iterate through the cluster hierachy to get at least 1 location // TODO: filter using time of the day (morning, midday, evening, night), week day, month,... ClusterItem<LocationInstance<TripSummary>> cluster = startLocationRoot.GetLeaf(lat, lon); prediction.ClusterLevel = 0; while (cluster.GetNrOfLocations() == 0) { var parentItem = cluster.GetParentItem(); if (parentItem != null) { if (parentItem is ClusterItem<LocationInstance<TripSummary>>) { cluster = parentItem as ClusterItem<LocationInstance<TripSummary>>; prediction.ClusterLevel++; } else { // return an empty prediction result return prediction; } } else { // return an empty prediction result return prediction; } } Dictionary<ClusterLeaf<TripSummary>, RoutePredictionItem> leafs = new Dictionary<ClusterLeaf<TripSummary>, RoutePredictionItem>(); // create a list of endLocation leafs and count how many times an endlocation is part of the leaf foreach (var location in cluster.GetLocations()) { ClusterLeaf<TripSummary> leaf = location.LocationObject.GetParentItem() as ClusterLeaf<TripSummary>; if (!leafs.ContainsKey(leaf)) { leafs[leaf] = new RoutePredictionItem() { Lat = leaf.CenterLat, Lon = leaf.CenterLon, NrOfEndPoints = 0, NrOfDayMatches = 0, NrOfTimeMatches = 0, NrOfWorkdayMatches = 0 }; } leafs[leaf].NrOfEndPoints++; leafs[leaf].TripIds.Add(location.LocationObject.LocationObject.TripId); if (location.LocationObject.LocationObject.StartTime.DayOfWeek == time.DayOfWeek) { leafs[leaf].NrOfDayMatches++; } ; if (IsWeekend(location.LocationObject.LocationObject.StartTime) == IsWeekend(time)) { leafs[leaf].NrOfWorkdayMatches++; } if (GetTimeSlot(location.LocationObject.LocationObject.StartTime) == GetTimeSlot(time)) { leafs[leaf].NrOfTimeMatches++; } leafs[leaf].CalculateProbability(cluster.GetNrOfLocations()); } prediction.Predictions = leafs.Values.ToList(); prediction.Predictions.Sort(); return prediction; }