Amélioration de l'algo de recouvrement pour choisir aléatoirement l'action de recouvrement avec coût minimal. Permet de trouver des solutions pour toutes les probabilités d'absence à partir de 0.5. Début d'un fichier de résultats de simulations.

This commit is contained in:
Francois Berube\frabe 2018-04-12 21:13:04 -04:00
parent ca614425c1
commit 1c3f6b2b0b
4 changed files with 55 additions and 28 deletions

Binary file not shown.

View file

@ -10,7 +10,7 @@ package AbsenceSchedules;
* @author frabe
*/
public interface ParametersAbsencesSimulator {
public final double probPresence = 0.90;
public final double probPresence = 0.99;
public final double probReturn = 0.50;
public final int numberAbsenceSimulations = 1;
public final int numberAbsenceSimulations = 1000;
}

View file

@ -15,7 +15,7 @@ import java.util.PriorityQueue;
public class MainClass {
public static void main(String[] args) {
List<SchedulesArray> initialSchedulesArrayList = generateInitialSchedules();
List<BankAbsenceSchedules> listBankAbsenceSchedules = GenerateAbsencesSchedules(initialSchedulesArrayList);
@ -24,7 +24,6 @@ public class MainClass {
SchedulesWindows.ShowSolutionResultsFrame initialSchedulesViewer = new SchedulesWindows.ShowSolutionResultsFrame(bankRecoveredSchedulesOrderedByMeanCost);
}
private static List<SchedulesArray> generateInitialSchedules() {
@ -34,9 +33,9 @@ public class MainClass {
InitialSchedules.ParametersInitialSchedules myScheduleParameters = new InitialSchedules.ParametersInitialSchedules();
int minFullTimeEmployee = 5; //La solution avec 1 employes est trop lente
int minFullTimeEmployee = 2; //La solution avec 1 employes est trop lente
int maxFullTimeEmployee = 5; //C'est le max d'employes a temps plein pour la presente requiredWorkforce
int maxFullTimeEmployee = 9; //9 est le max d'employes a temps plein pour la presente requiredWorkforce
int simulationNumber = 1;
@ -116,7 +115,10 @@ public class MainClass {
RecoveredSchedulesArray recoveredSchedule = new RecoveredSchedulesArray(absenceSchedule);
listRecoveredSchedules.add(recoveredSchedule); // to be removed
bankRecoveredSimulations.addRecoveredSchedules(recoveredSchedule);
totalCostRecoveredSimulations += recoveredSchedule.totalScheduleCost;
if (recoveredSchedule.totalScheduleCost != Integer.MAX_VALUE){
totalCostRecoveredSimulations += recoveredSchedule.totalScheduleCost;
}
}
bankRecoveredSimulations.meanCostRecoveredSimulations = totalCostRecoveredSimulations / bankRecoveredSimulations.bankRecoveredSimulation.size();
bankRecoveredSchedulesOrderedByMeanCost.add(bankRecoveredSimulations);

View file

@ -31,20 +31,12 @@ public class RecoveredSchedulesArray extends SchedulesArray{
boolean[][] alreadyRecoveredWorkPeriodByPartTimeEmployees = new boolean[this.getNumberPartTimeEmployee()][remainingRecoveringAction];
boolean[][] alreadyRecoveredWorkPeriodByFullTimeEmployees = new boolean[this.getNumberFullTimeEmployee()][remainingRecoveringAction];
for (int i = 0 ; i < this.getNumberPartTimeEmployee() ; i++) {
Arrays.fill(alreadyRecoveredWorkPeriodByPartTimeEmployees[i], Boolean.FALSE);
}
for (int i = 0 ; i < this.getNumberFullTimeEmployee() ; i++) {
Arrays.fill(alreadyRecoveredWorkPeriodByFullTimeEmployees[i], Boolean.FALSE);
}
initializeRecoveredWorkPeriodMatrix (alreadyRecoveredWorkPeriodByPartTimeEmployees, alreadyRecoveredWorkPeriodByFullTimeEmployees);
RecoveringActionComparator recoveringActionCostComparator = new RecoveringActionComparator();
ScheduleState currentScheduleState = new ScheduleState(currentRecoveredScheduleOfPartTimeEmployees, currentRecoveredScheduleOfFullTimeEmployees,
ScheduleState initialScheduleState = new ScheduleState(currentRecoveredScheduleOfPartTimeEmployees, currentRecoveredScheduleOfFullTimeEmployees,
remainingRecoveringAction);
List< ScheduleState > scheduleStatesNodes = new ArrayList<>();
scheduleStatesNodes.add(currentScheduleState);
RecoveringAction currentRecoveringAction;
ScheduleState currentScheduleState = null;
boolean isSolutionFound = false;
boolean isAbsenceFound = remainingRecoveringAction != 0;
@ -56,8 +48,13 @@ public class RecoveredSchedulesArray extends SchedulesArray{
getPossibleRecoveringActions(currentRecoveredScheduleOfPartTimeEmployees, currentRecoveredScheduleOfFullTimeEmployees,
alreadyRecoveredWorkPeriodByPartTimeEmployees, alreadyRecoveredWorkPeriodByFullTimeEmployees, remainingRecoveringAction, recoveringActionCostComparator);
if (recoveringActionsOrderedByCost.size() > 0){
// On prend l'action avec un cout minimal
currentRecoveringAction = recoveringActionsOrderedByCost.poll();
RecoveringAction currentRecoveringAction;
if (recoveringActionsOrderedByCost.size() == 1){
currentRecoveringAction = recoveringActionsOrderedByCost.poll();
} else {
// On prend une des actions ayant un cout minimal.
currentRecoveringAction = chooseMinimalCostRecoveringActionRandomly(recoveringActionsOrderedByCost);
}
boolean[][] recoveredScheduleOfPartTimeEmployeesAfterAction = this.getDeepCopyEmployeesSchedules(currentRecoveredScheduleOfPartTimeEmployees);
boolean[][] recoveredScheduleOfFullTimeEmployeesAfterAction = this.getDeepCopyEmployeesSchedules(currentRecoveredScheduleOfFullTimeEmployees);
@ -70,22 +67,21 @@ public class RecoveredSchedulesArray extends SchedulesArray{
alreadyRecoveredWorkPeriodByPartTimeEmployees[currentRecoveringAction.employee][remainingRecoveringAction-1] = true;
}
ScheduleState scheduleState = new ScheduleState(recoveredScheduleOfPartTimeEmployeesAfterAction, recoveredScheduleOfFullTimeEmployeesAfterAction,
currentScheduleState = new ScheduleState(recoveredScheduleOfPartTimeEmployeesAfterAction, recoveredScheduleOfFullTimeEmployeesAfterAction,
remainingRecoveringAction - 1);
scheduleStatesNodes.add(scheduleState);
} else if (numberBackTrack > this.getNumberFullTimeEmployee() + this.getNumberPartTimeEmployee()) {
//Si le nombre de retour au sommet atteint le nombre total d'employes, la solution n'est pas trouvee par cette methode, il faudrait faire une fouille complete.
//Si le nombre de retour au sommet atteint le nombre total d'employes, on reinitialize les matrices de noeuds visites.
initializeRecoveredWorkPeriodMatrix (alreadyRecoveredWorkPeriodByPartTimeEmployees, alreadyRecoveredWorkPeriodByFullTimeEmployees);
} else if (numberBackTrack > 10000) {
isSolutionFound = false;
System.out.println("No solution Found");
break;
} else{
// Lorsqu'on est bloque dans l'arbre de recherche, on revient au sommet de l'arbre et on recommence une nouvelle fouille.
currentScheduleState = scheduleStatesNodes.get(0);
scheduleStatesNodes.clear();
scheduleStatesNodes.add(currentScheduleState);
numberBackTrack++;
currentScheduleState = initialScheduleState;
remainingRecoveringAction = currentScheduleState.remainingRecoveringAction;
numberBackTrack++;
}
@ -93,7 +89,6 @@ public class RecoveredSchedulesArray extends SchedulesArray{
isSolutionFound = true;
}
currentScheduleState = scheduleStatesNodes.get(scheduleStatesNodes.size()-1);
currentRecoveredScheduleOfPartTimeEmployees = currentScheduleState.currentRecoveredScheduleOfPartTimeEmployees;
currentRecoveredScheduleOfFullTimeEmployees = currentScheduleState.currentRecoveredScheduleOfFullTimeEmployees;
remainingRecoveringAction = currentScheduleState.remainingRecoveringAction;
@ -111,6 +106,36 @@ public class RecoveredSchedulesArray extends SchedulesArray{
}
private void initializeRecoveredWorkPeriodMatrix (boolean[][] alreadyRecoveredWorkPeriodByPartTimeEmployees, boolean[][] alreadyRecoveredWorkPeriodByFullTimeEmployees){
for (int i = 0 ; i < this.getNumberPartTimeEmployee() ; i++) {
Arrays.fill(alreadyRecoveredWorkPeriodByPartTimeEmployees[i], Boolean.FALSE);
}
for (int i = 0 ; i < this.getNumberFullTimeEmployee() ; i++) {
Arrays.fill(alreadyRecoveredWorkPeriodByFullTimeEmployees[i], Boolean.FALSE);
}
}
private RecoveringAction chooseMinimalCostRecoveringActionRandomly(PriorityQueue<RecoveringAction> recoveringActionsOrderedByCost){
Random rand = new Random();
RecoveringAction minimalCurrentRecoveringAction = recoveringActionsOrderedByCost.peek();
int minimalCost = minimalCurrentRecoveringAction.recoveringActionCost;
List<RecoveringAction> minimalCostRecoveringActions = new ArrayList<>();
RecoveringAction currentRecoveringAction = recoveringActionsOrderedByCost.poll();
while (currentRecoveringAction.recoveringActionCost == minimalCost)
{
minimalCostRecoveringActions.add(currentRecoveringAction);
if (recoveringActionsOrderedByCost.isEmpty()) {
break;
}
currentRecoveringAction = recoveringActionsOrderedByCost.poll();
}
int index = rand.nextInt(minimalCostRecoveringActions.size());
return minimalCostRecoveringActions.get(index);
}
private PriorityQueue<RecoveringAction> getPossibleRecoveringActions(boolean[][] currentPartTimeSchedule, boolean[][] currentFullTimeSchedule,
boolean[][] alreadyRecoveredWorkPeriodByPartTimeEmployees, boolean[][] alreadyRecoveredWorkPeriodByFullTimeEmployees,
int remainingRecoveringAction, Comparator recoveringActionCostComparator) {