Пример #1
0
		//---------------------------------------------------------------------

		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;
		}
        //---------------------------------------------------------------------

        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 (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;
        }
		//---------------------------------------------------------------------

		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;
		}