Ejemplo n.º 1
0
        private double GetTransitionAttributeTargetMultiplier(
            int transitionAttributeTypeId, int stratumId, int?secondaryStratumId, int?tertiaryStratumId, int iteration, int timestep)
        {
            TransitionAttributeTarget t = this.m_TransitionAttributeTargetMap.GetAttributeTarget(
                transitionAttributeTypeId, stratumId, secondaryStratumId, tertiaryStratumId, iteration, timestep);

            if (t == null || t.IsDisabled)
            {
                return(1.0);
            }
            else
            {
                return(t.Multiplier);
            }
        }
Ejemplo n.º 2
0
        public override STSimDistributionBase Clone()
        {
            TransitionAttributeTarget t = new TransitionAttributeTarget(
                this.TransitionAttributeTargetId, this.Iteration, this.Timestep, this.StratumId, this.SecondaryStratumId, this.TertiaryStratumId,
                this.TransitionAttributeTypeId, this.DistributionValue, this.DistributionTypeId, this.DistributionFrequency, this.DistributionSD,
                this.DistributionMin, this.DistributionMax, this.m_Scenario);

            t.TargetRemaining = this.TargetRemainingNoCheck;
            t.Multiplier      = this.MultiplierNoCheck;
            t.ExpectedAmount  = this.ExpectedAmountNoCheck;
            t.IsDisabled      = this.IsDisabled;

            if (this.m_Prioritizations != null)
            {
                t.SetPrioritizations(this.m_Prioritizations);
            }

            return(t);
        }
