import java.util.HashMap; /** * Created with IntelliJ IDEA. * User: rebeccamancy * Date: 26/10/2012 * Time: 14:50 * To change this template use File | Settings | File Templates. */ public class OH2000Model extends Model { private double eParam; private double cParam; private double alpha; /** * Constructor sets up model with two states (S-I) * @param alpha * @param cParam * @param eParam */ public OH2000Model(double eParam, double cParam, double alpha) { super.setModelStates(2,1); // states are S-I or occupied-unoccupied this.eParam = eParam; this.cParam = cParam; this.alpha = alpha; } /* *//** * Updates state at focal patch and rates at focal and all other patches * @param focalPatch patch that is changing state * @param patchStatus array of all patch status values * @param rates array of transition rates at all sites * @param hab habitat giving K and distances between sites * *//* public double[] updateRates(int focalPatch, int[] patchStatus, double[] rates, Habitat hab) { double contrib = 0; // Set rate for focal patch and all other patches given new status if (patchStatus[focalPatch] == 0) { // Update rate at focal patch rates[focalPatch] = getRate01(focalPatch, patchStatus, hab); // new colonisation rate at focal patch // Currently unoccupied, so DECREASE colonisation rate at other unoccupied patches by contribution of focal for (int otherPatch = 0; otherPatch < hab.getNumPatches(); otherPatch++) { // loop over all patches if ((otherPatch != focalPatch) && (patchStatus[otherPatch] == 0)) { // all unoccupied other patches // contrib = colonRate(alpha, hab.getK(focalPatch), hab.lookupDist(focalPatch, otherPatch) ); contrib = contribRate(hab, focalPatch, otherPatch); rates[otherPatch] -= contrib; //System.out.println("Decreasing rate at site " + otherPatch + " by " + contrib); //System.out.println(" with parameters dist=" + hab.lookupDist(focalPatch, otherPatch)); } } } else { // currently in state 1 (occupied or I) // Update rate at focal patch rates[focalPatch] = getRate10(hab.getK(focalPatch)); // new extinction rate at focal patch // Currently occupied, so INCREASE colonisation rate at other unoccupied patches by contribution of focal for (int otherPatch = 0; otherPatch < hab.getNumPatches(); otherPatch++) { // loop over all patches if ((otherPatch != focalPatch) && (patchStatus[otherPatch] == 0)) { // all unoccupied other patches //contrib = colonRate(alpha, hab.getK(focalPatch), hab.lookupDist(focalPatch, otherPatch) ); contrib = contribRate(hab, focalPatch, otherPatch); rates[otherPatch] += contrib; //System.out.println("Increasing rate at site " + otherPatch + " by " + contrib); //System.out.println(" with parameters dist=" + hab.lookupDist(focalPatch, otherPatch)); } } } return rates; }*/ public double getRate(int focalPatch, int[] patchStatus, Habitat hab) { int focalStatus = patchStatus[focalPatch]; if (focalStatus == 0) { return getRate01(focalPatch, patchStatus, hab); } else { return getRate10(hab.getK(focalPatch)); } } /** * Returns rate of S-I (colonisation) for a specified patch given by eParam / K * @param K patch size or carrying capacity * @return (colonisation) rate */ private double getRate10(double K) { return this.eParam / K; } /** * Returns rate of I-S (extinction) for a specified patch * @param focPatch identifier of patch * @param hab habitat * @return (extinction) rate */ private double getRate01(int focPatch, int[] patchStatus, Habitat hab) { // Rate of I-S is given by sum over all occupied patches * ( size of patch * e^(alpha * dist) ) double rate = 0; for (int otherPatch = 0; otherPatch < hab.getNumPatches(); otherPatch++) { // rate = rate + (patchStatus[otherPatch] * colonRate(this.alpha, hab.getK(otherPatch), hab.lookupDist(focPatch, otherPatch))); rate = rate + (patchStatus[otherPatch] * contribRate(hab, otherPatch, focPatch)); } rate = this.cParam * rate; return rate; } /** * Calculates the contribution of the colonisation rate of a specific site to a site at a given distance * @param alpha alpha parameter * @param K carrying capacity of patch * @param dist distance between patches * @return contribution to colonisation rate */ //private double colonRate(double alpha, double K, double dist) { // return K * Math.exp(-alpha * dist); //} /** * Calculate contribution rate from one site to another (colonisation) - for matC * @param hab * @param from * @param to * @return */ public double contribRate (Habitat hab, int from, int to) { double K = hab.getK(from); // it's the size of the from patch that counts in OH2000 double dist = hab.lookupDist(from,to); return this.cParam * K * Math.exp(-alpha * dist); } /** * Calculate extinction rate from a site (todo - to is not used here?) * @param hab * @param from * @param to * @return */ public double extRate (Habitat hab, int from, int to) { double K = hab.getK(from); return this.eParam/K; } private double getConnex(double dist) { return Math.exp(-alpha * dist); } /** * Calculates the appropriate m_{ij} value * @param focalPatch first patch * @param otherPatch other patch * @return the mij value for the landscape matrix M */ public double mijValue(int focalPatch, int otherPatch, Habitat hab) { if (focalPatch == otherPatch) { return 0.0; } else { return Math.exp(-alpha * hab.lookupDist(focalPatch,otherPatch)) * hab.getK(otherPatch) * hab.getK(focalPatch); } } public void seteParam(double eParam) { this.eParam = eParam; } public void setcParam(double cParam) { this.cParam = cParam; } public void setAlpha(double alpha) { this.alpha = alpha; } public double geteParam() { return this.eParam; } public double getcParam() { return this.cParam; } public double getAlpha() { return this.alpha; } }