/** * this is a standard experiment for XOR emulation; is passed a name of a started genome and a * number of times can be execute this experiment; */ public static void Experiment1(String xFileName, int gens) { String fname_prefix = "c:\\jneat\\dati\\population.natural"; Population pop = null; StringTokenizer st; String curword; String xline; String fnamebuf; int gen; IOseq xFile; int id; int expcount = 0; String mask6 = "000000"; DecimalFormat fmt6 = new DecimalFormat(mask6); System.out.println("------ Start experiment 1 -------"); xFile = new IOseq(xFileName); boolean ret = xFile.IOseqOpenR(); if (ret) { try { System.out.println(" Start XOR experiment"); System.out.println(" .read start genome.."); xline = xFile.IOseqRead(); st = new StringTokenizer(xline); // skip curword = st.nextToken(); // id of genome can be readed curword = st.nextToken(); id = Integer.parseInt(curword); System.out.println(" .create genome id " + id); Genome start_genome = new Genome(id, xFile); // backup this 'initial' genome (is only for test // if the read & write are correct start_genome.print_to_filename("c:\\jneat\\dati\\genome.readed"); for (expcount = 0; expcount < Neat.p_num_runs; expcount++) { System.out.println(" Spawned population off genome"); pop = new Population(start_genome, Neat.p_pop_size); System.out.print("\n\n Verifying Spawned Pop"); pop.verify(); System.out.print("\n"); for (gen = 1; gen <= gens; gen++) { System.out.print("\n---------------- E P O C H < " + gen + " >--------------"); fnamebuf = "g_" + fmt6.format(gen); boolean esito = xor_epoch(pop, gen, fnamebuf); } System.out.print("\n Population : innov num = " + pop.getCur_innov_num()); System.out.print("\n : cur_node_id = " + pop.getCur_node_id()); pop.print_to_filename(fname_prefix); } } catch (Throwable e) { System.err.println(e + " : error during read " + xFileName); } xFile.IOseqCloseR(); } else System.err.print("\n : error during open " + xFileName); System.out.println("\n\n End of experiment"); }