public void WeightComparer_GetDifferentToCohort_ReturnsExpected() { WeightComparer comparer = new WeightComparer(); double expected = -5.0; double actual = comparer.GetDifferenceToCohort(120, 125.0); Assert.AreEqual(expected, actual); }
public void WeightComparer_GetCohort_ReturnsExpected() { WeightComparer comparer = new WeightComparer(); Int32[] sampleGroup = { 100, 200, 300, 400 }; double expected = 250.0; double actual = comparer.GetCohort(sampleGroup); Assert.AreEqual(expected, actual); }
//--------------------------------------------------------------------- // Generate a RelativeLocation array for one quarter of the neighborhood. // Check each cell within a box to the northeast the center point. This will // create a set of POTENTIAL neighbors. These potential neighbors // will need to be later checked to ensure that they are within the landscape // and active. private static IEnumerable <RelativeLocationWeighted> InitializeMaxSeedNeighborhood() { int maxSeedDistance = 0; foreach (ISpecies species in Model.Core.Species) { maxSeedDistance = Math.Max(maxSeedDistance, species.MaxSeedDist); } double CellLength = Model.Core.CellLength; UI.WriteLine(" Creating Dispersal Neighborhood List."); List <RelativeLocationWeighted> neighborhood = new List <RelativeLocationWeighted>(); int neighborRadius = maxSeedDistance; int numCellRadius = (int)(neighborRadius / CellLength); UI.WriteLine(" Dispersal: NeighborRadius={0}, CellLength={1}, numCellRadius={2}", neighborRadius, CellLength, numCellRadius); double centroidDistance = 0; double cellLength = CellLength; for (int row = 1; row <= numCellRadius; row++) { for (int col = 0; col <= numCellRadius; col++) { centroidDistance = DistanceFromCenter(row, col); //UI.WriteLine("Centroid Distance = {0}.", centroidDistance); if (centroidDistance <= neighborRadius) { RelativeLocation reloc = new RelativeLocation(row, col); neighborhood.Add(new RelativeLocationWeighted(reloc, centroidDistance)); } } } //Add same cell: neighborhood.Add(new RelativeLocationWeighted(new RelativeLocation(0, 0), 0.0)); WeightComparer weightComp = new WeightComparer(); neighborhood.Sort(weightComp); foreach (RelativeLocationWeighted reloc in neighborhood) { UI.WriteLine("Neighbor distance = {0}.", reloc.Weight); } return(neighborhood); }
//--------------------------------------------------------------------- // Generate a RelativeLocation array for one quarter of the neighborhood. // Check each cell within a box to the northeast the center point. This will // create a set of POTENTIAL neighbors. These potential neighbors // will need to be later checked to ensure that they are within the landscape // and active. public static void InitializeMaxSeedNeighborhood() { int maxSeedDistance = 0; foreach (ISpecies species in Model.Core.Species) { maxSeedDistance = Math.Max(maxSeedDistance, species.MaxSeedDist); } double cellLength = (double)Model.Core.CellLength; UI.WriteLine(" Creating Dispersal Neighborhood List."); List <RelativeLocationWeighted> neighborhood = new List <RelativeLocationWeighted>(); double neighborRadius = maxSeedDistance + (cellLength / 2.0); int numCellRadius = (int)(neighborRadius / cellLength); UI.WriteLine(" Dispersal: NeighborRadius={0}, CellLength={1}, numCellRadius={2}", neighborRadius, cellLength, numCellRadius); double centroidDistance = 0.0; for (int row = 1; row <= numCellRadius + 1; row++) { for (int col = 0; col <= numCellRadius + 1; col++) { centroidDistance = DistanceFromCenter((double)row, (double)col); //UI.WriteLine("Centroid Distance = {0}.", centroidDistance); if (centroidDistance <= neighborRadius) { RelativeLocation reloc = new RelativeLocation(row, col); neighborhood.Add(new RelativeLocationWeighted(reloc, centroidDistance)); } } } WeightComparer weightComp = new WeightComparer(); neighborhood.Sort(weightComp); //foreach(RelativeLocationWeighted reloc in neighborhood) //UI.WriteLine("Row = {0}. Col = {1}. Neighbor distance = {2}.", reloc.Location.Row, reloc.Location.Column, reloc.Weight); MaxSeedQuarterNeighborhood = neighborhood; return; }
//--------------------------------------------------------------------- private bool Spread(ActiveSite initiationSite, SizeType fireSizeType, bool BUI, double severityCalibrate) { //First, check for fire overlap: if (SiteVars.Event[initiationSite] != null) { return(false); } if (isDebugEnabled) { PlugIn.ModelCore.UI.WriteLine(" Spreading fire event started at {0} ...", initiationSite.Location); } IFireRegion fire_region = SiteVars.FireRegion[initiationSite]; int totalSiteSeverities = 0; int siteCohortsKilled = 0; int totalISI = 0; totalSitesDamaged = 1; this.initiationFuel = SiteVars.CFSFuelType[initiationSite]; this.initiationPercentConifer = SiteVars.PercentConifer[initiationSite]; //PlugIn.ModelCore.UI.WriteLine(" Calculated max fire size or duration = {0:0.0}", maxFireParameter); //PlugIn.ModelCore.UI.WriteLine(" Fuel Type = {0}", activeFT.ToString()); //Next, calculate the fire area: List <Site> FireLocations = new List <Site>(); if (isDebugEnabled) { PlugIn.ModelCore.UI.WriteLine(" Calling SizeFireCostSurface ..."); } FireLocations = EventRegion.SizeFireCostSurface(this, fireSizeType, BUI); if (isDebugEnabled) { PlugIn.ModelCore.UI.WriteLine(" FireLocations.Count = {0}", FireLocations.Count); } if (FireLocations.Count == 0) { return(false); } //Attach travel time weights here if (isDebugEnabled) { PlugIn.ModelCore.UI.WriteLine(" Computing SizeFireCostSurface ..."); } List <WeightedSite> FireCostSurface = new List <WeightedSite>(0); foreach (Site site in FireLocations) { double myWeight = SiteVars.TravelTime[site]; if ((Double.IsNaN(myWeight)) || (Double.IsInfinity(myWeight))) { } else { FireCostSurface.Add(new WeightedSite(site, myWeight)); } } WeightComparer weightComp = new WeightComparer(); FireCostSurface.Sort(weightComp); FireLocations = new List <Site>(); double cellArea = (PlugIn.ModelCore.CellLength * PlugIn.ModelCore.CellLength) / 10000; //convert to ha double totalArea = 0.0; int cellCnt = 0; double durMax = 0; if (isDebugEnabled) { PlugIn.ModelCore.UI.WriteLine(" Determining cells burned ..."); } if (fireSizeType == SizeType.size_based) { foreach (WeightedSite weighted in FireCostSurface) { //weightCnt++; cellCnt++; if (totalArea > this.maxFireParameter) { SiteVars.Event[weighted.Site] = null; } else { totalArea += cellArea; FireLocations.Add(weighted.Site); if (SiteVars.TravelTime[weighted.Site] > durMax) { durMax = SiteVars.TravelTime[weighted.Site]; } } } this.maxDuration = durMax; //PlugIn.ModelCore.UI.WriteLine(" Fire Summary: Cells Checked={0}, BurnedArea={1:0.0} (ha), Target Area={2:0.0} (ha).", cellCnt, totalArea, this.maxFireParameter); //if(totalArea < this.maxFireParameter) // PlugIn.ModelCore.UI.WriteLine(" NOTE: Partial fire burn; fire may have spread to the edge of the active area."); } else if (fireSizeType == SizeType.duration_based) { double durationAdj = this.maxFireParameter; if (durationAdj >= 1440) { durationAdj = durationAdj * this.FireSeason.DayLengthProp; } foreach (WeightedSite weighted in FireCostSurface) { cellCnt++; if (weighted.Site == this.initiationSite) { totalArea += cellArea; FireLocations.Add(weighted.Site); if (SiteVars.TravelTime[weighted.Site] > durMax) { durMax = SiteVars.TravelTime[weighted.Site]; } } else { if (weighted.Weight > durationAdj) { SiteVars.Event[weighted.Site] = null; } else { totalArea += cellArea; FireLocations.Add(weighted.Site); //-----Added by BRM----- if (SiteVars.TravelTime[weighted.Site] > durMax) { durMax = SiteVars.TravelTime[weighted.Site]; } //---------- } } } this.maxDuration = durMax; //PlugIn.ModelCore.UI.WriteLine(" Fire Summary: Cells Checked={0}, BurnedArea={1:0.0} (ha), Target Duration={2:0.0}, Adjusted Duration = {3:0.0}.", cellCnt, totalArea, this.maxFireParameter, durationAdj); //if(durationAdj - durMax > 5.0) // PlugIn.ModelCore.UI.WriteLine(" NOTE: Partial fire burn; fire may have spread to the edge of the active area."); } if (isDebugEnabled) { PlugIn.ModelCore.UI.WriteLine(" FireLocations.Count = {0}", FireLocations.Count); } int FMC = this.FMC; //Foliar Moisture Content if (FireLocations.Count == 0) { return(false); } if (isDebugEnabled) { PlugIn.ModelCore.UI.WriteLine(" Damaging cohorts at burned sites ..."); } foreach (Site site in FireLocations) { currentSite = (ActiveSite)site; if (site.IsActive) { this.numSitesChecked++; this.siteSeverity = FireSeverity.CalcFireSeverity(currentSite, this, severityCalibrate, FMC); SiteVars.Severity[currentSite] = (byte)siteSeverity; siteCohortsKilled = Damage(currentSite); this.totalSitesDamaged++; totalSiteSeverities += this.siteSeverity; totalISI += (int)SiteVars.ISI[site]; IFireRegion siteFireRegion = SiteVars.FireRegion[site]; sitesInEvent[siteFireRegion.Index]++; SiteVars.Disturbed[currentSite] = true; if (siteSeverity > 0) { SiteVars.LastSeverity[currentSite] = (byte)siteSeverity; } } } if (this.totalSitesDamaged == 0) { this.eventSeverity = 0; } else { this.eventSeverity = ((double)totalSiteSeverities) / (double)this.totalSitesDamaged; } this.isi = (int)((double)totalISI / (double)this.totalSitesDamaged); if (isDebugEnabled) { PlugIn.ModelCore.UI.WriteLine(" Done spreading"); } return(true); }