void explore (struct attractor *a) { do getRandom (a); while (!isAttractorConverging (a)); }
/* Compute an attractor previously allocated by newAttractor */ void computeAttractor (struct attractor *a, char *code) { struct timeval t1, t2; if (code == NULL || checkCode (code)) { explore (a); } else { strncpy (a->code, code, a->polynom->length * a->dimension + 3); applyCode (a->polynom, code); if (!isAttractorConverging (a)) fprintf (stderr, "Bad code - attractor not converging\n"); } a->polynom->sum = getPolynomSum (a->polynom); displayPolynom (a->polynom); fprintf (stdout, "Lyapunov exponent: %.6f\n", a->lyapunov->ly); gettimeofday (&t1, NULL); iterateMap (a); gettimeofday (&t2, NULL); diffTime ("Map iteration", &t1, &t2); a->r = getRadius (a); centerAttractor (a); computeDimension (a); fprintf (stdout, "Correlation dimension: %.6f\n", a->correlationDimension); fprintf (stdout, "Code: %s\n", a->code); }
static void * backgroundCompute (void *v) { struct attractor *a; int i, dir, iter; double baseSum = AT_INFINITY; dir = -1; iter = 0; /* Under windows, random is working strangely with threads */ #ifdef __MINGW__ srand (time (NULL)); #endif while (1) { a = at[1 - frontBuffer]; do { copyPolynom (a, at[frontBuffer]->polynom); strncpy (a->code, at[frontBuffer]->code, a->polynom->length * a->dimension + 3); setClosePolynom (a, at[frontBuffer]->polynom, dir); iter++; dset.divergence = fabs (baseSum - a->polynom->sum); if (baseSum == AT_INFINITY || iter > MAX_ITER || dset.divergence > MAX_DIVERGENCE) { baseSum = a->polynom->sum; dir = -dir; iter = 0; } } while (!isAttractorConverging (a)); // OK is now using a polynom close to its sibling. And it is converging - time to do the full calculation for (i = 0; i < a->numPoints; i++) { free (a->array[i]); } for (i = 0; i < 2; i++) { free (a->bound[i]); } iterateMap (a); a->r = getRadius (a); centerAttractor (a); pthread_mutex_lock (&mt); threadRunning = 0; pthread_mutex_unlock (&mt); while (threadRunning == 0); } /* To please the compiler */ return NULL; }