Environmental Engineering Reference
In-Depth Information
FILE *outfile;
//name of the file for output
float z_calc(void);
//initialises normal
distribution routine
float round(float PrF);
//initialises rounding
routine
srand((unsigned)time(NULL));
//initialises random number
generator
outfile = fopen(“output.out”,”w”);
//opens output file
//starting population
for (t = 0; t < Years; t++) {Pop[t]=0; Harvest[t]=0;}
Pop[0] = N1;
//************************* years **************************
for (t = 0; t < Years-1; t++)
{
PrF = r*Pop[t]*(1-Pop[t]/K);
//logistic productivity
Prod = round(PrF);
//births must be a whole number
Cost = a - b*Pop[t];
//mean hunter cost
for (i = 0; i < Hunters; i++)
//hunter decision-making
{
zval = z_calc();
//get a random number from
normal dist
IndC = Cost + zval*s;
//hunter cost
if (IndC < 0) IndC = 0;
//ensure no negative costs
B = P - IndC;
//profitability
if (B>0) {Harvest[t]++;}
//hunting decision
} //i (hunters)
if (Harvest[t] > Pop[t] +
//can't harvest more than
Prod) Harvest[t] = Pop[t] + Prod;
is there
Pop[t+1] = Pop[t] + Prod -
//next year's population
Harvest[t];
printf(“%d %.0f %.0f %.0f %.0f\n”, t,Pop[t],
Prod,Harvest[t],Pop[t+1]);
//onscreen output
} //t (years)
//*********************** end bits *************************
for (t = 0; t < Years; t++)
fprintf(outfile,”%d %.0f %.0f\n”,
t,Pop[t],prod,Harvest[t]);
//output to file
fclose(outfile);
} //end
//*********************** functions ************************
Search WWH ::




Custom Search