Ejemplo n.º 1
0
 public static bool Algorithm(ISpecies species,
                              ActiveSite site)
 {
     return(Reproduction.SufficientResources(species, site) &&
            Reproduction.Establish(species, site) &&
            Reproduction.MaturePresent(species, site));
 }
Ejemplo n.º 2
0
        //---------------------------------------------------------------------
        

        /// <summary>
        /// Initializes the instance and its associated site variables.
        /// </summary>
        protected void Initialize(PlugIns.ICore modelCore,
                                  double[,] establishProbabilities,
                                  SeedingAlgorithms seedAlg,
                                  Reproduction.Delegates.AddNewCohort addNewCohort)
        {
            Model.Core = modelCore;
            SiteVars.Initialize();
            Seeding.InitializeMaxSeedNeighborhood();

            disturbedSites = new DisturbedSiteEnumerator(Model.Core.Landscape,
                                                         SiteVars.Disturbed);

            SeedingAlgorithm algorithm;
            switch (seedAlg)
            {
                case SeedingAlgorithms.NoDispersal:
                    algorithm = NoDispersal.Algorithm;
                    break;

                case SeedingAlgorithms.UniversalDispersal:
                    algorithm = UniversalDispersal.Algorithm;
                    break;

                case SeedingAlgorithms.WardSeedDispersal:
                    algorithm = WardSeedDispersal.Algorithm;
                    break;

                default:
                    throw new ArgumentException(string.Format("Unknown seeding algorithm: {0}", seedAlg));
            }

            Reproduction.Initialize(establishProbabilities, algorithm,
                                    addNewCohort == null ? null : new Reproduction.Delegates.AddNewCohort(addNewCohort));
        }
Ejemplo n.º 3
0
        //---------------------------------------------------------------------


        /// <summary>
        /// Initializes the instance and its associated site variables.
        /// </summary>
        protected void Initialize(ICore modelCore,
                                  SeedingAlgorithms seedAlg)
        {
            Model.Core = modelCore;
            SiteVars.Initialize();
            Seeding.InitializeMaxSeedNeighborhood();

            disturbedSites = new DisturbedSiteEnumerator(Model.Core.Landscape,
                                                         SiteVars.Disturbed);

            SeedingAlgorithm algorithm;

            switch (seedAlg)
            {
            case SeedingAlgorithms.NoDispersal:
                algorithm = NoDispersal.Algorithm;
                break;

            case SeedingAlgorithms.UniversalDispersal:
                algorithm = UniversalDispersal.Algorithm;
                break;

            case SeedingAlgorithms.WardSeedDispersal:
                algorithm = WardSeedDispersal.Algorithm;
                break;

            default:
                throw new ArgumentException(string.Format("Unknown seeding algorithm: {0}", seedAlg));
            }

            Reproduction.Initialize(algorithm);
        }
Ejemplo n.º 4
0
        //---------------------------------------------------------------------


        /// <summary>
        /// Initializes the instance and its associated site variables.
        /// </summary>
        protected void Initialize(PlugIns.ICore modelCore,
                                  double[,] establishProbabilities,
                                  SeedingAlgorithms seedAlg,
                                  Reproduction.Delegates.AddNewCohort addNewCohort)
        {
            Model.Core = modelCore;
            SiteVars.Initialize();
            Seeding.InitializeMaxSeedNeighborhood();

            disturbedSites = new DisturbedSiteEnumerator(Model.Core.Landscape,
                                                         SiteVars.Disturbed);

            SeedingAlgorithm algorithm;

            switch (seedAlg)
            {
            case SeedingAlgorithms.NoDispersal:
                algorithm = NoDispersal.Algorithm;
                break;

            case SeedingAlgorithms.UniversalDispersal:
                algorithm = UniversalDispersal.Algorithm;
                break;

            case SeedingAlgorithms.WardSeedDispersal:
                algorithm = WardSeedDispersal.Algorithm;
                break;

            default:
                throw new ArgumentException(string.Format("Unknown seeding algorithm: {0}", seedAlg));
            }

            Reproduction.Initialize(establishProbabilities, algorithm,
                                    addNewCohort == null ? null : new Reproduction.Delegates.AddNewCohort(addNewCohort));
        }
