public void AddSite([NotNull] CalcSite srcSite)
 {
     CalcSites.Add(srcSite);
     foreach (CalcLocation location in srcSite.Locations)
     {
         LocationSiteLookup.Add(location, srcSite);
     }
 }
 public void ActivateStep([NotNull] TimeStep startTimeStep, [NotNull] CalcTransportationDevice pickedDevice,
                          int pickeddurationInTimesteps, [NotNull] CalcSite srcSite, [NotNull] CalcSite dstSite,
                          [NotNull] string travelRouteName, [NotNull] string personName
                          , [NotNull] TimeStep transportationEventStartTimeStep, [NotNull] TimeStep transportationEventEndTimeStep)
 {
     pickedDevice.Activate(startTimeStep, pickeddurationInTimesteps, srcSite, dstSite,
                           travelRouteName, personName, transportationEventStartTimeStep, transportationEventEndTimeStep);
     if (_vehiclePool.Contains(pickedDevice))
     {
         _vehiclePool.Remove(pickedDevice);
     }
 }
 public CalcTravelRoute([NotNull] string pName, [NotNull] CalcSite siteA, [NotNull] CalcSite siteB,
                        [NotNull][ItemNotNull] List <CalcTransportationDevice> vehiclePool,
                        [NotNull][ItemNotNull] List <CalcTransportationDevice> locationUnlimitedDevices,
                        [NotNull] HouseholdKey householdkey, StrGuid guid,
                        CalcRepo calcRepo) : base(pName, guid)
 {
     _householdkey = householdkey;
     _calcRepo     = calcRepo;
     SiteA         = siteA;
     SiteB         = siteB;
     siteA.AddRoute(this);
     _vehiclePool = vehiclePool;
     _locationUnlimitedDevices = locationUnlimitedDevices;
 }
        public bool IsAvailableRouteFor([NotNull] CalcSite srcSite, [NotNull] CalcSite dstSite, [ItemNotNull][NotNull] List <CalcTransportationDevice> devicesAtSrcLoc)
        {
            if (SiteA == srcSite && dstSite == SiteB)
            {
                List <CalcTransportationDeviceCategory> neededCategories =
                    CollectNeededCalcTransportationDeviceCategory();
                if (neededCategories.Count == 0)
                {
                    return(true);
                }

                bool areCategoriesAvailable = srcSite.AreCategoriesAvailable(neededCategories, _vehiclePool, devicesAtSrcLoc);
                return(areCategoriesAvailable);
            }

            return(false);
        }
Ejemplo n.º 5
0
 //[CanBeNull]
 //private CalcAffordanceBase _MainAffordance;
 public AffordanceBaseTransportDecorator([NotNull] ICalcAffordanceBase sourceAffordance,
                                         [NotNull] CalcSite site, [NotNull] TransportationHandler transportationHandler,
                                         [NotNull] string name, [NotNull] HouseholdKey householdkey,
                                         StrGuid guid, CalcRepo calcRepo)
     : base(name, guid)
 {
     if (!site.Locations.Contains(sourceAffordance.ParentLocation))
     {
         throw new LPGException("Wrong site. Bug. Please report.");
     }
     _householdkey = householdkey;
     _calcRepo     = calcRepo;
     _calcRepo.OnlineLoggingData.AddTransportationStatus(new TransportationStatus(new TimeStep(0, 0, false), householdkey, "Initializing affordance base transport decorator for " + name));
     Site = site;
     _transportationHandler = transportationHandler;
     _sourceAffordance      = sourceAffordance;
 }
Ejemplo n.º 6
0
        private void AdjustCurrentsiteByTimestep([NotNull] TimeStep timestep)
        {
            if (Category.IsLimitedToSingleLocation)
            {
                if (_targetSiteByTimeStep.ContainsKey(timestep.InternalStep))
                {
                    _currentSite = _targetSiteByTimeStep[timestep.InternalStep];
                    _targetSiteByTimeStep.Remove(timestep.InternalStep);
                }

                foreach (var ts in _targetSiteByTimeStep.Keys)
                {
                    if (ts < timestep.InternalStep)
                    {
                        throw new LPGException("Leftover old timestep");
                    }
                }
            }
        }
        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);
        }
Ejemplo n.º 8
0
        public void Activate([NotNull] TimeStep startTimeStep, int durationInTimesteps, [NotNull] CalcSite srcSite,
                             [NotNull] CalcSite dstSite,
                             [NotNull] string travelRouteName,
                             [NotNull] string personName, [NotNull] TimeStep transportationEventStartTimeStep,
                             [NotNull] TimeStep transportationEventEndTimeStep)
        {
            if (startTimeStep < transportationEventStartTimeStep || transportationEventEndTimeStep < startTimeStep)
            {
                throw new LPGException("Bug in the transportation module. Start time earlier than possible.");
            }

            if (durationInTimesteps == 0)
            {
                throw new LPGException("Can't activate with a duration of 0 timesteps");
            }

            _lastUsingPerson = personName;
            if (startTimeStep < _activationStopTimestep && Category.IsLimitedToSingleLocation)
            {
                throw new LPGException(
                          "Double activation of a transportation device. This seems to be a bug. Please fix.");
            }

            if (_currentSite != srcSite && _currentSite != null)
            {
                throw new LPGException("Trying to activate a device that is not at the source location");
            }

            _activationStartTimestep = startTimeStep;
            _activationStopTimestep  = startTimeStep.AddSteps(durationInTimesteps);
            if (Category.IsLimitedToSingleLocation)
            {
                _targetSiteByTimeStep.Add(startTimeStep.InternalStep, null);
                _targetSiteByTimeStep.Add(_activationStopTimestep.InternalStep, dstSite);
            }

            //_currentSite = dstSite;
            for (int i = transportationEventStartTimeStep.InternalStep;
                 i < transportationEventEndTimeStep.InternalStep && i < _isBusyArray.Length;
                 i++)
            {
                _isBusyArray[i] = true;
            }

            foreach (CalcDeviceLoad load in _loads)
            {
                var transportationDeviceProfile = new List <double>(durationInTimesteps);
                for (var i = 0; i < durationInTimesteps; i++)
                {
                    transportationDeviceProfile.Add(load.Value);
                }

                var cp = new CalcProfile(srcSite.Name + " - " + dstSite.Name + " - " + Name,
                                         System.Guid.NewGuid().ToStrGuid(),
                                         transportationDeviceProfile,
                                         ProfileType.Relative,
                                         "Synthetic for " + Name);
                SetTimeprofile(cp, startTimeStep, load.LoadType, "Transport via " + Name,
                               personName + " - " + travelRouteName, _calcDeviceDto.LocationGuid);
            }
        }
Ejemplo n.º 9
0
 public List <CalcTravelRoute> GetAllRoutesTo([NotNull] CalcSite dstSite, [ItemNotNull][NotNull] List <CalcTransportationDevice> devicesAtSrc)
 {
     return(MyRoutes.Where(x => x.IsAvailableRouteFor(this, dstSite, devicesAtSrc)).ToList());
 }