blob: 8666664990520343386e9695f30b15722711b540 [file] [log] [blame]
package org.eclipse.stem.diseasemodels.vector.impl;
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
import java.util.Collections;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.BasicEObjectImpl;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.stem.core.graph.Edge;
import org.eclipse.stem.core.graph.EdgeLabel;
import org.eclipse.stem.core.graph.LabelValue;
import org.eclipse.stem.core.graph.Node;
import org.eclipse.stem.core.graph.NodeLabel;
import org.eclipse.stem.core.model.STEMTime;
import org.eclipse.stem.definitions.labels.AreaLabel;
import org.eclipse.stem.definitions.labels.CommonBorderRelationshipLabelValue;
import org.eclipse.stem.definitions.labels.RoadTransportRelationshipLabelValue;
import org.eclipse.stem.definitions.labels.impl.CommonBorderRelationshipLabelImpl;
import org.eclipse.stem.definitions.labels.impl.RoadTransportRelationshipLabelImpl;
import org.eclipse.stem.diseasemodels.standard.DiseaseModelLabel;
import org.eclipse.stem.diseasemodels.standard.DiseaseModelLabelValue;
import org.eclipse.stem.diseasemodels.standard.Infector;
import org.eclipse.stem.diseasemodels.standard.SIInfector;
import org.eclipse.stem.diseasemodels.standard.StandardDiseaseModel;
import org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabel;
import org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabelValue;
import org.eclipse.stem.diseasemodels.standard.StandardFactory;
import org.eclipse.stem.diseasemodels.vector.DengueModelHostLabel;
import org.eclipse.stem.diseasemodels.vector.DengueModelHostLabelValue;
import org.eclipse.stem.diseasemodels.vector.DengueModelVectorLabel;
import org.eclipse.stem.diseasemodels.vector.DengueModelVectorLabelValue;
import org.eclipse.stem.diseasemodels.vector.VectorFactory;
import org.eclipse.stem.diseasemodels.vector.VectorPackage;
import org.eclipse.stem.diseasemodels.vector.VerySimpleDengueModel;
/**
* <!-- begin-user-doc --> An implementation of the model object '
* <em><b>Very Simple Dengue Model</b></em>'. <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.stem.diseasemodels.vector.impl.VerySimpleDengueModelImpl#getHostTransmissionRate <em>Host Transmission Rate</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.vector.impl.VerySimpleDengueModelImpl#getHostIncubationRate <em>Host Incubation Rate</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.vector.impl.VerySimpleDengueModelImpl#getHostRecoveryRate <em>Host Recovery Rate</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.vector.impl.VerySimpleDengueModelImpl#getHostImmunityLossRate <em>Host Immunity Loss Rate</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.vector.impl.VerySimpleDengueModelImpl#getVectorTransmissionRate <em>Vector Transmission Rate</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.vector.impl.VerySimpleDengueModelImpl#getVectorIncubationRate <em>Vector Incubation Rate</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.vector.impl.VerySimpleDengueModelImpl#getADE <em>ADE</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.vector.impl.VerySimpleDengueModelImpl#getCrossImmunity <em>Cross Immunity</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class VerySimpleDengueModelImpl extends VectorDiseaseModelImpl implements
VerySimpleDengueModel {
/**
* The default value of the '{@link #getHostTransmissionRate() <em>Host Transmission Rate</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getHostTransmissionRate()
* @generated
* @ordered
*/
protected static final double HOST_TRANSMISSION_RATE_EDEFAULT = 0.041;
/**
* The cached value of the '{@link #getHostTransmissionRate() <em>Host Transmission Rate</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getHostTransmissionRate()
* @generated
* @ordered
*/
protected double hostTransmissionRate = HOST_TRANSMISSION_RATE_EDEFAULT;
/**
* The default value of the '{@link #getHostIncubationRate() <em>Host Incubation Rate</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getHostIncubationRate()
* @generated
* @ordered
*/
protected static final double HOST_INCUBATION_RATE_EDEFAULT = 0.178;
/**
* The cached value of the '{@link #getHostIncubationRate() <em>Host Incubation Rate</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getHostIncubationRate()
* @generated
* @ordered
*/
protected double hostIncubationRate = HOST_INCUBATION_RATE_EDEFAULT;
/**
* The default value of the '{@link #getHostRecoveryRate() <em>Host Recovery Rate</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getHostRecoveryRate()
* @generated
* @ordered
*/
protected static final double HOST_RECOVERY_RATE_EDEFAULT = 0.274;
/**
* The cached value of the '{@link #getHostRecoveryRate() <em>Host Recovery Rate</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getHostRecoveryRate()
* @generated
* @ordered
*/
protected double hostRecoveryRate = HOST_RECOVERY_RATE_EDEFAULT;
/**
* The default value of the '{@link #getHostImmunityLossRate() <em>Host Immunity Loss Rate</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getHostImmunityLossRate()
* @generated
* @ordered
*/
protected static final double HOST_IMMUNITY_LOSS_RATE_EDEFAULT = 0.0055;
/**
* The cached value of the '{@link #getHostImmunityLossRate() <em>Host Immunity Loss Rate</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getHostImmunityLossRate()
* @generated
* @ordered
*/
protected double hostImmunityLossRate = HOST_IMMUNITY_LOSS_RATE_EDEFAULT;
/**
* The default value of the '{@link #getVectorTransmissionRate() <em>Vector Transmission Rate</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getVectorTransmissionRate()
* @generated
* @ordered
*/
protected static final double VECTOR_TRANSMISSION_RATE_EDEFAULT = 1.452;
/**
* The cached value of the '{@link #getVectorTransmissionRate() <em>Vector Transmission Rate</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getVectorTransmissionRate()
* @generated
* @ordered
*/
protected double vectorTransmissionRate = VECTOR_TRANSMISSION_RATE_EDEFAULT;
/**
* The default value of the '{@link #getVectorIncubationRate() <em>Vector Incubation Rate</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getVectorIncubationRate()
* @generated
* @ordered
*/
protected static final double VECTOR_INCUBATION_RATE_EDEFAULT = 0.082;
/**
* The cached value of the '{@link #getVectorIncubationRate() <em>Vector Incubation Rate</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getVectorIncubationRate()
* @generated
* @ordered
*/
protected double vectorIncubationRate = VECTOR_INCUBATION_RATE_EDEFAULT;
/**
* The default value of the '{@link #getADE() <em>ADE</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #getADE()
* @generated
* @ordered
*/
protected static final double ADE_EDEFAULT = 1.0;
/**
* The cached value of the '{@link #getADE() <em>ADE</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #getADE()
* @generated
* @ordered
*/
protected double ade = ADE_EDEFAULT;
/**
* The default value of the '{@link #getCrossImmunity() <em>Cross Immunity</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getCrossImmunity()
* @generated
* @ordered
*/
protected static final double CROSS_IMMUNITY_EDEFAULT = 0.0;
/**
* The cached value of the '{@link #getCrossImmunity() <em>Cross Immunity</em>}' attribute.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @see #getCrossImmunity()
* @generated
* @ordered
*/
protected double crossImmunity = CROSS_IMMUNITY_EDEFAULT;
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
public VerySimpleDengueModelImpl() {
super();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return VectorPackage.Literals.VERY_SIMPLE_DENGUE_MODEL;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public double getHostTransmissionRate() {
return hostTransmissionRate;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setHostTransmissionRate(double newHostTransmissionRate) {
double oldHostTransmissionRate = hostTransmissionRate;
hostTransmissionRate = newHostTransmissionRate;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_TRANSMISSION_RATE, oldHostTransmissionRate, hostTransmissionRate));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public double getADE() {
return ade;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setADE(double newADE) {
double oldADE = ade;
ade = newADE;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VectorPackage.VERY_SIMPLE_DENGUE_MODEL__ADE, oldADE, ade));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public double getCrossImmunity() {
return crossImmunity;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setCrossImmunity(double newCrossImmunity) {
double oldCrossImmunity = crossImmunity;
crossImmunity = newCrossImmunity;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VectorPackage.VERY_SIMPLE_DENGUE_MODEL__CROSS_IMMUNITY, oldCrossImmunity, crossImmunity));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public double getHostIncubationRate() {
return hostIncubationRate;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setHostIncubationRate(double newHostIncubationRate) {
double oldHostIncubationRate = hostIncubationRate;
hostIncubationRate = newHostIncubationRate;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_INCUBATION_RATE, oldHostIncubationRate, hostIncubationRate));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public double getHostRecoveryRate() {
return hostRecoveryRate;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setHostRecoveryRate(double newHostRecoveryRate) {
double oldHostRecoveryRate = hostRecoveryRate;
hostRecoveryRate = newHostRecoveryRate;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_RECOVERY_RATE, oldHostRecoveryRate, hostRecoveryRate));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public double getHostImmunityLossRate() {
return hostImmunityLossRate;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setHostImmunityLossRate(double newHostImmunityLossRate) {
double oldHostImmunityLossRate = hostImmunityLossRate;
hostImmunityLossRate = newHostImmunityLossRate;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_IMMUNITY_LOSS_RATE, oldHostImmunityLossRate, hostImmunityLossRate));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public double getVectorTransmissionRate() {
return vectorTransmissionRate;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setVectorTransmissionRate(double newVectorTransmissionRate) {
double oldVectorTransmissionRate = vectorTransmissionRate;
vectorTransmissionRate = newVectorTransmissionRate;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_TRANSMISSION_RATE, oldVectorTransmissionRate, vectorTransmissionRate));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public double getVectorIncubationRate() {
return vectorIncubationRate;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setVectorIncubationRate(double newVectorIncubationRate) {
double oldVectorIncubationRate = vectorIncubationRate;
vectorIncubationRate = newVectorIncubationRate;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_INCUBATION_RATE, oldVectorIncubationRate, vectorIncubationRate));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_TRANSMISSION_RATE:
return getHostTransmissionRate();
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_INCUBATION_RATE:
return getHostIncubationRate();
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_RECOVERY_RATE:
return getHostRecoveryRate();
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_IMMUNITY_LOSS_RATE:
return getHostImmunityLossRate();
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_TRANSMISSION_RATE:
return getVectorTransmissionRate();
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_INCUBATION_RATE:
return getVectorIncubationRate();
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__ADE:
return getADE();
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__CROSS_IMMUNITY:
return getCrossImmunity();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_TRANSMISSION_RATE:
setHostTransmissionRate((Double)newValue);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_INCUBATION_RATE:
setHostIncubationRate((Double)newValue);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_RECOVERY_RATE:
setHostRecoveryRate((Double)newValue);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_IMMUNITY_LOSS_RATE:
setHostImmunityLossRate((Double)newValue);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_TRANSMISSION_RATE:
setVectorTransmissionRate((Double)newValue);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_INCUBATION_RATE:
setVectorIncubationRate((Double)newValue);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__ADE:
setADE((Double)newValue);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__CROSS_IMMUNITY:
setCrossImmunity((Double)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_TRANSMISSION_RATE:
setHostTransmissionRate(HOST_TRANSMISSION_RATE_EDEFAULT);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_INCUBATION_RATE:
setHostIncubationRate(HOST_INCUBATION_RATE_EDEFAULT);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_RECOVERY_RATE:
setHostRecoveryRate(HOST_RECOVERY_RATE_EDEFAULT);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_IMMUNITY_LOSS_RATE:
setHostImmunityLossRate(HOST_IMMUNITY_LOSS_RATE_EDEFAULT);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_TRANSMISSION_RATE:
setVectorTransmissionRate(VECTOR_TRANSMISSION_RATE_EDEFAULT);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_INCUBATION_RATE:
setVectorIncubationRate(VECTOR_INCUBATION_RATE_EDEFAULT);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__ADE:
setADE(ADE_EDEFAULT);
return;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__CROSS_IMMUNITY:
setCrossImmunity(CROSS_IMMUNITY_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_TRANSMISSION_RATE:
return hostTransmissionRate != HOST_TRANSMISSION_RATE_EDEFAULT;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_INCUBATION_RATE:
return hostIncubationRate != HOST_INCUBATION_RATE_EDEFAULT;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_RECOVERY_RATE:
return hostRecoveryRate != HOST_RECOVERY_RATE_EDEFAULT;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__HOST_IMMUNITY_LOSS_RATE:
return hostImmunityLossRate != HOST_IMMUNITY_LOSS_RATE_EDEFAULT;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_TRANSMISSION_RATE:
return vectorTransmissionRate != VECTOR_TRANSMISSION_RATE_EDEFAULT;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__VECTOR_INCUBATION_RATE:
return vectorIncubationRate != VECTOR_INCUBATION_RATE_EDEFAULT;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__ADE:
return ade != ADE_EDEFAULT;
case VectorPackage.VERY_SIMPLE_DENGUE_MODEL__CROSS_IMMUNITY:
return crossImmunity != CROSS_IMMUNITY_EDEFAULT;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
if (eIsProxy()) return super.toString();
StringBuffer result = new StringBuffer(super.toString());
result.append(" (hostTransmissionRate: ");
result.append(hostTransmissionRate);
result.append(", hostIncubationRate: ");
result.append(hostIncubationRate);
result.append(", hostRecoveryRate: ");
result.append(hostRecoveryRate);
result.append(", hostImmunityLossRate: ");
result.append(hostImmunityLossRate);
result.append(", vectorTransmissionRate: ");
result.append(vectorTransmissionRate);
result.append(", vectorIncubationRate: ");
result.append(vectorIncubationRate);
result.append(", ADE: ");
result.append(ade);
result.append(", crossImmunity: ");
result.append(crossImmunity);
result.append(')');
return result.toString();
}
@Override
public StandardDiseaseModelLabelValue computeDiseaseDeltas(STEMTime time,
StandardDiseaseModelLabelValue currentState,
StandardDiseaseModelLabel diseaseLabel, long timeDelta,
DiseaseModelLabelValue returnValue) {
if (diseaseLabel instanceof DengueModelHostLabel) {
DengueModelHostLabelValue hostDelta = (DengueModelHostLabelValue) returnValue;
DengueModelHostLabelValue host = (DengueModelHostLabelValue) currentState;
double hostPopulationCount = host.getPopulationCount();
if (hostPopulationCount == 0.0) {
hostDelta.reset();
return hostDelta;
}
DengueModelVectorLabelValue vector = null;
EList<NodeLabel> allLabels = diseaseLabel.getNode().getLabels();
for (NodeLabel label : allLabels) {
if (label instanceof DengueModelVectorLabel) {
DengueModelVectorLabel vectorLabel = (DengueModelVectorLabel) label;
if (vectorLabel.getDecorator() == this) {
vector = (DengueModelVectorLabelValue) vectorLabel
.getTempValue();
}
}
}
double adjustedHostTransmissionRate = getHostTransmissionRate()
* (double) timeDelta / (double) getTimePeriod();
double adjustedHostIncubationRate = getHostIncubationRate()
* (double) timeDelta / (double) getTimePeriod();
double adjustedHostRecoveryRate = getHostRecoveryRate()
* (double) timeDelta / (double) getTimePeriod();
double adjustedHostImmunityLossRate = getHostImmunityLossRate()
* (double) timeDelta / (double) getTimePeriod();
double infectionRateFromS = adjustedHostTransmissionRate
* host.getS() / hostPopulationCount;
double fromStoE1 = infectionRateFromS * vector.getI1();
double fromStoE2 = infectionRateFromS * vector.getI2();
double fromStoE3 = infectionRateFromS * vector.getI3();
double fromStoE4 = infectionRateFromS * vector.getI4();
double fromE1toI1 = adjustedHostIncubationRate * host.getE1();
double fromE2toI2 = adjustedHostIncubationRate * host.getE2();
double fromE3toI3 = adjustedHostIncubationRate * host.getE3();
double fromE4toI4 = adjustedHostIncubationRate * host.getE4();
double fromI1toT1 = adjustedHostRecoveryRate * host.getI1();
double fromI2toT2 = adjustedHostRecoveryRate * host.getI2();
double fromI3toT3 = adjustedHostRecoveryRate * host.getI3();
double fromI4toT4 = adjustedHostRecoveryRate * host.getI4();
double fromT1toR1 = adjustedHostImmunityLossRate * host.getT1();
double fromT2toR2 = adjustedHostImmunityLossRate * host.getT2();
double fromT3toR3 = adjustedHostImmunityLossRate * host.getT3();
double fromT4toR4 = adjustedHostImmunityLossRate * host.getT4();
double infectionRateFromT = (1 - getCrossImmunity())
* adjustedHostTransmissionRate / hostPopulationCount;
double infectionRateFromT1 = infectionRateFromT * host.getT1();
double infectionRateFromT2 = infectionRateFromT * host.getT2();
double infectionRateFromT3 = infectionRateFromT * host.getT3();
double infectionRateFromT4 = infectionRateFromT * host.getT4();
double fromT1toE12 = infectionRateFromT1 * vector.getI2();
double fromT1toE13 = infectionRateFromT1 * vector.getI3();
double fromT1toE14 = infectionRateFromT1 * vector.getI4();
double fromT2toE21 = infectionRateFromT2 * vector.getI1();
double fromT2toE23 = infectionRateFromT2 * vector.getI3();
double fromT2toE24 = infectionRateFromT2 * vector.getI4();
double fromT3toE31 = infectionRateFromT3 * vector.getI1();
double fromT3toE32 = infectionRateFromT3 * vector.getI2();
double fromT3toE34 = infectionRateFromT3 * vector.getI4();
double fromT4toE41 = infectionRateFromT4 * vector.getI1();
double fromT4toE42 = infectionRateFromT4 * vector.getI2();
double fromT4toE43 = infectionRateFromT4 * vector.getI3();
double infectionRateFromR = adjustedHostTransmissionRate
/ hostPopulationCount;
double infectionRateFromR1 = infectionRateFromR * host.getR1();
double infectionRateFromR2 = infectionRateFromR * host.getR2();
double infectionRateFromR3 = infectionRateFromR * host.getR3();
double infectionRateFromR4 = infectionRateFromR * host.getR4();
double fromR1toE12 = infectionRateFromR1 * vector.getI2();
double fromR1toE13 = infectionRateFromR1 * vector.getI3();
double fromR1toE14 = infectionRateFromR1 * vector.getI4();
double fromR2toE21 = infectionRateFromR2 * vector.getI1();
double fromR2toE23 = infectionRateFromR2 * vector.getI3();
double fromR2toE24 = infectionRateFromR2 * vector.getI4();
double fromR3toE31 = infectionRateFromR3 * vector.getI1();
double fromR3toE32 = infectionRateFromR3 * vector.getI2();
double fromR3toE34 = infectionRateFromR3 * vector.getI4();
double fromR4toE41 = infectionRateFromR4 * vector.getI1();
double fromR4toE42 = infectionRateFromR4 * vector.getI2();
double fromR4toE43 = infectionRateFromR4 * vector.getI3();
double fromE12toI12 = adjustedHostIncubationRate * host.getE12();
double fromE13toI13 = adjustedHostIncubationRate * host.getE13();
double fromE14toI14 = adjustedHostIncubationRate * host.getE14();
double fromE21toI21 = adjustedHostIncubationRate * host.getE21();
double fromE23toI23 = adjustedHostIncubationRate * host.getE23();
double fromE24toI24 = adjustedHostIncubationRate * host.getE24();
double fromE31toI31 = adjustedHostIncubationRate * host.getE31();
double fromE32toI32 = adjustedHostIncubationRate * host.getE32();
double fromE34toI34 = adjustedHostIncubationRate * host.getE34();
double fromE41toI41 = adjustedHostIncubationRate * host.getE41();
double fromE42toI42 = adjustedHostIncubationRate * host.getE42();
double fromE43toI43 = adjustedHostIncubationRate * host.getE43();
double fromI12toR12 = adjustedHostRecoveryRate * host.getI12();
double fromI13toR13 = adjustedHostRecoveryRate * host.getI13();
double fromI14toR14 = adjustedHostRecoveryRate * host.getI14();
double fromI21toR21 = adjustedHostRecoveryRate * host.getI21();
double fromI23toR23 = adjustedHostRecoveryRate * host.getI23();
double fromI24toR24 = adjustedHostRecoveryRate * host.getI24();
double fromI31toR31 = adjustedHostRecoveryRate * host.getI31();
double fromI32toR32 = adjustedHostRecoveryRate * host.getI32();
double fromI34toR34 = adjustedHostRecoveryRate * host.getI34();
double fromI41toR41 = adjustedHostRecoveryRate * host.getI41();
double fromI42toR42 = adjustedHostRecoveryRate * host.getI42();
double fromI43toR43 = adjustedHostRecoveryRate * host.getI43();
hostDelta.setS(-fromStoE1 - fromStoE2 - fromStoE3 - fromStoE4);
hostDelta.setE1(fromStoE1 - fromE1toI1);
hostDelta.setE2(fromStoE2 - fromE2toI2);
hostDelta.setE3(fromStoE3 - fromE3toI3);
hostDelta.setE4(fromStoE4 - fromE4toI4);
hostDelta.setI1(fromE1toI1 - fromI1toT1);
hostDelta.setI2(fromE2toI2 - fromI2toT2);
hostDelta.setI3(fromE3toI3 - fromI3toT3);
hostDelta.setI4(fromE4toI4 - fromI4toT4);
hostDelta.setT1(fromI1toT1 - fromT1toR1 - fromT1toE12 - fromT1toE13
- fromT1toE14);
hostDelta.setT2(fromI2toT2 - fromT2toR2 - fromT2toE21 - fromT2toE23
- fromT2toE24);
hostDelta.setT3(fromI3toT3 - fromT3toR3 - fromT3toE31 - fromT3toE32
- fromT3toE34);
hostDelta.setT4(fromI4toT4 - fromT4toR4 - fromT4toE41 - fromT4toE42
- fromT4toE43);
hostDelta.setR1(fromT1toR1 - fromR1toE12 - fromR1toE13
- fromR1toE14);
hostDelta.setR2(fromT2toR2 - fromR2toE21 - fromR2toE23
- fromR2toE24);
hostDelta.setR3(fromT3toR3 - fromR3toE31 - fromR3toE32
- fromR3toE34);
hostDelta.setR4(fromT4toR4 - fromR4toE41 - fromR4toE42
- fromR4toE43);
hostDelta.setE12(fromT1toE12 + fromR1toE12 - fromE12toI12);
hostDelta.setE13(fromT1toE13 + fromR1toE13 - fromE13toI13);
hostDelta.setE14(fromT1toE14 + fromR1toE14 - fromE14toI14);
hostDelta.setE21(fromT2toE21 + fromR2toE21 - fromE21toI21);
hostDelta.setE23(fromT2toE23 + fromR2toE23 - fromE23toI23);
hostDelta.setE24(fromT2toE24 + fromR2toE24 - fromE24toI24);
hostDelta.setE31(fromT3toE31 + fromR3toE31 - fromE31toI31);
hostDelta.setE32(fromT3toE32 + fromR3toE32 - fromE32toI32);
hostDelta.setE34(fromT3toE34 + fromR3toE34 - fromE34toI34);
hostDelta.setE41(fromT4toE41 + fromR4toE41 - fromE41toI41);
hostDelta.setE42(fromT4toE42 + fromR4toE42 - fromE42toI42);
hostDelta.setE43(fromT4toE43 + fromR4toE43 - fromE43toI43);
hostDelta.setI12(fromE12toI12 - fromI12toR12);
hostDelta.setI13(fromE13toI13 - fromI13toR13);
hostDelta.setI14(fromE14toI14 - fromI14toR14);
hostDelta.setI21(fromE21toI21 - fromI21toR21);
hostDelta.setI23(fromE23toI23 - fromI23toR23);
hostDelta.setI24(fromE24toI24 - fromI24toR24);
hostDelta.setI31(fromE31toI31 - fromI31toR31);
hostDelta.setI32(fromE32toI32 - fromI32toR32);
hostDelta.setI34(fromE34toI34 - fromI34toR34);
hostDelta.setI41(fromE41toI41 - fromI41toR41);
hostDelta.setI42(fromE42toI42 - fromI42toR42);
hostDelta.setI43(fromE43toI43 - fromI43toR43);
hostDelta.setR(fromI12toR12 + fromI13toR13 + fromI14toR14
+ fromI21toR21 + fromI23toR23 + fromI24toR24 + fromI31toR31
+ fromI32toR32 + fromI34toR34 + fromI41toR41 + fromI42toR42
+ fromI43toR43);
hostDelta.setIncidence1(fromStoE1);
hostDelta.setIncidence2(fromStoE2);
hostDelta.setIncidence3(fromStoE3);
hostDelta.setIncidence4(fromStoE4);
hostDelta.setIncidence12(fromR1toE12);
hostDelta.setIncidence13(fromR1toE13);
hostDelta.setIncidence14(fromR1toE14);
hostDelta.setIncidence21(fromR2toE21);
hostDelta.setIncidence23(fromR2toE23);
hostDelta.setIncidence24(fromR2toE24);
hostDelta.setIncidence31(fromR3toE31);
hostDelta.setIncidence32(fromR3toE32);
hostDelta.setIncidence34(fromR3toE34);
hostDelta.setIncidence41(fromR4toE41);
hostDelta.setIncidence42(fromR4toE42);
hostDelta.setIncidence43(fromR4toE43);
hostDelta.setIncidence(fromStoE1 + fromStoE2 + fromStoE3
+ fromStoE4 + fromR1toE12 + fromR1toE13 + fromR1toE14
+ fromR2toE21 + fromR2toE23 + fromR2toE24 + fromR3toE31
+ fromR3toE32 + fromR3toE34 + fromR4toE41 + fromR4toE42
+ fromR4toE43);
hostDelta.setDiseaseDeaths1(0.0);
hostDelta.setDiseaseDeaths2(0.0);
hostDelta.setDiseaseDeaths3(0.0);
hostDelta.setDiseaseDeaths4(0.0);
hostDelta.setDiseaseDeaths12(0.0);
hostDelta.setDiseaseDeaths13(0.0);
hostDelta.setDiseaseDeaths14(0.0);
hostDelta.setDiseaseDeaths21(0.0);
hostDelta.setDiseaseDeaths23(0.0);
hostDelta.setDiseaseDeaths24(0.0);
hostDelta.setDiseaseDeaths31(0.0);
hostDelta.setDiseaseDeaths32(0.0);
hostDelta.setDiseaseDeaths34(0.0);
hostDelta.setDiseaseDeaths41(0.0);
hostDelta.setDiseaseDeaths42(0.0);
hostDelta.setDiseaseDeaths43(0.0);
hostDelta.setDiseaseDeaths(0.0);
return hostDelta;
} else if (diseaseLabel instanceof DengueModelVectorLabel) {
DengueModelVectorLabelValue vectorDelta = (DengueModelVectorLabelValue) returnValue;
DengueModelVectorLabelValue vector = (DengueModelVectorLabelValue) currentState;
if (vector.getPopulationCount() == 0.0) {
vectorDelta.reset();
return vectorDelta;
}
DengueModelHostLabelValue host = null;
DengueModelHostLabel hostLabel = null;
EList<NodeLabel> allLabels = diseaseLabel.getNode().getLabels();
for (NodeLabel label : allLabels) {
if (label instanceof DengueModelHostLabel
&& ((DengueModelHostLabel) label).getDecorator() == this) {
hostLabel = (DengueModelHostLabel) label;
host = (DengueModelHostLabelValue) hostLabel.getTempValue();
break;
}
}
double adjustedVectorTransmissionRate = getVectorTransmissionRate()
* (double) timeDelta / (double) getTimePeriod();
double adjustedVectorIncubationRate = getVectorIncubationRate()
* (double) timeDelta / (double) getTimePeriod();
double fromStoE1 = 0.0;
double fromStoE2 = 0.0;
double fromStoE3 = 0.0;
double fromStoE4 = 0.0;
// include all primary and secondary infectious compartments of host
if (host.getPopulationCount() != 0.0) {
EList<Double> effectives = getNormalizedEffectiveInfectious(hostLabel);
double effectiveI1 = effectives.get(0);
double effectiveI12 = effectives.get(1);
double effectiveI13 = effectives.get(2);
double effectiveI14 = effectives.get(3);
double effectiveI2 = effectives.get(4);
double effectiveI21 = effectives.get(5);
double effectiveI23 = effectives.get(6);
double effectiveI24 = effectives.get(7);
double effectiveI3 = effectives.get(8);
double effectiveI31 = effectives.get(9);
double effectiveI32 = effectives.get(10);
double effectiveI34 = effectives.get(11);
double effectiveI4 = effectives.get(12);
double effectiveI41 = effectives.get(13);
double effectiveI42 = effectives.get(14);
double effectiveI43 = effectives.get(15);
double effectiveII1 = effectiveI21 + effectiveI31
+ effectiveI41;
double effectiveII2 = effectiveI12 + effectiveI32
+ effectiveI42;
double effectiveII3 = effectiveI13 + effectiveI23
+ effectiveI43;
double effectiveII4 = effectiveI14 + effectiveI24
+ effectiveI34;
double primaryInfectionRateFromS = adjustedVectorTransmissionRate
* vector.getS();
double secondaryInfectionRateFromS = getADE()
* primaryInfectionRateFromS;
fromStoE1 = primaryInfectionRateFromS * effectiveI1
+ secondaryInfectionRateFromS * effectiveII1;
fromStoE2 = primaryInfectionRateFromS * effectiveI2
+ secondaryInfectionRateFromS * effectiveII2;
fromStoE3 = primaryInfectionRateFromS * effectiveI3
+ secondaryInfectionRateFromS * effectiveII3;
fromStoE4 = primaryInfectionRateFromS * effectiveI4
+ secondaryInfectionRateFromS * effectiveII4;
}
double fromE1toI1 = adjustedVectorIncubationRate * vector.getE1();
double fromE2toI2 = adjustedVectorIncubationRate * vector.getE2();
double fromE3toI3 = adjustedVectorIncubationRate * vector.getE3();
double fromE4toI4 = adjustedVectorIncubationRate * vector.getE4();
vectorDelta.setS(-fromStoE1 - fromStoE2 - fromStoE3 - fromStoE4);
vectorDelta.setE1(fromStoE1 - fromE1toI1);
vectorDelta.setE2(fromStoE2 - fromE2toI2);
vectorDelta.setE3(fromStoE3 - fromE3toI3);
vectorDelta.setE4(fromStoE4 - fromE4toI4);
vectorDelta.setI1(fromE1toI1);
vectorDelta.setI2(fromE2toI2);
vectorDelta.setI3(fromE3toI3);
vectorDelta.setI4(fromE4toI4);
vectorDelta.setIncidence1(fromStoE1);
vectorDelta.setIncidence2(fromStoE2);
vectorDelta.setIncidence3(fromStoE3);
vectorDelta.setIncidence4(fromStoE4);
vectorDelta.setIncidence(fromStoE1 + fromStoE2 + fromStoE3
+ fromStoE4);
vectorDelta.setDiseaseDeaths(0.0);
return vectorDelta;
}
return null;
}
@Override
public DiseaseModelLabel createDiseaseModelLabel(String populationIdentifier) {
if (populationIdentifier.equals(vectorPopulationIdentifier)) {
return VectorFactory.eINSTANCE.createDengueModelVectorLabel();
} else {
return VectorFactory.eINSTANCE.createDengueModelHostLabel();
}
}
@Override
public DiseaseModelLabelValue createDiseaseModelLabelValue(
String populationIdentifier) {
if (populationIdentifier.equals(vectorPopulationIdentifier)) {
return VectorFactory.eINSTANCE.createDengueModelVectorLabelValue();
} else {
return VectorFactory.eINSTANCE.createDengueModelHostLabelValue();
}
}
@Override
public Infector createInfector() {
SIInfector retValue = StandardFactory.eINSTANCE.createSIInfector();
retValue.setDiseaseName(getDiseaseName());
retValue.setPopulationIdentifier(getPopulationIdentifier());
return retValue;
}
@Override
public void doModelSpecificAdjustments(LabelValue currentState) {
// Do nothing
}
/**
* Returns the effective infectious fraction for all infectious compartments
* in the following order: I1, I12, I13, I14, I2, I21, I23, I24, I3, I31,
* I32, I34, I4, I41, I42, I43.
* {@link StandardDiseaseModel#getNormalizedEffectiveInfectious(StandardDiseaseModelLabel, EList)}
* can also be used to do, but uses more memory, since {@link Double}
* objects are created for
* {@link BasicEObjectImpl#eGet(org.eclipse.emf.ecore.EStructuralFeature)}
* and
* {@link BasicEObjectImpl#eSet(org.eclipse.emf.ecore.EStructuralFeature, Object)}
* .
*
* @param diseaseLabel
* label to compute the fractions for
* @return effective infectious fraction for all infectious compartments
*/
private EList<Double> getNormalizedEffectiveInfectious(
DengueModelHostLabel diseaseLabel) {
Node node = diseaseLabel.getNode();
DengueModelHostLabelValue value = (DengueModelHostLabelValue) diseaseLabel
.getTempValue();
int count = 16;
double[] totalInfectious = new double[count];
double totalPopulation = value.getPopulationCount();
totalInfectious[0] = value.getI1();
totalInfectious[1] = value.getI12();
totalInfectious[2] = value.getI13();
totalInfectious[3] = value.getI14();
totalInfectious[4] = value.getI2();
totalInfectious[5] = value.getI21();
totalInfectious[6] = value.getI23();
totalInfectious[7] = value.getI24();
totalInfectious[8] = value.getI3();
totalInfectious[9] = value.getI31();
totalInfectious[10] = value.getI32();
totalInfectious[11] = value.getI34();
totalInfectious[12] = value.getI4();
totalInfectious[13] = value.getI41();
totalInfectious[14] = value.getI42();
totalInfectious[15] = value.getI43();
for (Edge borderEdge : CommonBorderRelationshipLabelImpl
.getCommonBorderEdgesFromNode(node)) {
// If it exists, we're looking for the label this disease model
// updates on the node at the other end of the border edge.
// sum up the changes from each connected node.
// NOTE: some of these changes could be negative
final Node otherNode = borderEdge.getOtherNode(node);
double borderLength = ((CommonBorderRelationshipLabelValue) borderEdge
.getLabel().getCurrentValue()).getBorderLength();
double otherArea = 0.0;
for (NodeLabel otherLabel : otherNode.getLabels()) {
if (otherLabel instanceof AreaLabel) {
otherArea = ((AreaLabel) otherLabel).getCurrentAreaValue()
.getArea();
break;
}
}
double mixingFactor = Math.min(characteristicMixingDistance
* borderLength / otherArea, 1.0);
for (NodeLabel otherLabel : otherNode.getLabels()) {
if (otherLabel instanceof DengueModelHostLabel) {
DengueModelHostLabel otherDiseaseLabel = (DengueModelHostLabel) otherLabel;
if (otherDiseaseLabel.getDecorator() == this
&& otherDiseaseLabel.getIdentifier().equals(
diseaseLabel.getIdentifier())) {
DengueModelHostLabelValue otherValue = (DengueModelHostLabelValue) otherDiseaseLabel
.getTempValue();
if (frequencyDependent) {
totalInfectious[0] += mixingFactor
* otherValue.getI1();
totalInfectious[1] += mixingFactor
* otherValue.getI12();
totalInfectious[2] += mixingFactor
* otherValue.getI13();
totalInfectious[3] += mixingFactor
* otherValue.getI14();
totalInfectious[4] += mixingFactor
* otherValue.getI2();
totalInfectious[5] += mixingFactor
* otherValue.getI21();
totalInfectious[6] += mixingFactor
* otherValue.getI23();
totalInfectious[7] += mixingFactor
* otherValue.getI24();
totalInfectious[8] += mixingFactor
* otherValue.getI3();
totalInfectious[9] += mixingFactor
* otherValue.getI31();
totalInfectious[10] += mixingFactor
* otherValue.getI32();
totalInfectious[11] += mixingFactor
* otherValue.getI34();
totalInfectious[12] += mixingFactor
* otherValue.getI4();
totalInfectious[13] += mixingFactor
* otherValue.getI41();
totalInfectious[14] += mixingFactor
* otherValue.getI42();
totalInfectious[15] += mixingFactor
* otherValue.getI43();
} else {
// TODO
}
totalPopulation += mixingFactor
* otherValue.getPopulationCount();
break;
}
}
}
} // for each border edge
for (Edge roadEdge : RoadTransportRelationshipLabelImpl
.getRoadEdgesFromNode(node)) {
// find the number of edges from the road edge - could be more than
// one
// also, roads have differenct capacities
EdgeLabel edgeLabel = roadEdge.getLabel();
double numCrossings = ((RoadTransportRelationshipLabelValue) edgeLabel
.getCurrentValue()).getNumberCrossings();
double infectiousProportion = Math.min(
roadNetworkInfectiousProportion * numCrossings, 1.0);
// If it exists, we're looking for the label this disease model
// updates on the node at the other end of the border edge.
Node otherNode = roadEdge.getOtherNode(node);
for (NodeLabel otherLabel : otherNode.getLabels()) {
if (otherLabel instanceof DengueModelHostLabel) {
DengueModelHostLabel otherDiseaseLabel = (DengueModelHostLabel) otherLabel;
if (otherDiseaseLabel.getDecorator() == this
&& otherDiseaseLabel.getIdentifier().equals(
diseaseLabel.getIdentifier())) {
DengueModelHostLabelValue otherValue = (DengueModelHostLabelValue) otherDiseaseLabel
.getTempValue();
if (frequencyDependent) {
totalInfectious[0] += infectiousProportion
* otherValue.getI1();
totalInfectious[1] += infectiousProportion
* otherValue.getI12();
totalInfectious[2] += infectiousProportion
* otherValue.getI13();
totalInfectious[3] += infectiousProportion
* otherValue.getI14();
totalInfectious[4] += infectiousProportion
* otherValue.getI2();
totalInfectious[5] += infectiousProportion
* otherValue.getI21();
totalInfectious[6] += infectiousProportion
* otherValue.getI23();
totalInfectious[7] += infectiousProportion
* otherValue.getI24();
totalInfectious[8] += infectiousProportion
* otherValue.getI3();
totalInfectious[9] += infectiousProportion
* otherValue.getI31();
totalInfectious[10] += infectiousProportion
* otherValue.getI32();
totalInfectious[11] += infectiousProportion
* otherValue.getI34();
totalInfectious[12] += infectiousProportion
* otherValue.getI4();
totalInfectious[13] += infectiousProportion
* otherValue.getI41();
totalInfectious[14] += infectiousProportion
* otherValue.getI42();
totalInfectious[15] += infectiousProportion
* otherValue.getI43();
} else {
// TODO
}
totalPopulation += infectiousProportion
* otherValue.getPopulationCount();
break;
}
}
}
} // for each road edge
// return the sum normalized to the total population
EList<Double> retVal = new BasicEList<Double>(count);
if (totalPopulation > 0.0) {
for (double infectious : totalInfectious) {
retVal.add(infectious / totalPopulation);
}
} else {
retVal.addAll(Collections.nCopies(count, 0.0));
}
return retVal;
}
@Override
public boolean isDeterministic() {
return true;
}
} // VerySimpleDengueModelImpl