/*
 * 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.ModelFullTimeEmployeesInitialSchedules;
import InitialSchedules.ParametersInitialSchedules;
import org.chocosolver.solver.Solution;

/**
 *
 * @author frabe
 */
public class FullTimeEmployeeScheduleArray {
    public int initialScheduleSolutionNumber;
    public final boolean[][] fullTimeSchedules;
    final ParametersInitialSchedules myParametersInitialSchedules;
    
    public FullTimeEmployeeScheduleArray(ModelFullTimeEmployeesInitialSchedules m, Solution s) {
        this.myParametersInitialSchedules = m.myScheduleParameters;

        this.fullTimeSchedules = new boolean[getNumberOfFullTimeEmployees(s, m)][myParametersInitialSchedules.getWorkPeriodsPerSchedule()];
        
        int fullTimeEmployee = 0;
        for (int i = 0; i < m.numberOfFullTimeEmployees; i++) {
            if (isFullTimeEmployeeActive (i, s, m)) {
                for (int workPeriod = 0; workPeriod < myParametersInitialSchedules.getWorkPeriodsPerSchedule(); workPeriod++) {
                    this.fullTimeSchedules[fullTimeEmployee][workPeriod] = s.getIntVal(m.workPeriodsSchedulesOfFullTimeEmployees[i][workPeriod]) == 1;
                }
                fullTimeEmployee++;
            }
        }
        
    }
    
    private int getNumberOfFullTimeEmployees( Solution s, ModelFullTimeEmployeesInitialSchedules m ) {
        int numberFullTimeEmployee = 0;
        for (int employee = 0; employee < m.numberOfFullTimeEmployees; employee++) {
            if (isFullTimeEmployeeActive (employee, s, m)) {
                numberFullTimeEmployee++;
            }
        }
        return numberFullTimeEmployee;
    }
        
    private boolean isFullTimeEmployeeActive ( int employee, Solution s, ModelFullTimeEmployeesInitialSchedules m ) {
        int workPeriod = 0;
        while (workPeriod < myParametersInitialSchedules.getWorkPeriodsPerSchedule()) {
            if (s.getIntVal(m.workPeriodsSchedulesOfFullTimeEmployees[employee][workPeriod]) == 1){
                return true;
            }
            workPeriod++;
        }
        return false;
    }
    
    public int getEmployeesWorkingPerWorkPeriod(int workPeriod) {
        int employeesWorking = 0;
        for (int employee = 0; employee < this.getNumberFullTimeEmployee(); employee++) {
            if (this.fullTimeSchedules[employee][workPeriod]) {employeesWorking += 1;}
        }
        return employeesWorking;
    }

    private int getNumberFullTimeEmployee() {
        return this.fullTimeSchedules.length;
    }
}
