public void AddRoute([NotNull] CalcTravelRoute route) { if (MyRoutes.Contains(route)) { return; } MyRoutes.Add(route); }
public CalcTravelRoute GetTravelRouteFromSrcLoc([NotNull] CalcLocation srcLocation, [NotNull] CalcSite dstSite, [NotNull] TimeStep startTimeStep, [NotNull] string personName, CalcRepo calcRepo) { CalcSite srcSite = LocationSiteLookup[srcLocation]; if (srcSite == dstSite) { return(SameSiteRoutes[srcSite]); } //first get the routes, no matter if busy var devicesAtSrc = AllMoveableDevices.Where(x => x.Currentsite == srcSite).ToList(); var possibleRoutes = srcSite.GetAllRoutesTo(dstSite, devicesAtSrc); if (possibleRoutes.Count == 0) { return(null); } //check if the route is busy by calculating the duration. If busy, duration will be null int? dur = null; CalcTravelRoute ctr = null; while (dur == null && possibleRoutes.Count > 0) { ctr = possibleRoutes[calcRepo.Rnd.Next(possibleRoutes.Count)]; possibleRoutes.Remove(ctr); dur = ctr.GetDuration(startTimeStep, personName, AllMoveableDevices); } if (dur == null) { ctr = null; } return(ctr); }
//BitArray ICalcAffordanceBase.IsBusyArray { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public void Activate(TimeStep startTime, string activatorName, CalcLocation personSourceLocation, out ICalcProfile personTimeProfile) { if (_myLastTimeEntry.TimeOfLastEvalulation != startTime) { throw new LPGException("trying to activate without first checking if the affordance is busy is a bug. Please report."); } CalcTravelRoute route = _myLastTimeEntry.PreviouslySelectedRoutes[personSourceLocation]; int routeduration = route.Activate(startTime, activatorName, out var usedDevices); if (routeduration == 0) { _calcRepo.OnlineLoggingData.AddTransportationStatus( new TransportationStatus(startTime, _householdkey, "\tActivating " + Name + " at " + startTime + " with no transportation and moving from " + personSourceLocation + " to " + _sourceAffordance.ParentLocation.Name + " for affordance " + _sourceAffordance.Name)); } else { _calcRepo.OnlineLoggingData.AddTransportationStatus(new TransportationStatus( startTime, _householdkey, "\tActivating " + Name + " at " + startTime + " with a transportation duration of " + routeduration + " for moving from " + personSourceLocation + " to " + _sourceAffordance.ParentLocation.Name)); } TimeStep affordanceStartTime = startTime.AddSteps(routeduration); if (affordanceStartTime.InternalStep < _calcRepo.CalcParameters.InternalTimesteps) { _sourceAffordance.Activate(affordanceStartTime, activatorName, personSourceLocation, out var sourcePersonProfile); CalcProfile newPersonProfile = new CalcProfile( "Travel Profile for Route " + route.Name + " to affordance " + _sourceAffordance.Name, System.Guid.NewGuid().ToStrGuid(), CalcProfile.MakeListwithValue1AndCustomDuration(routeduration), ProfileType.Absolute, sourcePersonProfile.DataSource); newPersonProfile.AppendProfile(sourcePersonProfile); personTimeProfile = newPersonProfile; string usedDeviceNames = String.Join(", ", usedDevices.Select(x => x.Device.Name + "(" + x.DurationInSteps + ")")); _calcRepo.OnlineLoggingData.AddTransportationEvent(_householdkey, activatorName, startTime, personSourceLocation.CalcSite?.Name ?? "", Site.Name, route.Name, usedDeviceNames, routeduration, sourcePersonProfile.StepValues.Count, _sourceAffordance.Name, usedDevices); } else { //this is if the simulation ends during a transport CalcProfile newPersonProfile = new CalcProfile( "Travel Profile for Route " + route.Name + " to affordance " + _sourceAffordance.Name, System.Guid.NewGuid().ToStrGuid(), CalcProfile.MakeListwithValue1AndCustomDuration(routeduration), ProfileType.Absolute, _sourceAffordance.Name); personTimeProfile = newPersonProfile; string usedDeviceNames = String.Join(", ", usedDevices.Select(x => x.Device.Name + "(" + x.DurationInSteps + ")")); _calcRepo.OnlineLoggingData.AddTransportationEvent(_householdkey, activatorName, startTime, personSourceLocation.CalcSite?.Name ?? "", Site.Name, route.Name, usedDeviceNames, routeduration, newPersonProfile.StepValues.Count, _sourceAffordance.Name, usedDevices); } }