Example #1
0
 private void MakeSubAffordances([NotNull] DtoCalcLocationDict locations, [NotNull] CalcVariableRepository variableRepository,
                                 [NotNull] CalcAffordanceDto affordancedto, [NotNull] CalcAffordance caff)
 {
     foreach (CalcSubAffordanceDto sdto in affordancedto.SubAffordance)
     {
         CalcLocation      subaffLocation     = locations.GetCalcLocationByGuid(sdto.LocGuid);
         List <CalcDesire> satisfactionValues = MakeCalcDesires(sdto.Satisfactionvalues);
         var varOps = MakeVariableOps(locations, sdto.VariableOps, variableRepository);
         //subaffordances have no time limits
         BitArray          isBusySub = new BitArray(_calcRepo.CalcParameters.InternalTimesteps, false);
         CalcSubAffordance csuf      = new CalcSubAffordance(sdto.Name,
                                                             subaffLocation,
                                                             satisfactionValues,
                                                             sdto.MiniumAge, sdto.MaximumAge,
                                                             sdto.Delaytimesteps,
                                                             sdto.PermittedGender,
                                                             sdto.AffCategory,
                                                             sdto.IsInterruptable,
                                                             sdto.IsInterrupting,
                                                             caff,
                                                             varOps,
                                                             sdto.Weight,
                                                             sdto.SourceTrait,
                                                             sdto.Guid, isBusySub, variableRepository, caff.BodilyActivityLevel, _calcRepo);
         caff.SubAffordances.Add(csuf);
     }
 }
Example #2
0
        public void SetAllAffordaces([NotNull][ItemNotNull] List <CalcAffordanceDto> affordances,
                                     [NotNull] DtoCalcLocationDict locations,
                                     [NotNull] CalcVariableRepository variableRepository,
                                     [ItemNotNull][NotNull] List <CalcDevice> devices)
        {
            if (affordances.Count == 0)
            {
                throw new LPGException("No Affordances found.");
            }

            foreach (CalcAffordanceDto affordancedto in affordances)
            {
                CalcProfile  personProfile = CalcDeviceFactory.MakeCalcProfile(affordancedto.PersonProfile, _calcRepo.CalcParameters);
                CalcLocation calcLocation  = locations.GetCalcLocationByGuid(affordancedto.CalcLocationGuid);
                var          calcDesires   = MakeCalcDesires(affordancedto.Satisfactionvalues);
                var          color         = new ColorRGB(affordancedto.ColorR, affordancedto.ColorG, affordancedto.ColorB);
                var          variableOps   = MakeVariableOps(locations, affordancedto.VariableOps, variableRepository);
                List <VariableRequirement> requirements = new List <VariableRequirement>();
                foreach (VariableRequirementDto requirementDto in affordancedto.VariableRequirements)
                {
                    VariableRequirement vrq = new VariableRequirement(requirementDto.Name,
                                                                      requirementDto.Value, requirementDto.CalcLocationName, requirementDto.LocationGuid,
                                                                      requirementDto.VariableCondition, variableRepository, requirementDto.VariableGuid);
                    requirements.Add(vrq);
                }

                var deviceEnergyProfiles = MakeDeviceEnergyProfileTuples(devices, affordancedto);

                var            busyarr = _availabilityDtoRepository.GetByGuid(affordancedto.IsBusyArray.Guid);
                CalcAffordance caff    = new CalcAffordance(
                    affordancedto.Name,
                    personProfile, calcLocation,
                    affordancedto.RandomEffect,
                    calcDesires,
                    affordancedto.MiniumAge,
                    affordancedto.MaximumAge,
                    affordancedto.PermittedGender,
                    affordancedto.NeedsLight,
                    affordancedto.TimeStandardDeviation,
                    color,
                    affordancedto.AffCategory,
                    affordancedto.IsInterruptable,
                    affordancedto.IsInterrupting,
                    variableOps,
                    requirements,
                    affordancedto.ActionAfterInterruption,
                    affordancedto.TimeLimitName,
                    affordancedto.Weight,
                    affordancedto.RequireAllDesires,
                    affordancedto.SrcTrait,
                    affordancedto.Guid,
                    variableRepository, deviceEnergyProfiles,
                    busyarr, affordancedto.BodilyActivityLevel, _calcRepo);
                MakeSubAffordances(locations, variableRepository, affordancedto, caff);

                calcLocation.AddAffordance(caff);
            }
        }
