Fix for mixing bug reported by Taras
diff --git a/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/functions/CTDLFunctions.java b/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/functions/CTDLFunctions.java
index cacc506..12ed3e1 100644
--- a/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/functions/CTDLFunctions.java
+++ b/models/epidemiology/org.eclipse.stem.diseasemodels/src/org/eclipse/stem/diseasemodels/functions/CTDLFunctions.java
@@ -14,6 +14,9 @@
 import org.eclipse.stem.core.graph.NodeLabel;
 import org.eclipse.stem.core.model.IntegrationDecorator;
 import org.eclipse.stem.core.model.STEMTime;
+import org.eclipse.stem.definitions.edges.MixingEdge;
+import org.eclipse.stem.definitions.edges.MixingEdgeLabelValue;
+import org.eclipse.stem.definitions.edges.impl.MixingEdgeLabelImpl;
 import org.eclipse.stem.definitions.labels.AreaLabel;
 import org.eclipse.stem.definitions.labels.CommonBorderRelationshipLabelValue;
 import org.eclipse.stem.definitions.labels.RoadTransportRelationshipLabelValue;
@@ -181,6 +184,7 @@
 		
 		double onsiteInfectious = diseaseLabel.getProbeValue().eGetDouble(infectiousAttribute.getFeatureID());
 		
+		
 		// For performance, check if mixing parameters are zero. If so, just
 		// return the unmixed result
 				
@@ -198,7 +202,13 @@
 		double populationChangeFromMixing = 0.0;
 
 		List<Edge>cEdges = new ArrayList<Edge>();
-		CommonBorderRelationshipLabelImpl.getCommonBorderEdgesFromNode(node, cEdges);
+		boolean useMixingEdges = false;
+		MixingEdgeLabelImpl.getMixingEdgesFromNode(node, disease.getPopulationIdentifier(), cEdges);
+		if(cEdges.size() > 0) {
+			useMixingEdges = true;
+		} else {
+			CommonBorderRelationshipLabelImpl.getCommonBorderEdgesFromNode(node, cEdges);
+		}
 		
 		for(int i=0;i<cEdges.size();++i) {
 			Edge borderEdge = cEdges.get(i);
@@ -208,9 +218,7 @@
 			// NOTE: some of these changes could be negative
 
 			final Node otherNode = borderEdge.getOtherNode(node);
-			double borderLength = ((CommonBorderRelationshipLabelValue) borderEdge
-					.getLabel().getCurrentValue()).getBorderLength();
-
+			
 			if (otherNode instanceof Region) {
 				double otherArea = 0.0;
 				double otherPopulation = 0.0;
@@ -238,15 +246,37 @@
 					}
 				}
 
-				double mixingFactor = Math.min(mixingParam
-						* borderLength / otherArea, 1.0);
-				
-				if (otherArea == 0.0) {
-					mixingFactor = 0.0;
-				}
+				if(!useMixingEdges) {
+					double borderLength = ((CommonBorderRelationshipLabelValue) borderEdge
+							.getLabel().getCurrentValue()).getBorderLength();
 
-				infectiousChangeFromMixing += mixingFactor * otherInfective;
-				populationChangeFromMixing += mixingFactor * otherPopulation;
+					double mixingFactor = Math.min(mixingParam
+							* borderLength / otherArea, 1.0);
+				
+					if (otherArea == 0.0) {
+						mixingFactor = 0.0;
+					}
+
+					infectiousChangeFromMixing += mixingFactor * otherInfective;
+					populationChangeFromMixing += mixingFactor * otherPopulation;
+				} else {
+					// use mixing edge
+					MixingEdge mixingEdge =(MixingEdge)cEdges.get(i);
+					MixingEdgeLabelValue mixingLabelValue = mixingEdge.getLabel().getCurrentValue();
+					double mixingRateOrAbs = mixingLabelValue.getMixingRate();
+					boolean useAbsoluteValue = mixingEdge.isUseAbsoluteValues();
+					
+					if(useAbsoluteValue && otherPopulation > 0.0) {
+						if(mixingRateOrAbs > otherPopulation) // Cannot mix with more people than currently available
+							mixingRateOrAbs = otherPopulation;
+						double fraction = mixingRateOrAbs / otherPopulation; // Do get the right scaling for the population change we need this
+						infectiousChangeFromMixing += fraction * otherInfective;
+						populationChangeFromMixing += fraction * otherPopulation;
+					} else {
+						infectiousChangeFromMixing += mixingRateOrAbs * otherInfective;
+						populationChangeFromMixing += mixingRateOrAbs * otherPopulation;
+					}
+				}
 			}
 		} // for each border edge
 		
@@ -306,4 +336,6 @@
 
 		return retVal;		
 	}
-}
+	
+
+}
\ No newline at end of file