fix
diff --git a/org.eclipse.stem/core/org.eclipse.stem.solvers.stochastic/src/org/eclipse/stem/solvers/stochastic/impl/StandardStochasticImpl.java b/org.eclipse.stem/core/org.eclipse.stem.solvers.stochastic/src/org/eclipse/stem/solvers/stochastic/impl/StandardStochasticImpl.java
index 21a6f8f..549a41a 100644
--- a/org.eclipse.stem/core/org.eclipse.stem.solvers.stochastic/src/org/eclipse/stem/solvers/stochastic/impl/StandardStochasticImpl.java
+++ b/org.eclipse.stem/core/org.eclipse.stem.solvers.stochastic/src/org/eclipse/stem/solvers/stochastic/impl/StandardStochasticImpl.java
@@ -367,11 +367,13 @@
probability = 0;
if(probability > 1.0)
probability = 1.0;
- double stochasticMigration = binomialDist.fastPickFromBinomialDist(probability, (int)Math.round(roundedSourceCount));
+ double stochasticMigration = binomialDist.fastPickFromBinomialDist(probability, roundedSourceCount);
+ if(stochasticMigration > sourceCount)
+ stochasticMigration = sourceCount;
// END FIX
// Draw stochastically the number of people migrating in
- //int sumMigration=0;
+ int sumMigration=0;
if(sourceCount > 0) {
// The rest of the labels in the "otherLabels" array are organized in pairs, where the first is the source
// disease model label and the second is the target. We draw for each compartment of type Standard stochastically
@@ -395,6 +397,8 @@
//int iMigrationCount = binomialDist.fastPickFromBinomialDist(draw, (int)Math.round(sourceCount));
// SED FIX:
int iMigrationCount = (int)Math.round(weightedTransition);
+ if(sumMigration+iMigrationCount > stochasticMigration)
+ iMigrationCount = (int)(stochasticMigration - sumMigration); // Fix for rounding problem with Math.round(x.5) => x+1
if(otherDiseaseModelLabelValue.eGetDouble(ea.getFeatureID()) < iMigrationCount)
iMigrationCount = (int)Math.floor(otherDiseaseModelLabelValue.eGetDouble(ea.getFeatureID()));
// Subtract from the source the number of people migrating out of the state
@@ -406,7 +410,7 @@
thisDiseaseModelLabelValue.eGetDouble(ea.getFeatureID())+iMigrationCount);
// SED FIX not needed
- //sumMigration += iMigrationCount;
+ sumMigration += iMigrationCount;
}
}
}
@@ -445,11 +449,14 @@
probability = 0;
if(probability > 1.0)
probability = 1.0;
- double stochasticAging = binomialDist.fastPickFromBinomialDist(probability, (int)Math.round(roundedSourceCount));
+ double stochasticAging = binomialDist.fastPickFromBinomialDist(probability, roundedSourceCount);
+ if(stochasticAging > sourceCount)
+ stochasticAging = sourceCount;
+
// END FIX
// Draw stochastically the number of people aging in
- //int sumAging=0;
+ int sumAging=0;
if(sourceCount > 0) {
// The rest of the labels in the "otherLabels" array are organized in pairs, where the first is the source
// disease model label and the second is the target. We draw for each compartment of type Standard stochastically
@@ -473,6 +480,10 @@
//int iAgingCount = binomialDist.fastPickFromBinomialDist(draw, (int)Math.round(sourceCount));
int iAgingCount = (int)Math.round(weightedTransition);
+
+ if(sumAging+iAgingCount > stochasticAging)
+ iAgingCount = (int)(stochasticAging - iAgingCount); // Fix for rounding problem with Math.round(x.5) => x+1
+
if(iAgingCount > sourceCount)
iAgingCount = (int)Math.floor(sourceCount); // safe, don't age more than available
// Subtract from the source the number of people migrating out of the state
@@ -482,7 +493,7 @@
thisDiseaseModelLabelValue.eSetDouble(ea.getFeatureID(),
thisDiseaseModelLabelValue.eGetDouble(ea.getFeatureID())+iAgingCount);
- //sumAging += iAgingCount;
+ sumAging += iAgingCount;
}
}