Ejemplo n.º 5
0
 public static bool Algorithm(ISpecies species,
                              ActiveSite site)
 {
     return(Reproduction.SufficientResources(species, site) &&
            Reproduction.Establish(species, site) &&
            //Reproduction.MaturePresent(species, site);
            SiteVars.Cohorts[site].IsMaturePresent(species));
 }
Ejemplo n.º 6
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Does cohort reproduction at certain specified sites.
        /// </summary>
        /// <param name="sites">
        /// The sites where cohort reproduction should be done.
        /// </param>
        /// <remarks>
        /// Because this is the last stage of succession during a timestep,
        /// the NextTimeToRun is updated after all the sites are processed.
        /// </remarks>
        public void ReproduceCohorts(IEnumerable <ActiveSite> sites)
        {
            logger.Debug(string.Format("{0:G}", DateTime.Now));
            int maxGeneration = GC.MaxGeneration;

            for (int generation = 0; generation <= maxGeneration; generation++)
            {
                logger.Debug(string.Format("  gen {0}: {1}", generation,
                                           GC.CollectionCount(generation)));
            }

            ProgressBar progressBar = null;

            if (ShowProgress)
            {
                System.Console.WriteLine("Cohort reproduction ...");
                prevSiteDataIndex = null;
                progressBar       = Landis.Model.iui.CreateProgressMeter(Model.Core.Landscape.ActiveSiteCount); // NewProgressBar();
            }

            foreach (ActiveSite site in sites)
            {
                Reproduction.Reproduce(site);

                /*#if WATCH_CHANGING_GC
                 *              bool collectionCountChanged = false;
                 *              for (int generation = 0; generation <= maxGeneration; generation++) {
                 *                  int currentCount = GC.CollectionCount(generation);
                 *                  if (collectionCounts[generation] != currentCount) {
                 *                      collectionCountChanged = true;
                 *                      collectionCounts[generation] = currentCount;
                 *                  }
                 *              }
                 *              if (collectionCountChanged) {
                 *                  logger.Info(string.Format("Site {0}, index = {1}", site.Location, site.DataIndex));
                 *                  for (int generation = 0; generation <= maxGeneration; generation++)
                 *                      logger.Info(string.Format("  gen {0}: {1}", generation, collectionCounts[generation]));
                 *              }
                 #endif*/
                if (ShowProgress)
                {
                    Update(progressBar, site.DataIndex);
                }
            }
            if (ShowProgress)
            {
                CleanUp(progressBar);
            }

            logger.Debug(string.Format("{0:G}", DateTime.Now));
            for (int generation = 0; generation <= maxGeneration; generation++)
            {
                logger.Debug(string.Format("  gen {0}: {1}", generation,
                                           GC.CollectionCount(generation)));
            }
        }