Ejemplo n.º 3
0
        private double?GetAttributeTargetProbabilityOverride(TransitionType tt, Cell simulationCell, int iteration, int timestep)
        {
            foreach (int tatId in this.m_TransitionAttributeTypesWithTarget.Keys)
            {
                foreach (TransitionGroup tg in tt.TransitionGroups)
                {
                    double?AttrValue = this.m_TransitionAttributeValueMap.GetAttributeValue(
                        tatId, tg.TransitionGroupId, simulationCell.StratumId, simulationCell.SecondaryStratumId, simulationCell.TertiaryStratumId,
                        simulationCell.StateClassId, iteration, timestep, simulationCell.Age, simulationCell.TstValues);

                    if (AttrValue.HasValue)
                    {
                        if (AttrValue.Value > 0.0)
                        {
                            TransitionAttributeTarget target = this.m_TransitionAttributeTargetMap.GetAttributeTarget(
                                tatId, simulationCell.StratumId, simulationCell.SecondaryStratumId, simulationCell.TertiaryStratumId,
                                iteration, timestep);

                            if (target != null && !target.IsDisabled && target.HasPrioritizations)
                            {
                                TransitionAttributeTargetPrioritization pri = target.GetPrioritization(
                                    simulationCell.StratumId, simulationCell.SecondaryStratumId,
                                    simulationCell.TertiaryStratumId, tg.TransitionGroupId, simulationCell.StateClassId,
                                    iteration, timestep);

                                if (pri != null)
                                {
                                    return(pri.ProbabilityOverride);
                                }
                            }

                            break;
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        private void ResetTransitionAttributeTargetMultipliers(
            int iteration, int timestep, Dictionary <int, TransitionGroup> remainingTransitionGroups,
            MultiLevelKeyMap1 <Dictionary <int, TransitionAttributeTarget> > tatMap, TransitionGroup currentTransitionGroup)
        {
            if (this.m_TransitionAttributeTargets.Count == 0)
            {
                return;
            }

            foreach (TransitionAttributeTarget tat in this.m_TransitionAttributeTargets)
            {
                if (!tat.IsDisabled)
                {
                    tat.Multiplier     = 1.0;
                    tat.ExpectedAmount = 0.0;

                    if (tat.HasPrioritizations)
                    {
                        List <TransitionAttributeTargetPrioritization> pl = tat.GetPrioritizations(iteration, timestep);

                        if (pl != null)
                        {
                            foreach (TransitionAttributeTargetPrioritization pri in pl)
                            {
                                pri.PossibleAmount           = 0.0;
                                pri.ExpectedAmount           = 0.0;
                                pri.DesiredAmount            = null;
                                pri.CumulativePossibleAmount = 0.0;
                                pri.ProbabilityMultiplier    = 1.0;
                                pri.ProbabilityOverride      = null;
                            }
                        }
                    }
                }
            }

            foreach (Cell simulationCell in this.m_Cells)
            {
                //Only iterate over the transition attribute types that have a target associated with them in this timestep.

                foreach (int tatId in this.m_TransitionAttributeTypesWithTarget.Keys)
                {
                    TransitionAttributeType ta = this.m_TransitionAttributeTypes[tatId];

                    TransitionAttributeTarget Target = this.m_TransitionAttributeTargetMap.GetAttributeTarget(
                        ta.TransitionAttributeId, simulationCell.StratumId, simulationCell.SecondaryStratumId,
                        simulationCell.TertiaryStratumId, iteration, timestep);

                    if (Target == null || Target.IsDisabled)
                    {
                        continue;
                    }

                    foreach (Transition tr in simulationCell.Transitions)
                    {
                        TransitionType tt    = this.m_TransitionTypes[tr.TransitionTypeId];
                        bool           Found = false;

                        foreach (TransitionGroup rtg in remainingTransitionGroups.Values)
                        {
                            if (tt.PrimaryTransitionGroups.Contains(rtg.TransitionGroupId))
                            {
                                Found = true;
                                break;
                            }
                        }

                        if (!Found)
                        {
                            continue;
                        }

                        if (tt.TransitionGroups.Count == 0)
                        {
                            continue;
                        }

                        if ((tatMap != null) && (currentTransitionGroup != null))
                        {
                            if (tt.TransitionGroups.Contains(currentTransitionGroup.TransitionGroupId))
                            {
                                Dictionary <int, TransitionAttributeTarget> d = tatMap.GetItemExact(Target.StratumId);

                                if (d == null)
                                {
                                    d = new Dictionary <int, TransitionAttributeTarget>();
                                    tatMap.AddItem(Target.StratumId, d);
                                }

                                if (!d.ContainsKey(Target.TransitionAttributeTargetId))
                                {
                                    d.Add(Target.TransitionAttributeTargetId, Target);
                                }
                            }
                        }

                        double TransMult = this.GetTransitionMultiplier(tr.TransitionTypeId, iteration, timestep, simulationCell);
                        TransMult *= this.GetExternalTransitionMultipliers(tr.TransitionTypeId, iteration, timestep, simulationCell);

                        if (this.IsSpatial)
                        {
                            TransMult *= this.GetTransitionSpatialMultiplier(simulationCell, tr.TransitionTypeId, iteration, timestep);

                            foreach (TransitionGroup tg in tt.TransitionGroups)
                            {
                                TransMult *= this.GetTransitionAdjacencyMultiplier(tg.TransitionGroupId, iteration, timestep, simulationCell);
                                TransMult *= this.GetExternalSpatialMultipliers(simulationCell, iteration, timestep, tg.TransitionGroupId);
                            }

                            Debug.Assert(TransMult >= 0.0);
                        }

                        if (TransMult == 0.0)
                        {
                            continue;
                        }

                        foreach (TransitionGroup tg in tt.TransitionGroups)
                        {
                            if (this.IsSpatial)
                            {
                                if (!remainingTransitionGroups.ContainsKey(tg.TransitionGroupId))
                                {
                                    continue;
                                }
                            }

                            double?AttrValue = this.m_TransitionAttributeValueMap.GetAttributeValue(
                                ta.TransitionAttributeId, tg.TransitionGroupId, simulationCell.StratumId,
                                simulationCell.SecondaryStratumId, simulationCell.TertiaryStratumId,
                                simulationCell.StateClassId, iteration, timestep, simulationCell.Age,
                                simulationCell.TstValues);

                            if (AttrValue.HasValue)
                            {
                                double Expectation = tr.Probability * tr.Proportion * this.m_AmountPerCell * AttrValue.Value * TransMult;
                                Target.ExpectedAmount += Expectation;

                                Debug.Assert(Expectation >= 0.0);
                                Debug.Assert(Target.ExpectedAmount >= 0.0);

                                if (Target.HasPrioritizations)
                                {
                                    TransitionAttributeTargetPrioritization pri = Target.GetPrioritization(
                                        simulationCell.StratumId, simulationCell.SecondaryStratumId, simulationCell.TertiaryStratumId,
                                        tg.TransitionGroupId, simulationCell.StateClassId, iteration, timestep);

                                    if (pri != null)
                                    {
                                        pri.PossibleAmount += this.m_AmountPerCell * AttrValue.Value;
                                        pri.ExpectedAmount += Expectation;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (TransitionAttributeTarget tat in this.m_TransitionAttributeTargets)
            {
                if (!tat.IsDisabled && tat.ExpectedAmount != 0.0)
                {
                    tat.Multiplier = tat.TargetRemaining / tat.ExpectedAmount;
                    Debug.Assert(tat.Multiplier >= 0.0);

                    if (tat.HasPrioritizations)
                    {
                        double PreviousCumulativeAmount      = 0.0;
                        double TotalCumulativePossibleAmount = 0.0;

                        List <TransitionAttributeTargetPrioritization> pl = tat.GetPrioritizations(iteration, timestep);

                        if (pl != null)
                        {
                            foreach (TransitionAttributeTargetPrioritization pri in pl)
                            {
                                TotalCumulativePossibleAmount += pri.PossibleAmount;
                                pri.CumulativePossibleAmount   = TotalCumulativePossibleAmount;

                                if (tat.TargetRemaining >= pri.CumulativePossibleAmount)
                                {
                                    pri.ProbabilityOverride = 1.0;
                                }
                                else
                                {
                                    if (tat.TargetRemaining > PreviousCumulativeAmount)
                                    {
                                        pri.DesiredAmount         = tat.TargetRemaining - PreviousCumulativeAmount;
                                        pri.ProbabilityMultiplier = pri.DesiredAmount.Value / pri.ExpectedAmount;
                                    }
                                    else
                                    {
                                        pri.ProbabilityOverride = 0.0;
                                    }
                                }

                                PreviousCumulativeAmount = pri.CumulativePossibleAmount;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Modifies a transition multiplier by any transition attribute target multipliers that apply to that transition type
        /// </summary>
        /// <param name="multiplier"></param>
        /// <param name="tt"></param>
        /// <param name="simulationCell"></param>
        /// <param name="iteration"></param>
        /// <param name="timestep"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private double ModifyMultiplierForTransitionAttributeTarget(double multiplier, TransitionType tt, Cell simulationCell, int iteration, int timestep)
        {
            foreach (int tatId in this.m_TransitionAttributeTypesWithTarget.Keys)
            {
                foreach (TransitionGroup tg in tt.TransitionGroups)
                {
                    double?AttrValue = this.m_TransitionAttributeValueMap.GetAttributeValue(
                        tatId, tg.TransitionGroupId, simulationCell.StratumId, simulationCell.SecondaryStratumId, simulationCell.TertiaryStratumId,
                        simulationCell.StateClassId, iteration, timestep, simulationCell.Age, simulationCell.TstValues);

                    if (AttrValue.HasValue)
                    {
                        if (AttrValue.Value > 0.0)
                        {
                            bool TargetPrioritizationMultiplierApplied = false;

                            TransitionAttributeTarget target = this.m_TransitionAttributeTargetMap.GetAttributeTarget(
                                tatId, simulationCell.StratumId, simulationCell.SecondaryStratumId, simulationCell.TertiaryStratumId,
                                iteration, timestep);

                            if (target != null && !target.IsDisabled && target.HasPrioritizations)
                            {
                                TransitionAttributeTargetPrioritization pri = target.GetPrioritization(
                                    simulationCell.StratumId, simulationCell.SecondaryStratumId,
                                    simulationCell.TertiaryStratumId, tg.TransitionGroupId, simulationCell.StateClassId,
                                    iteration, timestep);

                                if (pri != null && pri.ProbabilityOverride.HasValue)
                                {
                                    Debug.Assert(pri.ProbabilityOverride.Value == 1.0 || pri.ProbabilityOverride.Value == 0.0);

                                    if (pri.ProbabilityOverride.Value == 1.0)
                                    {
                                        return(multiplier);
                                    }
                                    else if (pri.ProbabilityOverride.Value == 0.0)
                                    {
                                        multiplier *= 0.0;
                                        TargetPrioritizationMultiplierApplied = true;
                                    }
                                }
                                else
                                {
                                    multiplier *= pri.ProbabilityMultiplier;
                                    TargetPrioritizationMultiplierApplied = true;
                                }
                            }

                            if (!TargetPrioritizationMultiplierApplied)
                            {
                                multiplier *= this.GetTransitionAttributeTargetMultiplier(
                                    tatId, simulationCell.StratumId, simulationCell.SecondaryStratumId,
                                    simulationCell.TertiaryStratumId, iteration, timestep);
                            }

                            break;
                        }
                    }
                }
            }

            return(multiplier);
        }