Beispiel #1
0
        private List <CalcAffordanceVariableOpDto> MakeVariableOps([NotNull] CalcLocationDto calcloc,
                                                                   [NotNull] LocationDtoDict
                                                                   locDict, [NotNull] HouseholdKey householdKey,
                                                                   AffordanceWithTimeLimit aff)
        {
            var variableOps = new List <CalcAffordanceVariableOpDto>();

            foreach (var affVariableOperation in aff.Affordance.ExecutedVariables)
            {
                CalcLocationDto loc = null;
                if (affVariableOperation.LocationMode == VariableLocationMode.OtherLocation)
                {
                    if (affVariableOperation.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    if (locDict.SimulateLocation(affVariableOperation.Location))
                    {
                        loc = locDict.GetDtoForLocation(affVariableOperation.Location);
                    }

                    // if the Location does not exist, don't do anything.
                }
                else
                {
                    loc = calcloc;
                }

                if (loc != null)
                {
                    if (affVariableOperation.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    var variable = _variableRepository.RegisterVariableIfNotRegistered(
                        affVariableOperation.Variable, affVariableOperation.Location, householdKey, locDict);

                    variableOps.Add(new CalcAffordanceVariableOpDto(affVariableOperation.Variable.Name,
                                                                    affVariableOperation.Value, loc.Name, loc.Guid, affVariableOperation.Action,
                                                                    affVariableOperation.ExecutionTime, variable.Guid));
                }
            }

            return(variableOps);
        }
Beispiel #2
0
        private List <VariableRequirementDto> MakeVariableRequirements([NotNull] CalcLocationDto calcloc,
                                                                       [NotNull] LocationDtoDict locDict,
                                                                       [NotNull] HouseholdKey householdKey,
                                                                       AffordanceWithTimeLimit aff)
        {
            var variableRequirements =
                new List <VariableRequirementDto>();

            foreach (var affVariableRequirement in aff.Affordance.RequiredVariables)
            {
                CalcLocationDto loc = null;
                if (affVariableRequirement.LocationMode == VariableLocationMode.OtherLocation)
                {
                    if (affVariableRequirement.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    if (locDict.SimulateLocation(affVariableRequirement.Location))
                    {
                        loc = locDict.GetDtoForLocation(affVariableRequirement.Location);
                    }
                }
                else
                {
                    loc = calcloc;
                }

                if (loc != null)
                {
                    if (affVariableRequirement.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    var variable = _variableRepository.RegisterVariableIfNotRegistered
                                       (affVariableRequirement.Variable, affVariableRequirement.Location, householdKey, locDict);
                    variableRequirements.Add(new VariableRequirementDto(affVariableRequirement.Variable.Name,
                                                                        affVariableRequirement.Value, loc.Name, loc.Guid, affVariableRequirement.Condition,
                                                                        variable.Guid));
                }
            }

            return(variableRequirements);
        }
        public CalcHouseholdDto MakeCalcModularHouseholdDto([NotNull] Simulator sim, [NotNull] ModularHousehold mhh,
                                                            [NotNull] TemperatureProfile temperatureProfile, [NotNull] HouseholdKey householdKey, [NotNull] GeographicLocation geographicLocation,
                                                            [NotNull] out LocationDtoDict locationDict,
                                                            [CanBeNull] TransportationDeviceSet transportationDeviceSet,
                                                            [CanBeNull] TravelRouteSet travelRouteSet, EnergyIntensityType energyIntensity,
                                                            [CanBeNull] ChargingStationSet chargingStationSet)
        {
            //  _lf.RegisterKey(householdKey, mhh.PrettyName);
            var name = CalcAffordanceFactory.FixAffordanceName(mhh.Name, sim.MyGeneralConfig.CSVCharacter);

            if (geographicLocation == null)
            {
                throw new DataIntegrityException("no geographic Location was set");
            }
            var et = energyIntensity;

            if (et == EnergyIntensityType.AsOriginal)
            {
                et = mhh.EnergyIntensityType;
            }
            name = name + " " + householdKey.Key;
            var locations = mhh.CollectLocations();
            //var deviceLocationDict = new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var deviceLocationDtoDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();

            locationDict = new LocationDtoDict();
            List <DeviceCategoryDto> deviceCategoryDtos = new List <DeviceCategoryDto>();

            foreach (var deviceCategory in sim.DeviceCategories.It)
            {
                deviceCategoryDtos.Add(new DeviceCategoryDto(deviceCategory.FullPath, Guid.NewGuid().ToStrGuid()));
            }
            var locationDtos = _calcLocationDtoFactory.MakeCalcLocations(locations,
                                                                         householdKey,
                                                                         et, deviceLocationDtoDict, sim.DeviceActions.It, locationDict, deviceCategoryDtos);

            // persons

            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            var personDtos = _calcPersonDtoFactory.MakePersonDtos(mhh.Persons.ToList(), householdKey,
                                                                  mhh.Vacation.VacationTimeframes(), mhh.CollectTraitDesires(), mhh.Name);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(personDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //mhh.Persons.ToList(),mhh.Vacation.VacationTimeframes(),  sim.MyGeneralConfig.RepetitionCount,householdKey, locs[0],name);
            //CalcPersonFactory.AddTraitDesires(mhh.CollectTraitDesires(), calcpersons,sim.MyGeneralConfig.TimeStepsPerHour, chh.Name, new Dictionary<Desire, SharedDesireValue>());
            //check if unhungry and unhungry join only have been added both
            //can't check it in the integrity checker, because that would mean having to duplicate the entire
            // desire collection logic

            /*  foreach (CalcPerson person in calcpersons) {
             *    var desires =
             *        person.PersonDesires.Desires.Values.Where(x => x.Name.ToLower().Contains("unhungry") || x.Name.ToLower().Contains("un-hungry")).ToList();
             *    if (desires.Count > 1) {
             *        throw new DataIntegrityException("More than one unhungry desire for the person " + person.Name, mhh);
             *    }
             * }*/

            // devices

            var deviceLocations = new List <DeviceLocationTuple>();

            foreach (var modularHouseholdTrait in mhh.Traits)
            {
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (modularHouseholdTrait.HouseholdTrait != null)
                {
                    CollectDevicesFromTrait(modularHouseholdTrait.HouseholdTrait, deviceLocations);
                }
            }

            var deviceDtos = _calcDeviceDtoFactory.MakeCalcDevices(locationDtos,
                                                                   deviceLocations, et, householdKey, deviceLocationDtoDict, sim.DeviceActions.It, _ltDict, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(deviceDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //autodevs
            var autonomousDevices = mhh.CollectAutonomousDevices();

            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            var autoDevDtos = _calcDeviceDtoFactory.MakeCalcAutoDevDtos(autonomousDevices,
                                                                        energyIntensity, householdKey, mhh.Vacation.VacationTimeframes(),
                                                                        mhh.Name + "###" + householdKey,
                                                                        sim.DeviceActions.It, locationDict,
                                                                        temperatureProfile, geographicLocation, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(autoDevDtos.ConvertAll(x => (IHouseholdKey)x));
            }

            //affordances
            var affordancesAtLoc =
                new Dictionary <CalcLocationDto, List <AffordanceWithTimeLimit> >();

            foreach (var location in locations)
            {
                affordancesAtLoc.Add(locationDict.GetDtoForLocation(location), mhh.GetAllAffordancesForLocation(location));
            }
            if (mhh.Vacation == null)
            {
                throw new LPGException("Vacation was null");
            }

            List <CalcAffordanceDto> allAffordances = _calcAffordanceDtoFactory.SetCalcAffordances(locationDtos, temperatureProfile,
                                                                                                   _ltDict,
                                                                                                   geographicLocation, _random, sim.MyGeneralConfig.TimeStepsPerHour,
                                                                                                   sim.MyGeneralConfig.InternalStepSize, mhh.Vacation.VacationTimeframes(),
                                                                                                   mhh.Name + "###" + householdKey, sim.DeviceActions.MyItems, affordancesAtLoc, locationDict,
                                                                                                   out List <DateTime> bridgeDays, householdKey, deviceDtos, deviceCategoryDtos);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.SaveList(allAffordances.ConvertAll(x => (IHouseholdKey)x));
                _calcRepo.InputDataLogger.SaveList(_calcVariableRepositoryDtoFactory.GetAllVariableDtos()
                                                   .ConvertAll(x => (IHouseholdKey)x));
            }

            //                SaveVariableDefinitionsDtos(_calcVariableRepositoryDtoFactory.GetAllVariableDtos());
            //CalcVariableRepository variableRepository = _calcVariableRepositoryDtoFactory.GetRepository(householdKey);
            List <CalcSiteDto> sites = null;
            List <CalcTransportationDeviceDto> transportationDevices = null;
            List <CalcTravelRouteDto>          routes = null;

            if (_calcRepo.CalcParameters.TransportationEnabled)
            {
                _transportationDtoFactory.MakeTransportationDtos(sim, mhh, transportationDeviceSet,
                                                                 travelRouteSet, chargingStationSet,
                                                                 out sites, out transportationDevices,
                                                                 out routes, locationDtos, householdKey);
                if (_calcRepo.CalcParameters.IsSet(CalcOption.TransportationStatistics))
                {
                    _calcRepo.InputDataLogger.SaveList(sites.ConvertAll(x => (IHouseholdKey)x));
                    _calcRepo.InputDataLogger.SaveList(transportationDevices.ConvertAll(x => (IHouseholdKey)x));
                    _calcRepo.InputDataLogger.SaveList(routes.ConvertAll(x => (IHouseholdKey)x));
                }
            }
            var chh = new CalcHouseholdDto(name, mhh.IntID, temperatureProfile.Name, householdKey, Guid.NewGuid().ToStrGuid(),
                                           geographicLocation.Name,
                                           bridgeDays, autoDevDtos, locationDtos, personDtos, deviceDtos,
                                           allAffordances, mhh.Vacation.VacationTimeframes(),
                                           sites, routes, transportationDevices,
                                           mhh.Description);

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                _calcRepo.InputDataLogger.Save(householdKey, chh);
            }

            if (_calcRepo.CalcParameters.Options.Contains(CalcOption.HouseholdContents))
            {
                BridgeDayEntries bdes = new BridgeDayEntries(householdKey, chh.BridgeDays);
                _calcRepo.InputDataLogger.Save(householdKey, bdes);
            }

            return(chh);
        }
Beispiel #4
0
        private void MakeSubAffordances([NotNull] CalcAffordanceDto caff, [NotNull] Affordance aff, int timeStepsPerHour,
                                        TimeSpan internalStepSize, [NotNull] CalcLocationDto calcloc,
                                        [NotNull] LocationDtoDict locDict,
                                        [NotNull] string csvCharacter, int weight, [NotNull] string srcTrait,
                                        [NotNull] HouseholdKey householdKey)
        {
            // Subaffordanzen durchgehen
            foreach (var affsubaff in aff.SubAffordances)
            {
                var calcDesires = new List <CalcDesireDto>();
                if (affsubaff.SubAffordance == null)
                {
                    throw new LPGException("SubAffordance was null");
                }

                var name = CalcAffordanceFactory.FixAffordanceName(affsubaff.SubAffordance.Name, csvCharacter);
                // f�r alle desires calcdesires anlegen
                foreach (var subaffDesire in affsubaff.SubAffordance.SubAffordanceDesires)
                {
                    if (subaffDesire.Desire == null)
                    {
                        throw new LPGException("Desire was null");
                    }

                    var cd = new CalcDesireDto(name + " - " + subaffDesire.Name, subaffDesire.Desire.IntID, 0, 0,
                                               subaffDesire.SatisfactionValue, 0, timeStepsPerHour, subaffDesire.Desire.CriticalThreshold,
                                               null, srcTrait, "");
                    calcDesires.Add(cd);
                }

                var minutesperstep   = (decimal)internalStepSize.TotalMinutes;
                var delayTimeInSteps = (int)(affsubaff.DelayTime / minutesperstep);
                // variables
                var calcAffordanceVariableOps = new List <CalcAffordanceVariableOpDto>();
                foreach (var affVariableOp in affsubaff.SubAffordance.SubAffordanceVariableOps)
                {
                    CalcLocationDto loc = null;
                    if (affVariableOp.LocationMode == VariableLocationMode.OtherLocation)
                    {
                        if (affVariableOp.Location != null && locDict.SimulateLocation(affVariableOp.Location))
                        {
                            loc = locDict.GetDtoForLocation(affVariableOp.Location);
                        }
                    }
                    else
                    {
                        loc = calcloc;
                    }

                    if (loc != null && affVariableOp.Variable != null)
                    {
                        if (affVariableOp.Location == null)
                        {
                            throw new LPGException("Variable Location was null");
                        }
                        var variable =
                            _variableRepository.RegisterVariableIfNotRegistered(affVariableOp.Variable,
                                                                                affVariableOp.Location, householdKey, locDict);
                        calcAffordanceVariableOps.Add(new CalcAffordanceVariableOpDto(affVariableOp.Variable.Name,
                                                                                      affVariableOp.Value, loc.Name, loc.Guid, affVariableOp.VariableAction, affVariableOp.ExecutionTime,
                                                                                      variable.Guid));
                    }
                }

                // CalcSubaffordanz anlegen
                var affName = CalcAffordanceFactory.FixAffordanceName(aff.Name, csvCharacter);
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                var csubaff = new CalcSubAffordanceDto(name + " (" + affName + ")", affsubaff.IntID, calcloc.Name, calcloc.Guid,
                                                       calcDesires, affsubaff.SubAffordance.MinimumAge, affsubaff.SubAffordance.MaximumAge,
                                                       delayTimeInSteps, affsubaff.SubAffordance.PermittedGender, aff.AffCategory,
                                                       affsubaff.SubAffordance.IsInterruptable, affsubaff.SubAffordance.IsInterrupting,
                                                       calcAffordanceVariableOps, weight, srcTrait, Guid.NewGuid().ToStrGuid());
                caff.SubAffordance.Add(csubaff);
            }
        }