Beispiel #1
0
StackIndex args_extract(const char* caller, Pointer args, int min, int max)
{
    StackIndex before = valuestack_top();

    // First process the mandatory args.
    for (int i = 0; i < min; i++) {
        if (args.type != Type_pair) {
            // We've run out of args.
            THROW("%s: %s%d arg%s expected, %d provided",
                caller, min == max ? "" : "at least ",
                min, PLURAL(min), i);
        }
        PUSH(pair_get(args, 0));
        args = pair_get(args, 1);
    }

    // Then process the optional args, if required.
    for (int i = min; args.type != Type_nil && (i < max); i++) {
        PUSH(pair_get(args, 0));
        args = pair_get(args, 1);
    }

    // Now check that there aren't any more args.
    if (args.type != Type_nil) {
        int got = max + args_count(args);

        THROW("%s: %s%d arg%s expected, %d provided",
              caller, min == max ? "" : "no more than ",
              max, PLURAL(max), got);
    }

    return before;
}
Beispiel #2
0
	/**
	 * Returns the nth argument.
	 *
	 * @throws std::out_of_range @a n exceeds args_count().
	 */
	const std::string& arg(size_t n) const
	{
		if(n > args_count()) {
			throw std::out_of_range("control line argument range exceeded");
		}

		return args_[n];
	}
Beispiel #3
0
Datei: main.c Projekt: jviki/cgp
int main(int argc, char **argv)
{
	int count = args_count(argc, argv);
	if(count < 0)
		return -1;

	FILE *cfd = args_output_file(argc, argv);
	if(cfd == NULL)
		return -2;

	int ccount = 0;
	struct chromo_t *basec = args_chromos(argc, argv, &ccount);
	if(ccount < 0)
		return -3;

	size_t gener = 0;
	size_t runs  = 0;

	for(int i = 0; i < count; ++i) {
		struct timeval now;
		gettimeofday(&now, NULL);

		srand(now.tv_usec);

		fitness_t f;
		size_t g;
		cgp_run(&g, &f, cfd, basec, (size_t) ccount);
		fflush(cfd);

		fprintf(stderr, "Elapsed: %ld s\n", ms_elapsed(&now) / 1000);

		if(fitness_isacceptable(f)) {
			gener += g;
			runs  += 1;
		}
	}

	if(basec != NULL)
		chromo_free(basec);

	fclose(cfd);
	printf("Avarage generations: %zu\n", gener / runs);
	return 0;
}