Example #3
0
        public void MakeTransportation([NotNull] CalcHouseholdDto household,
                                       [NotNull] DtoCalcLocationDict locDict,
                                       [NotNull] CalcHousehold chh)
        {
            if (household.CalcTravelRoutes == null || household.CalcSites == null ||
                household.CalcTransportationDevices == null)
            {
                Logger.Info("Missing something for the transportation");
                if (household.CalcTravelRoutes == null)
                {
                    Logger.Info("No travel routes are set");
                }

                if (household.CalcSites == null)
                {
                    Logger.Info("No sites are set");
                }

                if (household.CalcTransportationDevices == null)
                {
                    Logger.Info("No Transportation devices are set");
                }

                return;
            }

            TransportationHandler th = new TransportationHandler();

            chh.TransportationHandler = th;
            Logger.Info("Making Calc Sites");
            var sites = MakeCalcSites(household, locDict, _loadTypeDict, th);

            foreach (var site in sites)
            {
                th.AddSite(site);
            }
            Logger.Info("Making travel routes");
            MakeTravelRoutes(household.CalcTravelRoutes, chh, sites, th);
            Logger.Info("Making Transportation devices");
            MakeTransportationDevice(chh, household.CalcTransportationDevices);
            Logger.Info("Setting affordances");
            SetAffordances(chh);
            Logger.Info("Finished initalizing the transportation");
        }
Example #4
0
        private static List <CalcAffordanceVariableOp> MakeVariableOps([NotNull] DtoCalcLocationDict locations,
                                                                       [NotNull][ItemNotNull]
                                                                       List <CalcAffordanceVariableOpDto> affordancedto,
                                                                       [NotNull] CalcVariableRepository repository)
        {
            List <CalcAffordanceVariableOp> variableOps = new List <CalcAffordanceVariableOp>();

            foreach (CalcAffordanceVariableOpDto variableOpDto in affordancedto)
            {
                if (!repository.IsVariableRegistered(variableOpDto.VariableGuid))
                {
                    throw new LPGException("Variable " + variableOpDto.Name + " was not registered.");
                }

                CalcLocation variableLocation = locations.GetCalcLocationByGuid(variableOpDto.LocationGuid);
                var          variableOp       = new CalcAffordanceVariableOp(variableOpDto.Name, variableOpDto.Value,
                                                                             variableLocation, variableOpDto.VariableAction, variableOpDto.ExecutionTime,
                                                                             variableOpDto.VariableGuid);
                variableOps.Add(variableOp);
            }

            return(variableOps);
        }
        public List <CalcAutoDev> MakeCalcAutoDevs(
            [NotNull][ItemNotNull] List <CalcAutoDevDto> autoDevices,
            [NotNull] DtoCalcLocationDict locationDict)
        {
            var autodevs = new List <CalcAutoDev>(autoDevices.Count);

            foreach (var autoDevDto in autoDevices)
            {
                if (_loadTypeDictionary.SimulateLoadtype(autoDevDto.LoadtypeGuid))
                {
                    var         deviceLoads = MakeCalcDeviceLoads(autoDevDto, _loadTypeDictionary);
                    CalcProfile cp          = MakeCalcProfile(autoDevDto.CalcProfile, _calcRepo.CalcParameters);

                    var          loadtype     = _loadTypeDictionary.GetLoadtypeByGuid(autoDevDto.LoadtypeGuid);
                    CalcLocation calcLocation = locationDict.GetCalcLocationByGuid(autoDevDto.CalcLocationGuid);
                    List <VariableRequirement> requirements = new List <VariableRequirement>();
                    foreach (var req in  autoDevDto.Requirements)
                    {
                        VariableRequirement vreq = new VariableRequirement(req.Name,
                                                                           req.Value, req.CalcLocationName, req.LocationGuid,
                                                                           req.VariableCondition, _calcVariableRepository, req.VariableGuid);
                        requirements.Add(vreq);
                    }

                    autoDevDto.AdditionalName = " (autonomous)";
                    var cautodev = new CalcAutoDev(cp, loadtype,
                                                   deviceLoads, autoDevDto.TimeStandardDeviation,
                                                   1, calcLocation,
                                                   requirements, autoDevDto, _calcRepo);
                    var busyarr = _availabilityDtoRepository.GetByGuid(autoDevDto.BusyArr.Guid);
                    cautodev.ApplyBitArry(busyarr, loadtype);
                    autodevs.Add(cautodev);
                }
            }

            return(autodevs);
        }
Example #6
0
        private List <CalcSite> MakeCalcSites([NotNull] CalcHouseholdDto household, [NotNull]
                                              DtoCalcLocationDict locDict, [NotNull] CalcLoadTypeDictionary ltDict,
                                              [NotNull] TransportationHandler th
                                              )
        {
            List <CalcSite> sites = new List <CalcSite>();

            //Dictionary<string, CalcSite> siteDictByGuid = new Dictionary<string, CalcSite>();
            if (household.CalcSites == null)
            {
                throw new LPGException("CalcSites was null"); //for the bug in the null checking
            }

            foreach (var siteDto in household.CalcSites)
            {
                var calcSite = new CalcSite(siteDto.Name, siteDto.Guid, household.HouseholdKey);
                sites.Add(calcSite);
                //siteDictByGuid.Add(siteDto.Guid, calcSite);
                foreach (var locGuid in siteDto.LocationGuid)
                {
                    CalcLocation calcLoc = locDict.GetCalcLocationByGuid(locGuid);
                    calcLoc.CalcSite = calcSite;
                    calcSite.Locations.Add(calcLoc);
                }

                foreach (var chargingStation in siteDto.ChargingStations)
                {
                    var gridLt = ltDict.GetLoadtypeByGuid(chargingStation.GridChargingLoadType.Guid);
                    var carLt  = ltDict.GetLoadtypeByGuid(chargingStation.CarChargingLoadType.Guid);
                    var cat    = th.GetCategory(chargingStation.DeviceCategory);
                    calcSite.AddChargingStation(gridLt, cat, chargingStation.MaxChargingPower,
                                                carLt, _calcRepo);
                }
            }
            return(sites);
        }
