| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evomodel.continuous; |
| 27 |
|
| 28 |
import dr.geo.cartogram.CartogramMapping; |
| 29 |
import dr.inference.model.Parameter; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
import java.awt.geom.Rectangle2D; |
| 33 |
import java.util.ArrayList; |
| 34 |
import java.util.List; |
| 35 |
import java.util.logging.Logger; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class MixtureCartogramDiffusionModel extends CartogramDiffusionModel { |
| 42 |
|
| 43 |
public static final String DIFFUSION_PROCESS = "mixtureCartogramDiffusionModel"; |
| 44 |
public static final String MIXTURE = "mixture"; |
| 45 |
public static final String MAP = "map"; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public MixtureCartogramDiffusionModel(String name, Parameter precision, Parameter mixture) { |
| 52 |
super(name, precision); |
| 53 |
this.mixture = mixture; |
| 54 |
Logger.getLogger("dr.evomodel.continuous").info( |
| 55 |
"\tMixture: " + mixture.getId() |
| 56 |
); |
| 57 |
addVariable(mixture); |
| 58 |
} |
| 59 |
|
| 60 |
public void addMapping(CartogramMapping mapping) { |
| 61 |
|
| 62 |
if (mappingList == null) |
| 63 |
mappingList = new ArrayList<CartogramMapping>(); |
| 64 |
|
| 65 |
mappingList.add(mapping); |
| 66 |
Logger.getLogger("dr.evomodel.continuous").info( |
| 67 |
"\tMapping : " + mapping.toString() + " with density "+mapping.getAverageDensity() |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
protected CartogramMapping getMapping() { |
| 72 |
final int index = (int)mixture.getParameterValue(0)-1; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
return mappingList.get(index); |
| 78 |
} |
| 79 |
|
| 80 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 81 |
|
| 82 |
public String getParserName() { |
| 83 |
return DIFFUSION_PROCESS; |
| 84 |
} |
| 85 |
|
| 86 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 87 |
|
| 88 |
Rectangle2D boundingBox = parseRectangle2D(xo); |
| 89 |
|
| 90 |
Parameter diffusionParam = (Parameter) xo.getChild(Parameter.class); |
| 91 |
|
| 92 |
Parameter mixtureParam = (Parameter) xo.getChild(MIXTURE).getChild(Parameter.class); |
| 93 |
|
| 94 |
MixtureCartogramDiffusionModel model = new MixtureCartogramDiffusionModel(xo.getId(), |
| 95 |
diffusionParam, mixtureParam); |
| 96 |
|
| 97 |
for(int i=0; i<xo.getChildCount(); i++) { |
| 98 |
if (xo.getChildName(i).equals(MAP)) { |
| 99 |
XMLObject cxo = (XMLObject) xo.getChild(i); |
| 100 |
CartogramMapping mapping = parseCartogramMapping(cxo,boundingBox); |
| 101 |
model.addMapping(mapping); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
return model; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public String getParserDescription() { |
| 113 |
return "Describes a bivariate diffusion process using cartogram distances."; |
| 114 |
} |
| 115 |
|
| 116 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 117 |
return rules; |
| 118 |
} |
| 119 |
|
| 120 |
private final XMLSyntaxRule[] rules = { |
| 121 |
new ElementRule(Parameter.class), |
| 122 |
new ElementRule(MIXTURE, new XMLSyntaxRule[] { |
| 123 |
new ElementRule(Parameter.class) |
| 124 |
}), |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
boundingBoxRules, |
| 130 |
}; |
| 131 |
|
| 132 |
public Class getReturnType() { |
| 133 |
return MultivariateDiffusionModel.class; |
| 134 |
} |
| 135 |
}; |
| 136 |
|
| 137 |
private final Parameter mixture; |
| 138 |
private List<CartogramMapping> mappingList; |
| 139 |
} |