Search in sources :

Example 6 with SimpleNeighbour

use of org.cpsolver.ifs.model.SimpleNeighbour in project cpsolver by UniTime.

the class RoomChange 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 || old.getNrRooms() != 1)
            continue;
        List<RoomLocation> values = lecture.roomLocations();
        if (values.isEmpty())
            continue;
        int valIdx = ToolBox.random(values.size());
        for (int j = 0; j < values.size(); j++) {
            RoomLocation room = values.get((j + valIdx) % values.size());
            if (room.getPreference() > 50)
                continue;
            if (room.equals(old.getRoomLocation()))
                continue;
            Placement placement = new Placement(lecture, old.getTimeLocation(), room);
            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;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement) RoomLocation(org.cpsolver.coursett.model.RoomLocation) SimpleNeighbour(org.cpsolver.ifs.model.SimpleNeighbour) TimetableModel(org.cpsolver.coursett.model.TimetableModel)

Example 7 with SimpleNeighbour

use of org.cpsolver.ifs.model.SimpleNeighbour 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;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) TimeLocation(org.cpsolver.coursett.model.TimeLocation) Placement(org.cpsolver.coursett.model.Placement) SimpleNeighbour(org.cpsolver.ifs.model.SimpleNeighbour) TimetableModel(org.cpsolver.coursett.model.TimetableModel)

Aggregations

SimpleNeighbour (org.cpsolver.ifs.model.SimpleNeighbour)7 Lecture (org.cpsolver.coursett.model.Lecture)4 Placement (org.cpsolver.coursett.model.Placement)4 TimetableModel (org.cpsolver.coursett.model.TimetableModel)4 HashMap (java.util.HashMap)3 Lock (java.util.concurrent.locks.Lock)3 ArrayList (java.util.ArrayList)2 RoomLocation (org.cpsolver.coursett.model.RoomLocation)2 TimeLocation (org.cpsolver.coursett.model.TimeLocation)2 Exam (org.cpsolver.exam.model.Exam)1 ExamModel (org.cpsolver.exam.model.ExamModel)1 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)1 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)1 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)1 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)1 Enrollment (org.cpsolver.studentsct.model.Enrollment)1 Request (org.cpsolver.studentsct.model.Request)1