Пример #1
0
        public TransitionTargetPrioritization GetPrioritization(
            int?stratumId,
            int?secondaryStratumId,
            int?tertiaryStratumId,
            int?stateClassId,
            int iteration,
            int timestep)
        {
            TransitionTargetPrioritization pri = this.m_ItemMap.GetPrioritization(
                stratumId, secondaryStratumId, tertiaryStratumId, stateClassId, iteration, timestep);

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

            List <TransitionTargetPrioritization> lst = this.m_ListMap.GetPrioritizations(iteration, timestep);

            if (lst != null)
            {
                pri = lst.Last();
                Debug.Assert(pri.Priority == double.MaxValue);

                return(pri);
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Resets the transition target multipliers for this cell, iteration, timestep and explicit transition group
        /// </summary>
        /// <param name="iteration">The current iteration</param>
        /// <param name="timestep">The current timestep</param>
        /// <param name="explicitGroup">transition group must be provided if spatial - should be null if non spatial</param>
        /// <remarks></remarks>
        private void ResetTransitionTargetMultipliers(int iteration, int timestep, TransitionGroup explicitGroup)
        {
            Debug.Assert(explicitGroup != null);

            if (this.m_TransitionTargets.Count == 0)
            {
                return;
            }

            foreach (TransitionTarget tt in this.m_TransitionTargets)
            {
                if (!tt.IsDisabled)
                {
                    tt.Multiplier     = 1.0;
                    tt.ExpectedAmount = 0.0;

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

                        if (pl != null)
                        {
                            foreach (TransitionTargetPrioritization 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)
            {
                foreach (Transition tr in simulationCell.Transitions)
                {
                    TransitionType ttype = this.m_TransitionTypes[tr.TransitionTypeId];

                    if (this.IsSpatial)
                    {
                        if (!ttype.PrimaryTransitionGroups.Contains(explicitGroup.TransitionGroupId))
                        {
                            continue;
                        }
                    }

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

                    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 ttype.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 tgroup in ttype.TransitionGroups)
                    {
                        TransitionTarget tt = this.m_TransitionTargetMap.GetTransitionTarget(
                            tgroup.TransitionGroupId, simulationCell.StratumId, simulationCell.SecondaryStratumId,
                            simulationCell.TertiaryStratumId, iteration, timestep);

                        if (tt != null && !tt.IsDisabled)
                        {
                            tt.ExpectedAmount += (tr.Probability * tr.Proportion * this.m_AmountPerCell * TransMult);
                            Debug.Assert(tt.ExpectedAmount >= 0.0);

                            if (tt.HasPrioritizations)
                            {
                                TransitionTargetPrioritization pri = tt.GetPrioritization(
                                    simulationCell.StratumId, simulationCell.SecondaryStratumId, simulationCell.TertiaryStratumId,
                                    simulationCell.StateClassId, iteration, timestep);

                                if (pri != null)
                                {
                                    pri.PossibleAmount += this.m_AmountPerCell;
                                    pri.ExpectedAmount += (tr.Probability * tr.Proportion * this.m_AmountPerCell * TransMult);
                                }
                            }
                        }
                    }
                }
            }

            foreach (TransitionTarget ttarg in this.m_TransitionTargets)
            {
                if (!ttarg.IsDisabled && ttarg.ExpectedAmount != 0)
                {
                    ttarg.Multiplier = ttarg.CurrentValue.Value / ttarg.ExpectedAmount;
                    Debug.Assert(ttarg.Multiplier >= 0.0);

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

                        List <TransitionTargetPrioritization> pl = ttarg.GetPrioritizations(iteration, timestep);

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

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

                                PreviousCumulativeAmount = pri.CumulativePossibleAmount;
                            }
                        }
                    }
                }
            }
        }