Inheritance: ICohortDisturbance
Exemplo n.º 1
0
 //---------------------------------------------------------------------
 private void LogEvent(int currentTime,
                       Epidemic CurrentEvent,
                       int ROS, IAgent agent)
 {
     log.Write("{0},{1},{2},{3},{4},{5:0.0}",
               currentTime,
               ROS,
               agent.AgentName,
               CurrentEvent.CohortsKilled,
               CurrentEvent.TotalSitesDamaged,
               CurrentEvent.MeanSeverity);
     log.WriteLine("");
 }
Exemplo n.º 2
0
        //---------------------------------------------------------------------
        ///<summary>
        ///Simulate an Epidemic - This is the controlling function that calls the
        ///subsequent function.  The basic logic of an epidemic resides here.
        ///</summary>
        public static Epidemic Simulate(IAgent agent,
                                        int currentTime,
                                        int timestep,
                                        int ROS)
        {
            Epidemic CurrentEpidemic = new Epidemic(agent);

            PlugIn.ModelCore.Log.WriteLine("   New BDA Epidemic Activated.");

            //SiteResources.SiteResourceDominance(agent, ROS, SiteVars.Cohorts);
            SiteResources.SiteResourceDominance(agent, ROS);
            SiteResources.SiteResourceDominanceModifier(agent);

            if (agent.Dispersal)
            {
                //Asynchronous - Simulate Agent Dispersal

                // Calculate Site Vulnerability without considering the Neighborhood
                // If neither disturbance modifiers nor ecoregion modifiers are active,
                //  Vulnerability will equal SiteReourceDominance.
                SiteResources.SiteVulnerability(agent, ROS, false);

                Epicenters.NewEpicenters(agent, timestep);
            }
            else
            {
                //Synchronous:  assume that all Active sites can potentially be
                //disturbed without regard to initial locations.
                foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
                {
                    agent.OutbreakZone[site] = Zone.Newzone;
                }
            }

            //Consider the Neighborhood if requested:
            if (agent.NeighborFlag)
            {
                SiteResources.NeighborResourceDominance(agent);
            }

            //Recalculate Site Vulnerability considering neighbors if necessary:
            SiteResources.SiteVulnerability(agent, ROS, agent.NeighborFlag);

            CurrentEpidemic.DisturbSites(agent);

            return(CurrentEpidemic);
        }
        //---------------------------------------------------------------------
        ///<summary>
        ///Simulate an Epidemic - This is the controlling function that calls the
        ///subsequent function.  The basic logic of an epidemic resides here.
        ///</summary>
        public static Epidemic Simulate(IAgent agent,
                                        int currentTime,
                                        int timestep,
                                        int ROS)
        {


            Epidemic CurrentEpidemic = new Epidemic(agent);
            PlugIn.ModelCore.Log.WriteLine("   New BDA Epidemic Activated.");

            //SiteResources.SiteResourceDominance(agent, ROS, SiteVars.Cohorts);
            SiteResources.SiteResourceDominance(agent, ROS);
            SiteResources.SiteResourceDominanceModifier(agent);

            if(agent.Dispersal) {
                //Asynchronous - Simulate Agent Dispersal

                // Calculate Site Vulnerability without considering the Neighborhood
                // If neither disturbance modifiers nor ecoregion modifiers are active,
                //  Vulnerability will equal SiteReourceDominance.
                SiteResources.SiteVulnerability(agent, ROS, false);

                Epicenters.NewEpicenters(agent, timestep);

            } else
            {
                //Synchronous:  assume that all Active sites can potentially be
                //disturbed without regard to initial locations.
                foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
                    agent.OutbreakZone[site] = Zone.Newzone;

            }

            //Consider the Neighborhood if requested:
            if (agent.NeighborFlag)
                SiteResources.NeighborResourceDominance(agent);

            //Recalculate Site Vulnerability considering neighbors if necessary:
            SiteResources.SiteVulnerability(agent, ROS, agent.NeighborFlag);

            CurrentEpidemic.DisturbSites(agent);

            return CurrentEpidemic;
        }
Exemplo n.º 4
0
 //---------------------------------------------------------------------
 private void LogEvent(int   currentTime,
                       Epidemic CurrentEvent,
                       int ROS, IAgent agent)
 {
     log.Write("{0},{1},{2},{3},{4},{5:0.0}",
               currentTime,
               ROS,
               agent.AgentName,
               CurrentEvent.CohortsKilled,
               CurrentEvent.TotalSitesDamaged,
               CurrentEvent.MeanSeverity);
     log.WriteLine("");
 }