Example #7
0
        public List <CalcLocation> MakeCalcLocations([NotNull][ItemNotNull] List <CalcLocationDto> locations,
                                                     [NotNull] DtoCalcLocationDict locdict, CalcRepo calcRepo)
        {
            var locs = new List <CalcLocation>();

            foreach (var t in locations)
            {
                // loc anlegen
                var cloc = new CalcLocation(t.Name, t.Guid);
                foreach (var locdev in t.LightDevices)
                {
                    var deviceLoads = CalcDeviceFactory.MakeCalcDeviceLoads(locdev, _calcLoadTypeDict);
                    var deviceName  = CalcAffordanceFactory.FixAffordanceName(locdev.Name, _calcRepo.CalcParameters.CSVCharacter);
                    locdev.Name = deviceName;
                    var clightdevice = new CalcDevice(deviceLoads,
                                                      cloc, locdev, calcRepo);
                    cloc.AddLightDevice(clightdevice);
                }
                //deviceLocationDict.Add(cloc, new List<IAssignableDevice>());
                locs.Add(cloc);
                locdict.LocationDtoDict.Add(t, cloc);
            }
            return(locs);
        }
        public CalcHousehold MakeCalcModularHousehold([NotNull] CalcHouseholdDto householdDto,
                                                      [NotNull] out DtoCalcLocationDict dtoCalcLocationDict,
                                                      [CanBeNull] string houseName,
                                                      [CanBeNull] string houseDescription, [NotNull] CalcRepo calcRepo)
        {
            CalcHousehold chh = null;

            _calcRepo.FileFactoryAndTracker.RegisterHousehold(householdDto.HouseholdKey,
                                                              householdDto.Name,
                                                              HouseholdKeyType.Household,
                                                              householdDto.Description,
                                                              houseName,
                                                              houseDescription);
            string name = householdDto.Name + " " + householdDto.HouseholdKey;

            try {
                dtoCalcLocationDict = new DtoCalcLocationDict();
                var calcLocations = _clf.MakeCalcLocations(householdDto.LocationDtos, dtoCalcLocationDict, calcRepo);
                if (calcLocations.Count == 0)
                {
                    throw new LPGException("Not a single location could be created. Something in this household is wrong. Please fix.");
                }

                // devices
                var calcDevices = new List <CalcDevice>();
                _cdf.MakeCalcDevices(calcLocations, householdDto.DeviceDtos, calcDevices,
                                     householdDto.HouseholdKey, _ltDict, calcRepo);

                var autodevs = _cdf.MakeCalcAutoDevs(householdDto.AutoDevices, dtoCalcLocationDict);

                //affordances

                /*if (householdDto.Vacation == null)
                 * {
                 *  throw new LPGException("Vacation was null");
                 * }*/

                //_cdf.MakeCalcDevices(calcLocations, householdDto.DeviceDtos, calcDevices,householdDto.HouseholdKey, _ltDict);
                var calcpersons = _cpf.MakeCalcPersons(householdDto.Persons, calcLocations[0], householdDto.Name);
                chh = new CalcHousehold(name,
                                        householdDto.GeographicLocationName,
                                        householdDto.TemperatureprofileName,
                                        householdDto.HouseholdKey,
                                        householdDto.Guid,
                                        _calcVariableRepository,
                                        calcLocations,
                                        calcpersons,
                                        householdDto.Description,
                                        _calcRepo);
                HashSet <StrGuid> deviceGuids = new HashSet <StrGuid>();
                foreach (CalcDevice device in calcDevices)
                {
                    if (!deviceGuids.Add(device.Guid))
                    {
                        throw new LPGException("Tried to add the same device guid twice");
                    }
                }

                chh.SetDevices(calcDevices);
                chh.SetAutoDevs(autodevs);
                //chh.BridgeDays = householdDto.BridgeDays;
                _caf.SetAllAffordaces(householdDto.Affordances, dtoCalcLocationDict,
                                      _calcVariableRepository, calcDevices);
                CheckCalcAffordancesForExecutability(chh);
                if (householdDto.CalcTravelRoutes != null)
                {
                    Logger.Info("Starting to initialize transportation for household " + householdDto.Name + "...");
                    _ctf.MakeTransportation(householdDto, dtoCalcLocationDict, chh);
                }
                else
                {
                    Logger.Info("No travel route was set for for household " + householdDto.Name + ", skipping transportation");
                }

                return(chh);
            }
            catch {
                chh?.Dispose();
                throw;
            }
        }