Exemple #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);
        }
Exemple #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);
        }
Exemple #3
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);
            }
        }