/// <summary> /// Get a itinerary from station 'start' to station 'end' based on the 'preference'. /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="preference"></param> /// <returns></returns> public Itinerary GetItinerary(StationController start, StationController end, TravelPreference preference) { if (start.Equals(end)) { return(null); } if (start.outOfService || end.outOfService) { return(null); } var itineraries = new List <Itinerary>(GetItineraries(start, end)); switch (preference) { case TravelPreference.none: break; case TravelPreference.transit: itineraries.Sort((x, y) => x.Transits.Count.CompareTo(y.Transits.Count)); break; default: case TravelPreference.time: itineraries.Sort((x, y) => x.GetTotalTravelTime().CompareTo(y.GetTotalTravelTime())); break; } if (itineraries.Count < 1) { //Debug.LogFormat("No itinery between {0}, {1}", start, end); return(null); } return(itineraries[0]); }
public FlashPedestriansProfile(float speed, bool englishSpeaker, bool italianSpeaker, float chanceOfSubscription, bool willingToChangeDestination, float chanceOfTakingABike, float chanceOfBelievingRumours, bool carAwareness, TravelPreference preference) { this.speed = speed; this.englishSpeaker = englishSpeaker; this.italianSpeaker = italianSpeaker; this.chanceOfSubscription = chanceOfSubscription; this.willingToChangeDestination = willingToChangeDestination; this.chanceOfTakingABike = chanceOfTakingABike; this.weatherFactorOnTakingBikes = 1.0f; this.chanceOfBelievingRumours = chanceOfBelievingRumours; this.carAwareness = carAwareness; this.travelPreference = preference; }
void SpawnTraveler(int start, int end, TravelPreference preference = TravelPreference.time) { var itinerary = routingController.GetItinerary(start, end, preference); int index = Mathf.FloorToInt(UnityEngine.Random.Range(0, spawnPoints.Count)); //if (itinerary == null) // return; GameObject newTraveler = TravelerController.CreateGameObject(itinerary); newTraveler.transform.SetParent(travelers.transform); newTraveler.transform.position = RandomSpawnPoint(spawnPoints[index]); //Debug.Log(itinerary); }
void SpawnTravelers(int numberOfSpawns, TravelPreference preference) { for (int i = 0; i < numberOfSpawns; i++) { int s1 = routingController.GetRandomStationId(); int s2; do { s2 = routingController.GetRandomStationId(); } while (s1 == s2); SpawnTraveler(s1, s2, preference); //SpawnTraveler(5, 11, TravelPreference.transit); } }
/// <summary> /// Bubble algorithm to find the best itinerary between the stations given and the stations close to the destination point. /// </summary> /// <param name="startingPoint">Point in the map where the pedestrian starts.</param> /// <param name="destination">Final destination of the pedestrian.</param> /// <param name="stationsNearby">Stations nearby considered by the pedestrian.</param> /// <param name="travelPreference">Travel preferences of the pedestrian.</param> /// <returns>An Itinerary object with the best itinerary for the pedestrian (empty itinerary if anything better than walking has been found).</returns> public Itinerary FindBestItinerary(Vector3 startingPoint, FlashPedestriansDestination destination, StationController[] stationsNearby, TravelPreference travelPreference) { Itinerary bestItineraryFound = new Itinerary(new List <StationController>()); // The default travel time taken into account is the possibility of walking all the way float bestTravelTime = Vector3.Distance(startingPoint, destination.transform.position) * secondsPerMeter; for (int i = 0; i < stationsNearby.Length; i++) { for (int j = 0; j < destination.stationsNearThisDestination.Length; j++) { Itinerary nextItinerary = routingController.GetItinerary( stationsNearby[i], destination.stationsNearThisDestination[j].GetComponent <StationController>(), travelPreference); if (nextItinerary != null) { // Check the total travel time considering walking times form the starting point to the first station and from th last station to the destination float timeWalkingToFirstStation = Vector3.Distance(startingPoint, nextItinerary.FirstStop.transform.position) * secondsPerMeter; float timeWalkingFromLastStation = Vector3.Distance(nextItinerary.LastStop.transform.position, destination.transform.position) * secondsPerMeter; float travelTime = nextItinerary.GetTotalTravelTime() + timeWalkingToFirstStation + timeWalkingFromLastStation; if (travelTime < bestTravelTime) { bestTravelTime = travelTime; bestItineraryFound = nextItinerary; } } } } if (bestItineraryFound == null) { Debug.Log("No itinerary found"); } return(bestItineraryFound); }
/// <summary> /// Get a itinerary from stationId 'start' to stationId 'end' based on the 'preference'. /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="preference"></param> /// <returns></returns> public Itinerary GetItinerary(int start, int end, TravelPreference preference) { return(GetItinerary(Stations[start.ToString()], Stations[end.ToString()], preference)); }