#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX_DUTY_CENTERS 12
#define MAX_MOUNTH 31
struct Duty {
char center_name[6];
unsigned short int number_of_duties;
unsigned short int number_of_helpers;
float last_delta;
unsigned short int actual_duty;
unsigned short int busy;
};
struct Dates {
unsigned short int date;
char center_name[6];
unsigned short int weekend;
};
void calendar_grid_duty(struct Duty *List_of_Duty, struct Dates *Duty_date, unsigned short int tmp_cntr, unsigned short int tmp_date);
void calendar_grid_helpers(struct Duty *List_of_Duty, struct Dates *Duty_date, unsigned short int tmp_cntr, unsigned short int tmp_date);
int main()
{
struct Duty List_of_Duty[MAX_DUTY_CENTERS];
struct Dates Duty_date[MAX_MOUNTH];
FILE* Centers = fopen("C:\\Projects\\Sheduler\\Center_list.txt", "r");
FILE* Calendar = fopen("C:\\Projects\\Sheduler\\bin\\Debug\\Calendar.txt", "r");
FILE* Duty_list = fopen("C:\\Projects\\Sheduler\\bin\\Debug\\Duty_list.txt", "w");
int tmp_cntr = 0;
int tmp_date = 0;
while(!feof(Centers)){
fscanf(Centers, "%s%hu%hu%f%hu%hu",
List_of_Duty[tmp_cntr].center_name,
&(List_of_Duty[tmp_cntr].number_of_duties),
&(List_of_Duty[tmp_cntr].number_of_helpers),
&(List_of_Duty[tmp_cntr].last_delta),
&(List_of_Duty[tmp_cntr].actual_duty),
&(List_of_Duty[tmp_cntr].busy));
tmp_cntr++;
}
while(!feof(Calendar)){
fscanf(Calendar, "%hu%hu",
&(Duty_date[tmp_date].date),
&(Duty_date[tmp_date].weekend));
tmp_date++;
}
////-----------------------CHECK CENTER READ-------------------------
printf("tmp_center = %d\n", tmp_cntr);
// for(int i = 0; i < tmp_cntr; i++){
// printf("CenterName = %s\nDuties = %d\nHelpers = %d\nDelta = %.4f\nActual duty = %hu\n\n",
// List_of_Duty[i].center_name,
// List_of_Duty[i].number_of_duties,
// List_of_Duty[i].number_of_helpers,
// List_of_Duty[i].last_delta,
// List_of_Duty[i].actual_duty);
// }
//----------------------------CHECK DATE READ------------------------
printf("tmp_date = %d\n", tmp_date);
//
// for(int j = 0; j < tmp_date; j++){
// printf("Date = %u W: %d Center: %s\n",
// Duty_date[j].date,
// Duty_date[j].weekend,
// Duty_date[j].center_name);
// }
calendar_grid_duty(List_of_Duty, Duty_date, tmp_cntr, tmp_date);
// calendar_grid_helpers(List_of_Duty, Duty_date, tmp_cntr, tmp_date);
}
void calendar_grid_duty(struct Duty *List_of_Duty, struct Dates *Duty_date, unsigned short int tmp_cntr, unsigned short int tmp_date){
//---------CALENDAR GRID DISTRIBUTION----(FOR "MAX DAYS" LEIGHT)----------------------------------
//-----Initial weights 1 \ n are initialized, where n is the number of attendants-----------------
for(int i = 0; i < tmp_cntr; i++){
List_of_Duty[i].actual_duty = 1;
List_of_Duty[i].last_delta = List_of_Duty[i].actual_duty / (float)List_of_Duty[i].number_of_duties;
printf("Fist %hu center delta value = %.4f and factic: %hu\n", i+1, List_of_Duty[i].last_delta, List_of_Duty[i].actual_duty);
}
float tmp_delta = List_of_Duty[0].last_delta;
int nowID;
for(int i = 0; i < tmp_date; i++){
tmp_delta = List_of_Duty[0].last_delta;
for(int j = 0; j < tmp_cntr; j++){
if(List_of_Duty[j].busy != 0){
continue;
} else
if(List_of_Duty[j].last_delta <= tmp_delta){
nowID = j;
tmp_delta = List_of_Duty[j].last_delta;
}
}
memcpy(Duty_date[i].center_name, List_of_Duty[nowID].center_name, sizeof(Duty_date[i].center_name));
List_of_Duty[nowID].actual_duty++;
List_of_Duty[nowID].last_delta = (float)List_of_Duty[nowID].actual_duty / (float)List_of_Duty[nowID].number_of_helpers;
List_of_Duty[nowID].busy = 1;
for(int k = 0; k < tmp_cntr; k++){
if(k == nowID){
continue;
} else {
List_of_Duty[k].busy = 0;}
}
strcm
for(int s = 0; s < tmp_cntr; s++){
printf("%d center have delta = %f\n", s+1, List_of_Duty[s].last_delta);
}
printf("\n");
}
for(int i = 0; i < tmp_cntr; i++){
printf("Second %hu center delta value = %.4f and factic: %hu\n", i+1, List_of_Duty[i].last_delta, List_of_Duty[i].actual_duty);
}
printf("Duty men:\n");
for(int i = 0; i < tmp_cntr; i++){
printf("%6s\t", List_of_Duty[i].center_name);
for(int j = 0; j < tmp_date; j++){
if((strcmp(List_of_Duty[i].center_name, Duty_date[j].center_name)) == 0){
printf("%hu ", Duty_date[j].date);
}
}
printf("\n");
}
printf("\n");
}
printf("Helpers mens:\n");
for(int i = 0; i < tmp_cntr; i++){
printf("%6s\t", List_of_Duty[i].center_name);
for(int j = 0; j < tmp_date; j++){
if((strcmp(List_of_Duty[i].center_name, Duty_date[j].center_name)) == 0){
printf("%hu ", Duty_date[j].date);
}
}
printf("\n");
}
}