private void GraphTripPurpose(Distribution.DistributionInformation[] distributionData) { TashaHousehold Household = new TashaHousehold(); TashaPerson person = new TashaPerson(); List <int> primaryWork = new List <int>(); person.Licence = false; person.Male = GenderLocal; SchedulerHousehold.CreateHouseholdProjects(Household); SchedulerPerson.InitializePersonalProjects(person); SchedulerPerson.GenerateWorkSchoolSchedule(person, null); SchedulerTripChain.GetTripChain(person); var trip = SchedulerTrip.GetTrip(0); Occupation[] Occupations = { Occupation.Professional, Occupation.Manufacturing, Occupation.Retail, Occupation.Office, Occupation.Unknown, Occupation.NotEmployed }; LoadDistributioNumbers(person, primaryWork, Occupations); float[] data = new float[this.StartTimeQuantums]; foreach (int ID in primaryWork) { var table = distributionData[ID].StartTimeFrequency; for (int i = 0; i < this.StartTimeQuantums; i++) { for (int j = 0; j < this.MaxFrequencyLocal; j++) { data[i] += table[i][j]; } } } // Make all data in terms of percentages of total. float sum = data.Sum(); for (int number = 0; number < data.Length; number++) { data[number] = data[number] / sum * 100; Writer.WriteLine("{0}, {1}", (Time.FromMinutes((60 * 4) + number * (1440 / this.StartTimeQuantums))), data[number]); } GenerateChart(String.Format("OfficeDur.png"), data, "Time of Day", "Probability"); }
public override void GenerateTrips(ITashaHousehold household, int householdIterations, Time minimumAtHomeTime) { /* * Now we need to generate the trips. * For each episode, we need to check if the person goes home first or not * If the do go home we need to add a trip there and a trip to i+1 */ SchedulerTripChain currentChain = null; int i = 0; bool atHome = true; int tripNumber = 1; var homeZone = household.HomeZone; for (; i < EpisodeCount; i++) { var isAtHomeEpisode = AtHomeActivity(Episodes[i].ActivityType); // if we are already at home and we are going to be doing a household activity just continue if (atHome && isAtHomeEpisode) { continue; } // if we are not currently working on a trip chain, setup a new one and add it to our person if (currentChain == null) { currentChain = SchedulerTripChain.GetTripChain(Owner); Owner.TripChains.Add(currentChain); } // If we are out or we want to head out build our trip to leave SchedulerTrip trip = SchedulerTrip.GetTrip(householdIterations); trip.Purpose = Episodes[i].ActivityType; trip.ActivityStartTime = Episodes[i].StartTime; trip.OriginalZone = (i == 0 ? homeZone : Episodes[i - 1].Zone); trip.DestinationZone = Episodes[i].Zone; // Check to see if we should go home unless we are already there OR the activity we are going to brings us to home anyways if (!atHome && !isAtHomeEpisode) { Time toHome = Scheduler.TravelTime(Owner, Episodes[i - 1].Zone, homeZone, Episodes[i - 1].EndTime); Time toNext = Scheduler.TravelTime(Owner, homeZone, Episodes[i].Zone, Episodes[i].StartTime); if (toHome + toNext + minimumAtHomeTime < Episodes[i].StartTime - Episodes[i - 1].EndTime) { // Set a course, for home SchedulerHomeTrip toHomeTrip = SchedulerHomeTrip.GetTrip(householdIterations); toHomeTrip.TripStartTime = Episodes[i - 1].EndTime; toHomeTrip.OriginalZone = Episodes[i - 1].Zone; toHomeTrip.DestinationZone = homeZone; toHomeTrip.Purpose = GetGoingHomePurpose(Episodes[i - 1].ActivityType); toHomeTrip.TripChain = currentChain; toHomeTrip.TripNumber = tripNumber; currentChain.Trips.Add(toHomeTrip); // the next trip starts back at one tripNumber = 1; // Now we can move onto the next chain currentChain = SchedulerTripChain.GetTripChain(Owner); Owner.TripChains.Add(currentChain); // We also need to update the zone that we are coming from (home) trip.OriginalZone = homeZone; } } trip.TripChain = currentChain; trip.TripNumber = tripNumber++; currentChain.Trips.Add(trip); if (isAtHomeEpisode) { currentChain = null; } atHome = isAtHomeEpisode; } // Now that everything is scheduled if (!atHome) { SchedulerHomeTrip toHome = SchedulerHomeTrip.GetTrip(householdIterations); toHome.OriginalZone = Episodes[EpisodeCount - 1].Zone; if (Episodes[EpisodeCount - 1].Zone == null) { throw new XTMFRuntimeException("An episode had a null zone!"); } if (toHome.OriginalZone.ZoneNumber == Tasha.Scheduler.Scheduler.Tasha.ZoneSystem.RoamingZoneNumber) { throw new XTMFRuntimeException ( "We are trying to make a trip from the roaming zone to home!" + "\r\nHHLD:" + household.HouseholdId + "\r\nPrevious Purpose" + Episodes[EpisodeCount - 1].ActivityType.ToString() ); } toHome.DestinationZone = homeZone; toHome.Purpose = GetGoingHomePurpose(Episodes[EpisodeCount - 1].ActivityType); toHome.TripChain = currentChain; toHome.TripStartTime = Episodes[EpisodeCount - 1].EndTime; // this will have already been increased in the while loop toHome.TripNumber = tripNumber; currentChain.Trips.Add(toHome); } }