use of org.cpsolver.coursett.model.Placement in project cpsolver by UniTime.
the class TimeChange method selectNeighbour.
@Override
public Neighbour<Lecture, Placement> selectNeighbour(Solution<Lecture, Placement> solution) {
TimetableModel model = (TimetableModel) solution.getModel();
Assignment<Lecture, Placement> assignment = solution.getAssignment();
int varIdx = ToolBox.random(model.variables().size());
for (int i = 0; i < model.variables().size(); i++) {
Lecture lecture = model.variables().get((i + varIdx) % model.variables().size());
Placement old = assignment.getValue(lecture);
if (old == null)
continue;
List<TimeLocation> values = lecture.timeLocations();
if (values.isEmpty())
continue;
int valIdx = ToolBox.random(values.size());
for (int j = 0; j < values.size(); j++) {
TimeLocation time = values.get((j + valIdx) % values.size());
if (time.getPreference() > 50)
continue;
Placement placement = null;
if (lecture.getNrRooms() == 0)
placement = new Placement(lecture, time, (RoomLocation) null);
else if (lecture.getNrRooms() == 1)
placement = new Placement(lecture, time, old.getRoomLocation());
else
placement = new Placement(lecture, time, old.getRoomLocations());
if (placement.isValid() && !model.inConflict(assignment, placement)) {
SimpleNeighbour<Lecture, Placement> n = new SimpleNeighbour<Lecture, Placement>(lecture, placement);
if (!iHC || n.value(assignment) <= 0)
return n;
}
}
}
return null;
}
use of org.cpsolver.coursett.model.Placement in project cpsolver by UniTime.
the class SctStudent method getJenrConflictWeight.
/**
* Conflict weight of a lecture pair
*/
public double getJenrConflictWeight(Lecture l1, Lecture l2) {
Placement p1 = getModel().getAssignment().getValue(l1);
Placement p2 = getModel().getAssignment().getValue(l2);
if (p1 == null || p2 == null)
return 0.0;
if (getModel().getStudentConflictCriteria() == null) {
if (JenrlConstraint.isInConflict(p1, p2, getModel().getTimetableModel().getDistanceMetric()))
return getStudent().getJenrlWeight(l1, l2);
return 0.0;
}
double weight = 0.0;
for (StudentConflict sc : getModel().getStudentConflictCriteria()) if (sc.isApplicable(getStudent(), p1.variable(), p2.variable()) && sc.inConflict(p1, p2))
weight += sc.getWeight() * getStudent().getJenrlWeight(l1, l2);
return weight;
}
Aggregations