Ejemplo n.º 7
0
        //---------------------------------------------------------------------

        public void Do(ActiveSite site)
        {
            for (int i = 0; i < Model.Core.Species.Count; i++)
            {
                ISpecies species = Model.Core.Species[i];
                if (seedingAlgorithm(species, site))
                {
                    Reproduction.AddNewCohort(species, site);
                    if (isDebugEnabled)
                    {
                        log.DebugFormat("site {0}: seeded {1}",
                                        site.Location, species.Name);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        //---------------------------------------------------------------------


        /// <summary>
        /// Initializes the instance and its associated site variables.
        /// </summary>
        protected void Initialize(ICore modelCore,
                                  SeedingAlgorithms seedAlg)//,
        //Reproduction.Delegates.AddNewCohort addNewCohort)
        {
            Model.Core = modelCore;
            SiteVars.Initialize();
            Seeding.InitializeMaxSeedNeighborhood();

            disturbedSites = new DisturbedSiteEnumerator(Model.Core.Landscape,
                                                         SiteVars.Disturbed);

            SeedingAlgorithm algorithm = SeedingAlgorithmsUtil.GetAlgorithm(seedAlg,
                                                                            Timestep);

            Reproduction.Initialize(algorithm);
        }
        //---------------------------------------------------------------------

        bool IFormOfReproduction.TryAt(ActiveSite site)
        {
            bool     success = false;
            BitArray selectedSpeciesAtSite = selectedSpecies[site];

            for (int index = 0; index < speciesDataset.Count; ++index)
            {
                if (selectedSpeciesAtSite.Get(index))
                {
                    ISpecies species = speciesDataset[index];
                    if (PreconditionsSatisfied(species, site))
                    {
                        Reproduction.AddNewCohort(species, site);
                        success = true;
                    }
                }
            }

            return(success);
        }
Ejemplo n.º 10
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Does cohort reproduction at certain specified sites.
        /// </summary>
        /// <param name="sites">
        /// The sites where cohort reproduction should be done.
        /// </param>
        /// <remarks>
        /// Because this is the last stage of succession during a timestep,
        /// the NextTimeToRun is updated after all the sites are processed.
        /// </remarks>
        public void ReproduceCohorts(IEnumerable <ActiveSite> sites)
        {
            logger.Debug(string.Format("{0:G}", DateTime.Now));
            int maxGeneration = GC.MaxGeneration;

            for (int generation = 0; generation <= maxGeneration; generation++)
            {
                logger.Debug(string.Format("  gen {0}: {1}", generation,
                                           GC.CollectionCount(generation)));
            }

            ProgressBar progressBar = null;

            if (ShowProgress)
            {
                System.Console.WriteLine("Cohort reproduction ...");
                prevSiteDataIndex = null;
                progressBar       = Model.Core.UI.CreateProgressMeter(Model.Core.Landscape.ActiveSiteCount); // NewProgressBar();
            }

            foreach (ActiveSite site in sites)
            {
                Reproduction.Reproduce(site);

                if (ShowProgress)
                {
                    Update(progressBar, site.DataIndex);
                }
            }
            if (ShowProgress)
            {
                CleanUp(progressBar);
            }

            logger.Debug(string.Format("{0:G}", DateTime.Now));
            for (int generation = 0; generation <= maxGeneration; generation++)
            {
                logger.Debug(string.Format("  gen {0}: {1}", generation,
                                           GC.CollectionCount(generation)));
            }
        }
Ejemplo n.º 11
0
        //---------------------------------------------------------------------

        bool IFormOfReproduction.TryAt(ActiveSite site)
        {
            bool     success = false;
            BitArray selectedSpeciesAtSite = selectedSpecies[site];

            for (int index = 0; index < speciesDataset.Count; ++index)
            {
                if (selectedSpeciesAtSite.Get(index))
                {
                    ISpecies species = speciesDataset[index];
                    if (PreconditionsSatisfied(species, site))
                    {
                        Reproduction.AddNewCohort(species, site);
                        success = true;
                    }
                }
            }
            // Reset the BitArray to be empty so planting does not continue to recur on the site
            selectedSpecies[site].SetAll(false);
            return(success);
        }
Ejemplo n.º 12
0
        //---------------------------------------------------------------------

        public static bool Algorithm(ISpecies species,
                                     ActiveSite site)
        {
            //if (species.EffectiveSeedDist == EffectiveSeedDist.Universal)
            //if (species.EffectiveSeedDist == Landis.Species.EffectiveSeedDist.Universal)
            if (species.EffectiveSeedDist == Universal)
            {
                return(UniversalDispersal.Algorithm(species, site));
            }

            if (!Reproduction.SufficientResources(species, site))
            {
                if (isDebugEnabled)
                {
                    log.DebugFormat("site {0}: {1} not seeded: insufficient light",
                                    site.Location, species.Name);
                }
                return(false);
            }

            if (!Reproduction.Establish(species, site))
            {
                if (isDebugEnabled)
                {
                    log.DebugFormat("site {0}: {1} not seeded: cannot establish",
                                    site.Location, species.Name);
                }
                return(false);
            }

            // if (Reproduction.MaturePresent(species, site)) {
            if (SiteVars.Cohorts[site].IsMaturePresent(species))
            {
                if (isDebugEnabled)
                {
                    log.DebugFormat("site {0}: {1} seeded on site",
                                    site.Location, species.Name);
                }
                return(true);
            }

            if (isDebugEnabled)
            {
                log.DebugFormat("site {0}: search neighbors for {1}",
                                site.Location, species.Name);
            }

            //UI.WriteLine("   Ward seed disersal.  Spp={0}, site={1},{2}.", species.Name, site.Location.Row, site.Location.Column);
            foreach (RelativeLocationWeighted reloc in Seeding.MaxSeedQuarterNeighborhood)
            {
                double distance = reloc.Weight;
                int    rRow     = (int)reloc.Location.Row;
                int    rCol     = (int)reloc.Location.Column;

                double EffD = (double)species.EffectiveSeedDist;
                double MaxD = (double)species.MaxSeedDist;

                if (distance > MaxD + ((double)Model.Core.CellLength / 2.0 * 1.414))
                {
                    return(false);  //Check no further
                }
                double dispersalProb = GetDispersalProbability(EffD, MaxD, distance);
                //UI.WriteLine("      DispersalProb={0}, EffD={1}, MaxD={2}, distance={3}.", dispersalProb, EffD, MaxD, distance);

                //First check the Southeast quadrant:
                if (dispersalProb > Model.Core.GenerateUniform())
                {
                    Site neighbor = site.GetNeighbor(reloc.Location);
                    if (neighbor != null && neighbor.IsActive)
                    {
                        // if (Reproduction.MaturePresent(species, neighbor))
                        if (SiteVars.Cohorts[site].IsMaturePresent(species))
                        {
                            return(true);
                        }
                    }
                }

                //Next, check all other quadrants:
                if (dispersalProb > Model.Core.GenerateUniform())
                {
                    Site neighbor = site.GetNeighbor(new RelativeLocation(rRow * -1, rCol));
                    if (rCol == 0)
                    {
                        neighbor = site.GetNeighbor(new RelativeLocation(0, rRow));
                    }
                    if (neighbor != null && neighbor.IsActive)
                    {
                        // if (Reproduction.MaturePresent(species, neighbor))
                        if (SiteVars.Cohorts[site].IsMaturePresent(species))
                        {
                            return(true);
                        }
                    }
                }

                if (dispersalProb > Model.Core.GenerateUniform())
                {
                    Site neighbor = site.GetNeighbor(new RelativeLocation(rRow * -1, rCol * -1));
                    if (neighbor != null && neighbor.IsActive)
                    {
                        // if (Reproduction.MaturePresent(species, neighbor))
                        if (SiteVars.Cohorts[site].IsMaturePresent(species))
                        {
                            return(true);
                        }
                    }
                }

                if (dispersalProb > Model.Core.GenerateUniform())
                {
                    Site neighbor = site.GetNeighbor(new RelativeLocation(rRow, rCol * -1));
                    if (rCol == 0)
                    {
                        neighbor = site.GetNeighbor(new RelativeLocation(0, rRow * -1));
                    }
                    if (neighbor != null && neighbor.IsActive)
                    {
                        // if (Reproduction.MaturePresent(species, neighbor))
                        if (SiteVars.Cohorts[site].IsMaturePresent(species))
                        {
                            return(true);
                        }
                    }
                }
            }  // end foreach relativelocation

            return(false);
        }
Ejemplo n.º 13
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Are the conditions necessary for planting a species at site
        /// satified?
        /// </summary>
        protected override bool PreconditionsSatisfied(ISpecies species,
                                                       ActiveSite site)
        {
            //return true;
            return(Reproduction.PlantingEstablish(species, site));
        }