Skip to content

Commit

Permalink
Happy path, part #1 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
mjunkin committed Jun 11, 2024
1 parent 8bbf95c commit 3cbc0ed
Show file tree
Hide file tree
Showing 7 changed files with 698 additions and 529 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public static void estimateNetDecayAndWasteVolume(
Region region, UtilizationClass utilizationClass, Coefficients aAdjust,
String genus, float loreyHeight, float ageBreastHeight,
Map<String, Coefficients> netDecayWasteCoeMap,
MatrixMap2<String, Region, Float> wasteModifierMap, Coefficients quadMeanDiameterUtil,
Coefficients closeUtilizationUtil,
MatrixMap2<String, Region, Float> wasteModifierMap,
Coefficients quadMeanDiameterUtil, Coefficients closeUtilizationUtil,
Coefficients closeUtilizationNetOfDecayUtil, Coefficients closeUtilizationNetOfDecayAndWasteUtil
) throws ProcessingException {
estimateUtilization(
Expand Down Expand Up @@ -720,7 +720,7 @@ private static void estimateUtilization(
continue;
}

var result = processor.apply(uc, input.getCoe(uc.index));
var result = processor.apply(uc, inputValue);
output.setCoe(uc.index, result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import java.util.Optional;

public enum UtilizationClass {
SMALL(-1, "<7.5 cm", 0f, 7.5f), //
ALL(0, ">=7.5 cm", 7.5f, 10000f), //
U75TO125(1, "7.5 - 12.5 cm", 7.5f, 12.5f), //
U125TO175(2, "12.5 - 17.5 cm", 12.5f, 17.5f), //
U175TO225(3, "17.5 - 22.5 cm", 17.5f, 22.5f), //
OVER225(4, ">22.5 cm", 22.5f, 10000f);
SMALL(-1, "<7.5 cm", 0f, 7.5f), // 0
ALL(0, ">=7.5 cm", 7.5f, 10000f), // 1
U75TO125(1, "7.5 - 12.5 cm", 7.5f, 12.5f), // 2
U125TO175(2, "12.5 - 17.5 cm", 12.5f, 17.5f), // 3
U175TO225(3, "17.5 - 22.5 cm", 17.5f, 22.5f), // 4
OVER225(4, ">22.5 cm", 22.5f, 10000f); // 5

public final int index;
public final String className;
Expand All @@ -28,6 +28,9 @@ public enum UtilizationClass {
);

public static final Collection<UtilizationClass> ALL_BUT_SMALL = Collections
.unmodifiableList(new ArrayList<>(Arrays.asList(ALL, U75TO125, U125TO175, U175TO225, OVER225)));

public static final Collection<UtilizationClass> ALL_BUT_SMALL_AND_ALL = Collections
.unmodifiableList(new ArrayList<>(Arrays.asList(U75TO125, U125TO175, U175TO225, OVER225)));

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,11 @@ public class ForwardProcessingEngine {
/** π/10⁴ */
public static final float PI_40K = (float) (Math.PI / 40_000);

private final ForwardProcessingState fps;
/* pp */ final ForwardProcessingState fps;

public ForwardProcessingEngine(Map<String, Object> controlMap) {

this(new ForwardProcessingState(controlMap));
}

/* pp */ ForwardProcessingEngine(ForwardProcessingState fps) {

this.fps = fps;
this.fps = new ForwardProcessingState(controlMap);
}

public enum ExecutionStep {
Expand Down Expand Up @@ -124,7 +119,7 @@ private void executeForwardAlgorithm(
ExecutionStep lastStep
) throws ProcessingException {

PolygonProcessingState pps = fps.getProcessingState();
PolygonProcessingState pps = fps.getPolygonProcessingState();
Bank bank = fps.getBank(0, LayerType.PRIMARY);

logger.info(
Expand All @@ -141,7 +136,7 @@ private void executeForwardAlgorithm(

// SCINXSET - note these are calculated directly from the Primary bank of instance 1
if (lastStep.ordinal() >= ExecutionStep.CalculateMissingSiteCurves.ordinal()) {
calculateMissingSiteCurves(bank, fps.getSiteCurveMap(), fps.getProcessingState());
calculateMissingSiteCurves(bank, fps.getSiteCurveMap(), fps.getPolygonProcessingState());
}

// VPRIME, method == 1
Expand Down Expand Up @@ -188,8 +183,11 @@ static void setCompatibilityVariables(
// Note: L1COM2 (INL1VGRP, INL1DGRP, INL1BGRP) is initialized when
// PolygonProcessingState (volumeEquationGroups, decayEquationGroups
// breakageEquationGroups, respectively) is constructed. Copying
// the values into LCOM1 is not necessary, with the exception that
// VolumeEquationGroup 10 is mapped to 11 (VGRPFIND)
// the values into LCOM1 is not necessary. Note, however, that
// VolumeEquationGroup 10 is mapped to 11 (VGRPFIND) - this is done
// when volumeEquationGroups is built (i.e., when the equivalent to
// INL1VGRP is built, rather than when LCOM1 VGRPL is built in the
// original code.)

var cvVolume = new MatrixMap3[pps.getNSpecies() + 1];
var cvBasalArea = new MatrixMap2[pps.getNSpecies() + 1];
Expand All @@ -200,7 +198,7 @@ static void setCompatibilityVariables(

String genusName = pps.wallet.speciesNames[s];

float spLoreyHeight_All = pps.wallet.loreyHeights[s][0];
float spLoreyHeight_All = pps.wallet.loreyHeights[s][UtilizationClass.ALL.ordinal()];

Coefficients basalAreas = Utils.utilizationVector();
Coefficients wholeStemVolumes = Utils.utilizationVector();
Expand All @@ -211,31 +209,34 @@ static void setCompatibilityVariables(
Coefficients treesPerHectare = Utils.utilizationVector();

cvVolume[s] = new MatrixMap3Impl<UtilizationClass, VolumeVariable, LayerType, Float>(
UtilizationClass.ALL_BUT_SMALL, VolumeVariable.ALL, LayerType.ALL_USED, (k1, k2, k3) -> 0f
UtilizationClass.ALL_BUT_SMALL_AND_ALL, VolumeVariable.ALL, LayerType.ALL_USED, (k1, k2, k3) -> 0f
);
cvBasalArea[s] = new MatrixMap2Impl<UtilizationClass, LayerType, Float>(
UtilizationClass.ALL_BUT_SMALL, LayerType.ALL_USED, (k1, k2) -> 0f
UtilizationClass.ALL_BUT_SMALL_AND_ALL, LayerType.ALL_USED, (k1, k2) -> 0f
);
cvQuadraticMeanDiameter[s] = new MatrixMap2Impl<UtilizationClass, LayerType, Float>(
UtilizationClass.ALL_BUT_SMALL, LayerType.ALL_USED, (k1, k2) -> 0f
UtilizationClass.ALL_BUT_SMALL_AND_ALL, LayerType.ALL_USED, (k1, k2) -> 0f
);

for (UtilizationClass uc : UtilizationClass.ALL_BUT_SMALL) {

float adjustment;
float baseVolume;

basalAreas.setCoe(uc.index, pps.wallet.basalAreas[s][uc.index]);
wholeStemVolumes.setCoe(uc.index, pps.wallet.wholeStemVolumes[s][uc.index]);
closeUtilizationVolumes.setCoe(uc.index, pps.wallet.closeUtilizationVolumes[s][uc.index]);
closeUtilizationVolumesNetOfDecay.setCoe(uc.index, pps.wallet.cuVolumesMinusDecay[s][uc.index]);
basalAreas.setCoe(uc.index, pps.wallet.basalAreas[s][uc.ordinal()]);
wholeStemVolumes.setCoe(uc.index, pps.wallet.wholeStemVolumes[s][uc.ordinal()]);
closeUtilizationVolumes.setCoe(uc.index, pps.wallet.closeUtilizationVolumes[s][uc.ordinal()]);
closeUtilizationVolumesNetOfDecay.setCoe(uc.index, pps.wallet.cuVolumesMinusDecay[s][uc.ordinal()]);
closeUtilizationVolumesNetOfDecayAndWaste
.setCoe(uc.index, pps.wallet.cuVolumesMinusDecayAndWastage[s][uc.index]);
.setCoe(uc.index, pps.wallet.cuVolumesMinusDecayAndWastage[s][uc.ordinal()]);

quadMeanDiameters.setCoe(uc.index, pps.wallet.quadMeanDiameters[s][uc.index]);
quadMeanDiameters.setCoe(uc.index, pps.wallet.quadMeanDiameters[s][uc.ordinal()]);
if (uc != UtilizationClass.ALL && quadMeanDiameters.getCoe(uc.index) <= 0.0f) {
quadMeanDiameters.setCoe(uc.index, DEFAULT_QUAD_MEAN_DIAMETERS[uc.index]);
quadMeanDiameters.setCoe(uc.index, DEFAULT_QUAD_MEAN_DIAMETERS[uc.ordinal()]);
}
}

for (UtilizationClass uc : UtilizationClass.ALL_BUT_SMALL_AND_ALL) {

float adjustment;
float baseVolume;

// Volume less decay and waste
adjustment = 0.0f;
Expand All @@ -246,10 +247,11 @@ static void setCompatibilityVariables(

// EMP094
EstimationMethods.estimateNetDecayAndWasteVolume(
pps.getBecZone()
.getRegion(), uc, aAdjust, pps.wallet.speciesNames[s], spLoreyHeight_All, pps.wallet.yearsAtBreastHeight[s], pps
.getNetDecayWasteCoeMap(), pps
.getWasteModifierMap(), quadMeanDiameters, closeUtilizationVolumes, closeUtilizationVolumesNetOfDecay, closeUtilizationVolumesNetOfDecayAndWaste
pps.getBecZone().getRegion(), uc, aAdjust, pps.wallet.speciesNames[s],
spLoreyHeight_All, pps.wallet.yearsAtBreastHeight[s],
pps.getNetDecayWasteCoeMap(), pps.getWasteModifierMap(),
quadMeanDiameters, closeUtilizationVolumes, closeUtilizationVolumesNetOfDecay,
closeUtilizationVolumesNetOfDecayAndWaste
);

float actualVolume = pps.wallet.cuVolumesMinusDecayAndWastage[s][uc.ordinal()];
Expand All @@ -270,10 +272,10 @@ static void setCompatibilityVariables(
// EMP094
int decayGroup = pps.decayEquationGroups[s];
EstimationMethods.estimateNetDecayVolume(
pps.wallet.speciesNames[s], pps.getBecZone()
.getRegion(), uc, aAdjust, decayGroup, spLoreyHeight_All, pps.wallet.yearsAtBreastHeight[s], pps
.getNetDecayCoeMap(), pps
.getDecayModifierMap(), quadMeanDiameters, closeUtilizationVolumes, closeUtilizationVolumesNetOfDecay
pps.wallet.speciesNames[s],
pps.getBecZone().getRegion(), uc, aAdjust, decayGroup, spLoreyHeight_All,
pps.wallet.yearsAtBreastHeight[s], pps.getNetDecayCoeMap(), pps.getDecayModifierMap(),
quadMeanDiameters, closeUtilizationVolumes, closeUtilizationVolumesNetOfDecay
);

float actualVolume = pps.wallet.cuVolumesMinusDecay[s][uc.ordinal()];
Expand Down Expand Up @@ -320,7 +322,7 @@ static void setCompatibilityVariables(
.getWholeStemUtilizationComponentMap(), quadMeanDiameters, basalAreas, wholeStemVolumes
);

for (UtilizationClass uc : UtilizationClass.ALL_BUT_SMALL) {
for (UtilizationClass uc : UtilizationClass.ALL_BUT_SMALL_AND_ALL) {
float adjustment = 0.0f;
float basalArea = pps.wallet.basalAreas[s][uc.ordinal()];
if (allowCompatibilitySetting == 0 && basalArea > 0.0f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void setPolygon(VdypPolygon polygon) {
processingState = new PolygonProcessingState(this, polygon, banks[toIndex(0, LayerType.PRIMARY)], controlMap);
}

public PolygonProcessingState getProcessingState() {
public PolygonProcessingState getPolygonProcessingState() {
return processingState;
}

Expand Down
Loading

0 comments on commit 3cbc0ed

Please sign in to comment.