Daftar dan Belajar Sekarang!

Menambah jumlah step -> process exited with value 3221225477

foto DPul
1 Kontribusi 0 Coto
1 minggu yang lalu
Saya coba nambah step dari MaxStep=10.000 menjadi MaxStep=100.0000. Tapi yang terjadi program berhenti pada step 20999 sekian dan Process exited with value 3221225477. Mohon pencerahannya, saya masih baru di programming. Terima kasih.
/*************internal processing*************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#include<math.h>
#include<time.h>
//#include<memory.h>
#define NUMBER 100
#define DISPLAY_INTERVAL 
#define DISPLAY_MODE  

    //filename
/********field parameter********/

#define O 0         //identifier
#define A 1
#define B 2
#define C 3
#define D 4
#define E 5
#define F 6
#define G 7
#define H 8
#define I 9
#define J 10
#define K 11
#define L 12
#define M 13
#define N 14
#define P 15
#define Q 16
#define R 17
#define S 18
#define T 19
#define U 20
#define Y 21
#define Nu 20
#define FILENAME "TESTNEW.csv"  //filename
/**ƒOƒ[ƒoƒ‹•Ï”**/
double dp=0, predm=0;
double BA=1, MA=0;
double gr=0.001;
double G1=0.15;

#define SIZE 100
#define AREA (SIZE * SIZE)
#define outfield 10000
#define MaxStep 10000
#define trial 10
int sarray[trial];
/*************parameter*************/

//basal parameter of A
#define FdensA 0.03             //A‚̉Šú–§“x(First Density of A)
#define BirthA BA           //A‚Ì‘B—¦(Birth rate of A) //B//21
#define MortalA 0.1             //A‚Ì”íH—¦(Mortality rate of A) //G
#define GrazeA G1 + gr*(Nu-A)           //grazing rate
#define DispReachA 40           //3/4A‚ÌŽíŽqŽU•z‰Â”\”͈Í(Dispersion Reach of A)

//B‚̃pƒ‰ƒ[ƒ^
#define FdensB 0.03             //B‚̉Šú–§“x
#define BirthB BirthA-0.002*(B-1)           //B‚Ì‘B—¦
#define MortalB 0.1             //B‚Ì”íH—¦
#define GrazeB G1 + gr*(Nu-B)           //grazing rate
#define DispReachB 40           //B‚ÌŽíŽqŽU•z‰Â”\”͈Í

//C‚̃pƒ‰ƒ[ƒ^
#define FdensC 0.03             //C‚̉Šú–§“x
#define BirthC BirthA-0.002*(C-1)           //C‚Ì‘B—¦
#define MortalC 0.1             //C‚Ì”íH—¦
#define GrazeC G1 + gr*(Nu-C)           //grazing rate
#define DispReachC 40           //C‚ÌŽíŽqŽU•z‰Â”\”͈Í

//D‚̃pƒ‰ƒ[ƒ^
#define FdensD 0.03             //D‚̉Šú–§“x
#define BirthD BirthA-0.002*(D-1)               //D‚Ì‘B—¦
#define MortalD 0.1             //D‚Ì”íH—¦
#define GrazeD G1 + gr*(Nu-D)           //grazing rate
#define DispReachD 40           //D‚ÌŽíŽqŽU•z‰Â”\”͈Í

//E‚̃pƒ‰ƒ[ƒ^
#define FdensE 0.03             //E‚̉Šú–§“x
#define BirthE BirthA-0.002*(E-1)               //E‚Ì‘B—¦
#define MortalE 0.1         //E‚Ì”íH—¦
#define GrazeE G1 + gr*(Nu-E)           //grazing rate
#define DispReachE 40           //E‚ÌŽíŽqŽU•z‰Â”\”͈Í

//F‚̃pƒ‰ƒ[ƒ^
#define FdensF 0.03             //F‚̉Šú–§“x
#define BirthF BirthA-0.002*(F-1)           //F‚Ì‘B—¦
#define MortalF 0.1             //F‚Ì”íH—¦
#define GrazeF G1 + gr*(Nu-F)           //grazing rate
#define DispReachF 40           //F‚ÌŽíŽqŽU•z‰Â”\”͈Í

