Skip to content

Commit

Permalink
Examination Timetabling: Soft Rooms
Browse files Browse the repository at this point in the history
- added ability to have rooms that do not check for conflicts (room checking disabled in UniTime)
  • Loading branch information
tomas-muller committed Aug 18, 2020
1 parent e6ff523 commit 5f66634
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/org/cpsolver/exam/model/ExamModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ public Document save(Assignment<Exam, ExamPlacement> assignment) {
r.addAttribute("name", room.getName());
r.addAttribute("size", String.valueOf(room.getSize()));
r.addAttribute("alt", String.valueOf(room.getAltSize()));
if (!room.isHard())
r.addAttribute("hard", "false");
if (room.getCoordX() != null && room.getCoordY() != null)
r.addAttribute("coordinates", room.getCoordX() + "," + room.getCoordY());
for (ExamPeriod period : getPeriods()) {
Expand Down Expand Up @@ -868,6 +870,7 @@ else if (root.attribute("initiative") != null)
Integer.parseInt(e.attributeValue("size")), Integer.parseInt(e.attributeValue("alt")),
(coords == null ? null : Double.valueOf(coords.substring(0, coords.indexOf(',')))),
(coords == null ? null : Double.valueOf(coords.substring(coords.indexOf(',') + 1))));
room.setHard("true".equalsIgnoreCase(e.attributeValue("hard", "true")));
addConstraint(room);
getRooms().add(room);
rooms.put(new Long(room.getId()), room);
Expand Down
10 changes: 9 additions & 1 deletion src/org/cpsolver/exam/model/ExamRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ExamRoom extends ConstraintWithContext<Exam, ExamPlacement, ExamRoo
private String iName;
private int iSize, iAltSize;
private Double iCoordX, iCoordY;
private boolean iHard = true;

/**
* Constructor
Expand Down Expand Up @@ -79,6 +80,11 @@ public ExamRoom(ExamModel model, long id, String name, int size, int altSize, Do
}
}

public void setHard(boolean hard) { iHard = hard; }

@Override
public boolean isHard() { return iHard; }

private Map<Long, Double> iDistanceCache = new HashMap<Long, Double>();
/**
* Distance between two rooms. See {@link DistanceMetric}
Expand Down Expand Up @@ -226,6 +232,7 @@ public ExamRoomSharing getRoomSharing() {
*/
@Override
public void computeConflicts(Assignment<Exam, ExamPlacement> assignment, ExamPlacement p, Set<ExamPlacement> conflicts) {
if (!isHard()) return;
if (!p.contains(this)) return;

if (getRoomSharing() == null) {
Expand All @@ -243,6 +250,7 @@ public void computeConflicts(Assignment<Exam, ExamPlacement> assignment, ExamPla
*/
@Override
public boolean inConflict(Assignment<Exam, ExamPlacement> assignment, ExamPlacement p) {
if (!isHard()) return false;
if (!p.contains(this)) return false;

if (getRoomSharing() == null) {
Expand All @@ -259,7 +267,7 @@ public boolean inConflict(Assignment<Exam, ExamPlacement> assignment, ExamPlacem
*/
@Override
public boolean isConsistent(ExamPlacement p1, ExamPlacement p2) {
return (p1.getPeriod() != p2.getPeriod() || !p1.contains(this) || !p2.contains(this));
return !isHard() || (p1.getPeriod() != p2.getPeriod() || !p1.contains(this) || !p2.contains(this));
}

/**
Expand Down

0 comments on commit 5f66634

Please sign in to comment.