fix stochastic modelling of control labels for SIR, SEIR
diff --git a/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/standard/impl/SEIRImpl.java b/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/standard/impl/SEIRImpl.java
index 1c6fc68..00ec1ec 100644
--- a/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/standard/impl/SEIRImpl.java
+++ b/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/standard/impl/SEIRImpl.java
@@ -155,9 +155,11 @@
double deltaR = numberOfInfectedToRecovered - numberOfRecoveredToSusceptible;
StandardInterventionLabel scl = findInterventionLabel((Node)diseaseLabel.getIdentifiable());
+ double vaccinations = 0;
+ double isolations = 0;
if(scl != null) {
- double vaccinations = ((StandardInterventionLabelValue)scl.getCurrentValue()).getVaccinations();
- double isolations = ((StandardInterventionLabelValue)scl.getCurrentValue()).getIsolations();
+ vaccinations = ((StandardInterventionLabelValue)scl.getCurrentValue()).getVaccinations();
+ isolations = ((StandardInterventionLabelValue)scl.getCurrentValue()).getIsolations();
vaccinations *= ((double) timeDelta / (double) getTimePeriod());
isolations *= ((double) timeDelta / (double) getTimePeriod());
if(currentSEIR.getS() < vaccinations) vaccinations = currentSEIR.getS();
@@ -205,6 +207,26 @@
rsExchange.setCount(numberOfRecoveredToSusceptible);
rsExchange.setType(ExchangeType.COMPARTMENT_TRANSITION);
deltaValue.getDepartures().add(rsExchange);
+
+ // S->R
+ if(vaccinations > 0) {
+ Exchange srExchange = (Exchange)ExchangePool.POOL.get();
+ srExchange.setSource(StandardPackage.eINSTANCE.getStandardDiseaseModelLabelValue_S());
+ srExchange.setTarget(StandardPackage.eINSTANCE.getSIRLabelValue_R());
+ srExchange.setCount(vaccinations);
+ srExchange.setType(ExchangeType.COMPARTMENT_TRANSITION);
+ deltaValue.getDepartures().add(srExchange);
+ }
+
+ // I->R
+ if(isolations > 0) {
+ Exchange irIsoExchange = (Exchange)ExchangePool.POOL.get();
+ irIsoExchange.setSource(StandardPackage.eINSTANCE.getSILabelValue_I());
+ irIsoExchange.setTarget(StandardPackage.eINSTANCE.getSIRLabelValue_R());
+ irIsoExchange.setCount(isolations);
+ irIsoExchange.setType(ExchangeType.COMPARTMENT_TRANSITION);
+ deltaValue.getDepartures().add(irIsoExchange);
+ }
// added to express the transitions. Necessary to support stochastic modeling
/////////////////////////////////////////////////////////////////////////////
diff --git a/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/standard/impl/SIRImpl.java b/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/standard/impl/SIRImpl.java
index 833eeae..b3aa9ec 100644
--- a/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/standard/impl/SIRImpl.java
+++ b/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/standard/impl/SIRImpl.java
@@ -161,6 +161,27 @@
// Determine delta R
double deltaR = numberOfInfectedToRecovered - numberOfRecoveredToSusceptible;
+
+ // If there is a control label attached to the region, we need to adjust for any interventions in effect.
+
+ StandardInterventionLabel scl = findInterventionLabel((Node)diseaseLabel.getIdentifiable());
+ double vaccinations = 0;
+ double isolations = 0;
+ if(scl != null) {
+ vaccinations = ((StandardInterventionLabelValue)scl.getCurrentValue()).getVaccinations();
+ isolations = ((StandardInterventionLabelValue)scl.getCurrentValue()).getIsolations();
+ vaccinations *= ((double) timeDelta / (double) getTimePeriod());
+ isolations *= ((double) timeDelta / (double) getTimePeriod());
+
+ if(currentSIR.getS() < vaccinations) vaccinations = currentSIR.getS();
+ if(currentSIR.getI() < isolations) isolations = currentSIR.getI();
+
+ deltaS -= vaccinations;
+ deltaR += vaccinations;
+ deltaI -= isolations;
+ deltaR += isolations;
+ }
+
/////////////////////////////////////////////////////////////////////////////
// added to express the transitions. Necessary to support stochastic modeling
// S->I
@@ -187,26 +208,28 @@
rsExchange.setCount(numberOfRecoveredToSusceptible);
rsExchange.setType(ExchangeType.COMPARTMENT_TRANSITION);
deltaValue.getDepartures().add(rsExchange);
+
+ // S->R
+ if(vaccinations > 0) {
+ Exchange srExchange = (Exchange)ExchangePool.POOL.get();
+ srExchange.setSource(StandardPackage.eINSTANCE.getStandardDiseaseModelLabelValue_S());
+ srExchange.setTarget(StandardPackage.eINSTANCE.getSIRLabelValue_R());
+ srExchange.setCount(vaccinations);
+ srExchange.setType(ExchangeType.COMPARTMENT_TRANSITION);
+ deltaValue.getDepartures().add(srExchange);
+ }
+
+ // I->R
+ if(isolations > 0) {
+ Exchange irIsoExchange = (Exchange)ExchangePool.POOL.get();
+ irIsoExchange.setSource(StandardPackage.eINSTANCE.getSILabelValue_I());
+ irIsoExchange.setTarget(StandardPackage.eINSTANCE.getSIRLabelValue_R());
+ irIsoExchange.setCount(isolations);
+ irIsoExchange.setType(ExchangeType.COMPARTMENT_TRANSITION);
+ deltaValue.getDepartures().add(irIsoExchange);
+ }
// added to express the transitions. Necessary to support stochastic modeling
/////////////////////////////////////////////////////////////////////////////
-
- // If there is a control label attached to the region, we need to adjust for any interventions in effect.
-
- StandardInterventionLabel scl = findInterventionLabel((Node)diseaseLabel.getIdentifiable());
- if(scl != null) {
- double vaccinations = ((StandardInterventionLabelValue)scl.getCurrentValue()).getVaccinations();
- double isolations = ((StandardInterventionLabelValue)scl.getCurrentValue()).getIsolations();
- vaccinations *= ((double) timeDelta / (double) getTimePeriod());
- isolations *= ((double) timeDelta / (double) getTimePeriod());
-
- if(currentSIR.getS() < vaccinations) vaccinations = currentSIR.getS();
- if(currentSIR.getI() < isolations) isolations = currentSIR.getI();
-
- deltaS -= vaccinations;
- deltaR += vaccinations;
- deltaI -= isolations;
- deltaR += isolations;
- }
SIRLabelValueImpl ret = (SIRLabelValueImpl)deltaValue;
ret.setS(deltaS);