Only allocate someone if they weren't allocated the previous day

This commit is contained in:
Rhizome 2024-04-08 18:45:40 +01:00
parent e20c3167e9
commit 05b6c54895
2 changed files with 25 additions and 11 deletions

View File

@ -83,23 +83,27 @@ int main(void)
void generate_rota(struct slot_result *rota_out)
{
int prev[MAX_JOBS];
for (int job = 0; job < num_jobs; ++job)
prev[job] = num_people;
for (int slot = 0; slot < num_slots; ++slot) {
do {
for (int j = 0; j < num_jobs; ++j) {
struct allocation *allocation = &rota_out[slot].allocations[j];
for (int job = 0; job < num_jobs; ++job) {
struct allocation *allocation
= &rota_out[slot].allocations[job];
do {
generate_allocation(slot, j, allocation);
} while (!satisfies_allocation_constraints(allocation));
allocation->slot = slot;
allocation->job = job;
allocation->person = rand() % num_people;
} while (!satisfies_allocation_constraints(allocation)
|| previously_allocated(prev, allocation->person));
}
} while (!satisfies_slot_constraints(&rota_out[slot]));
}
}
void generate_allocation(int slot, int job, struct allocation *allocation_out)
{
allocation_out->slot = slot;
allocation_out->job = job;
allocation_out->person = rand() % num_people;
for (int job = 0; job < num_jobs; ++job)
prev[job] = rota_out[slot].allocations[job].person;
}
}
bool satisfies_allocation_constraints(const struct allocation *allocation)
@ -127,6 +131,15 @@ bool satisfies_allocation_constraints(const struct allocation *allocation)
return true;
}
bool previously_allocated(int prev[MAX_JOBS], int person)
{
for (int job = 0; job < num_jobs; ++job) {
if (prev[job] == person)
return true;
}
return false;
}
bool satisfies_slot_constraints(const struct slot_result *result)
{
for (int i = 0; i < num_jobs; ++i) {

View File

@ -32,6 +32,7 @@ struct slot_result {
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);
bool satisfies_slot_constraints(const struct slot_result *slot);
void print_rota(const struct slot_result *rota);