//--------------------------------------------------------------------- public RemoveTrees(ICohortCutter cohortCutter, Planting.SpeciesList speciesToPlant, bool repeatHarvest) { this.cohortCutter = cohortCutter; this.speciesToPlant = speciesToPlant; this.repeat = repeatHarvest; }
LandCover.IChange ProcessLandCoverChange(InputVar <string> landCoverChangeType) { InputVar <bool> repeatableHarvest = new InputVar <bool>("RepeatHarvest?"); bool repeatHarvest = false; if (ReadOptionalVar(repeatableHarvest)) { repeatHarvest = repeatableHarvest.Value.Actual; } LandCover.IChange landCoverChange = null; if (landCoverChangeType.Value.Actual == LandCover.NoChange.TypeName) { landCoverChange = noLandCoverChange; } else if (landCoverChangeType.Value.Actual == LandCover.RemoveTrees.TypeName) { LandCover.LandCover.DontParseTrees = true; PartialThinning.CohortSelectors.Clear(); //Clear static storage selector to prevent writing across land uses InputValues.Register <AgeRange>(PartialThinning.ReadAgeOrRange); ICohortSelector selector = selector = ReadSpeciesAndCohorts("LandUse", ParameterNames.Plant, "Tony Bonanza", "LandCoverChange"); ICohortCutter cohortCutter = CohortCutterFactory.CreateCutter(selector, Main.ExtType); Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant(); landCoverChange = new LandCover.RemoveTrees(cohortCutter, speciesToPlant, repeatHarvest); PartialThinning.CohortSelectors.Clear(); //Prevent interactions with Biomass Harvest LandCover.LandCover.DontParseTrees = false; } else if (landCoverChangeType.Value.Actual == LandCover.InsectDefoliation.TypeName) { //Insects will reduce biomass of cohorts rather than directly affecting demographics InputValues.Register <AgeRange>(LandCover.LandCover.ReadAgeOrRange); ICohortSelector selector = ReadSpeciesAndCohorts("LandUse", ParameterNames.Plant, "Vito Tortellini", "LandCoverChange"); Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant(); landCoverChange = new LandCover.InsectDefoliation(LandCover.LandCover.CohortSelectors, speciesToPlant, repeatHarvest); LandCover.LandCover.CohortSelectors.Clear(); //Clear static storage selector to prevent writing across land uses } else { throw new InputValueException(landCoverChangeType.Value.String, "\"{0}\" is not a type of land cover change", landCoverChangeType.Value.Actual); } //landCoverChange.PrintLandCoverDetails(); return(landCoverChange); }
//--------------------------------------------------------------------- public RepeatHarvest(string name, IStandRankingMethod rankingMethod, ISiteSelector siteSelector, ICohortCutter cohortCutter, Planting.SpeciesList speciesToPlant, ISiteSelector additionalSiteSelector, int minTimeSinceDamage, bool preventEstablishment, int interval) : base(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, minTimeSinceDamage, preventEstablishment) { this.interval = interval; this.spreadingSiteSelector = siteSelector as StandSpreading; this.additionalSiteSelector = additionalSiteSelector; this.harvestedStands = new List<Stand>(); }
//--------------------------------------------------------------------- public RepeatHarvest(string name, IStandRankingMethod rankingMethod, ISiteSelector siteSelector, ICohortCutter cohortCutter, Planting.SpeciesList speciesToPlant, ISiteSelector additionalSiteSelector, int minTimeSinceDamage, bool preventEstablishment, int interval) : base(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, minTimeSinceDamage, preventEstablishment) { this.interval = interval; this.spreadingSiteSelector = siteSelector as StandSpreading; this.additionalSiteSelector = additionalSiteSelector; this.harvestedStands = new List <Stand>(); }
//--------------------------------------------------------------------- public Prescription(string name, IStandRankingMethod rankingMethod, ISiteSelector siteSelector, ICohortCutter cohortCutter, Planting.SpeciesList speciesToPlant, int minTimeSinceDamage, bool preventEstablishment) { this.number = nextNumber; nextNumber++; this.name = name; this.rankingMethod = rankingMethod; this.siteSelector = siteSelector; this.cohortCutter = cohortCutter; this.speciesToPlant = speciesToPlant; this.minTimeSinceDamage = minTimeSinceDamage; this.preventEstablishment = preventEstablishment; cohortCounts = new CohortCounts(); }
//--------------------------------------------------------------------- public SingleRepeatHarvest(string name, IStandRankingMethod rankingMethod, ISiteSelector siteSelector, ICohortCutter cohortCutter, Planting.SpeciesList speciesToPlant, ICohortCutter additionalCohortCutter, Planting.SpeciesList additionalSpeciesToPlant, int minTimeSinceDamage, bool preventEstablishment, int interval) : base(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, minTimeSinceDamage, preventEstablishment, interval) { this.initialCohortCutter = cohortCutter; this.initialSiteSelector = SiteSelector; this.initialSpeciesToPlant = speciesToPlant; this.additionalCohortCutter = additionalCohortCutter; this.additionalSpeciesToPlant = additionalSpeciesToPlant; this.isSingleRepeatPrescription = true; }
//--------------------------------------------------------------------- public SingleRepeatHarvest(string name, IStandRankingMethod rankingMethod, ISiteSelector siteSelector, ICohortCutter cohortCutter, Planting.SpeciesList speciesToPlant, ICohortCutter additionalCohortCutter, Planting.SpeciesList additionalSpeciesToPlant, ISiteSelector additionalSiteSelector, int minTimeSinceDamage, bool preventEstablishment, int interval) : base(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, additionalSiteSelector, minTimeSinceDamage, preventEstablishment, interval) { this.initialCohortSelector = cohortCutter; this.initialSpeciesToPlant = speciesToPlant; this.additionalCohortCutter = additionalCohortCutter; this.additionalSpeciesToPlant = additionalSpeciesToPlant; this.additionalSiteSelector = additionalSiteSelector; }
//--------------------------------------------------------------------- public RepeatHarvest(string name, IStandRankingMethod rankingMethod, ISiteSelector siteSelector, ICohortCutter cohortCutter, Planting.SpeciesList speciesToPlant, int minTimeSinceDamage, bool preventEstablishment, int interval, int timesToRepeat = 0) : base(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, minTimeSinceDamage, preventEstablishment) { this.interval = interval; this.spreadingSiteSelector = siteSelector as StandSpreading; this.harvestedStands = new List <Stand>(); if (timesToRepeat > 1) { this.timesToRepeat = timesToRepeat; } else { this.timesToRepeat = int.MaxValue; } }
//--------------------------------------------------------------------- public RemoveTrees(ICohortCutter cohortCutter, Planting.SpeciesList speciesToPlant) { this.cohortCutter = cohortCutter; this.speciesToPlant = speciesToPlant; }
private static ICohortCutter CopyCohortCutter(ICohortCutter cohortCutter, double cuttingMultiplier) { ICohortSelector cohortSelectorCopy; if (cohortCutter.CohortSelector is ClearCut) { cohortSelectorCopy = new ClearCut(); } else if (cohortCutter.CohortSelector is MultiSpeciesCohortSelector multiSpeciesCohortSelector) { var multiSpeciesCohortSelectorCopy = new MultiSpeciesCohortSelector(); var selectionMethods = GetTypePrivateField <Dictionary <ISpecies, SelectCohorts.Method> >(multiSpeciesCohortSelector, "selectionMethods"); foreach (var selectionMethod in selectionMethods) { if (selectionMethod.Value.Method.DeclaringType == typeof(SpecificAgesCohortSelector)) { var agesAndRanges = GetTypePrivateField <AgesAndRanges>(selectionMethod.Value.Target, "agesAndRanges"); var ages = GetTypePrivateField <List <ushort> >(agesAndRanges, "ages"); var ranges = GetTypePrivateField <List <AgeRange> >(agesAndRanges, "ranges"); multiSpeciesCohortSelectorCopy[selectionMethod.Key] = new SpecificAgesCohortSelector(new List <ushort>(ages), new List <AgeRange>(ranges)) .SelectCohorts; } else { multiSpeciesCohortSelectorCopy[selectionMethod.Key] = selectionMethod.Value; } } cohortSelectorCopy = multiSpeciesCohortSelector; } else { throw new Exception(); } if (cohortCutter is PartialCohortCutter partialCohortCutter) { var selectors = GetTypePrivateField <PartialCohortSelectors>(partialCohortCutter, "partialCohortSelectors"); foreach (var partialCohortSelector in selectors.Values) { var percentageList = GetTypePrivateField <IDictionary <ushort, Percentage> >(partialCohortSelector, "percentages"); var percentageListCopy = new Dictionary <ushort, Percentage>(); foreach (var percentage in percentageList) { var newValue = percentage.Value * cuttingMultiplier; if (newValue > 1) { newValue = 1; } percentageListCopy.Add(percentage.Key, new Percentage(newValue)); } percentageList.Clear(); foreach (var percentage in percentageListCopy) { percentageList.Add(percentage.Key, percentage.Value); } } return(cohortCutter); } return(new WholeCohortCutter(cohortSelectorCopy, HarvestExtensionMain.ExtType)); }
//--------------------------------------------------------------------- protected void ReadLandUses() { InputVar <string> name = new InputVar <string>("LandUse"); InputVar <ushort> mapCode = new InputVar <ushort>("MapCode"); InputVar <bool> allowHarvest = new InputVar <bool>("AllowHarvest?"); InputVar <string> landCoverChangeType = new InputVar <string>("LandCoverChange"); Dictionary <string, int> nameLineNumbers = new Dictionary <string, int>(); Dictionary <ushort, int> mapCodeLineNumbers = new Dictionary <ushort, int>(); while (!AtEndOfInput) { int nameLineNum = LineNumber; ReadVar(name); int lineNumber; if (nameLineNumbers.TryGetValue(name.Value.Actual, out lineNumber)) { throw new InputValueException(name.Value.String, "The land use \"{0}\" was previously used on line {1}", name.Value.Actual, lineNumber); } else { nameLineNumbers[name.Value.Actual] = nameLineNum; } int mapCodeLineNum = LineNumber; ReadVar(mapCode); if (mapCodeLineNumbers.TryGetValue(mapCode.Value.Actual, out lineNumber)) { throw new InputValueException(mapCode.Value.String, "The map code \"{0}\" was previously used on line {1}", mapCode.Value.Actual, lineNumber); } else { mapCodeLineNumbers[mapCode.Value.Actual] = mapCodeLineNum; } ReadVar(allowHarvest); // By default, a land use allows trees to establish. bool allowEstablishment = true; ReadVar(landCoverChangeType); LandCover.IChange landCoverChange = null; if (landCoverChangeType.Value.Actual == LandCover.NoChange.TypeName) { landCoverChange = noLandCoverChange; } else if (landCoverChangeType.Value.Actual == LandCover.RemoveTrees.TypeName) { ICohortSelector selector = ReadSpeciesAndCohorts("LandUse", ParameterNames.Plant, ParameterNames.PreventEstablishment); ICohortCutter cohortCutter = CohortCutterFactory.CreateCutter(selector, Main.ExtType); Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant(); landCoverChange = new LandCover.RemoveTrees(cohortCutter, speciesToPlant); if (ReadPreventEstablishment()) { allowEstablishment = false; } } else { throw new InputValueException(landCoverChangeType.Value.String, "\"{0}\" is not a type of land cover change", landCoverChangeType.Value.Actual); } LandUse landUse = new LandUse(name.Value.Actual, mapCode.Value.Actual, allowHarvest.Value.Actual, allowEstablishment, landCoverChange); LandUseRegistry.Register(landUse); } }
//--------------------------------------------------------------------- /// <summary> /// Reads 0 or more prescriptions from text input. /// </summary> protected void ReadPrescriptions(List <Prescription> prescriptions, int harvestTimestep) { Dictionary <string, int> lineNumbers = new Dictionary <string, int>(); InputVar <int> singleRepeat = new InputVar <int>(Names.SingleRepeat); InputVar <int> multipleRepeat = new InputVar <int>(Names.MultipleRepeat); int nameLineNumber = LineNumber; InputVar <string> prescriptionName = new InputVar <string>(Names.Prescription); while (ReadOptionalVar(prescriptionName)) { string name = prescriptionName.Value.Actual; int lineNumber; if (lineNumbers.TryGetValue(name, out lineNumber)) { throw new InputValueException(prescriptionName.Value.String, "The name {0} was previously used on line {1}", prescriptionName.Value.String, lineNumber); } else { lineNumbers[name] = nameLineNumber; } //get ranking method rankingMethod = ReadRankingMethod(); //get stand-harvesting requirements, will modify rankingMethod variable ReadForestTypeTable(); //get site selection method ISiteSelector siteSelector = ReadSiteSelector(); //get the minTimeSinceDamage int minTimeSinceDamage = 0; InputVar <int> minTimeSinceDamageVar = new InputVar <int>("MinTimeSinceDamage"); if (ReadOptionalVar(minTimeSinceDamageVar)) { minTimeSinceDamage = minTimeSinceDamageVar.Value; } bool preventEstablishment = ReadPreventEstablishment(); ICohortSelector cohortSelector = ReadCohortSelector(false); ICohortCutter cohortCutter = CreateCohortCutter(cohortSelector); Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant(); // Repeat harvest? int repeatParamLineNumber = LineNumber; if (ReadOptionalVar(singleRepeat)) { int interval = ValidateRepeatInterval(singleRepeat.Value, repeatParamLineNumber, harvestTimestep); ICohortSelector additionalCohortSelector = ReadCohortSelector(true); ICohortCutter additionalCohortCutter = CreateCohortCutter(additionalCohortSelector); Planting.SpeciesList additionalSpeciesToPlant = ReadSpeciesToPlant(); ISiteSelector additionalSiteSelector = new CompleteStand(); prescriptions.Add(new SingleRepeatHarvest(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, additionalCohortCutter, additionalSpeciesToPlant, additionalSiteSelector, minTimeSinceDamage, preventEstablishment, interval)); } else if (ReadOptionalVar(multipleRepeat)) { int interval = ValidateRepeatInterval(multipleRepeat.Value, repeatParamLineNumber, harvestTimestep); ISiteSelector additionalSiteSelector = new CompleteStand(); prescriptions.Add(new RepeatHarvest(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, additionalSiteSelector, minTimeSinceDamage, preventEstablishment, interval)); } else { prescriptions.Add(new Prescription(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, minTimeSinceDamage, preventEstablishment)); } } }