//G‚̃pƒ‰ƒ[ƒ^
#define FdensG 0.03             //G‚̉Šú–§“x
#define BirthG BirthA-0.002*(G-1)               //G‚Ì‘B—¦
#define MortalG 0.1             //G‚Ì”íH—¦
#define GrazeG G1 + gr*(Nu-G)           //grazing rate
#define DispReachG 40           //G‚ÌŽíŽqŽU•z‰Â”\”͈Í

//H‚̃pƒ‰ƒ[ƒ^
#define FdensH 0.03             //H‚̉Šú–§“x
#define BirthH BirthA-0.002*(H-1)               //H‚Ì‘B—¦
#define MortalH 0.1             //H‚Ì”íH—¦
#define GrazeH G1 + gr*(Nu-H)           //grazing rate
#define DispReachH 40           //H‚ÌŽíŽqŽU•z‰Â”\”͈Í

//I‚̃pƒ‰ƒ[ƒ^
#define FdensI 0.03             //I‚̉Šú–§“x
#define BirthI BirthA-0.002*(I-1)               //I‚Ì‘B—¦
#define MortalI 0.1             //I‚Ì”íH—¦
#define GrazeI G1 + gr*(Nu-I)           //grazing rate
#define DispReachI 40           //I‚ÌŽíŽqŽU•z‰Â”\”͈Í

//J‚̃pƒ‰ƒ[ƒ^
#define FdensJ 0.03             //J‚̉Šú–§“x
#define BirthJ BirthA-0.002*(J-1)               //J‚Ì‘B—¦
#define MortalJ 0.1             //J‚Ì”íH—¦
#define GrazeJ G1 + gr*(Nu-J)           //grazing rate
#define DispReachJ 40           //J‚ÌŽíŽqŽU•z‰Â”\”͈Í

//K‚̃pƒ‰ƒ[ƒ^
#define FdensK 0.03             //K‚̉Šú–§“x(First Density of A)
#define BirthK BirthA-0.002*(K-1)           //K‚Ì‘B—¦(Birth rate of A)
#define MortalK 0.1             //K‚Ì”íH—¦(Mortality rate of A)
#define GrazeK G1 + gr*(Nu-K)           //grazing rate
#define DispReachK 40           //K‚ÌŽíŽqŽU•z‰Â”\”͈Í(Dispersion Reach of A)

//L‚̃pƒ‰ƒ[ƒ^
#define FdensL 0.03             //L‚̉Šú–§“x
#define BirthL BirthA-0.002*(L-1)               //L‚Ì‘B—¦
#define MortalL 0.1             //L‚Ì”íH—¦
#define GrazeL G1 + gr*(Nu-L)           //grazing rate
#define DispReachL 40           //L‚ÌŽíŽqŽU•z‰Â”\”͈Í

//M‚̃pƒ‰ƒ[ƒ^
#define FdensM 0.03             //M‚̉Šú–§“x
#define BirthM BirthA-0.002*(M-1)               //M‚Ì‘B—¦
#define MortalM 0.1             //M‚Ì”íH—¦
#define GrazeM G1 + gr*(Nu-M)           //grazing rate
#define DispReachM 40           //M‚ÌŽíŽqŽU•z‰Â”\”͈Í

//N‚̃pƒ‰ƒ[ƒ^
#define FdensN 0.03             //N‚̉Šú–§“x
#define BirthN BirthA-0.002*(N-1)               //N‚Ì‘B—¦
#define MortalN 0.1             //N‚Ì”íH—¦
#define GrazeN G1 + gr*(Nu-N)           //grazing rate
#define DispReachN 40           //N‚ÌŽíŽqŽU•z‰Â”\”͈Í

//P‚̃pƒ‰ƒ[ƒ^
#define FdensP 0.03             //P‚̉Šú–§“x
#define BirthP BirthA-0.002*(P-1)               //P‚Ì‘B—¦
#define MortalP 0.1             //P‚Ì”íH—¦
#define GrazeP G1 + gr*(Nu-P)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
#define DispReachP 40           //P‚ÌŽíŽqŽU•z‰Â”\”͈Í

//Q‚̃pƒ‰ƒ[ƒ^
#define FdensQ 0.03             //Q‚̉Šú–§“x
#define BirthQ BirthA-0.002*(Q-1)           //Q‚Ì‘B—¦
#define MortalQ 0.1             //Q‚Ì”íH—¦
#define GrazeQ G1 + gr*(Nu-Q)           //grazing rate
#define DispReachQ 40           //Q‚ÌŽíŽqŽU•z‰Â”\”͈Í

