예제 #1
0
        //---------------------------------------------------------------------

        public override void Run()
        {
            if (SiteLog.Enabled)
            {
                SiteLog.TimestepSetUp();
            }

            ProcessInputMap(
                delegate(Site site,
                         LandUse newLandUse)
            {
                LandUse currentLandUse = SiteVars.LandUse[site];
                if (newLandUse != currentLandUse)
                {
                    SiteVars.LandUse[site] = newLandUse;
                    string transition      = string.Format("{0} --> {1}", currentLandUse.Name, newLandUse.Name);
                    if (!currentLandUse.AllowEstablishment && newLandUse.AllowEstablishment)
                    {
                        string message = string.Format("Error: The land-use change ({0}) at pixel {1} requires re-enabling establishment, but that's not currently supported",
                                                       transition,
                                                       site.Location);
                        throw new System.ApplicationException(message);
                    }
                    else if (currentLandUse.AllowEstablishment && !newLandUse.AllowEstablishment)
                    {
                        Reproduction.PreventEstablishment((ActiveSite)site);
                    }

                    if (isDebugEnabled)
                    {
                        log.DebugFormat("    LU at {0}: {1}", site.Location, transition);
                    }
                    newLandUse.LandCoverChange.ApplyTo((ActiveSite)site);
                    if (SiteLog.Enabled)
                    {
                        SiteLog.WriteTotalsFor((ActiveSite)site);
                    }
                    return(transition);
                }
                else
                {
                    return(null);
                }
            });

            if (SiteLog.Enabled)
            {
                SiteLog.TimestepTearDown();
            }
        }
예제 #2
0
        //---------------------------------------------------------------------

        public override void Run()
        {
            if (SiteLog.Enabled)
            {
                SiteLog.TimestepSetUp();
            }

            if (pauseFunction != null)
            {
                pauseFunction.PauseTimestep();
            }

            ProcessInputMap(
                delegate(Site site,
                         LandUse newLandUse)
            {
                LandUse currentLandUse = SiteVars.LandUse[site];
                string siteKey         = null;

                if (newLandUse != currentLandUse)
                {
                    SiteVars.LandUse[site] = newLandUse;
                    siteKey = string.Format("{0} --> {1}", currentLandUse.Name, newLandUse.Name);
                    if (!currentLandUse.AllowEstablishment && newLandUse.AllowEstablishment)
                    {
                        Reproduction.EnableEstablishment((ActiveSite)site);
                    }
                    else if (currentLandUse.AllowEstablishment && !newLandUse.AllowEstablishment)
                    {
                        Reproduction.PreventEstablishment((ActiveSite)site);
                    }

                    if (isDebugEnabled)
                    {
                        log.DebugFormat("    LU at {0}: {1}", site.Location, siteKey);
                    }

                    for (int i = 0; i < newLandUse.LandCoverChanges.Length; i++)
                    {
                        LandCover.IChange LandCoverChange = newLandUse.LandCoverChanges[i];
                        LandCoverChange.ApplyTo((ActiveSite)site, true);
                    }
                }
                else
                {
                    /*if (!currentLandUse.AllowEstablishment)
                     * {
                     *  Reproduction.PreventEstablishment((ActiveSite)site);
                     * }
                     * else
                     * {
                     *  Reproduction.EnableEstablishment((ActiveSite)site);
                     * }*/

                    for (int i = 0; i < currentLandUse.LandCoverChanges.Length; i++)
                    {
                        LandCover.IChange LandCoverChange = newLandUse.LandCoverChanges[i];
                        LandCoverChange.ApplyTo((ActiveSite)site, false);
                    }
                }

                if (SiteLog.Enabled)
                {
                    SiteLog.WriteTotalsFor((ActiveSite)site);
                }

                return(siteKey);
            });

            if (SiteLog.Enabled)
            {
                SiteLog.TimestepTearDown();
            }
        }
예제 #3
0
        //---------------------------------------------------------------------

        public override void Run()
        {
            SiteVars.GetExternalVars(); // ReInitialize();
            SiteVars.Prescription.ActiveSiteValues   = null;
            SiteVars.CohortsDamaged.ActiveSiteValues = 0;


            //harvest each management area in the list
            foreach (ManagementArea mgmtArea in managementAreas)
            {
                totalSites           = new int[Prescription.Count];
                totalDamagedSites    = new int[Prescription.Count];
                totalSpeciesCohorts  = new int[Prescription.Count, PlugIn.ModelCore.Species.Count];
                prescriptionReported = new bool[Prescription.Count];

                mgmtArea.HarvestStands();
                //and record each stand that's been harvested

                foreach (Stand stand in mgmtArea)
                {
                    if (stand.Harvested)
                    {
                        WriteLogEntry(mgmtArea, stand);
                    }
                }

                // updating for preventing establishment
                foreach (Stand stand in mgmtArea)
                {
                    if (stand.Harvested && stand.LastPrescription.PreventEstablishment)
                    {
                        List <ActiveSite> sitesToDelete = new List <ActiveSite>();

                        foreach (ActiveSite site in stand)
                        {
                            if (SiteVars.CohortsDamaged[site] > 0)
                            {
                                Reproduction.PreventEstablishment(site);
                                sitesToDelete.Add(site);
                            }
                        }

                        foreach (ActiveSite site in sitesToDelete)
                        {
                            stand.DelistActiveSite(site);
                        }
                    }
                } // foreach (Stand stand in mgmtArea)

                foreach (AppliedPrescription aprescription in mgmtArea.Prescriptions)
                {
                    Prescription prescription = aprescription.Prescription;
                    //string species_string = "";
                    double[] species_count = new double[modelCore.Species.Count];
                    foreach (ISpecies species in PlugIn.ModelCore.Species)
                    {
                        species_count[species.Index] += totalSpeciesCohorts[prescription.Number, species.Index];
                    }

                    if (totalSites[prescription.Number] > 0 && prescriptionReported[prescription.Number] != true)
                    {
                        //summaryLog.WriteLine("{0},{1},{2},{3}{4}",
                        //    PlugIn.ModelCore.CurrentTime,
                        //    mgmtArea.MapCode,
                        //    prescription.Name,
                        //    totalDamagedSites[prescription.Number],
                        //    species_string);
                        summaryLog.Clear();
                        SummaryLog sl = new SummaryLog();
                        sl.Time              = modelCore.CurrentTime;
                        sl.ManagementArea    = mgmtArea.MapCode;
                        sl.Prescription      = prescription.Name;
                        sl.HarvestedSites    = totalDamagedSites[prescription.Number];
                        sl.CohortsHarvested_ = species_count;
                        summaryLog.AddObject(sl);
                        summaryLog.WriteToFile();

                        prescriptionReported[prescription.Number] = true;
                    }
                }
            }
            prescriptionMaps.WriteMap(PlugIn.ModelCore.CurrentTime);
        }