//--------------------------------------------------------------------- /// <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 <MutableActiveSite> 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 ..."); progressBar = NewProgressBar(); } foreach (ActiveSite site in sites) { Reproduction.Do(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))); } }
//--------------------------------------------------------------------- public bool Seeds(ISpecies species, ActiveSite site) { if (!Reproduction.SufficientLight(species, site) || !Reproduction.Establish(species, site)) { return(false); } double randomNum = Random.GenerateUniform(); foreach (RelativeLocation relLoc in neighborhoods[species.Index]) { ActiveSite neighbor = site.GetNeighbor(relLoc) as ActiveSite; if (neighbor != null) { float probability = seedDispersalMethod(species, neighbor, site); if (randomNum < probability) { return(true); } } } return(false); }
//--------------------------------------------------------------------- /// <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)); }
//--------------------------------------------------------------------- /// <summary> /// Initializes the instance and its associated site variables. /// </summary> protected void Initialize(int timestep, double[,] establishProbabilities, int startTime, SeedingAlgorithms seedAlg, Reproduction.AddNewCohortMethod addNewCohort) { this.timestep = timestep; this.nextTimeToRun = startTime - 1 + timestep; this.updateNextTimeToRun = false; SiteVars.Initialize(); 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); }
public static bool Algorithm(ISpecies species, ActiveSite site) { return(Reproduction.SufficientLight(species, site) && Reproduction.Establish(species, site) && Reproduction.MaturePresent(species, site)); }
//--------------------------------------------------------------------- public void Do(ActiveSite site, BitArray hasSeeded) { for (int i = 0; i < Model.Core.Species.Count; i++) { if (hasSeeded != null && hasSeeded[i]) { continue; } 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); } if (hasSeeded != null) { hasSeeded[i] = true; } } } }
//--------------------------------------------------------------------- /// <summary> /// Initializes the instance and its associated site variables. /// </summary> protected void Initialize(int timestep, double[,] establishProbabilities) { this.timestep = timestep; this.nextTimeToRun = timestep; SiteVars.Initialize(); SiteVars.Reproduction.ActiveSiteValues = new ReproductionBySeeding(new UniversalSeeding()); Reproduction.SetEstablishProbabilities(establishProbabilities); }
//--------------------------------------------------------------------- /// <summary> /// Initializes the instance and its associated site variables. /// </summary> protected void Initialize(int timestep, double[,] establishProbabilities) { this.timestep = timestep; this.nextTimeToRun = timestep; SiteVars.Initialize(); defaultReproduction = new Seeding(WardSeedDispersal.Algorithm); SiteVars.Reproduction.ActiveSiteValues = defaultReproduction; Reproduction.SetEstablishProbabilities(establishProbabilities); }
//--------------------------------------------------------------------- public void Do(ActiveSite site) { for (int i = 0; i < Model.Species.Count; i++) { ISpecies species = Model.Species[i]; if (seedingAlgorithm(species, site)) { Reproduction.AddNewCohort(species, site); } } }
public static void Algorithm(//ISpecies species, ActiveSite site) { foreach (ISpecies species in Model.Core.Species) { if (Reproduction.SufficientLight(species, site) && Reproduction.Establish(species, site)) { Reproduction.AddNewCohort(species, site); } } //return Reproduction.SufficientLight(species, site) && // Reproduction.Establish(species, site); }
protected void Initialize(PlugIns.ICore modelCore, double[,] establishProbabilities, SeedingAlgorithms seedAlg, Reproduction.AddNewCohortMethod addNewCohort) { Reproduction.Delegates.AddNewCohort wrappedMethod = delegate(ISpecies species, ActiveSite site) { addNewCohort(species, site); }; Initialize(modelCore, establishProbabilities, seedAlg, wrappedMethod); //new Reproduction.Delegates.AddNewCohort(addNewCohort)); // System.Delegate.CreateDelegate(typeof (Reproduction.Delegates.AddNewCohort), // addNewCohort.Method)); }
//--------------------------------------------------------------------- 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); } } } }
//--------------------------------------------------------------------- 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); }
//--------------------------------------------------------------------- public static bool Algorithm(ISpecies species, ActiveSite site) { if (!Reproduction.SufficientLight(species, site) || !Reproduction.Establish(species, site)) { return(false); } foreach (NeighborInfo neighborInfo in neighborhoods[species.Index]) { ActiveSite neighbor = site.GetNeighbor(neighborInfo.RelativeLocation) as ActiveSite; if (neighbor != null) { if (Util.Random.GenerateUniform() < neighborInfo.DistanceProbability) { return(true); } } } return(false); }
//--------------------------------------------------------------------- public static void Algorithm(//ISpecies species, ActiveSite site) { foreach (RelativeLocationWeighted reloc in Seeding.MaxSeedQuarterNeighborhood) { double distance = reloc.Weight; foreach (ISpecies species in Model.Core.Species) { if (species.EffectiveSeedDist == EffectiveSeedDist.Universal) { if (Reproduction.SufficientLight(species, site) && Reproduction.Establish(species, site)) { Reproduction.AddNewCohort(species, site); break; } } int EffD = species.EffectiveSeedDist; int MaxD = species.MaxSeedDist; if (distance > MaxD) { break; //Check no further } double dispersalProb = 0.0; if (reloc.Location.Row == 0 && reloc.Location.Column == 0) //Check seeds on site { if (Reproduction.SufficientLight(species, site) && Reproduction.Establish(species, site) && Reproduction.MaturePresent(species, site)) { Reproduction.AddNewCohort(species, site); break; } } else { dispersalProb = GetDispersalProbability(EffD, MaxD, distance); //First check the Southeast quadrant: Site neighbor = site.GetNeighbor(reloc.Location); if (neighbor != null && neighbor.IsActive) { if (Reproduction.MaturePresent(species, neighbor)) { if (dispersalProb > Landis.Util.Random.GenerateUniform()) { Reproduction.AddNewCohort(species, site); break; } } } //Next, check all other quadrants: neighbor = site.GetNeighbor(new RelativeLocation(reloc.Location.Row * -1, reloc.Location.Column)); if (neighbor != null && neighbor.IsActive) { if (Reproduction.MaturePresent(species, neighbor)) { if (dispersalProb > Landis.Util.Random.GenerateUniform()) { Reproduction.AddNewCohort(species, site); break; } } } neighbor = site.GetNeighbor(new RelativeLocation(reloc.Location.Row, reloc.Location.Column * -1)); if (neighbor != null && neighbor.IsActive) { if (Reproduction.MaturePresent(species, neighbor)) { if (dispersalProb > Landis.Util.Random.GenerateUniform()) { Reproduction.AddNewCohort(species, site); break; } } } neighbor = site.GetNeighbor(new RelativeLocation(reloc.Location.Row * -1, reloc.Location.Column * -1)); if (neighbor != null && neighbor.IsActive) { if (Reproduction.MaturePresent(species, neighbor)) { if (dispersalProb > Landis.Util.Random.GenerateUniform()) { Reproduction.AddNewCohort(species, site); break; } } } } } //end species loop } // end foreach relativelocation return; }
//--------------------------------------------------------------------- public static bool Algorithm(ISpecies species, ActiveSite site) { if (!Reproduction.SufficientLight(species, site) || !Reproduction.Establish(species, site)) { return(false); } if (Reproduction.MaturePresent(species, site)) { return(true); } int row = (int)site.Location.Row; int col = (int)site.Location.Column; int cellDiam = (int)Model.CellLength; int EffD = species.EffectiveSeedDist; int MaxD = species.MaxSeedDist; double ratio = 0.95; //the portion of the probability in the effective distance //lambda1 parameterized for effective distance double lambda1 = Math.Log(1 - ratio) / EffD; //lambda2 parameterized for maximum distance double lambda2 = Math.Log(0.01) / MaxD; double lowBound = 0, upBound = 0; //bool suitableDist=false;//flag to trigger if seed (plural) can get to a site based on distance probability double distanceProb = 0.0; int pixRange = Math.Max((int)((float)MaxD / (float)cellDiam), 1); int maxrow = (int)Math.Min(row + pixRange, Model.Landscape.Rows); int minrow = Math.Max(row - pixRange, 1); for (int i = minrow; i <= maxrow; i++) { int x1, x2; //float b = 5.0; findX1X2(out x1, out x2, col, row, i, pixRange); for (int j = x1; j <= x2; j++) { Location loc = new Location((uint)i, (uint)j); if (Model.Landscape.GetSite(loc, ref neighbor) && neighbor.IsActive) { if (Reproduction.MaturePresent(species, neighbor)) { float distance = (float)Math.Sqrt((float)((row - i) * (row - i) + (col - j) * (col - j))) * cellDiam; //Pythag //set lower boundary to the theoretical (straight-line) edge of parent cell lowBound = distance - cellDiam; if (lowBound < 0) { lowBound = 0; } //set upper boundary to the outer theoretical boundary of the cell upBound = distance; if (cellDiam <= EffD) { //Draw probabilities from either EffD or MaxD curves if (distance <= (float)EffD) { //BCW May 04 distanceProb = Math.Exp(lambda1 * lowBound) - Math.Exp(lambda1 * upBound); } else { //BCW May 04 distanceProb = (1 - ratio) * Math.Exp(lambda2 * (lowBound - EffD)) - (1 - ratio) * Math.Exp(lambda2 * (upBound - EffD)); } } else { if (distance <= cellDiam) { //Draw probabilities from both EffD and MaxD curves distanceProb = Math.Exp(lambda1 * lowBound) - (1 - ratio) * Math.Exp(lambda2 * (upBound - EffD)); } else { distanceProb = (1 - ratio) * Math.Exp(lambda2 * (lowBound - EffD)) - (1 - ratio) * Math.Exp(lambda2 * (upBound - EffD)); } } if (distanceProb > Landis.Util.Random.GenerateUniform()) // && frand() < l->probRepro(speciesNum)) Modified BCW May '04 { // success = sites(row,col)->addNewCohort(s, sa, 10); return(true); } } } // if neighor is active } // for each column, j, of current row in neighborhood } // for each row, i, in the neighborhood // Search failed. return(false); }
public bool Seeds(ISpecies species, ActiveSite site) { return(Reproduction.SufficientLight(species, site) && Reproduction.Establish(species, site)); }
//--------------------------------------------------------------------- /// <summary> /// Are the conditions necessary for planting a species at site /// satified? /// </summary> protected override bool PreconditionsSatisfied(ISpecies species, ActiveSite site) { return(Reproduction.GetEstablishProbability(species, site) > 0); }
//--------------------------------------------------------------------- public static bool Algorithm(ISpecies species, ActiveSite site) { if (species.EffectiveSeedDist == EffectiveSeedDist.Universal) { return(UniversalDispersal.Algorithm(species, site)); } if (!Reproduction.SufficientLight(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 (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 > Landis.Util.Random.GenerateUniform()) { Site neighbor = site.GetNeighbor(reloc.Location); if (neighbor != null && neighbor.IsActive) { if (Reproduction.MaturePresent(species, neighbor)) { return(true); } } } //Next, check all other quadrants: if (dispersalProb > Landis.Util.Random.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)) { return(true); } } } if (dispersalProb > Landis.Util.Random.GenerateUniform()) { Site neighbor = site.GetNeighbor(new RelativeLocation(rRow * -1, rCol * -1)); if (neighbor != null && neighbor.IsActive) { if (Reproduction.MaturePresent(species, neighbor)) { return(true); } } } if (dispersalProb > Landis.Util.Random.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)) { return(true); } } } } // end foreach relativelocation return(false); }