//R‚̃pƒ‰ƒ[ƒ^
#define FdensR 0.03             //R‚̉Šú–§“x
#define BirthR BirthA-0.002*(R-1)               //R‚Ì‘B—¦
#define MortalR 0.1             //R‚Ì”íH—¦
#define GrazeR G1 + gr*(Nu-R)           //grazing rate
#define DispReachR 40           //R‚ÌŽíŽqŽU•z‰Â”\”͈Í

//S‚̃pƒ‰ƒ[ƒ^
#define FdensS 0.03             //S‚̉Šú–§“x
#define BirthS BirthA-0.002*(S-1)               //S‚Ì‘B—¦
#define MortalS 0.1             //S‚Ì”íH—¦
#define GrazeS G1 + gr*(Nu-S)           //grazing rate
#define DispReachS 40           //S‚ÌŽíŽqŽU•z‰Â”\”͈Í

//T‚̃pƒ‰ƒ[ƒ^
#define FdensT 0.03             //T‚̉Šú–§“x
#define BirthT BirthA-0.002*(T-1)               //T‚Ì‘B—¦
#define MortalT 0.1             //T‚Ì”íH—¦
#define GrazeT G1 + gr*(Nu-T)           //grazing rate
#define DispReachT 40           //T‚ÌŽíŽqŽU•z‰Â”\”͈Í

//U‚̃pƒ‰ƒ[ƒ^
#define FdensU 0.03             //U‚̉Šú–§“x
#define BirthU BirthA-0.002*(U-1)               
#define MortalU 0.1             //U‚Ì”íH—¦
#define GrazeU G1 + gr*(Nu-U)           //grazing rate
#define DispReachU 40           //U‚ÌŽíŽqŽU•z‰Â”\”͈Í

//Y‚̃pƒ‰ƒ[ƒ^
#define FdensY  0.4           //Y‚̉Šú–§“x
#define PredY   (1.0-predm)     //Y‚Ì•ßH—¦
#define BirthY 0.7                          //Y‚Ìo¶—¦
#define MortalY 0.05            //Y‚ÌŽ€–S—¦

//Z‚̃pƒ‰ƒ[ƒ^
//#define PredZ 0                       //Z‚Ì•ßH—¦




double birthA;      
double birthB;
double birthC;
double birthD;
double birthE;
double birthF;
double birthG;
double birthH;
double birthI;
double birthJ;
double birthK;
double birthL;
double birthM;
double birthN;
double birthP;
double birthQ;
double birthR;
double birthS;
double birthT;
double birthU;
double birthY;

int field[SIZE][SIZE];
int field2[SIZE][SIZE];

int step;

double frevisionA[SIZE][SIZE];         //field revision(=ƒÃ)
double frevisionB[SIZE][SIZE];
double frevisionC[SIZE][SIZE];
double frevisionD[SIZE][SIZE];
double frevisionE[SIZE][SIZE];
double frevisionF[SIZE][SIZE];
double frevisionG[SIZE][SIZE];
double frevisionH[SIZE][SIZE];
double frevisionI[SIZE][SIZE];
double frevisionJ[SIZE][SIZE];
double frevisionK[SIZE][SIZE];
double frevisionL[SIZE][SIZE];
double frevisionM[SIZE][SIZE];
double frevisionN[SIZE][SIZE];
double frevisionP[SIZE][SIZE];
double frevisionQ[SIZE][SIZE];
double frevisionR[SIZE][SIZE];
double frevisionS[SIZE][SIZE];
double frevisionT[SIZE][SIZE];
double frevisionU[SIZE][SIZE];
double frevisionY[SIZE][SIZE];

double mrateA[SIZE][SIZE];
double mrateB[SIZE][SIZE];
double mrateC[SIZE][SIZE];
double mrateD[SIZE][SIZE];
double mrateE[SIZE][SIZE];
double mrateF[SIZE][SIZE];
double mrateG[SIZE][SIZE];
double mrateH[SIZE][SIZE];
double mrateI[SIZE][SIZE];
double mrateJ[SIZE][SIZE];
double mrateK[SIZE][SIZE];
double mrateL[SIZE][SIZE];
double mrateM[SIZE][SIZE];
double mrateN[SIZE][SIZE];
double mrateP[SIZE][SIZE];
double mrateQ[SIZE][SIZE];
double mrateR[SIZE][SIZE];
double mrateS[SIZE][SIZE];
double mrateT[SIZE][SIZE];
double mrateU[SIZE][SIZE];
double mrateY[SIZE][SIZE];

