示例#1
0
        //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);
            }
        }