aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2014-03-04 15:26:03 +0100
committerThomas White <taw@physics.org>2014-03-04 15:26:03 +0100
commit9bb0d608b82f731356a58c24637522a61105ba29 (patch)
treebd60751ae7dab3aebbf7fa8a026a677d0de04a67 /src
parent3bcd0cb4cb5b328d54b4e8342215f47168216ace (diff)
Report the number of assignments changed since the start
Diffstat (limited to 'src')
-rw-r--r--src/ambigator.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/ambigator.c b/src/ambigator.c
index d86dc63c..8a3879e3 100644
--- a/src/ambigator.c
+++ b/src/ambigator.c
@@ -221,10 +221,13 @@ int main(int argc, char *argv[])
SymOpList *amb;
int n_iter = 1;
int n_crystals, n_chunks, max_crystals;
+ int n_dif;
Crystal **crystals;
Stream *st;
int i;
int *assignments;
+ int *orig_assignments;
+ gsl_rng *rng;
/* Long options */
const struct option longopts[] = {
@@ -384,22 +387,38 @@ int main(int argc, char *argv[])
}
- assignments = calloc(n_crystals, sizeof(int));
+ assignments = malloc(n_crystals*sizeof(int));
if ( assignments == NULL ) {
ERROR("Couldn't allocate memory for assignments.\n");
return 1;
}
+ orig_assignments = malloc(n_crystals*sizeof(int));
+ if ( orig_assignments == NULL ) {
+ ERROR("Couldn't allocate memory for original assignments.\n");
+ return 1;
+ }
+
+ rng = gsl_rng_alloc(gsl_rng_mt19937);
for ( i=0; i<n_crystals/2; i++ ) {
- assignments[i] = 1;
+ assignments[i] = (random_flat(rng, 1.0) > 0.5);
+ orig_assignments[i] = assignments[i];
}
for ( i=0; i<n_iter; i++ ) {
detwin(crystals, n_crystals, amb, assignments);
}
+ n_dif = 0;
+ for ( i=0; i<n_crystals/2; i++ ) {
+ if ( orig_assignments[i] != assignments[i] ) n_dif++;
+ }
+ STATUS("%i assignments are different from their starting values.\n",
+ n_dif);
+
free(assignments);
free(crystals);
+ gsl_rng_free(rng);
return 0;
}