double densA[MaxStep+1];
double densB[MaxStep+1];
double densC[MaxStep+1];
double densD[MaxStep+1];
double densE[MaxStep+1];
double densF[MaxStep+1];
double densG[MaxStep+1];
double densH[MaxStep+1];
double densI[MaxStep+1];
double densJ[MaxStep+1];
double densK[MaxStep+1];
double densL[MaxStep+1];
double densM[MaxStep+1];
double densN[MaxStep+1];
double densP[MaxStep+1];
double densQ[MaxStep+1];
double densR[MaxStep+1];
double densS[MaxStep+1];
double densT[MaxStep+1];
double densU[MaxStep+1];
double densY[MaxStep+1];

/*  random number(integer)  */
int randPoint(int r){       //0 to r-1
    return rand()%r;
}
/*  random number(probability)  */
double drand48(){
    return (double)rand()/RAND_MAX;     //0 to 1
}

/*  random number initializer   */
void srand48(long time_t){
    srand(time_t);
}

/*connect field ends*/
int mod(int x){
    int z;
    z = (x+SIZE)%SIZE;
    return z;
}

/* not connect field ends*/
int mod2(int x){
    int z;
    if(x>SIZE-2){
        z =outfield;
    }
    else if(x<0){

        z =outfield;

    }
    else{
        z=x;
    }
    return z;
}



/*reproduction process local*/
void ReproductionD(){           //Reproduction Disperse
  int species;
  int rx, ry;
  int rx1,ry1;
  int r1,r2;
  double revision=0,rate=1;

  int Reach[31]={0,DispReachA,DispReachB,DispReachC,DispReachD,DispReachE,DispReachF,DispReachG,DispReachH,DispReachI,DispReachJ,DispReachK,DispReachL,DispReachM,DispReachN,DispReachP,DispReachQ,DispReachR,DispReachS,DispReachT,DispReachU};

  rx=randPoint(SIZE);
    ry=randPoint(SIZE);

  if(field[rx][ry]!=O){
    if(field[rx][ry]==A){
      rate=BirthA;
      species=A;
    }
    else if(field[rx][ry]==B){
      rate=BirthB;
      species=B;
    }
    else if(field[rx][ry]==C){
      rate=BirthC;
      species=C;
    }
    else if(field[rx][ry]==D){
      rate=BirthD;
      species=D;
    }
    else if(field[rx][ry]==E){
      rate=BirthE;
      species=E;
    }
    else if(field[rx][ry]==F){
      rate=BirthF;
      species=F;
    }
    else if(field[rx][ry]==G){
      rate=BirthG;
      species=G;
    }
    else if(field[rx][ry]==H){
      rate=BirthH;
      species=H;
    }
    else if(field[rx][ry]==I){
      rate=BirthI;
      species=I;
    }
    else if(field[rx][ry]==J){
      rate=BirthJ;
      species=J;
    }
    else if(field[rx][ry]==K){
      rate=BirthK;
      species=K;
    }
    else if(field[rx][ry]==L){
      rate=BirthL;
      species=L;
    }
    else if(field[rx][ry]==M){
      rate=BirthM;
      species=M;
    }
    else if(field[rx][ry]==N){
      rate=BirthN;
      species=N;
    }
    else if(field[rx][ry]==P){
      rate=BirthP;
      species=P;
    }
    else if(field[rx][ry]==Q){
      rate=BirthQ;
      species=Q;
    }
    else if(field[rx][ry]==R){
      rate=BirthR;
      species=R;
    }
    else if(field[rx][ry]==S){
      rate=BirthS;
      species=S;
    }
    else if(field[rx][ry]==T){
      rate=BirthT;
      species=T;
    }else if(field[rx][ry]==U){
      rate=BirthU;
      species=U;
    }else if(field[rx][ry]==Y ){
    }else{
      printf("something is wrong in ReproductionD1.");
    }

    do{
      do{
    r1=randPoint(Reach[species]*2+1)-Reach[species];            //                                                              ›
    r2=randPoint(Reach[species]*2+1)-Reach[species];            //                                                            ›››
      }while(r1==0&&r2==0);                                     //except site occupied by disperser                         ››~››
    }while(abs(r1)+abs(r2)>=Reach[species]+1);                  //distance from disperser should be within its reach          ›››
    //                                                                                                                          ›


    rx1=mod(rx+r1);
    ry1=mod(ry+r2);

    if(field[rx][ry]==A){
      revision=frevisionA[rx1][ry1];
    }
    else if(field[rx][ry]==B){
      revision=frevisionB[rx1][ry1];
    }
    else if(field[rx][ry]==C){
      revision=frevisionC[rx1][ry1];
    }
    else if(field[rx][ry]==D){
      revision=frevisionD[rx1][ry1];
    }
    else if(field[rx][ry]==E){
      revision=frevisionE[rx1][ry1];
    }
    else if(field[rx][ry]==F){
      revision=frevisionF[rx1][ry1];
    }
    else if(field[rx][ry]==G){
      revision=frevisionG[rx1][ry1];
    }
    else if(field[rx][ry]==H){
      revision=frevisionH[rx1][ry1];
    }
    else if(field[rx][ry]==I){
      revision=frevisionI[rx1][ry1];
    }
    else if(field[rx][ry]==J){
      revision=frevisionJ[rx1][ry1];
    }
    else if(field[rx][ry]==K){
      revision=frevisionK[rx1][ry1];
    }
    else if(field[rx][ry]==L){
      revision=frevisionL[rx1][ry1];
    }
    else if(field[rx][ry]==M){
      revision=frevisionM[rx1][ry1];
    }
    else if(field[rx][ry]==N){
      revision=frevisionN[rx1][ry1];
    }
    else if(field[rx][ry]==P){
      revision=frevisionP[rx1][ry1];
    }
    else if(field[rx][ry]==Q){
      revision=frevisionQ[rx1][ry1];
    }
    else if(field[rx][ry]==R){
      revision=frevisionR[rx1][ry1];
    }
    else if(field[rx][ry]==S){
      revision=frevisionS[rx1][ry1];
    }
    else if(field[rx][ry]==T){
      revision=frevisionT[rx1][ry1];
    }
    else if(field[rx][ry]==U){
      revision=frevisionU[rx1][ry1];
    }else if(field[rx][ry]==Y){
    }else{
      printf("something is wrong in ReproductionD2.");
    }
    /*reproduction*/
    //if(rx1!=outfield && ry1!=outfield){
    if((field[rx1][ry1]==O) && drand48()<rate*revision){
      field[rx1][ry1]=species;
    }
    //}
  }
}

