|
|
@@ -3,7 +3,6 @@ package fr.jaquin.bdlg.planner.domain;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.OptionalInt;
|
|
|
|
|
|
public class PlanningInput {
|
|
|
private ArrayList<VolonteerRaw> volonteerList;
|
|
|
@@ -12,17 +11,26 @@ public class PlanningInput {
|
|
|
|
|
|
private ArrayList<TimeslotRaw> timeslots;
|
|
|
|
|
|
- private ArrayList<Assignement> assignements;
|
|
|
+ private ArrayList<AssignementPair> assignements;
|
|
|
|
|
|
- private ArrayList<MealAssignement> mealAssignements;
|
|
|
+ private ArrayList<AssignementPair> mealAssignements;
|
|
|
|
|
|
private ArrayList<Skill> constraints;
|
|
|
|
|
|
private int currentMaxId = 1;
|
|
|
|
|
|
+ public PlanningInput() {
|
|
|
+ this.volonteerList = new ArrayList<VolonteerRaw>();
|
|
|
+ this.mealSlots = new ArrayList<MealSlot>();
|
|
|
+ this.timeslots = new ArrayList<TimeslotRaw>();
|
|
|
+ this.assignements = new ArrayList<AssignementPair>();
|
|
|
+ this.mealAssignements = new ArrayList<AssignementPair>();
|
|
|
+ this.constraints = new ArrayList<Skill>();
|
|
|
+ }
|
|
|
+
|
|
|
public PlanningInput(ArrayList<VolonteerRaw> volonteerList, ArrayList<MealSlot> mealSlots,
|
|
|
- ArrayList<TimeslotRaw> timeslots, ArrayList<Assignement> assignements,
|
|
|
- ArrayList<MealAssignement> mealAssignements) {
|
|
|
+ ArrayList<TimeslotRaw> timeslots, ArrayList<AssignementPair> assignements,
|
|
|
+ ArrayList<AssignementPair> mealAssignements) {
|
|
|
this.volonteerList = volonteerList;
|
|
|
this.mealSlots = mealSlots;
|
|
|
this.timeslots = timeslots;
|
|
|
@@ -30,27 +38,34 @@ public class PlanningInput {
|
|
|
this.mealAssignements = mealAssignements;
|
|
|
}
|
|
|
|
|
|
- private void addMissingAssigment(ArrayList<Timeslot> timeslots) {
|
|
|
+ private ArrayList<Assignement> addMissingAssigment(ArrayList<Assignement> assignements,
|
|
|
+ ArrayList<Timeslot> timeslots) {
|
|
|
for (Timeslot slot : timeslots) {
|
|
|
int minAssignement = slot.getMinAttendee();
|
|
|
Long existingAssignementCount = assignements.stream()
|
|
|
.filter(predicate -> predicate.getSlot().getId().equals(slot.getId())).count();
|
|
|
Long missingAssignementCount = minAssignement - existingAssignementCount;
|
|
|
- if (missingAssignementCount > 0) {
|
|
|
- this.assignements.add(new Assignement(this.currentMaxId, slot));
|
|
|
+
|
|
|
+ while (missingAssignementCount > 0) {
|
|
|
+ assignements.add(new Assignement(this.currentMaxId, slot));
|
|
|
this.currentMaxId++;
|
|
|
+ missingAssignementCount--;
|
|
|
}
|
|
|
}
|
|
|
+ return assignements;
|
|
|
}
|
|
|
|
|
|
- private void addMissingMealAssigment(ArrayList<Volonteer> volonteerList) {
|
|
|
+ private ArrayList<MealAssignement> addMissingMealAssigment(
|
|
|
+ ArrayList<MealAssignement> mealAssignements, ArrayList<Volonteer> volonteerList) {
|
|
|
for (Volonteer volonteer : volonteerList) {
|
|
|
Long missingAssignementCount = 1 - mealAssignements.stream()
|
|
|
.filter(predicate -> predicate.getVolonteer().getId().equals(volonteer.getId())).count();
|
|
|
- if (missingAssignementCount > 0) {
|
|
|
- this.mealAssignements.add(new MealAssignement(volonteer));
|
|
|
+ while (missingAssignementCount > 0) {
|
|
|
+ mealAssignements.add(new MealAssignement(volonteer));
|
|
|
+ missingAssignementCount--;
|
|
|
}
|
|
|
}
|
|
|
+ return mealAssignements;
|
|
|
}
|
|
|
|
|
|
private ArrayList<Timeslot> getMappedTimeslots(HashMap<Integer, Skill> skillsMap) {
|
|
|
@@ -60,8 +75,8 @@ public class PlanningInput {
|
|
|
HashSet<Skill> hardCompetencies = new HashSet<Skill>();
|
|
|
HashSet<Skill> softCompetencies = new HashSet<Skill>();
|
|
|
|
|
|
- for (int i = 0; i < timeslot.getRawSkills().length; i++) {
|
|
|
- Skill e = skillsMap.get(timeslot.getRawSkills()[i]);
|
|
|
+ for (int i = 0; i < timeslot.getSkillsId().length; i++) {
|
|
|
+ Skill e = skillsMap.get(timeslot.getSkillsId()[i]);
|
|
|
|
|
|
if (e.getIsPreference()) {
|
|
|
preferences.add(e);
|
|
|
@@ -73,9 +88,10 @@ public class PlanningInput {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Timeslot newTimeslot = new Timeslot(timeslot.getId(), timeslot.getStartTime(),
|
|
|
- timeslot.getStartTime(), softCompetencies, hardCompetencies, preferences,
|
|
|
- timeslot.getMinAttendee(), timeslot.getMaxAttendee());
|
|
|
+ Timeslot newTimeslot =
|
|
|
+ new Timeslot(timeslot.getId(), timeslot.getStartTime(), timeslot.getStartTime(),
|
|
|
+ softCompetencies, hardCompetencies, preferences, timeslot.getMinAttendee());
|
|
|
+
|
|
|
output.add(newTimeslot);
|
|
|
}
|
|
|
return output;
|
|
|
@@ -101,22 +117,7 @@ public class PlanningInput {
|
|
|
}
|
|
|
|
|
|
public Planning generatePlanningProblem() {
|
|
|
- // Fix null list ??
|
|
|
- if (this.assignements == null) {
|
|
|
- this.assignements = new ArrayList<Assignement>();
|
|
|
- }
|
|
|
- // Add ids to assignements that don't have any
|
|
|
- OptionalInt existingMaxId = this.assignements.stream().mapToInt(o -> o.getId()).max();
|
|
|
|
|
|
- if (existingMaxId.isPresent()) {
|
|
|
- this.currentMaxId = existingMaxId.getAsInt();
|
|
|
- }
|
|
|
- for (Assignement assignement : this.assignements) {
|
|
|
- if (assignement.getId() == 0) {
|
|
|
- assignement.setId(currentMaxId);
|
|
|
- this.currentMaxId++;
|
|
|
- }
|
|
|
- }
|
|
|
// Create skills map
|
|
|
HashMap<Integer, Skill> skillMap = new HashMap<Integer, Skill>();
|
|
|
if (this.constraints != null) {
|
|
|
@@ -126,13 +127,74 @@ public class PlanningInput {
|
|
|
}
|
|
|
// Map skills to timseslots
|
|
|
ArrayList<Timeslot> timeslots = this.getMappedTimeslots(skillMap);
|
|
|
- this.addMissingAssigment(timeslots);
|
|
|
+
|
|
|
+ // Create slots map
|
|
|
+ HashMap<String, Timeslot> slotMap = new HashMap<String, Timeslot>();
|
|
|
+ for (Timeslot v : timeslots) {
|
|
|
+ slotMap.put(v.getId(), v);
|
|
|
+ }
|
|
|
+
|
|
|
// Map skills to volonteer
|
|
|
ArrayList<Volonteer> volonteerList = this.getMappedVolonteers(skillMap);
|
|
|
- this.addMissingMealAssigment(volonteerList);
|
|
|
+
|
|
|
+ // Create skills map
|
|
|
+ HashMap<Long, Volonteer> volonteerMap = new HashMap<Long, Volonteer>();
|
|
|
+ for (Volonteer v : volonteerList) {
|
|
|
+ volonteerMap.put(v.getId(), v);
|
|
|
+ }
|
|
|
+ Volonteer volonteer;
|
|
|
+ Timeslot timeslot;
|
|
|
+ // Create Assignements Objects
|
|
|
+ ArrayList<Assignement> assignements = new ArrayList<Assignement>();
|
|
|
+ if (this.assignements != null) {
|
|
|
+ for (AssignementPair pair : this.assignements) {
|
|
|
+ if (volonteerMap.containsKey(pair.volonteerId)) {
|
|
|
+ volonteer = volonteerMap.get(pair.volonteerId);
|
|
|
+ } else {
|
|
|
+ volonteer = null;
|
|
|
+ }
|
|
|
+ if (slotMap.containsKey(pair.slotId)) {
|
|
|
+ timeslot = slotMap.get(pair.slotId);
|
|
|
+ } else {
|
|
|
+ timeslot = null;
|
|
|
+ }
|
|
|
+ if (volonteer == null || timeslot == null) {
|
|
|
+ throw new NullPointerException(
|
|
|
+ "Impossible to find the corresponding assignement object." + pair.slotId);
|
|
|
+ } else {
|
|
|
+ assignements.add(new Assignement(currentMaxId, timeslot, volonteer));
|
|
|
+ currentMaxId++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assignements = this.addMissingAssigment(assignements, timeslots);
|
|
|
+
|
|
|
+ // Create MealAssignements Objects
|
|
|
+ ArrayList<MealAssignement> mealAssignements = new ArrayList<MealAssignement>();
|
|
|
+ MealSlot slot;
|
|
|
+ if (this.mealAssignements != null) {
|
|
|
+ for (AssignementPair pair : this.mealAssignements) {
|
|
|
+ if (volonteerMap.containsKey(pair.volonteerId)) {
|
|
|
+ volonteer = volonteerMap.get(pair.volonteerId);
|
|
|
+ } else {
|
|
|
+ volonteer = null;
|
|
|
+ }
|
|
|
+ int idx = this.mealSlots.indexOf(new MealSlot(pair.slotId));
|
|
|
+ if (idx < 0 || volonteer == null) {
|
|
|
+ throw new NullPointerException(
|
|
|
+ "Impossible to find the corresponding assignement objects." + pair.slotId);
|
|
|
+ } else {
|
|
|
+ slot = this.mealSlots.get(idx);
|
|
|
+ mealAssignements.add(new MealAssignement(currentMaxId, slot, volonteer));
|
|
|
+ currentMaxId++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mealAssignements = addMissingMealAssigment(mealAssignements, volonteerList);
|
|
|
+
|
|
|
// Create Planning problem to be optimized
|
|
|
- Planning outPlanning = new Planning(volonteerList, this.mealSlots, timeslots, this.assignements,
|
|
|
- this.mealAssignements);
|
|
|
+ Planning outPlanning =
|
|
|
+ new Planning(volonteerList, this.mealSlots, timeslots, assignements, mealAssignements);
|
|
|
return outPlanning;
|
|
|
}
|
|
|
|
|
|
@@ -163,22 +225,35 @@ public class PlanningInput {
|
|
|
this.timeslots = timeslots;
|
|
|
}
|
|
|
|
|
|
- public ArrayList<Assignement> getAssignements() {
|
|
|
+ public ArrayList<AssignementPair> getAssignements() {
|
|
|
return this.assignements;
|
|
|
}
|
|
|
|
|
|
- public void setAssignements(ArrayList<Assignement> assignements) {
|
|
|
+ public void setAssignements(ArrayList<AssignementPair> assignements) {
|
|
|
this.assignements = assignements;
|
|
|
}
|
|
|
|
|
|
- public ArrayList<MealAssignement> getMealAssignements() {
|
|
|
+ public ArrayList<AssignementPair> getMealAssignements() {
|
|
|
return this.mealAssignements;
|
|
|
}
|
|
|
|
|
|
- public void setMealAssignements(ArrayList<MealAssignement> mealAssignements) {
|
|
|
+ public void setMealAssignements(ArrayList<AssignementPair> mealAssignements) {
|
|
|
this.mealAssignements = mealAssignements;
|
|
|
}
|
|
|
|
|
|
+ public ArrayList<Skill> getConstraints() {
|
|
|
+ return this.constraints;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setConstraints(ArrayList<Skill> constraints) {
|
|
|
+ this.constraints = constraints;
|
|
|
+ }
|
|
|
|
|
|
+ public int getCurrentMaxId() {
|
|
|
+ return this.currentMaxId;
|
|
|
+ }
|
|
|
|
|
|
+ public void setCurrentMaxId(int currentMaxId) {
|
|
|
+ this.currentMaxId = currentMaxId;
|
|
|
+ }
|
|
|
}
|