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

/**
 *
 * @author frabe
 */
public class PartTimeEmployeeScheduleArray {
    public int initialScheduleSolutionNumber;
    public final boolean[][] partTimeSchedules;
    private final ParametersInitialSchedules myParametersInitialSchedules;
    
    public PartTimeEmployeeScheduleArray(ModelPartTimeEmployeesInitialSchedules m, Solution s) {
        this.myParametersInitialSchedules = m.myScheduleParameters;

        this.partTimeSchedules = new boolean[getNumberOfFullTimeEmployees(s, m)][myParametersInitialSchedules.getWorkPeriodsPerSchedule()];
        
        int partTimeEmployee = 0;
        for (int i = 0; i < m.maxPartTimeEmployee; i++) {
            if (isPartTimeEmployeeActive (i, s, m)) {
                for (int workPeriod = 0; workPeriod < myParametersInitialSchedules.getWorkPeriodsPerSchedule(); workPeriod++) {
                    this.partTimeSchedules[partTimeEmployee][workPeriod] = s.getIntVal(m.workPeriodsSchedulesOfPartTimeEmployees[i][workPeriod]) == 1;
                }
                partTimeEmployee++;
            }
        }
        
    }
    
    private int getNumberOfFullTimeEmployees( Solution s, ModelPartTimeEmployeesInitialSchedules m ) {
        int numberPartTimeEmployee = 0;
        for (int employee = 0; employee < m.maxPartTimeEmployee; employee++) {
            if (isPartTimeEmployeeActive (employee, s, m)) {
                numberPartTimeEmployee++;
            }
        }
        return numberPartTimeEmployee;
    }
    
    private boolean isPartTimeEmployeeActive ( int employee, Solution s, ModelPartTimeEmployeesInitialSchedules m ) {
        int workPeriod = 0;
        while (workPeriod < myParametersInitialSchedules.getWorkPeriodsPerSchedule()) {
            if (s.getIntVal(m.workPeriodsSchedulesOfPartTimeEmployees[employee][workPeriod]) == 1){
                return true;
            }
            workPeriod++;
        }
        return false;
    }
    
    public int getNumberPartTimeEmployee() {
        return this.partTimeSchedules.length;
    }
}
