/** * Created with IntelliJ IDEA. * User: rebeccamancy * Date: 22/01/2013 * Time: 15:11 * To change this template use File | Settings | File Templates. */ public class Ecology { private Habitat hab; private Model mod; private double lambdaM; private double[] x2Vi, xyVi; private int maxViPatch; private double[][] matC; private double[] vecE; private QSD qsd; /** * Constructor - uses hab and mod to create an Ecology object * @param hab * @param mod */ public Ecology (Habitat hab, Model mod) { this.hab = hab; this.mod = mod; int numPatches = hab.getNumPatches(); matC = new double[numPatches][numPatches]; vecE = new double[numPatches]; // Construct matC (colonisation rates) for (int to=0; to < numPatches; to++) { for (int from=0; from < numPatches; from++) { if (from==to) { matC[to][from] = 0; // no self-colonisation } else { matC[to][from] = mod.contribRate(hab, from, to); } } } // Construct vecE (extinction rates) for (int from=0; from < numPatches; from++) { vecE[from] = mod.extRate(hab, from, 1); // todo - 1 here refers to the to site which is irrelevant } M matM = new M(hab, mod); lambdaM = matM.getLambda(); x2Vi = matM.getNorx2Vi(); xyVi = matM.getNorxyVi(); maxViPatch = matM.getMaxViPatch(); } /** * Sets the QSD attribute given a qsd object * @param qsd */ public void setQsd(QSD qsd) { this.qsd = qsd; } public QSD getQsd() { return this.qsd; } public String getMetrics() { return lambdaM + "," + x2Vi.toString() + "," + xyVi.toString(); } public double getLambdaM() { return lambdaM; } public double getx2Vi(int patchID) { return x2Vi[patchID]; } public double getxyVi(int patchID) { return xyVi[patchID]; } public int getMaxViPatch() { return maxViPatch; } public Habitat getHab() { return hab; } public Model getMod() { return mod; } /** * Calculates transition rate for a particular focal patch, given other patch status (and using matC, vecE) * @param focalPatch the patch whose rates we're calculating * @param patchStatus status of all other patches * @return */ public double calcRate(int focalPatch, int[] patchStatus) { double r = 0; if (patchStatus[focalPatch] == 1) { // patch is alive so transition rate is just extinction rate r = vecE[focalPatch]; } else { for (int fromPatch=0; fromPatch 0) { strMatC += ", "; } strMatC += matC[to][from]; } strMatC += "\n"; } // Construct String for vector E for (int from=0; from < hab.getNumPatches(); from++) { if (from > 0) { strVecE += ", "; } strVecE += vecE[from]; } strVecE += "\n"; return strMatC + strVecE; } }