Пример #1
0
  /*********************************************
   * compute objective function
   *
   * input : regles : rules of the automata
   *         n : maximum of automata size
   *         nbIter : maximum number of iterations
   *
   * output : the maximum size solved
   *
   *********************************************/
  int Automata :: f(Regle regles, int n) {
    int nbFireTot = evol(regles, 2);
   
    int k = 2;

    while (nbFireTot == k && k <= n) {
      k++;
      nbFireTot = evol(regles, k);
    }
  
    if (k == 2)
      return 0;
    else
      return k - 1;
  }
Пример #2
0
/* 
 *      FUNCTION  
 *         Name:  red_evol
 *  Description:  
 * 
 */
int red_evol ( void* params, const double r[], double time_end, double step,
		const gsl_vector* req_red, gsl_matrix* red_m )
{
	struct f_params* pars = (struct f_params*) params ;

	unsigned int i ;                        /* counter for the for loops */

	/* 
	 *
	 *  evolving the systems
	 * 
	 */
	double t = 0 ; 

	/* setting the initial vector */
	gsl_vector* init_red = gsl_vector_calloc(4) ;
	for ( i = 0 ; i < 4 ; i++ )
		gsl_vector_set ( init_red, i, r[i] ) ;

	/* 
	 *
	 * Initializing the system for Redfield dynamics
	 *
	 */
	gsl_odeiv2_system red_sys = { generator, jac, 4, (void*) red_m } ;

	/* Choosing the step function type: Runge-Kutta-Fehlberg (4,5) */	
	/* gsl_odeiv2_step* s = gsl_odeiv2_step_alloc ( gsl_odeiv2_step_rkf45 , 4 ) ; */

	/* Choosing the step function type: Runge-Kutta Cash-Karp (4,5) */	
	gsl_odeiv2_step* r_s = gsl_odeiv2_step_alloc ( gsl_odeiv2_step_rkck , 4 ) ;

	/* Setting the step control: abserr=1e-9, relerr=1e-3 */
	gsl_odeiv2_control* r_c = gsl_odeiv2_control_standard_new ( 1e-9, 1e-3, 1, 1 ) ;

	/* Allocating the space for evolution function */
	gsl_odeiv2_evolve* r_e = gsl_odeiv2_evolve_alloc ( 4 ) ;

	/* opening the files */
	FILE* f_red = fopen ( "RED-EVOLUTION.dat", "w" ) ;
	FILE* g_red = fopen ( "RED-ENTROPY-PROD.dat", "w" ) ;
	FILE* h_red = fopen ( "RED-CURRENT.dat", "w" ) ;
	FILE* i_red = fopen ( "RED-ENTROPY.dat", "w" ) ;


	/* writing data */
	while ( t < t_end )
	{
		evol ( t, init_red, step, r_e, r_c, r_s, &red_sys ) ;
		fprintf ( f_red, "%.2f %.9f %.9f %.9f %.9f\n", t,
				VECTOR(init_red,1), VECTOR(init_red,2),
				VECTOR(init_red,3),
				gsl_hypot3(VECTOR(init_red,1),VECTOR(init_red,2),
					VECTOR(init_red,3)) ) ;
		fprintf ( g_red, "%.2f %.9f\n",
				t, entropy_production( init_red, req_red, red_m )) ;
		fprintf ( h_red, "%.2f %.9f\n",	t, tot_current(init_red, pars) ) ;
		fprintf ( i_red, "%.2f %.9f\n",
				t, entropy_of_state(init_red) ) ;
		t += step ;
	}
	
	/* final entropy */
	printf("Final entropy: %g\n", entropy_of_state(init_red) ) ;

	/*  close the files */
	fclose (f_red) ;
	fclose (g_red) ;
	fclose (h_red) ;
	fclose (i_red) ;

	/* free memory for evolution */
	gsl_odeiv2_evolve_free (r_e) ;
	gsl_odeiv2_control_free (r_c) ;
	gsl_odeiv2_step_free (r_s) ;

	return 0;
}		/* -----  end of function red_evol  ----- */