Skip to content

Commit

Permalink
fail if thisstate is less than zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Auxilus committed Jul 10, 2019
1 parent caa6766 commit 7ae73dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/brain.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ int neuron_update(struct neuron* n, struct brain* b)
n->n_fired += 1;
}
n->thisstate += n->nextstate;
// thisstate less than zero is not possible
assert(n->thisstate >= 0);
n->nextstate = 0;
n->fired = 0;
return n->fired;
Expand Down
30 changes: 21 additions & 9 deletions src/cbrain.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@ int main(int argc, char* argv[])
}
cbrain_print(0, "mutex initiated at %p\n", &lock);
srand(time(0));
if (argc < 2) {
printf("Number of neurons required\n");
exit(1);
}
int neurons_no = atoi(argv[1]);
//if (argc < 2) {
// printf("Number of neurons required\n");
// exit(1);
//}
//int neurons_no = atoi(argv[1]);
uint sleep_t;
sleep_t = (argc < 3) ? SLEEP_T : strtof(argv[2], NULL);

struct brain* b = parse_model_csv("src/models/conn.txt");

//struct brain* b = brain_init((uint)neurons_no);
//neuron_link_random(b);
cbrain_print(0, "%d neurons generated and randomly linked\n", b->nc);
neuron_fire(b->neurons[172], b);
neuron_fire(b->neurons[173], b);
neuron_update_range(0, 499, b);
//cbrain_print(0, "%d neurons generated and randomly linked\n", b->nc);
// run an infinite loop which gives food to c elegans
for (;;) {
neuron_fire(b->neurons[4], b);
neuron_fire(b->neurons[5], b);
neuron_fire(b->neurons[42], b);
neuron_fire(b->neurons[41], b);
neuron_fire(b->neurons[45], b);
neuron_fire(b->neurons[46], b);
neuron_fire(b->neurons[48], b);
neuron_fire(b->neurons[76], b);
neuron_fire(b->neurons[77], b);
neuron_fire(b->neurons[72], b);
neuron_fire(b->neurons[73], b);
neuron_update_range(0, 499, b);
}
//struct nthread* nt1 = thread_struct_new(0, neurons_no-1);
//thread_create(nt1, b, 0, sleep_t);
//struct nthread* at = thread_struct_new(0, 0);
Expand Down

0 comments on commit 7ae73dc

Please sign in to comment.