Example #1
0
void    tickchange_play (void)
{
    nplay.dtime--;
    if (nplay.dtime != 0)
	return;

    if (nplay.type != GREV_END)
	play_event (&nplay);
    else
    {
	isreplaying = 0;
	return;
    }

    while ((getnextevent (&curEVplay, &nplay) == 0) && (nplay.dtime == 0))
	play_event (&nplay);
}
Example #2
0
int     start_playing (void)
{
//    int     i;

#ifdef DEBSEQU
	fprintf (stderr, "-->start_playing\n");
#endif
    if (initcurEVplay == NULL)	/* il faut avoir qqchose a rejouer... */
    {
#ifdef DEBSEQU
	fprintf (stderr, "-->start_playing curEVplay == NULL on arrete de jouer\n");
#endif
	isreplaying = 0;
	return 0;
    }
    curEVplay = initcurEVplay;
    curEVplay->cur = 0;		/* JDJDJDJD un rewind violent */

#ifdef DEBSEQU
	fprintf (stderr, "-->start_playing debut lecture des freezes\n");
#endif
    while ((getnextevent (&curEVplay, &nplay) == 0) && (nplay.dtime == 0))	/* lire les freezes */
	play_event (&nplay);
#ifdef DEBSEQU
	fprintf (stderr, "-->start_playing fin lecture des freezes\n");
	fprintf (stderr, "-->start_playing debut resync patterns\n");
#endif
//    initPatbut (gpatbut[0], -2, -1, -1);
// fprintf (stderr, "fini i=0\n");
//     for (i = MAXSAMPLE; i < MAXVOICES; i++)	/* initialisation a partir de la valeur prochaine */
//     {
// fprintf (stderr, "on est en i=%d\n", i);
// 	initPatbut (gpatbut[i], -2, -1, -1);
//     }	    
	{   int voice = 0;
		    voice = tickchange_pattern (voice);
		    voice = tickchange_analogik (voice);
		    voice = tickchange_dyfilter (voice);
		    voice = tickchange_delay (voice);
	}
#ifdef DEBSEQU
	fprintf (stderr, "-->start_playing fin resync patterns\n");
#endif

    if (nplay.type != GREV_END)
	isreplaying = 1;
#ifdef DEBSEQU
	fprintf (stderr, "-->start_playing ca joue avec isreplaying=%d\n", isreplaying);
#endif
    return isreplaying;
}
Example #3
0
int main(int argc, char **argv)
{
#if DEBUG
  feenableexcept(FE_DIVBYZERO| FE_INVALID|FE_OVERFLOW); // enable exceptions
#endif
  if(argc ^ 2){
    printf("Usage: ./sa sa.config\n");
    exit(1);
  }
  if(read_config(argv[1])){           // read config
    printf("READDATA: Can't process %s \n", argv[1]);
    return 1;
  }  
  T = T+SKIP;               // increase T by SKIP to go from 0 to T all the way in time units
  
  // precomputing  
  I_Gamma = 1.0/Gamma;
  I_Alpha = 1.0/Alpha;    
  Bo = B;    
  X0_Be = pow(X0, Beta);
  GaBe  = Gamma * Beta;

  // event probabilites scaling by G;
  PE[0] = PE[0]*(double)G;
  PE[1] = PE[1]*(double)G;
  PE[2] = PE[2]*(double)G;
  
  initrand(Seed);
  init();          // note: method is in init.c  // allocate memory at initial  
  
  int i, j, ev, k = 0; // m;
  unsigned long seed;
  double dt, ct, tt;      // tt: time of simulation; dt: delta time after which next event occurs; ct: counter time to check with skip time for stat calculation
  time_t now;   
 
  for( i = 0; i < Runs; i++){
    tt = 0.0, ct = 0.0;
    k = 0; //m = 0;
    if(Seed == 0){      
      now = time(0);
      seed = ((unsigned long)now);  
      seed = 1454011037;
      initrand(seed);
      printf("\n run: %d rand seed: %lu\n",i+1, seed);
    }
    set_init_xrvpi();   // sets initial strategies vector, roles, valuations and payoffs       
     
    calc_stat(0, i);
    
    for( j = 0; j < N; j++) printf("%.4lf  ", V[0][j]); printf("\n");
    
    // Gillespie's stochastic simulation 
    while(tt < T){     
      // calc lambda; lambda = summation of P[j]s
      for(Lambda = 0, j = EVENTS; j--;)
	Lambda += PE[j];
      // select time for next event
      dt = randexp(Lambda); //printf("dt: %.4lf\n", dt);
      // select next event
      ev = select_event();
      // play the event      
      play_event(ev);
      // update time
      tt += dt;
      // calc stat
      ct += dt;
      if(ct >= SKIP){
        calc_stat(++k, i); // calculates all the stats	
	ct = 0.0;
      }
      // update events associated probabilites if necessary
    }
#if ALLDATAFILE
    calc_stat(-1, -1);    // free file pointers for individual run data files
#if !CLUSTER
    plotallIndividualRun(i, 0);      // note: method is in dataplot.c  
#if GRAPHS
    plotallIndividualRun(i, 1);      // note: method is in dataplot.c
#endif
#endif
    // write traits of final state
    {
      int m, n;
      char tstr[200], str[100];
      sprintf(str, "traits%d.dat", i);
      sprintf(str, "traits%d.dat", i); prep_file(tstr, str);
      FILE *fp = fopen(tstr, "w");
      for(m = 0; m < G; m++){
	for( n = 0; n < GS[m]; n++){
	  fprintf(fp, "%.4lf %.4lf    ", dxi[m][n], dsi[m][n]);
	}
	fprintf(fp, "\n");
      }
      fclose(fp);
    }
#if PUNISH
#if DISP_MATRIX
    plotTraits(i, 0);   // note: method is in dataplot.c
#endif
#if GRAPHS
    plotTraits(i, 1);   // note: method is in dataplot.c
#endif
#endif
#endif
  }  
  // write effort and payoff data
  writefile_effort_fertility();              // note: method is in dataplot.c
  writefile_threshold_aggressiveness();      // note: method is in dataplot.c
  // plot data with graphics using gnuplot
  if(!CLUSTER){    
    plotall(0);                              // note: method is in dataplot.c
#if GRAPHS
    plotall(1);                              // note: method is in dataplot.c
#endif
  }
#if PUNISH
#if DISP_MATRIX
  displayMatrix();                           
#endif  
#endif
  
  cleanup();                                 // note: method is in init.c
  return 0;
}