/*predation process*/
void Pred(){

 int rx, ry;
 int rx2, ry2;
 int r;
 double p;


  rx=randPoint(SIZE);
  ry=randPoint(SIZE);
  p=drand48();


        if(field2[rx][ry]==Y){
            if(field[rx][ry]!=O){
                if(field[rx][ry]==A){
                    if(p<GrazeA){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==B){
                    if(p<GrazeB){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==C){
                    if(p<GrazeC){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==D){
                    if(p<GrazeD){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==E){
                    if(p<GrazeE){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==F){
                    if(p<GrazeF){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==G){
                    if(p<GrazeG){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==H){
                    if(p<GrazeH){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==I){
                    if(p<GrazeI){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==J){
                    if(p<GrazeJ){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==K){
                    if(p<GrazeK){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==L){
                    if(p<GrazeL){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==M){
                    if(p<GrazeM){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==N){
                    if(p<GrazeN){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==P){
                    if(p<GrazeP){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==Q){
                    if(p<GrazeQ){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==R){
                    if(p<GrazeR){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==S){
                    if(p<GrazeS){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==T){
                    if(p<GrazeT){
                        field[rx][ry]=O;
                    }
                }else if(field[rx][ry]==U){
                    if(p<GrazeU){
                        field[rx][ry]=O;
                    }
                }
            }else if(field[rx][ry]==O){
             }
        }else if(field2[rx][ry]!=Y){
            }
        }








/*  disposer    */
void dispose(int species,double density){
  int num,i,j;
  int limit=(int)(AREA*density);

  for(num=0;num<limit;num++){
    do{
      i=randPoint(SIZE);
      j=randPoint(SIZE);
    }while(field[i][j]!=O);

    if(species==A){
      if(frevisionA[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionA[i][j]==0){
    num--;
      }
    }
    else if(species==B){
      if(frevisionB[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionB[i][j]==0){
    num--;
      }
    }
    else if(species==C){
      if(frevisionC[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionC[i][j]==0){
    num--;
      }
    }
    else if(species==D){
      if(frevisionD[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionD[i][j]==0){
    num--;
      }
    }
    else if(species==E){
      if(frevisionE[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionE[i][j]==0){
    num--;
      }
    }
    else if(species==F){
      if(frevisionF[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionF[i][j]==0){
    num--;
      }
    }
    else if(species==G){
      if(frevisionG[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionG[i][j]==0){
    num--;
      }
    }
    else if(species==H){
      if(frevisionH[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionH[i][j]==0){
    num--;
      }
    }
    else if(species==I){
      if(frevisionI[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionI[i][j]==0){
    num--;
      }
    }
    else if(species==J){
      if(frevisionJ[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionJ[i][j]==0){
    num--;
      }
    }
    else if(species==K){
      if(frevisionK[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionK[i][j]==0){
    num--;
      }
    }
    else if(species==L){
      if(frevisionL[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionL[i][j]==0){
    num--;
      }
    }
    else if(species==M){
      if(frevisionM[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionM[i][j]==0){
    num--;
      }
    }
    else if(species==N){
      if(frevisionN[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionN[i][j]==0 //•ú–q‚ª‘Œ´ŒQ—Ž‚̎푽—l«‚É—^‚¦‚é‰e‹¿
){
    num--;
      }
    }
    else if(species==P){
      if(frevisionP[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionP[i][j]==0){
    num--;
      }
    }
    else if(species==Q){
      if(frevisionQ[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionQ[i][j]==0){
    num--;
      }
    }
    else if(species==R){
      if(frevisionR[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionR[i][j]==0){
    num--;
      }
    }
    else if(species==S){
      if(frevisionS[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionS[i][j]==0){
    num--;
      }
    }
    else if(species==T){
      if(frevisionT[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionT[i][j]==0){
    num--;
      }
    }
    else if(species==U){
      if(frevisionU[i][j]!=0){
    field[i][j]=species;
      }
      else if(frevisionU[i][j]==0){
    num--;
      }
    }
  }
}

void Ydispose(int species,double density){
  int num,i,j;
  int limit=(int)(AREA*density);

  for(num=0;num<limit;num++){
    do{
      i=randPoint(SIZE);
      j=randPoint(SIZE);
    }while(field2[i][j]!=O);

        if(species==Y){
        if(frevisionY[i][j]!=0){
                    field2[i][j]=species;
        }
      else if(frevisionY[i][j]==0){
                num--;
      }
    }
  }
}

/*  ƒÃ disposer(0`1)    */
    void disprevC(){                                        //dispose revision continuous (0`1)
  int i,j;

  for(i=0;i<SIZE;i++){
    for(j=0;j<SIZE;j++){
      frevisionA[i][j]=drand48();
      frevisionB[i][j]=drand48();
      frevisionC[i][j]=drand48();
      frevisionD[i][j]=drand48();
      frevisionE[i][j]=drand48();
      frevisionF[i][j]=drand48();
      frevisionG[i][j]=drand48();
      frevisionH[i][j]=drand48();
      frevisionI[i][j]=drand48();
      frevisionJ[i][j]=drand48();
      frevisionK[i][j]=drand48();
      frevisionL[i][j]=drand48();
      frevisionM[i][j]=drand48();
      frevisionN[i][j]=drand48();
      frevisionP[i][j]=drand48();
      frevisionQ[i][j]=drand48();
      frevisionR[i][j]=drand48();
      frevisionS[i][j]=drand48();
      frevisionT[i][j]=drand48();
      frevisionU[i][j]=drand48();
      frevisionY[i][j]=drand48();
    }
  }
}



/*  density counter */
double CountDensity(int target){
  int i,j;
  double number=0;
  double density=0.0;
  for(i=0;i<SIZE;i++){
    for(j=0;j<SIZE;j++){
      if(field[i][j]==target){
    number++;
      }
    }
  }
  density=number/AREA;
  return(density);
}

double CountDensity2(int target){
  int i,j;
  double number=0;
  double density=0.0;
  for(i=0;i<SIZE;i++){
    for(j=0;j<SIZE;j++){
      if(field2[i][j]==target){
    number++;
      }
    } //•ú–q‚ª‘Œ´ŒQ—Ž‚̎푽—l«‚É—^‚¦‚é‰e‹¿

  }
  density=number/AREA;
  return(density);
}


int main(){
  FILE *fp;
  if ((fp = fopen(FILENAME, "w")) == NULL) {
    printf("file open error!!\n");
    exit(EXIT_FAILURE);
  }

  srand((unsigned)time(NULL));
int nn, nn1, nn2;


  double s=0,a=0;
    int n=0,p=0,m=0,size=0,area;
    int k,u,v,z;


float var=0;
  for(n=0;n<=trial-1;n+=1){ //start of trial
    //printf("%d\n",n);



    disprevC();                 //initial disposition of ƒÃ

    dispose(A,FdensA);      //initial disposition of species
    dispose(B,FdensB);
    dispose(C,FdensC);
    dispose(D,FdensD);
    dispose(E,FdensE);
    dispose(F,FdensF);
    dispose(G,FdensG);
    dispose(H,FdensH);
    dispose(I,FdensI);
    dispose(J,FdensJ);
    dispose(K,FdensK);
    dispose(L,FdensL);
    dispose(M,FdensM);
    dispose(N,FdensN);
    dispose(P,FdensP);
    dispose(Q,FdensQ);
    dispose(R,FdensR);
    dispose(S,FdensS);
    dispose(T,FdensT);
    dispose(U,FdensU);

    step=0;
int sinit=s;
        for(step=0;step<=MaxStep;step++){           //start of 1 trial

            for(u=0;u<SIZE;u++){
             for(v=0;v<SIZE;v++){
                 field2[u][v]=O;
             }
            }

            Ydispose(Y,FdensY);

            for (m=1;m<=AREA;m++){    //‘ŠiŽq”‰ñ•ª
                ReproductionD(); //reproductionprocess(local)
             for(z=0;z<3;z++){ //grazing times
                Pred(); //predation process
             }

            }


    densA[step]=CountDensity(A);
     densB[step]=CountDensity(B);
     densC[step]=CountDensity(C);
     densD[step]=CountDensity(D);
     densE[step]=CountDensity(E);
     densF[step]=CountDensity(F);
     densG[step]=CountDensity(G);
     densH[step]=CountDensity(H);
     densI[step]=CountDensity(I);
     densJ[step]=CountDensity(J);
     densK[step]=CountDensity(K);
     densL[step]=CountDensity(L);
     densM[step]=CountDensity(M);
     densN[step]=CountDensity(N);
     densP[step]=CountDensity(P);
     densQ[step]=CountDensity(Q);
     densR[step]=CountDensity(R);
     densS[step]=CountDensity(S);
     densT[step]=CountDensity(T);
     densU[step]=CountDensity(U);




        if(step==MaxStep){          //species counter


                if(densA[step]>0) s++;
                if(densB[step]>0) s++;
                if(densC[step]>0) s++;
                if(densD[step]>0) s++;
                if(densE[step]>0) s++;
                if(densF[step]>0) s++;
                if(densG[step]>0) s++;
                if(densH[step]>0) s++;
                if(densI[step]>0) s++;
                if(densJ[step]>0) s++;
                if(densK[step]>0) s++;
                if(densL[step]>0) s++;
                if(densM[step]>0) s++;
                if(densN[step]>0) s++;
                if(densP[step]>0) s++;
                if(densQ[step]>0) s++;
                if(densR[step]>0) s++;
                if(densS[step]>0) s++;
                if(densT[step]>0) s++;
                if(densU[step]>0) s++;

    }       //end of species counter

     printf("%d\n",step);

    }       //end  of 1 trial
sarray[n]=s-sinit;
  }     //end of trial

    //fprintf(fp,"%f,",s/trial);
float sd2=0;

for (n=0;n<trial;n++){
    sd2+=pow((sarray[n]-(s/trial)),2);
    }
    sd2=pow(sd2/(trial-1),0.5);

    fprintf(fp,"\n");
    fprintf(fp,"Grazingrate: %f\n Initial grazing: %f\n Birth rate: %f\n",gr,G1,BA );
    printf("number of survivors is %f\n",s/trial);
    fprintf(fp,"number of survivors is %f\n",s/trial);
    printf("lattice size is %d*%d\n",SIZE,SIZE);
    printf("standard deviation %f\n",sd2);
    fprintf(fp,"standard deviation is %f\n",sd2);
    //printf("birthA is %f\n",birthA);

  fclose(fp);
}
  • kamu paham yang kamu buat ? - codenoid

Tag: c++



Login untuk diksusi di forum sekolah koding