Skip to content

Commit

Permalink
conf scheduling: talkTypeSet on timeslot and room
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Mar 3, 2018
1 parent 5ae79c9 commit 52011af
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 11 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -24,8 +24,8 @@ public class Room extends AbstractPersistable {

private String name;

private Set<String> talkTypeSet;
private Set<Timeslot> unavailableTimeslotSet;

private Set<String> tagSet;

public Room() {
Expand Down Expand Up @@ -56,6 +56,14 @@ public void setName(String name) {
this.name = name;
}

public Set<String> getTalkTypeSet() {
return talkTypeSet;
}

public void setTalkTypeSet(Set<String> talkTypeSet) {
this.talkTypeSet = talkTypeSet;
}

public Set<Timeslot> getUnavailableTimeslotSet() {
return unavailableTimeslotSet;
}
Expand Down
Expand Up @@ -28,8 +28,8 @@ public class Timeslot extends AbstractPersistable {

private LocalDateTime startDateTime;
private LocalDateTime endDateTime;
private Set<String> talkTypeSet;

private Set<String> talkTypeSet;
private Set<String> tagSet;

public Timeslot() {
Expand Down
Expand Up @@ -71,7 +71,6 @@ public static void main(String[] args) {

private static final String LAB_TALK_TYPE = "Lab";
private static final String BREAKOUT_TALK_TYPE = "Breakout";
private static final String LAB_ROOM_TAG = "Lab_room";

private final LocalDate timeslotFirstDay = LocalDate.of(2018, 10, 1);

Expand Down Expand Up @@ -296,17 +295,20 @@ private void createRoomList(ConferenceSolution solution, int roomListSize) {
Room room = new Room();
room.setId((long) i);
room.setName("R " + ((i / roomsPerFloor * 100) + (i % roomsPerFloor) + 1));
LinkedHashSet<Timeslot> unavailableTimeslotSet = new LinkedHashSet<>();
Set<String> tagSet = new LinkedHashSet<>(roomTagProbabilityList.size());
Set<String> talkTypeSet = new LinkedHashSet<>();
Set<Timeslot> unavailableTimeslotSet = new LinkedHashSet<>();
if (i % 5 == 4) {
tagSet.add(LAB_ROOM_TAG);
talkTypeSet.add(LAB_TALK_TYPE);
unavailableTimeslotSet.addAll(solution.getTimeslotList().stream()
.filter(timeslot -> !timeslot.getTalkTypeSet().contains(LAB_TALK_TYPE)).collect(Collectors.toList()));
} else {
talkTypeSet.add(BREAKOUT_TALK_TYPE);
unavailableTimeslotSet.addAll(solution.getTimeslotList().stream()
.filter(timeslot -> timeslot.getTalkTypeSet().contains(LAB_TALK_TYPE)).collect(Collectors.toList()));
}
room.setTalkTypeSet(talkTypeSet);
room.setUnavailableTimeslotSet(unavailableTimeslotSet);
Set<String> tagSet = new LinkedHashSet<>(roomTagProbabilityList.size());
for (Pair<String, Double> roomTagProbability : roomTagProbabilityList) {
if (i == 0 || i == 4 || random.nextDouble() < roomTagProbability.getValue()) {
tagSet.add(roomTagProbability.getKey());
Expand Down Expand Up @@ -432,11 +434,7 @@ private void createTalkList(ConferenceSolution solution, int talkListSize) {
talk.setPreferredTimeslotTagSet(new LinkedHashSet<>());
talk.setProhibitedTimeslotTagSet(new LinkedHashSet<>());
talk.setUndesiredTimeslotTagSet(new LinkedHashSet<>());
Set<String> requiredRoomTagSet = new LinkedHashSet<>();
if (i < labTalkCount) {
requiredRoomTagSet.add(LAB_ROOM_TAG);
}
talk.setRequiredRoomTagSet(requiredRoomTagSet);
talk.setRequiredRoomTagSet(new LinkedHashSet<>());
talk.setPreferredRoomTagSet(new LinkedHashSet<>());
talk.setProhibitedRoomTagSet(new LinkedHashSet<>());
talk.setUndesiredRoomTagSet(new LinkedHashSet<>());
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
Expand All @@ -42,6 +43,7 @@
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -309,9 +311,11 @@ private void readRoomList() {
nextRow(false);
readHeaderCell("");
readHeaderCell("");
readHeaderCell("");
readTimeslotDaysHeaders();
nextRow(false);
readHeaderCell("Name");
readHeaderCell("Talk types");
readHeaderCell("Tags");
readTimeslotHoursHeaders();
List<Room> roomList = new ArrayList<>(currentSheet.getLastRowNum() - 1);
Expand All @@ -324,6 +328,21 @@ private void readRoomList() {
throw new IllegalStateException(currentPosition() + ": The room name (" + room.getName()
+ ") must match to the regular expression (" + VALID_NAME_PATTERN + ").");
}

room.setTalkTypeSet(Arrays.stream(nextStringCell().getStringCellValue().split(", "))
.filter(talkType -> !talkType.isEmpty()).collect(toCollection(LinkedHashSet::new)));
for (String talkType : room.getTalkTypeSet()) {
if (!totalTalkTypeSet.contains(talkType)) {
throw new IllegalStateException(currentPosition()
+ ": The room (" + room + ")'s talkType (" + talkType
+ ") does not exist in the talk types (" + totalTalkTypeSet
+ ") of the other sheet (Timeslots).");
}
}
if (room.getTalkTypeSet().isEmpty()) {
room.setTalkTypeSet(new LinkedHashSet<>(totalTalkTypeSet));
}

room.setTagSet(Arrays.stream(nextStringCell().getStringCellValue().split(", "))
.filter(tag -> !tag.isEmpty()).collect(toCollection(LinkedHashSet::new)));
for (String tag : room.getTagSet()) {
Expand Down Expand Up @@ -819,6 +838,7 @@ public Workbook write() {
writeRoomList();
writeSpeakerList();
writeTalkList();
writeScoreView();
writeRoomsView();
writeSpeakersView();
writeThemeTracksView();
Expand Down Expand Up @@ -963,14 +983,17 @@ private void writeRoomList() {
nextRow();
nextHeaderCell("");
nextHeaderCell("");
nextHeaderCell("");
writeTimeslotDaysHeaders();
nextRow();
nextHeaderCell("Name");
nextHeaderCell("Talk types");
nextHeaderCell("Tags");
writeTimeslotHoursHeaders();
for (Room room : solution.getRoomList()) {
nextRow();
nextCell().setCellValue(room.getName());
nextCell().setCellValue(String.join(", ", room.getTalkTypeSet()));
nextCell().setCellValue(String.join(", ", room.getTagSet()));
for (Timeslot timeslot : solution.getTimeslotList()) {
nextCell(room.getUnavailableTimeslotSet().contains(timeslot) ? unavailableStyle : defaultStyle)
Expand Down Expand Up @@ -1080,6 +1103,54 @@ private void writeTalkList() {
autoSizeColumnsWithHeader();
}

private void writeScoreView() {
nextSheet("Score view", 1, 1, true);
nextRow();
nextHeaderCell("Score");
nextCell().setCellValue(solution.getScore() == null ? "Not yet solved" : solution.getScore().toShortString());
nextRow();
nextRow();
nextHeaderCell("Talk type");
nextHeaderCell("Count");
nextHeaderCell("Usable timeslots");
nextHeaderCell("Usable rooms");
nextHeaderCell("Usable sessions");

Map<String, Long> talkTypeToCountMap = solution.getTalkList().stream()
.collect(groupingBy(Talk::getTalkType, LinkedHashMap::new, counting()));
for (Map.Entry<String, Long> entry : talkTypeToCountMap.entrySet()) {
String talkType = entry.getKey();
long count = entry.getValue();
nextRow();
nextHeaderCell(talkType);
nextCell().setCellValue(count);
List<Timeslot> timeslotList = solution.getTimeslotList().stream()
.filter(timeslot -> timeslot.getTalkTypeSet().contains(talkType))
.collect(toList());
int timeslotListSize = timeslotList.size();
nextCell().setCellValue(timeslotListSize);
List<Room> roomList = solution.getRoomList().stream()
.filter(room -> room.getTalkTypeSet().contains(talkType))
.collect(toList());
int roomListSize = roomList.size();
nextCell().setCellValue(roomListSize);
int sessionCount = timeslotListSize * roomListSize;
nextCell(sessionCount < count ? hardPenaltyStyle : defaultStyle).setCellValue(sessionCount);
}
nextRow();
nextRow();
nextHeaderCell("Total");
int talkListSize = solution.getTalkList().size();
nextCell().setCellValue(talkListSize);
int timeslotListSize = solution.getTimeslotList().size();
nextCell().setCellValue(timeslotListSize);
int roomListSize = solution.getRoomList().size();
nextCell().setCellValue(roomListSize);
int sessionCount = timeslotListSize * roomListSize;
nextCell(sessionCount < talkListSize ? hardPenaltyStyle : defaultStyle).setCellValue(sessionCount);
autoSizeColumnsWithHeader();
}

private void writeRoomsView() {
nextSheet("Rooms view", 1, 2, true);
nextRow();
Expand Down
Expand Up @@ -37,6 +37,12 @@ rule "Talk type of timeslot"
then
scoreHolder.addHardConstraintMatch(kcontext, -10000);
end
rule "Talk type of room"
when
Talk(room != null, !getRoom().getTalkTypeSet().contains(getTalkType()))
then
scoreHolder.addHardConstraintMatch(kcontext, -10000);
end

rule "Room unavailable timeslot"
when
Expand Down

0 comments on commit 52011af

Please sign in to comment.