#include "wf.h"
+// generate a random number generator seed from /dev/urandom
+// borrowed from SSC src/runtime/ssc_rts.c
+static unsigned sim_random_seed() {
+ unsigned random_seed;
+ FILE *rng = fopen("/dev/urandom", "r");
+ if (rng == NULL) {
+ fprintf(stderr,
+ "error: cannot read /dev/urandom randomness generator\n");
+ exit(1);
+ }
+ size_t num_random_read = fread(&random_seed, sizeof(random_seed), 1, rng);
+ if (num_random_read != 1) {
+ fprintf(stderr,
+ "error: cannot read /dev/urandom randomness generator\n");
+ exit(1);
+ }
+ fclose(rng);
+ return random_seed;
+}
+
+
// Run the program
void run(RunParameters &r) {
// Initialize RNG and set initial state, if importing from file
- static gsl_rng *rnd = gsl_rng_alloc(gsl_rng_taus); //pointer to random number generator state
+ static gsl_rng *rnd = gsl_rng_alloc(gsl_rng_taus2); //pointer to random number generator state
- srand((unsigned)time(0));
- gsl_rng_set(rnd,rand());
+ //srand((unsigned)time(0));
+ //gsl_rng_set(rnd,rand());
+ gsl_rng_set(rnd,sim_random_seed());
r.setFiles();
- //FILE *popout=fopen(r.trajectoryOutfile.c_str(),"w");
- FILE *supout=fopen(r.supplementaryOutfile.c_str(),"w");
+ FILE *popout=fopen(r.trajectoryOutfile.c_str(),"w"); // <outfile>.dat
+ FILE *supout=fopen(r.supplementaryOutfile.c_str(),"w"); // <outfile>.sum
if (r.importState) importState(r);
for (i=0; i<r.g; ++i) {
P.next_generation(H, rnd, r.useRelative, r.useVerbose);
- //P.write_population(popout,i);
+ P.write_population(popout,i);
if (r.runUntilEscape && P.escaped(H)) break;
// Run (w/out targeted epitope)
else {
-
- Hamiltonian H(r.couplingsInfile);
- H.set_temp(r.bh, r.bJ);
- Population P(H, r.n, r.mu);
-
- for (unsigned int i=0; i<r.g; ++i) {
+
+ //for (unsigned int n=0;n<r.num_runs;n++) {
- P.next_generation(H, rnd, r.useRelative, r.useVerbose);
- //P.write_population(popout,i);
-
- }
+ Hamiltonian H(r.couplingsInfile);
+ H.set_temp(r.bh, r.bJ);
+ Population P(H, r.n, r.mu);
+
+ unsigned int i;
+ for (i=0; i<r.g; ++i) {
+
+ P.next_generation(H, rnd, r.useRelative, r.useVerbose);
+ P.write_population(popout,i);
+
+ if (r.runUntilEscape && P.escaped(H)) break;
+
+ }
+
+ //}
}
gsl_rng_free(rnd); //Free up memory from random number generator
+ fclose(popout); // close file handles
+ fclose(supout);
+
}
}
+void usage()
+{
+ std::cout <<
+"Command line rules:\n"
+"\n"
+" -d (string) working directory\n"
+" -i (string) input couplings file\n"
+" -o (string) output file stem\n"
+" -s (string) input state file, containing initial population fraction and targeted epitope\n"
+" -n (int/double) population size\n"
+" -g (int/double) number of generations\n"
+" -mu (double) mutation rate\n"
+" -b (double) \"inverse temperature\" multiplier\n"
+" -e (int) (int) targeted epitope spans sites [e#1, ..., e#2], assuming all WT\n"
+" -r flag to use relative energy condition for survival probability\n"
+" -esc flag to run until escape observed (or max number of generations reached)\n"
+" -v flag for verbose output\n";
+ std::cout.flush();
+}
/*
* Command line rules:
else if (strcmp(argv[i],"-r")==0) { r.useRelative=true; }
else if (strcmp(argv[i],"-esc")==0) { r.runUntilEscape=true; }
else if (strcmp(argv[i],"-v")==0) { r.useVerbose=true; }
+
+ else if (strcmp(argv[i],"-h")==0) { usage(); return 0; }
else printf("Unrecognized command! '%s'\n",argv[i]);