From c6d01fd8ca379fc5557e8ddf5841d7484f37eaa6 Mon Sep 17 00:00:00 2001 From: Rhizome Date: Mon, 8 Apr 2024 18:45:40 +0100 Subject: [PATCH] Rename allocations to assignments --- rotagen.c | 28 ++++++++++++++-------------- rotagen.h | 12 +++++++----- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/rotagen.c b/rotagen.c index 06a556e..b67daf4 100644 --- a/rotagen.c +++ b/rotagen.c @@ -90,34 +90,34 @@ void generate_rota(struct slot_result *rota_out) for (int slot = 0; slot < num_slots; ++slot) { do { for (int job = 0; job < num_jobs; ++job) { - struct allocation *allocation - = &rota_out[slot].allocations[job]; + struct assignment *assignment + = &rota_out[slot].assignments[job]; do { - allocation->slot = slot; - allocation->job = job; - allocation->person = rand() % num_people; - } while (!satisfies_allocation_constraints(allocation) - || previously_allocated(prev, allocation->person)); + assignment->slot = slot; + assignment->job = job; + assignment->person = rand() % num_people; + } while (!satisfies_assignment_constraints(assignment) + || previously_allocated(prev, assignment->person)); } } while (!satisfies_slot_constraints(&rota_out[slot])); for (int job = 0; job < num_jobs; ++job) - prev[job] = rota_out[slot].allocations[job].person; + prev[job] = rota_out[slot].assignments[job].person; } } -bool satisfies_allocation_constraints(const struct allocation *allocation) +bool satisfies_assignment_constraints(const struct assignment *assignment) { for (int i = 0; i < num_constraints; ++i) { - if (allocation->person != constraints[i].person) + if (assignment->person != constraints[i].person) continue; switch (constraints[i].type) { case JOB_EXEMPTION_CONSTRAINT: - if (allocation->job == constraints[i].object.job) + if (assignment->job == constraints[i].object.job) return false; break; case SLOT_EXEMPTION_CONSTRAINT: - if (allocation->slot == constraints[i].object.slot) + if (assignment->slot == constraints[i].object.slot) return false; break; default: @@ -144,7 +144,7 @@ bool satisfies_slot_constraints(const struct slot_result *result) { for (int i = 0; i < num_jobs; ++i) { for (int j = i + 1; j < num_jobs; ++j) { - if (result->allocations[i].person == result->allocations[j].person) + if (result->assignments[i].person == result->assignments[j].person) return false; } } @@ -159,7 +159,7 @@ void print_rota(const struct slot_result *rota) printf("%s\t%s\t\t%s\n", job == 0 ? slots[slot] : " ", jobs[job], - people[rota[slot].allocations[job].person]); + people[rota[slot].assignments[job].person]); } } printf("----------------------------------------\n"); diff --git a/rotagen.h b/rotagen.h index ff09fe3..582a022 100644 --- a/rotagen.h +++ b/rotagen.h @@ -19,20 +19,22 @@ struct constraint { } object; }; -struct allocation { +struct assignment { int person; int job; int slot; }; struct slot_result { - struct allocation allocations[MAX_JOBS]; + struct assignment assignments[MAX_JOBS]; }; + + void generate_rota(struct slot_result *rota_out); -void generate_allocation(int slot, int job, struct allocation *allocation_out); -bool satisfies_allocation_constraints(const struct allocation *allocation); -bool previously_allocated(int previous_allocations[MAX_JOBS], int person); +void generate_assignment(int slot, int job, struct assignment *assignment_out); +bool satisfies_assignment_constraints(const struct assignment *assignment); +bool previously_allocated(int previous_assignments[MAX_JOBS], int person); bool satisfies_slot_constraints(const struct slot_result *slot); void print_rota(const struct slot_result *rota);