Exemplo n.º 5
0
        //---------------------------------------------------------------------
        ///<summary>
        /// Run the BDA extension at a particular timestep.
        ///</summary>
        public override void Run()
        {
            PlugIn.ModelCore.Log.WriteLine("   Processing landscape for BDA events ...");

            //SiteVars.Epidemic.SiteValues = null;

            int eventCount = 0;

            foreach (IAgent activeAgent in manyAgentParameters)
            {
                activeAgent.TimeSinceLastEpidemic += Timestep;

                int ROS = RegionalOutbreakStatus(activeAgent, Timestep);

                if (ROS > 0)
                {
                    Epidemic.Initialize(activeAgent);
                    Epidemic currentEpic = Epidemic.Simulate(activeAgent,
                                                             PlugIn.ModelCore.CurrentTime,
                                                             Timestep,
                                                             ROS);
                    //activeAgent.TimeSinceLastEpidemic = activeAgent.TimeSinceLastEpidemic + Timestep;

                    if (currentEpic != null)
                    {
                        LogEvent(PlugIn.ModelCore.CurrentTime, currentEpic, ROS, activeAgent);

                        //----- Write BDA severity maps --------
                        string path = MapNames.ReplaceTemplateVars(mapNameTemplate, activeAgent.AgentName, PlugIn.ModelCore.CurrentTime);
                        //IOutputRaster<SeverityPixel> map = CreateMap(PlugIn.ModelCore.CurrentTime, activeAgent.AgentName);
                        //using (map) {
                        //    SeverityPixel pixel = new SeverityPixel();
                        using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions))
                        {
                            ShortPixel pixel = outputRaster.BufferPixel;
                            foreach (Site site in PlugIn.ModelCore.Landscape.AllSites)
                            {
                                if (site.IsActive)
                                {
                                    if (SiteVars.Disturbed[site])
                                    {
                                        pixel.MapCode.Value = (short)(activeAgent.Severity[site] + 1);
                                    }
                                    else
                                    {
                                        pixel.MapCode.Value = 1;
                                    }
                                }
                                else
                                {
                                    //  Inactive site
                                    pixel.MapCode.Value = 0;
                                }
                                outputRaster.WriteBufferPixel();
                            }
                        }
                        if (!(srdMapNames == null))
                        {
                            //----- Write BDA SRD maps --------
                            string path2 = MapNames.ReplaceTemplateVars(srdMapNames, activeAgent.AgentName, PlugIn.ModelCore.CurrentTime);
                            using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path2, modelCore.Landscape.Dimensions))
                            {
                                ShortPixel pixel = outputRaster.BufferPixel;
                                foreach (Site site in PlugIn.ModelCore.Landscape.AllSites)
                                {
                                    if (site.IsActive)
                                    {
                                        pixel.MapCode.Value = (short)System.Math.Round(SiteVars.SiteResourceDom[site] * 100.00);
                                    }
                                    else
                                    {
                                        //  Inactive site
                                        pixel.MapCode.Value = 0;
                                    }
                                    outputRaster.WriteBufferPixel();
                                }
                            }
                        }
                        if (!(nrdMapNames == null))
                        {
                            //----- Write BDA NRD maps --------
                            string path3 = MapNames.ReplaceTemplateVars(nrdMapNames, activeAgent.AgentName, PlugIn.ModelCore.CurrentTime);
                            using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path3, modelCore.Landscape.Dimensions))
                            {
                                ShortPixel pixel = outputRaster.BufferPixel;

                                foreach (Site site in PlugIn.ModelCore.Landscape.AllSites)
                                {
                                    if (site.IsActive)
                                    {
                                        pixel.MapCode.Value = (short)System.Math.Round(SiteVars.NeighborResourceDom[site] * 100.00);
                                    }
                                    else
                                    {
                                        //  Inactive site
                                        pixel.MapCode.Value = 0;
                                    }
                                    outputRaster.WriteBufferPixel();
                                }
                            }
                        }
                        if (!(vulnMapNames == null))
                        {
                            //----- Write BDA Vulnerability maps --------
                            string path4 = MapNames.ReplaceTemplateVars(vulnMapNames, activeAgent.AgentName, PlugIn.ModelCore.CurrentTime);
                            using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path4, modelCore.Landscape.Dimensions))
                            {
                                ShortPixel pixel = outputRaster.BufferPixel;

                                foreach (Site site in PlugIn.ModelCore.Landscape.AllSites)
                                {
                                    if (site.IsActive)
                                    {
                                        pixel.MapCode.Value = (short)System.Math.Round(SiteVars.Vulnerability[site] * 100.00);
                                    }
                                    else
                                    {
                                        //  Inactive site
                                        pixel.MapCode.Value = 0;
                                    }
                                    outputRaster.WriteBufferPixel();
                                }
                            }
                        }

                        eventCount++;
                    }
                }
            }
        }