[avida-cvs] avida CVS commits: /current/source/main analyze.cc
mercere99
avida-cvs at alife.org
Tue Oct 14 23:35:01 PDT 2003
mercere99 Tue Oct 14 15:35:01 2003 EDT
Modified files:
/avida/current/source/main analyze.cc
Log:
Made changes to arrays in analyze mode so that they use tArray and
tMatrix to make them easier to use with variable sizes.
Index: avida/current/source/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.78 avida/current/source/main/analyze.cc:1.79
--- avida/current/source/main/analyze.cc:1.78 Tue Oct 14 10:49:23 2003
+++ avida/current/source/main/analyze.cc Tue Oct 14 15:35:00 2003
@@ -1976,11 +1976,17 @@
double av_task_site = 0; // average number of tasks per site
double av_t_s_norm = 0; // average number of tasks per site per task
- double std_task_position[num_cols]; // average StDev in positions used for a task
+ // average StDev in positions used for a task
+ tArray<double> std_task_position(num_cols);
- double * org_task = new double[num_cols]; // # of organisms actually doing a task
- double * av_num_inst = new double[num_cols]; // av. # of sites necessary for each of the tasks
- double * av_inst_task = new double[num_cols+1]; // number of sites involved in 0-9 tasks
+ // # of organisms actually doing a task
+ tArray<double> org_task(num_cols);
+
+ // av. # of sites necessary for each of the tasks
+ tArray<double> av_num_inst(num_cols);
+
+ // number of sites involved in 0-9 tasks
+ tArray<double> av_inst_task(num_cols+1);
for (int i = 0; i < num_cols; i++) {
av_num_inst[i] = 0;
@@ -2036,12 +2042,11 @@
}
// Create an initialize the counters for modularity
-
- int * num_task = new int[max_line]; // number of tasks instruction is used in
- int * num_inst = new int[num_cols]; // number of instructions involved in a task
- int sum[num_cols]; // helps with StDev calculations
- int sumsq[num_cols]; // helps with StDev calculations
- int * inst_task = new int[num_cols+1]; // # of inst's involved in 0,1,2,3... tasks
+ tArray<int> num_task(max_line); // number of tasks instruction is used in
+ tArray<int> num_inst(num_cols); // number of instructions involved in a task
+ tArray<int> sum(num_cols); // helps with StDev calculations
+ tArray<int> sumsq(num_cols); // helps with StDev calculations
+ tArray<int> inst_task(num_cols+1); // # of inst's involved in 0,1,2,3... tasks
for (int i = 0; i < num_cols; i++) {
num_inst[i] = 0;
@@ -2161,10 +2166,6 @@
for (int i = 0; i < max_line; i++) { inst_task[num_task[i]]++ ;}
for (int i = 0; i < num_cols+1; i++) { av_inst_task[i] = av_inst_task[i] + inst_task[i] * num_cpus;}
- delete [] num_inst;
- delete [] num_task;
- delete [] inst_task;
-
}
}
@@ -3305,8 +3306,8 @@
cGenome mod_genome(base_genome);
// Loop through all the lines of code, testing all mutations...
- double test_fitness[num_insts];
- double prob[num_insts];
+ tArray<double> test_fitness(num_insts);
+ tArray<double> prob(num_insts);
for (int line_num = 0; line_num < max_line; line_num++) {
int cur_inst = base_genome[line_num].GetOp();
//char cur_symbol = base_genome[line_num].GetSymbol();
@@ -3396,13 +3397,13 @@
if (genotype == NULL) return;
int seq_length = genotype->GetLength();
const int num_insts = inst_set.GetSize();
- int inst_stat[seq_length][num_insts];
+ tMatrix<int> inst_stat(seq_length, num_insts);
int pop_size = 0;
// Initializing inst_stat ...
for (int line_num = 0; line_num < seq_length; line_num ++)
for (int inst_num = 0; inst_num < num_insts; inst_num ++)
- inst_stat[line_num][inst_num] = 0;
+ inst_stat(line_num, inst_num) = 0;
while (genotype != NULL) {
pop_size ++;
@@ -3414,7 +3415,7 @@
}
for (int line_num = 0; line_num < seq_length; line_num ++) {
int cur_inst = base_genome[line_num].GetOp();
- inst_stat[line_num][cur_inst] ++;
+ inst_stat(line_num, cur_inst) ++;
}
genotype = batch_it.Next();
}
@@ -3423,8 +3424,8 @@
for (int line_num = 0; line_num < seq_length; line_num ++) {
double entropy = 0.0;
for (int inst_num = 0; inst_num < num_insts; inst_num ++) {
- if (inst_stat[line_num][inst_num] == 0) continue;
- float prob = (float) (inst_stat[line_num][inst_num]) / (float) (pop_size);
+ if (inst_stat(line_num, inst_num) == 0) continue;
+ float prob = (float) (inst_stat(line_num, inst_num)) / (float) (pop_size);
entropy += prob * log((double) 1.0/prob) / log((double) num_insts);
}
double complexity = 1 - entropy;
More information about the Avida-cvs
mailing list