Skip to content

Commit ae35395

Browse files
committed
count number of atoms and expose as a metric
1 parent 668ceb5 commit ae35395

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

verifier.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct per_cycle_measurements {
8383
int instruction_executions[NUMBER_OF_INSTRUCTIONS];
8484
int atom_grabs[NUMBER_OF_ATOM_TYPES];
8585
int maximum_absolute_arm_rotation;
86+
int number_of_atoms[NUMBER_OF_ATOM_TYPES];
8687
struct error error;
8788
bool valid;
8889
};
@@ -324,6 +325,7 @@ static struct per_cycle_measurements measure_at_current_cycle(struct verifier *v
324325
.instruction_executions = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
325326
.atom_grabs = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
326327
.maximum_absolute_arm_rotation = -1,
328+
.number_of_atoms = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
327329
.valid = true,
328330
};
329331
if (board->collision) {
@@ -336,6 +338,13 @@ static struct per_cycle_measurements measure_at_current_cycle(struct verifier *v
336338
error_measurements.error.description = "solution did not complete within cycle limit";
337339
return error_measurements;
338340
}
341+
struct per_cycle_measurements m = {
342+
.cycles = (int)board->cycle,
343+
.area = used_area(board),
344+
.executed_instructions = 0,
345+
.maximum_absolute_arm_rotation = solution ? solution->maximum_absolute_arm_rotation : -1,
346+
.valid = true,
347+
};
339348
struct area_dimension dimensions[] = {
340349
// height
341350
{ 0, -1, INT32_MIN, INT32_MAX },
@@ -365,14 +374,13 @@ static struct per_cycle_measurements measure_at_current_cycle(struct verifier *v
365374
return error_measurements;
366375
}
367376
}
377+
if (!(a & REMOVED) && !(a & VAN_BERLO_ATOM)) {
378+
for (int j = 0; j < NUMBER_OF_ATOM_TYPES; ++j) {
379+
if (board->grid.atoms_at_positions[i].atom & ATOM_OF_TYPE(j))
380+
m.number_of_atoms[j]++;
381+
}
382+
}
368383
}
369-
struct per_cycle_measurements m = {
370-
.cycles = (int)board->cycle,
371-
.area = used_area(board),
372-
.executed_instructions = 0,
373-
.maximum_absolute_arm_rotation = solution ? solution->maximum_absolute_arm_rotation : -1,
374-
.valid = true,
375-
};
376384
for (int i = 0; i < NUMBER_OF_ATOM_TYPES; ++i)
377385
m.atom_grabs[i] = (int)board->atom_grabs[i];
378386
if (has_atoms) {
@@ -532,6 +540,20 @@ static int lookup_per_cycle_metric(struct per_cycle_measurements *measurements,
532540
}
533541
*error = (struct error){ .description = "unknown atom type" };
534542
return -1;
543+
} else if (!strcmp(metric, "number of atoms")) {
544+
int value = 0;
545+
for (int i = 0; i < NUMBER_OF_ATOM_TYPES; ++i)
546+
value += measurements->number_of_atoms[i];
547+
return value;
548+
} else if (!strncmp("number of atoms of type ", metric, strlen("number of atoms of type "))) {
549+
metric += strlen("number of atoms of type ");
550+
for (int i = 0; i < NUMBER_OF_ATOM_TYPES; ++i) {
551+
const char *name = name_for_atom_type(i);
552+
if (name && !strcmp(metric, name))
553+
return measurements->number_of_atoms[i];
554+
}
555+
*error = (struct error){ .description = "unknown atom type" };
556+
return -1;
535557
} else {
536558
*error = (struct error){ .description = "unknown metric" };
537559
return -1;

0 commit comments

Comments
 (0)