/********************************************************************************/ /* */ /* This function computes the neighbourhood weights for events */ /* */ /********************************************************************************/ void birth_weights(current) struct individual *current; { struct individual *focal, *neighbour; double x1,y1,x2,y2; int i,j; int num=0; double effect[2], norm[2]; double distance; double weighting=0.0; double sum=0.0; int m,n; int spp1, spp2; num=0; focal=current; { weighting=0.0; x1 = focal->xpos; y1 = focal->ypos; spp1 = focal->species; focal->death_event = D1[spp1]; focal->birth_event = B1[spp1]; focal->move_event = M1[spp1]; focal->attack_event=0.0; neighbour = start; neighbour = start; { while(neighbour!=NULL) { x2 = neighbour->xpos; y2 = neighbour->ypos; spp2 = neighbour->species; /***Compute the pair distance allowing for periodic boundaries***/ distance = get_distance(x1,y1, x2,y2, wfoormax[spp1][spp2]); /* printf("D: %lf\n", distance);*/ /***Compute neighbourhood effect on death***/ if(neighbour != focal) if(distance<=wfoormax[spp1][spp2]) { num++; /***Bivariate normal competition kernel***/ if(wfoo_kernel == 1) { norm[0] = 2.0 * Pi * wfoostdv[spp1][spp2] * wfoostdv[spp1][spp2]; effect[0] = distance/wfoostdv[spp1][spp2]; effect[0]*= effect[0]; effect[0] = exp(-0.5 * effect[0]); effect[0]/=norm[0]; norm[1] = 2.0 * Pi * wfoostdv[spp2][spp1] * wfoostdv[spp2][spp1]; effect[1] = distance/wfoostdv[spp2][spp1]; effect[1]*= effect[1]; effect[1] = exp(-0.5 * effect[1]); effect[1]/=norm[1]; } /***Flat kernel***/ else if(wfoo_kernel == 2) { effect[0] = 1.0/(Pi * wfoormax[spp1][spp2] * wfoormax[spp1][spp2]); } focal->attack_event+= effect[0]*alpha[spp1][spp2]; neighbour->attack_event+= effect[1]*alpha[spp2][spp1]; extent+= effect[1]*alpha[spp2][spp1]; neighbour->death_event+=effect[1]*D2[spp2][spp1]; extent+=effect[1]*D2[spp2][spp1]; death_sum+=effect[1]*D2[spp2][spp1]; effect[0] *=D2[spp1][spp2]; weighting += effect[0]; sum+=effect[0]; /* fprintf(weight,"x1: %lf y1: %lf x2: %lf y2: %lf distance: %lf effect: %lf\n", x1,y1, x2,y2, distance, effect); fflush(weight);*/ } neighbour = neighbour->next; } /******************************************************************/ /*** Now add newborn's event probs to the number line ***/ /******************************************************************/ focal->death_event += weighting; death_sum += focal->death_event; extent += focal->death_event; birth_sum += focal->birth_event; extent += focal->birth_event; extent+=focal->attack_event; extent+=focal->move_event; } } /* if(num!=(population_size[0]-1)) printf("%d\t%d\n", num, population_size[0]);*/ }