Rename allocations to assignments

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

View File

@ -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");

View File

@ -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);