/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ScheduleUtil;

import InitialSchedules.*;
import jdistlib.rng.RandomEngine;
import org.chocosolver.solver.Solution;



/**
 *
 * @author frabe
 */
public class SchedulesArray {
    
    protected int[][] PartTimeSchedules;
    protected int[][] FullTimeSchedules;
    protected int[] employeesPerWorkPeriod;
    protected int[] workingPeriodsPerPartTimeEmployees;
    protected int[] workingPeriodsPerFullTimeEmployees;
    protected int maxPartTimeEmployee;
    protected int maxFullTimeEmployee;
    protected int workPeriodsPerSchedule;
    protected int workPeriodsPerDay;
    protected int daysPerSchedule;
    protected ModelInitialSchedules myModelInitialSchedules;
    
    protected SchedulesArray() {
        
    }
    
    // Constructeur Copie
    protected SchedulesArray(SchedulesArray myScheduleArray) {
        
        this.maxPartTimeEmployee = myScheduleArray.maxPartTimeEmployee;
        this.maxFullTimeEmployee = myScheduleArray.maxFullTimeEmployee;
        this.workPeriodsPerSchedule = myScheduleArray.workPeriodsPerSchedule;
        this.workPeriodsPerDay = myScheduleArray.workPeriodsPerDay;
        this.daysPerSchedule = myScheduleArray.daysPerSchedule;
        this.myModelInitialSchedules = myScheduleArray.myModelInitialSchedules;
        
        this.PartTimeSchedules = new int[this.maxPartTimeEmployee][this.workPeriodsPerSchedule];
        this.FullTimeSchedules = new int[this.maxFullTimeEmployee][this.workPeriodsPerSchedule];
        for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) {
            for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) {
                this.PartTimeSchedules[employee][workPeriod] = myScheduleArray.PartTimeSchedules[employee][workPeriod];
            }
        }

        for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) {
            for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) {
                this.FullTimeSchedules[employee][workPeriod] = myScheduleArray.FullTimeSchedules[employee][workPeriod];
            }
        }
        
        this.employeesPerWorkPeriod = new int[this.workPeriodsPerSchedule];
        this.workingPeriodsPerPartTimeEmployees = new int[this.maxPartTimeEmployee];
        this.workingPeriodsPerFullTimeEmployees = new int[this.maxFullTimeEmployee];
        
        updateEmployeesPerWorkPeriod();
        updateWorkingPeriodsPerPartTimeEmployees();
        updateWorkingPeriodsPerFullTimeEmployees();
        
    }
    
    public SchedulesArray(ModelInitialSchedules m, Solution s) {
        this.myModelInitialSchedules = m;
        Solution mySolution = s;
        this.maxPartTimeEmployee = myModelInitialSchedules.maxPartTimeEmployee;
        this.maxFullTimeEmployee = myModelInitialSchedules.maxFullTimeEmployee;
        this.workPeriodsPerSchedule = myModelInitialSchedules.myScheduleParameters.workPeriodsPerSchedule;
        this.workPeriodsPerDay = myModelInitialSchedules.myScheduleParameters.workPeriodsPerDay;
        this.daysPerSchedule = myModelInitialSchedules.myScheduleParameters.daysPerSchedule;
        
        this.PartTimeSchedules = new int[this.maxPartTimeEmployee][this.workPeriodsPerSchedule];
        this.FullTimeSchedules = new int[this.maxFullTimeEmployee][this.workPeriodsPerSchedule];
        for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) {
            for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) {
                this.PartTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfPartTimeEmployees[employee][workPeriod]);
            }
        }

        for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) {
            for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) {
                this.FullTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfFullTimeEmployees[employee][workPeriod]);
            }
        }
        
        this.employeesPerWorkPeriod = new int[this.workPeriodsPerSchedule];
        this.workingPeriodsPerPartTimeEmployees = new int[this.maxPartTimeEmployee];
        this.workingPeriodsPerFullTimeEmployees = new int[this.maxFullTimeEmployee];
        
        updateEmployeesPerWorkPeriod();
        updateWorkingPeriodsPerPartTimeEmployees();
        updateWorkingPeriodsPerFullTimeEmployees();

    }
    
    protected void updateEmployeesPerWorkPeriod() {
        
        for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) {
            this.employeesPerWorkPeriod[workPeriod] = 0;
            for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) {
                this.employeesPerWorkPeriod[workPeriod] += this.PartTimeSchedules[employee][workPeriod];
            }
            for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) {
                this.employeesPerWorkPeriod[workPeriod] += this.FullTimeSchedules[employee][workPeriod];
            }
        }
    }
    
    protected void updateWorkingPeriodsPerPartTimeEmployees() {
        
        for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) {
            this.workingPeriodsPerPartTimeEmployees[employee] = 0;
            for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) {
                this.workingPeriodsPerPartTimeEmployees[employee] += this.PartTimeSchedules[employee][workPeriod];
            }
        }
    }
    
    protected void updateWorkingPeriodsPerFullTimeEmployees() {
        
        for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) {
            this.workingPeriodsPerFullTimeEmployees[employee] = 0;
            for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) {
                this.workingPeriodsPerFullTimeEmployees[employee] += this.FullTimeSchedules[employee][workPeriod];
            }
        }
    }
    
    public int getMaxFullTimeEmployee() {
        return maxFullTimeEmployee;
    }

    public int getMaxPartTimeEmployee() {
        return maxPartTimeEmployee;
    }

    public int getWorkPeriodsPerSchedule() {
        return workPeriodsPerSchedule;
    }
    
    public int getDaysPerSchedule() {
        return daysPerSchedule;
    }
    
    public int getWorkPeriodPerDay() {
        return workPeriodsPerDay;
    }

    public int[][] getFullTimeSchedules() {
        return FullTimeSchedules;
    }

    public int[][] getPartTimeSchedules() {
        return PartTimeSchedules;
    }
    
    public boolean isPartTimeEmployeeWorking(int employee, int workPeriod) {
        return PartTimeSchedules[employee][workPeriod] == 1;
    }
    
    public boolean isFullTimeEmployeeWorking(int employee, int workPeriod) {
        return FullTimeSchedules[employee][workPeriod] == 1;
    }
    
    public int getRequiredWorkForce(int workPeriod) {
        return myModelInitialSchedules.myScheduleParameters.requiredWorkforce[workPeriod];
    }
    
    public int getEmployeesPerWorkPeriod(int workPeriod) {
        return employeesPerWorkPeriod[workPeriod];
    }
    
    public int getWorkingPeriodsPerPartTimeEmployees(int employee) {
        return workingPeriodsPerPartTimeEmployees[employee];
    }
    
    public int getWorkingPeriodsPerFullTimeEmployees(int employee) {
        return workingPeriodsPerFullTimeEmployees[employee];
    }
}
