void state_save_free(void) { int restag = get_resource_tag(); ss_entry **entry; /* iterate over entries */ for (entry = &ss_registry; *entry; ) { /* if this entry matches, free it */ if ((*entry)->restag == restag) { ss_entry *entry_to_free = *entry; /* de-link us from the list and free our memory */ *entry = (*entry)->next; free(entry_to_free->name); free(entry_to_free); } /* if not a match, move on */ else entry = &(*entry)->next; } /* now do the same with the function lists */ func_free(&ss_prefunc_reg); func_free(&ss_postfunc_reg); /* if we're clear of all registrations, reset the invalid counter */ if (ss_registry == NULL && ss_prefunc_reg == NULL && ss_postfunc_reg == NULL) ss_illegal_regs = 0; }
int exec_close(struct t_exec *exec) { struct item *item; parser_close(&exec->parser); item = exec->functions.first; while (item) { func_free(item->value); item = item->next; } list_empty(&exec->functions); item = exec->values.first; while (item) { value_free(item->value); item = item->next; } list_empty(&exec->values); item = exec->vars.first; while (item) { var_close(item->value); item = item->next; } list_empty(&exec->vars); item = exec->formats.first; while (item) { var_close(item->value); item = item->next; } list_empty(&exec->formats); return 0; }
int main(int argc, char *argv[0]) { if(argc < 2 || argc > 4) { printf("Usage: xcsf inputfile [MaxTrials] [NumExp]\n"); exit(EXIT_FAILURE); } // initialise environment constants_init(argc, argv); random_init(); func_init(argv[1]); gen_outfname(argv[1]); // run experiments double err[PERF_AVG_TRIALS]; double terr[PERF_AVG_TRIALS]; for(int e = 1; e < NUM_EXPERIMENTS+1; e++) { printf("\nExperiment: %d\n", e); pop_init(); outfile_init(e); // each trial in an experiment for(int cnt = 0; cnt < MAX_TRIALS; cnt++) { trial(cnt, true, err); // train trial(cnt, false, terr);// test // display performance if(cnt%PERF_AVG_TRIALS == 0 && cnt > 0) disp_perf(err, terr, cnt, pop_num); } // clean up set_kill(&pset); outfile_close(); } func_free(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int c; int n = 100; int slow = 1; while (EOF != (c = getopt(argc, argv, "dn:s:"))) switch (c) { case 'd': debug = 0; break; case 'n': n = atoi(optarg); break; case 's': slow = atoi(optarg); break; } preamble(stdout); #if 0 /* from left to right */ for (int k = 1; k < n; k++) { func_t *r = rhs(n); flatten(r, k); func_t *s = solution(r, 0); for (int repeat = 0; repeat < slow; repeat++) { showfunctiongraph(stdout, r, s); } func_free(r); func_free(s); } #endif #if 0 /* hierarchically */ int k = 2; while (k < 1024) { func_t *r = rhs(k - 1); func_t *s = solution(r, 0); for (int repeat = 0; repeat < slow; repeat++) { showfunctiongraph(stdout, r, s); } func_free(r); func_free(s); k <<= 1; } #endif /* random addition of points */ int exponent = log2(n); int repeats = 1; n = 1 << (++exponent); // next larger power of 2 func_t *r0 = rhs(n); int *use = (int *)calloc(n, sizeof(int)); for (int k = 1; k <= n; k++) { /* adapt the repeats */ repeats = 32 * pow(2, -k/16.); if (repeats < slow) { repeats = slow; } /* add a new point to the graph */ int index; while (1) { index = random() % n; if (0 == use[index]) { use[index] = 1; r0->highlight = index; break; } } /* mask some of the points in a copy of r0 */ func_t *r = func_copy(r0); double scale = (1. + r->n) / (1. + k); for (int i = 0; i < r->n; i++) { r->f[i] *= scale; r->f[i] *= use[i]; } /* create the associated solution */ func_t *s = solution(r, k); scale = 1/scale; for (int i = 0; i < r->n; i++) { r->f[i] *= scale; } /* display as many copies as necessary */ for (int repeat = 0; (repeat < (slow * repeats)) && (repeat < 25); repeat++) { printf("%% n = %d, figure = %4d, iteration = %4d, " "repeats = %2d, index = %4d\n", n, figcounter, k, repeats, index); showfunctiongraph(stdout, r, s); } func_free(r); func_free(s); } func_free(r0); postamble(stdout); exit(EXIT_SUCCESS); }