Search in sources :

Example 11 with RoomLocation

use of org.cpsolver.coursett.model.RoomLocation 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 12 with RoomLocation

use of org.cpsolver.coursett.model.RoomLocation in project cpsolver by UniTime.

the class Test method printSomeStuff.

/** Create info.txt with some more information about the problem 
     * @param solution current solution
     * @throws IOException an exception that may be thrown
     **/
public static void printSomeStuff(Solution<Lecture, Placement> solution) throws IOException {
    TimetableModel model = (TimetableModel) solution.getModel();
    Assignment<Lecture, Placement> assignment = solution.getAssignment();
    File outDir = new File(model.getProperties().getProperty("General.Output", "."));
    PrintWriter pw = new PrintWriter(new FileWriter(outDir.toString() + File.separator + "info.txt"));
    PrintWriter pwi = new PrintWriter(new FileWriter(outDir.toString() + File.separator + "info.csv"));
    String name = new File(model.getProperties().getProperty("General.Input")).getName();
    pwi.println("Instance," + name.substring(0, name.lastIndexOf('.')));
    pw.println("Solution info: " + ToolBox.dict2string(solution.getInfo(), 1));
    pw.println("Bounds: " + ToolBox.dict2string(model.getBounds(assignment), 1));
    Map<String, String> info = solution.getInfo();
    for (String key : new TreeSet<String>(info.keySet())) {
        if (key.equals("Memory usage"))
            continue;
        if (key.equals("Iteration"))
            continue;
        if (key.equals("Time"))
            continue;
        String value = info.get(key);
        if (value.indexOf(' ') > 0)
            value = value.substring(0, value.indexOf(' '));
        pwi.println(key + "," + value);
    }
    printRoomInfo(pw, model, assignment);
    printClassInfo(pw, model);
    long nrValues = 0;
    long nrTimes = 0;
    long nrRooms = 0;
    double totalMaxNormTimePref = 0.0;
    double totalMinNormTimePref = 0.0;
    double totalNormTimePref = 0.0;
    int totalMaxRoomPref = 0;
    int totalMinRoomPref = 0;
    int totalRoomPref = 0;
    long nrStudentEnrls = 0;
    long nrInevitableStudentConflicts = 0;
    long nrJenrls = 0;
    int nrHalfHours = 0;
    int nrMeetings = 0;
    int totalMinLimit = 0;
    int totalMaxLimit = 0;
    long nrReqRooms = 0;
    int nrSingleValueVariables = 0;
    int nrSingleTimeVariables = 0;
    int nrSingleRoomVariables = 0;
    long totalAvailableMinRoomSize = 0;
    long totalAvailableMaxRoomSize = 0;
    long totalRoomSize = 0;
    long nrOneOrMoreRoomVariables = 0;
    long nrOneRoomVariables = 0;
    HashSet<Student> students = new HashSet<Student>();
    HashSet<Long> offerings = new HashSet<Long>();
    HashSet<Long> configs = new HashSet<Long>();
    HashSet<Long> subparts = new HashSet<Long>();
    int[] sizeLimits = new int[] { 0, 25, 50, 75, 100, 150, 200, 400 };
    int[] nrRoomsOfSize = new int[sizeLimits.length];
    int[] minRoomOfSize = new int[sizeLimits.length];
    int[] maxRoomOfSize = new int[sizeLimits.length];
    int[] totalUsedSlots = new int[sizeLimits.length];
    int[] totalUsedSeats = new int[sizeLimits.length];
    int[] totalUsedSeats2 = new int[sizeLimits.length];
    int firstDaySlot = model.getProperties().getPropertyInt("General.FirstDaySlot", Constants.DAY_SLOTS_FIRST);
    int lastDaySlot = model.getProperties().getPropertyInt("General.LastDaySlot", Constants.DAY_SLOTS_LAST);
    int firstWorkDay = model.getProperties().getPropertyInt("General.FirstWorkDay", 0);
    int lastWorkDay = model.getProperties().getPropertyInt("General.LastWorkDay", Constants.NR_DAYS_WEEK - 1);
    for (Lecture lect : model.variables()) {
        if (lect.getConfiguration() != null) {
            offerings.add(lect.getConfiguration().getOfferingId());
            configs.add(lect.getConfiguration().getConfigId());
        }
        subparts.add(lect.getSchedulingSubpartId());
        nrStudentEnrls += (lect.students() == null ? 0 : lect.students().size());
        students.addAll(lect.students());
        nrValues += lect.values(solution.getAssignment()).size();
        nrReqRooms += lect.getNrRooms();
        for (RoomLocation room : lect.roomLocations()) if (room.getPreference() < Constants.sPreferenceLevelProhibited / 2)
            nrRooms++;
        for (TimeLocation time : lect.timeLocations()) if (time.getPreference() < Constants.sPreferenceLevelProhibited / 2)
            nrTimes++;
        totalMinLimit += lect.minClassLimit();
        totalMaxLimit += lect.maxClassLimit();
        if (!lect.values(solution.getAssignment()).isEmpty()) {
            Placement p = lect.values(solution.getAssignment()).get(0);
            nrMeetings += p.getTimeLocation().getNrMeetings();
            nrHalfHours += p.getTimeLocation().getNrMeetings() * p.getTimeLocation().getNrSlotsPerMeeting();
            totalMaxNormTimePref += lect.getMinMaxTimePreference()[1];
            totalMinNormTimePref += lect.getMinMaxTimePreference()[0];
            totalNormTimePref += Math.abs(lect.getMinMaxTimePreference()[1] - lect.getMinMaxTimePreference()[0]);
            totalMaxRoomPref += lect.getMinMaxRoomPreference()[1];
            totalMinRoomPref += lect.getMinMaxRoomPreference()[0];
            totalRoomPref += Math.abs(lect.getMinMaxRoomPreference()[1] - lect.getMinMaxRoomPreference()[0]);
            TimeLocation time = p.getTimeLocation();
            boolean hasRoomConstraint = false;
            for (RoomLocation roomLocation : lect.roomLocations()) {
                if (roomLocation.getRoomConstraint().getConstraint())
                    hasRoomConstraint = true;
            }
            if (hasRoomConstraint && lect.getNrRooms() > 0) {
                for (int d = firstWorkDay; d <= lastWorkDay; d++) {
                    if ((time.getDayCode() & Constants.DAY_CODES[d]) == 0)
                        continue;
                    for (int t = Math.max(time.getStartSlot(), firstDaySlot); t <= Math.min(time.getStartSlot() + time.getLength() - 1, lastDaySlot); t++) {
                        for (int l = 0; l < sizeLimits.length; l++) {
                            if (sizeLimits[l] <= lect.minRoomSize()) {
                                totalUsedSlots[l] += lect.getNrRooms();
                                totalUsedSeats[l] += lect.classLimit(assignment);
                                totalUsedSeats2[l] += lect.minRoomSize() * lect.getNrRooms();
                            }
                        }
                    }
                }
            }
        }
        if (lect.values(solution.getAssignment()).size() == 1) {
            nrSingleValueVariables++;
        }
        if (lect.timeLocations().size() == 1) {
            nrSingleTimeVariables++;
        }
        if (lect.roomLocations().size() == 1) {
            nrSingleRoomVariables++;
        }
        if (lect.getNrRooms() == 1) {
            nrOneRoomVariables++;
        }
        if (lect.getNrRooms() > 0) {
            nrOneOrMoreRoomVariables++;
        }
        if (!lect.roomLocations().isEmpty()) {
            int minRoomSize = Integer.MAX_VALUE;
            int maxRoomSize = Integer.MIN_VALUE;
            for (RoomLocation rl : lect.roomLocations()) {
                minRoomSize = Math.min(minRoomSize, rl.getRoomSize());
                maxRoomSize = Math.max(maxRoomSize, rl.getRoomSize());
                totalRoomSize += rl.getRoomSize();
            }
            totalAvailableMinRoomSize += minRoomSize;
            totalAvailableMaxRoomSize += maxRoomSize;
        }
    }
    for (JenrlConstraint jenrl : model.getJenrlConstraints()) {
        nrJenrls += jenrl.getJenrl();
        if ((jenrl.first()).timeLocations().size() == 1 && (jenrl.second()).timeLocations().size() == 1) {
            TimeLocation t1 = jenrl.first().timeLocations().get(0);
            TimeLocation t2 = jenrl.second().timeLocations().get(0);
            if (t1.hasIntersection(t2)) {
                nrInevitableStudentConflicts += jenrl.getJenrl();
                pw.println("Inevitable " + jenrl.getJenrl() + " student conflicts between " + jenrl.first() + " " + t1 + " and " + jenrl.second() + " " + t2);
            } else if (jenrl.first().values(solution.getAssignment()).size() == 1 && jenrl.second().values(solution.getAssignment()).size() == 1) {
                Placement p1 = jenrl.first().values(solution.getAssignment()).get(0);
                Placement p2 = jenrl.second().values(solution.getAssignment()).get(0);
                if (JenrlConstraint.isInConflict(p1, p2, ((TimetableModel) p1.variable().getModel()).getDistanceMetric())) {
                    nrInevitableStudentConflicts += jenrl.getJenrl();
                    pw.println("Inevitable " + jenrl.getJenrl() + (p1.getTimeLocation().hasIntersection(p2.getTimeLocation()) ? "" : " distance") + " student conflicts between " + p1 + " and " + p2);
                }
            }
        }
    }
    int totalCommitedPlacements = 0;
    for (Student student : students) {
        if (student.getCommitedPlacements() != null)
            totalCommitedPlacements += student.getCommitedPlacements().size();
    }
    pw.println("Total number of classes: " + model.variables().size());
    pwi.println("Number of classes," + model.variables().size());
    pw.println("Total number of instructional offerings: " + offerings.size() + " (" + sDoubleFormat.format(100.0 * offerings.size() / model.variables().size()) + "%)");
    // pwi.println("Number of instructional offerings,"+offerings.size());
    pw.println("Total number of configurations: " + configs.size() + " (" + sDoubleFormat.format(100.0 * configs.size() / model.variables().size()) + "%)");
    pw.println("Total number of scheduling subparts: " + subparts.size() + " (" + sDoubleFormat.format(100.0 * subparts.size() / model.variables().size()) + "%)");
    // pwi.println("Number of scheduling subparts,"+subparts.size());
    pw.println("Average number classes per subpart: " + sDoubleFormat.format(1.0 * model.variables().size() / subparts.size()));
    pwi.println("Avg. classes per instruction," + sDoubleFormat.format(1.0 * model.variables().size() / subparts.size()));
    pw.println("Average number classes per config: " + sDoubleFormat.format(1.0 * model.variables().size() / configs.size()));
    pw.println("Average number classes per offering: " + sDoubleFormat.format(1.0 * model.variables().size() / offerings.size()));
    pw.println("Total number of classes with only one value: " + nrSingleValueVariables + " (" + sDoubleFormat.format(100.0 * nrSingleValueVariables / model.variables().size()) + "%)");
    pw.println("Total number of classes with only one time: " + nrSingleTimeVariables + " (" + sDoubleFormat.format(100.0 * nrSingleTimeVariables / model.variables().size()) + "%)");
    pw.println("Total number of classes with only one room: " + nrSingleRoomVariables + " (" + sDoubleFormat.format(100.0 * nrSingleRoomVariables / model.variables().size()) + "%)");
    pwi.println("Classes with single value," + nrSingleValueVariables);
    // pwi.println("Classes with only one time/room,"+nrSingleTimeVariables+"/"+nrSingleRoomVariables);
    pw.println("Total number of classes requesting no room: " + (model.variables().size() - nrOneOrMoreRoomVariables) + " (" + sDoubleFormat.format(100.0 * (model.variables().size() - nrOneOrMoreRoomVariables) / model.variables().size()) + "%)");
    pw.println("Total number of classes requesting one room: " + nrOneRoomVariables + " (" + sDoubleFormat.format(100.0 * nrOneRoomVariables / model.variables().size()) + "%)");
    pw.println("Total number of classes requesting one or more rooms: " + nrOneOrMoreRoomVariables + " (" + sDoubleFormat.format(100.0 * nrOneOrMoreRoomVariables / model.variables().size()) + "%)");
    // pwi.println("% classes requesting no room,"+sDoubleFormat.format(100.0*(model.variables().size()-nrOneOrMoreRoomVariables)/model.variables().size())+"%");
    // pwi.println("% classes requesting one room,"+sDoubleFormat.format(100.0*nrOneRoomVariables/model.variables().size())+"%");
    // pwi.println("% classes requesting two or more rooms,"+sDoubleFormat.format(100.0*(nrOneOrMoreRoomVariables-nrOneRoomVariables)/model.variables().size())+"%");
    pw.println("Average number of requested rooms: " + sDoubleFormat.format(1.0 * nrReqRooms / model.variables().size()));
    pw.println("Average minimal class limit: " + sDoubleFormat.format(1.0 * totalMinLimit / model.variables().size()));
    pw.println("Average maximal class limit: " + sDoubleFormat.format(1.0 * totalMaxLimit / model.variables().size()));
    // pwi.println("Average class limit,"+sDoubleFormat.format(1.0*(totalMinLimit+totalMaxLimit)/(2*model.variables().size())));
    pw.println("Average number of placements: " + sDoubleFormat.format(1.0 * nrValues / model.variables().size()));
    // pwi.println("Average domain size,"+sDoubleFormat.format(1.0*nrValues/model.variables().size()));
    pwi.println("Avg. domain size," + sDoubleFormat.format(1.0 * nrValues / model.variables().size()));
    pw.println("Average number of time locations: " + sDoubleFormat.format(1.0 * nrTimes / model.variables().size()));
    pwi.println("Avg. number of avail. times/rooms," + sDoubleFormat.format(1.0 * nrTimes / model.variables().size()) + "/" + sDoubleFormat.format(1.0 * nrRooms / model.variables().size()));
    pw.println("Average number of room locations: " + sDoubleFormat.format(1.0 * nrRooms / model.variables().size()));
    pw.println("Average minimal requested room size: " + sDoubleFormat.format(1.0 * totalAvailableMinRoomSize / nrOneOrMoreRoomVariables));
    pw.println("Average maximal requested room size: " + sDoubleFormat.format(1.0 * totalAvailableMaxRoomSize / nrOneOrMoreRoomVariables));
    pw.println("Average requested room sizes: " + sDoubleFormat.format(1.0 * totalRoomSize / nrRooms));
    pwi.println("Average requested room size," + sDoubleFormat.format(1.0 * totalRoomSize / nrRooms));
    pw.println("Average maximum normalized time preference: " + sDoubleFormat.format(totalMaxNormTimePref / model.variables().size()));
    pw.println("Average minimum normalized time preference: " + sDoubleFormat.format(totalMinNormTimePref / model.variables().size()));
    pw.println("Average normalized time preference," + sDoubleFormat.format(totalNormTimePref / model.variables().size()));
    pw.println("Average maximum room preferences: " + sDoubleFormat.format(1.0 * totalMaxRoomPref / nrOneOrMoreRoomVariables));
    pw.println("Average minimum room preferences: " + sDoubleFormat.format(1.0 * totalMinRoomPref / nrOneOrMoreRoomVariables));
    pw.println("Average room preferences," + sDoubleFormat.format(1.0 * totalRoomPref / nrOneOrMoreRoomVariables));
    pw.println("Total number of students:" + students.size());
    pwi.println("Number of students," + students.size());
    pwi.println("Number of inevitable student conflicts," + nrInevitableStudentConflicts);
    pw.println("Total amount of student enrollments: " + nrStudentEnrls);
    pwi.println("Number of student enrollments," + nrStudentEnrls);
    pw.println("Total amount of joined enrollments: " + nrJenrls);
    pwi.println("Number of joint student enrollments," + nrJenrls);
    pw.println("Average number of students: " + sDoubleFormat.format(1.0 * students.size() / model.variables().size()));
    pw.println("Average number of enrollemnts (per student): " + sDoubleFormat.format(1.0 * nrStudentEnrls / students.size()));
    pwi.println("Avg. number of classes per student," + sDoubleFormat.format(1.0 * nrStudentEnrls / students.size()));
    pwi.println("Avg. number of committed classes per student," + sDoubleFormat.format(1.0 * totalCommitedPlacements / students.size()));
    pw.println("Total amount of inevitable student conflicts: " + nrInevitableStudentConflicts + " (" + sDoubleFormat.format(100.0 * nrInevitableStudentConflicts / nrStudentEnrls) + "%)");
    pw.println("Average number of meetings (per class): " + sDoubleFormat.format(1.0 * nrMeetings / model.variables().size()));
    pw.println("Average number of hours per class: " + sDoubleFormat.format(1.0 * nrHalfHours / model.variables().size() / 12.0));
    pwi.println("Avg. number of meetings per class," + sDoubleFormat.format(1.0 * nrMeetings / model.variables().size()));
    pwi.println("Avg. number of hours per class," + sDoubleFormat.format(1.0 * nrHalfHours / model.variables().size() / 12.0));
    int minRoomSize = Integer.MAX_VALUE;
    int maxRoomSize = Integer.MIN_VALUE;
    int nrDistancePairs = 0;
    double maxRoomDistance = Double.MIN_VALUE;
    double totalRoomDistance = 0.0;
    int[] totalAvailableSlots = new int[sizeLimits.length];
    int[] totalAvailableSeats = new int[sizeLimits.length];
    int nrOfRooms = 0;
    totalRoomSize = 0;
    for (RoomConstraint rc : model.getRoomConstraints()) {
        if (rc.variables().isEmpty())
            continue;
        nrOfRooms++;
        minRoomSize = Math.min(minRoomSize, rc.getCapacity());
        maxRoomSize = Math.max(maxRoomSize, rc.getCapacity());
        for (int l = 0; l < sizeLimits.length; l++) {
            if (sizeLimits[l] <= rc.getCapacity() && (l + 1 == sizeLimits.length || rc.getCapacity() < sizeLimits[l + 1])) {
                nrRoomsOfSize[l]++;
                if (minRoomOfSize[l] == 0)
                    minRoomOfSize[l] = rc.getCapacity();
                else
                    minRoomOfSize[l] = Math.min(minRoomOfSize[l], rc.getCapacity());
                if (maxRoomOfSize[l] == 0)
                    maxRoomOfSize[l] = rc.getCapacity();
                else
                    maxRoomOfSize[l] = Math.max(maxRoomOfSize[l], rc.getCapacity());
            }
        }
        totalRoomSize += rc.getCapacity();
        if (rc.getPosX() != null && rc.getPosY() != null) {
            for (RoomConstraint rc2 : model.getRoomConstraints()) {
                if (rc2.getResourceId().compareTo(rc.getResourceId()) > 0 && rc2.getPosX() != null && rc2.getPosY() != null) {
                    double distance = ((TimetableModel) solution.getModel()).getDistanceMetric().getDistanceInMinutes(rc.getId(), rc.getPosX(), rc.getPosY(), rc2.getId(), rc2.getPosX(), rc2.getPosY());
                    totalRoomDistance += distance;
                    nrDistancePairs++;
                    maxRoomDistance = Math.max(maxRoomDistance, distance);
                }
            }
        }
        for (int d = firstWorkDay; d <= lastWorkDay; d++) {
            for (int t = firstDaySlot; t <= lastDaySlot; t++) {
                if (rc.isAvailable(d * Constants.SLOTS_PER_DAY + t)) {
                    for (int l = 0; l < sizeLimits.length; l++) {
                        if (sizeLimits[l] <= rc.getCapacity()) {
                            totalAvailableSlots[l]++;
                            totalAvailableSeats[l] += rc.getCapacity();
                        }
                    }
                }
            }
        }
    }
    pw.println("Total number of rooms: " + nrOfRooms);
    pwi.println("Number of rooms," + nrOfRooms);
    pw.println("Minimal room size: " + minRoomSize);
    pw.println("Maximal room size: " + maxRoomSize);
    pwi.println("Room size min/max," + minRoomSize + "/" + maxRoomSize);
    pw.println("Average room size: " + sDoubleFormat.format(1.0 * totalRoomSize / model.getRoomConstraints().size()));
    pw.println("Maximal distance between two rooms: " + sDoubleFormat.format(maxRoomDistance));
    pw.println("Average distance between two rooms: " + sDoubleFormat.format(totalRoomDistance / nrDistancePairs));
    pwi.println("Average distance between two rooms [min]," + sDoubleFormat.format(totalRoomDistance / nrDistancePairs));
    pwi.println("Maximal distance between two rooms [min]," + sDoubleFormat.format(maxRoomDistance));
    for (int l = 0; l < sizeLimits.length; l++) {
        // sizeLimits.length;l++) {
        pwi.println("\"Room frequency (size>=" + sizeLimits[l] + ", used/avaiable times)\"," + sDoubleFormat.format(100.0 * totalUsedSlots[l] / totalAvailableSlots[l]) + "%");
        pwi.println("\"Room utilization (size>=" + sizeLimits[l] + ", used/available seats)\"," + sDoubleFormat.format(100.0 * totalUsedSeats[l] / totalAvailableSeats[l]) + "%");
        pwi.println("\"Number of rooms (size>=" + sizeLimits[l] + ")\"," + nrRoomsOfSize[l]);
        pwi.println("\"Min/max room size (size>=" + sizeLimits[l] + ")\"," + minRoomOfSize[l] + "-" + maxRoomOfSize[l]);
    // pwi.println("\"Room utilization (size>="+sizeLimits[l]+", minRoomSize)\","+sDoubleFormat.format(100.0*totalUsedSeats2[l]/totalAvailableSeats[l])+"%");
    }
    pw.println("Average hours available: " + sDoubleFormat.format(1.0 * totalAvailableSlots[0] / nrOfRooms / 12.0));
    int totalInstructedClasses = 0;
    for (InstructorConstraint ic : model.getInstructorConstraints()) {
        totalInstructedClasses += ic.variables().size();
    }
    pw.println("Total number of instructors: " + model.getInstructorConstraints().size());
    pwi.println("Number of instructors," + model.getInstructorConstraints().size());
    pw.println("Total class-instructor assignments: " + totalInstructedClasses + " (" + sDoubleFormat.format(100.0 * totalInstructedClasses / model.variables().size()) + "%)");
    pwi.println("Number of class-instructor assignments," + totalInstructedClasses);
    pw.println("Average classes per instructor: " + sDoubleFormat.format(1.0 * totalInstructedClasses / model.getInstructorConstraints().size()));
    pwi.println("Average classes per instructor," + sDoubleFormat.format(1.0 * totalInstructedClasses / model.getInstructorConstraints().size()));
    // pw.println("Average hours available: "+sDoubleFormat.format(1.0*totalAvailableSlots/model.getInstructorConstraints().size()/12.0));
    // pwi.println("Instructor availability [h],"+sDoubleFormat.format(1.0*totalAvailableSlots/model.getInstructorConstraints().size()/12.0));
    int nrGroupConstraints = model.getGroupConstraints().size() + model.getSpreadConstraints().size();
    int nrHardGroupConstraints = 0;
    int nrVarsInGroupConstraints = 0;
    for (GroupConstraint gc : model.getGroupConstraints()) {
        if (gc.isHard())
            nrHardGroupConstraints++;
        nrVarsInGroupConstraints += gc.variables().size();
    }
    for (SpreadConstraint sc : model.getSpreadConstraints()) {
        nrVarsInGroupConstraints += sc.variables().size();
    }
    pw.println("Total number of group constraints: " + nrGroupConstraints + " (" + sDoubleFormat.format(100.0 * nrGroupConstraints / model.variables().size()) + "%)");
    // pwi.println("Number of group constraints,"+nrGroupConstraints);
    pw.println("Total number of hard group constraints: " + nrHardGroupConstraints + " (" + sDoubleFormat.format(100.0 * nrHardGroupConstraints / model.variables().size()) + "%)");
    // pwi.println("Number of hard group constraints,"+nrHardGroupConstraints);
    pw.println("Average classes per group constraint: " + sDoubleFormat.format(1.0 * nrVarsInGroupConstraints / nrGroupConstraints));
    // pwi.println("Average classes per group constraint,"+sDoubleFormat.format(1.0*nrVarsInGroupConstraints/nrGroupConstraints));
    pwi.println("Avg. number distribution constraints per class," + sDoubleFormat.format(1.0 * nrVarsInGroupConstraints / model.variables().size()));
    pwi.println("Joint enrollment constraints," + model.getJenrlConstraints().size());
    pw.flush();
    pw.close();
    pwi.flush();
    pwi.close();
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) RoomConstraint(org.cpsolver.coursett.constraint.RoomConstraint) TimeLocation(org.cpsolver.coursett.model.TimeLocation) FileWriter(java.io.FileWriter) DepartmentSpreadConstraint(org.cpsolver.coursett.constraint.DepartmentSpreadConstraint) SpreadConstraint(org.cpsolver.coursett.constraint.SpreadConstraint) Placement(org.cpsolver.coursett.model.Placement) TreeSet(java.util.TreeSet) TimetableModel(org.cpsolver.coursett.model.TimetableModel) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet) JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Student(org.cpsolver.coursett.model.Student) DepartmentSpreadConstraint(org.cpsolver.coursett.constraint.DepartmentSpreadConstraint) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint) SpreadConstraint(org.cpsolver.coursett.constraint.SpreadConstraint) GroupConstraint(org.cpsolver.coursett.constraint.GroupConstraint) Constraint(org.cpsolver.ifs.model.Constraint) RoomConstraint(org.cpsolver.coursett.constraint.RoomConstraint) JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint) GroupConstraint(org.cpsolver.coursett.constraint.GroupConstraint) File(java.io.File)

Example 13 with RoomLocation

use of org.cpsolver.coursett.model.RoomLocation in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadSection.

/**
     * Load section
     * @param sectionEl section element
     * @param subpart parent subpart
     * @param sectionTable section table (of the offering)
     * @param timetable provided timetable
     * @return loaded section
     */
@SuppressWarnings("deprecation")
protected Section loadSection(Element sectionEl, Subpart subpart, Map<Long, Section> sectionTable, Map<Long, Placement> timetable) {
    Section parentSection = null;
    if (sectionEl.attributeValue("parent") != null)
        parentSection = sectionTable.get(Long.valueOf(sectionEl.attributeValue("parent")));
    Placement placement = null;
    if (timetable != null) {
        placement = timetable.get(Long.parseLong(sectionEl.attributeValue("id")));
    } else {
        TimeLocation time = null;
        Element timeEl = sectionEl.element("time");
        if (timeEl != null) {
            time = new TimeLocation(Integer.parseInt(timeEl.attributeValue("days"), 2), Integer.parseInt(timeEl.attributeValue("start")), Integer.parseInt(timeEl.attributeValue("length")), 0, 0, timeEl.attributeValue("datePattern") == null ? null : Long.valueOf(timeEl.attributeValue("datePattern")), timeEl.attributeValue("datePatternName", ""), createBitSet(timeEl.attributeValue("dates")), Integer.parseInt(timeEl.attributeValue("breakTime", "0")));
            if (timeEl.attributeValue("pattern") != null)
                time.setTimePatternId(Long.valueOf(timeEl.attributeValue("pattern")));
        }
        List<RoomLocation> rooms = new ArrayList<RoomLocation>();
        for (Iterator<?> m = sectionEl.elementIterator("room"); m.hasNext(); ) {
            Element roomEl = (Element) m.next();
            Double posX = null, posY = null;
            if (roomEl.attributeValue("location") != null) {
                String loc = roomEl.attributeValue("location");
                posX = Double.valueOf(loc.substring(0, loc.indexOf(',')));
                posY = Double.valueOf(loc.substring(loc.indexOf(',') + 1));
            }
            RoomLocation room = new RoomLocation(Long.valueOf(roomEl.attributeValue("id")), roomEl.attributeValue("name", "R" + roomEl.attributeValue("id")), roomEl.attributeValue("building") == null ? null : Long.valueOf(roomEl.attributeValue("building")), 0, Integer.parseInt(roomEl.attributeValue("capacity")), posX, posY, "true".equals(roomEl.attributeValue("ignoreTooFar")), null);
            rooms.add(room);
        }
        placement = (time == null ? null : new Placement(null, time, rooms));
    }
    List<Instructor> instructors = new ArrayList<Instructor>();
    for (Iterator<?> m = sectionEl.elementIterator("instructor"); m.hasNext(); ) {
        Element instructorEl = (Element) m.next();
        instructors.add(new Instructor(Long.parseLong(instructorEl.attributeValue("id")), instructorEl.attributeValue("externalId"), instructorEl.attributeValue("name"), instructorEl.attributeValue("email")));
    }
    if (instructors.isEmpty() && sectionEl.attributeValue("instructorIds") != null)
        instructors = Instructor.toInstructors(sectionEl.attributeValue("instructorIds"), sectionEl.attributeValue("instructorNames"));
    Section section = new Section(Long.parseLong(sectionEl.attributeValue("id")), Integer.parseInt(sectionEl.attributeValue("limit")), sectionEl.attributeValue("name", "S" + sectionEl.attributeValue("id")), subpart, placement, instructors, parentSection);
    section.setSpaceHeld(Double.parseDouble(sectionEl.attributeValue("hold", "0.0")));
    section.setSpaceExpected(Double.parseDouble(sectionEl.attributeValue("expect", "0.0")));
    section.setCancelled("true".equalsIgnoreCase(sectionEl.attributeValue("cancelled", "false")));
    for (Iterator<?> m = sectionEl.elementIterator("cname"); m.hasNext(); ) {
        Element cNameEl = (Element) m.next();
        section.setName(Long.parseLong(cNameEl.attributeValue("id")), cNameEl.getText());
    }
    Element ignoreEl = sectionEl.element("no-conflicts");
    if (ignoreEl != null) {
        for (Iterator<?> m = ignoreEl.elementIterator("section"); m.hasNext(); ) section.addIgnoreConflictWith(Long.parseLong(((Element) m.next()).attributeValue("id")));
    }
    return section;
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) Placement(org.cpsolver.coursett.model.Placement) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Element(org.dom4j.Element) Instructor(org.cpsolver.studentsct.model.Instructor) ArrayList(java.util.ArrayList) Section(org.cpsolver.studentsct.model.Section)

Example 14 with RoomLocation

use of org.cpsolver.coursett.model.RoomLocation in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadTimetable.

/**
     * Load given timetable
     * @param timetableRoot document root in the course timetabling XML format
     * @return loaded timetable (map class id: assigned placement)
     */
protected Map<Long, Placement> loadTimetable(Element timetableRoot) {
    Map<Long, Placement> timetable = new HashMap<Long, Placement>();
    HashMap<Long, RoomLocation> rooms = new HashMap<Long, RoomLocation>();
    for (Iterator<?> i = timetableRoot.element("rooms").elementIterator("room"); i.hasNext(); ) {
        Element roomEl = (Element) i.next();
        Long roomId = Long.valueOf(roomEl.attributeValue("id"));
        Double posX = null, posY = null;
        if (roomEl.attributeValue("location") != null) {
            String loc = roomEl.attributeValue("location");
            posX = Double.valueOf(loc.substring(0, loc.indexOf(',')));
            posY = Double.valueOf(loc.substring(loc.indexOf(',') + 1));
        }
        RoomLocation room = new RoomLocation(Long.valueOf(roomEl.attributeValue("id")), roomEl.attributeValue("name", "R" + roomEl.attributeValue("id")), roomEl.attributeValue("building") == null ? null : Long.valueOf(roomEl.attributeValue("building")), 0, Integer.parseInt(roomEl.attributeValue("capacity")), posX, posY, "true".equals(roomEl.attributeValue("ignoreTooFar")), null);
        rooms.put(roomId, room);
    }
    for (Iterator<?> i = timetableRoot.element("classes").elementIterator("class"); i.hasNext(); ) {
        Element classEl = (Element) i.next();
        Long classId = Long.valueOf(classEl.attributeValue("id"));
        TimeLocation time = null;
        Element timeEl = null;
        for (Iterator<?> j = classEl.elementIterator("time"); j.hasNext(); ) {
            Element e = (Element) j.next();
            if ("true".equals(e.attributeValue("solution", "false"))) {
                timeEl = e;
                break;
            }
        }
        if (timeEl != null) {
            time = new TimeLocation(Integer.parseInt(timeEl.attributeValue("days"), 2), Integer.parseInt(timeEl.attributeValue("start")), Integer.parseInt(timeEl.attributeValue("length")), 0, 0, classEl.attributeValue("datePattern") == null ? null : Long.valueOf(classEl.attributeValue("datePattern")), classEl.attributeValue("datePatternName", ""), createBitSet(classEl.attributeValue("dates")), Integer.parseInt(timeEl.attributeValue("breakTime", "0")));
            if (timeEl.attributeValue("pattern") != null)
                time.setTimePatternId(Long.valueOf(timeEl.attributeValue("pattern")));
        }
        List<RoomLocation> room = new ArrayList<RoomLocation>();
        for (Iterator<?> j = classEl.elementIterator("room"); j.hasNext(); ) {
            Element roomEl = (Element) j.next();
            if (!"true".equals(roomEl.attributeValue("solution", "false")))
                continue;
            room.add(rooms.get(Long.valueOf(roomEl.attributeValue("id"))));
        }
        Placement placement = (time == null ? null : new Placement(null, time, room));
        if (placement != null)
            timetable.put(classId, placement);
    }
    return timetable;
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) HashMap(java.util.HashMap) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Placement(org.cpsolver.coursett.model.Placement)

Example 15 with RoomLocation

use of org.cpsolver.coursett.model.RoomLocation in project cpsolver by UniTime.

the class StudentSectioningXMLSaver method saveSection.

/**
     * Save section
     * @param sectionEl section element to be populated
     * @param section section to be saved
     */
protected void saveSection(Element sectionEl, Section section) {
    sectionEl.addAttribute("id", getId("section", section.getId()));
    sectionEl.addAttribute("limit", String.valueOf(section.getLimit()));
    if (section.isCancelled())
        sectionEl.addAttribute("cancelled", "true");
    if (section.getNameByCourse() != null)
        for (Map.Entry<Long, String> entry : section.getNameByCourse().entrySet()) sectionEl.addElement("cname").addAttribute("id", entry.getKey().toString()).setText(entry.getValue());
    if (section.getParent() != null)
        sectionEl.addAttribute("parent", getId("section", section.getParent().getId()));
    if (section.hasInstructors()) {
        for (Instructor instructor : section.getInstructors()) {
            Element instructorEl = sectionEl.addElement("instructor");
            instructorEl.addAttribute("id", getId("instructor", instructor.getId()));
            if (iShowNames && instructor.getName() != null)
                instructorEl.addAttribute("name", instructor.getName());
            if (iShowNames && instructor.getExternalId() != null)
                instructorEl.addAttribute("externalId", instructor.getExternalId());
            if (iShowNames && instructor.getEmail() != null)
                instructorEl.addAttribute("email", instructor.getExternalId());
        }
    }
    if (iShowNames)
        sectionEl.addAttribute("name", section.getName());
    if (section.getPlacement() != null) {
        TimeLocation tl = section.getPlacement().getTimeLocation();
        if (tl != null) {
            Element timeLocationEl = sectionEl.addElement("time");
            timeLocationEl.addAttribute("days", sDF[7].format(Long.parseLong(Integer.toBinaryString(tl.getDayCode()))));
            timeLocationEl.addAttribute("start", String.valueOf(tl.getStartSlot()));
            timeLocationEl.addAttribute("length", String.valueOf(tl.getLength()));
            if (tl.getBreakTime() != 0)
                timeLocationEl.addAttribute("breakTime", String.valueOf(tl.getBreakTime()));
            if (iShowNames && tl.getTimePatternId() != null)
                timeLocationEl.addAttribute("pattern", getId("timePattern", tl.getTimePatternId()));
            if (iShowNames && tl.getDatePatternId() != null)
                timeLocationEl.addAttribute("datePattern", tl.getDatePatternId().toString());
            if (iShowNames && tl.getDatePatternName() != null && tl.getDatePatternName().length() > 0)
                timeLocationEl.addAttribute("datePatternName", tl.getDatePatternName());
            timeLocationEl.addAttribute("dates", bitset2string(tl.getWeekCode()));
            if (iShowNames)
                timeLocationEl.setText(tl.getLongName(true));
        }
        for (RoomLocation rl : section.getRooms()) {
            Element roomLocationEl = sectionEl.addElement("room");
            roomLocationEl.addAttribute("id", getId("room", rl.getId()));
            if (iShowNames && rl.getBuildingId() != null)
                roomLocationEl.addAttribute("building", getId("building", rl.getBuildingId()));
            if (iShowNames && rl.getName() != null)
                roomLocationEl.addAttribute("name", rl.getName());
            roomLocationEl.addAttribute("capacity", String.valueOf(rl.getRoomSize()));
            if (rl.getPosX() != null && rl.getPosY() != null)
                roomLocationEl.addAttribute("location", rl.getPosX() + "," + rl.getPosY());
            if (rl.getIgnoreTooFar())
                roomLocationEl.addAttribute("ignoreTooFar", "true");
        }
    }
    if (iSaveOnlineSectioningInfo) {
        if (section.getSpaceHeld() != 0.0)
            sectionEl.addAttribute("hold", sStudentWeightFormat.format(section.getSpaceHeld()));
        if (section.getSpaceExpected() != 0.0)
            sectionEl.addAttribute("expect", sStudentWeightFormat.format(section.getSpaceExpected()));
    }
    if (section.getIgnoreConflictWithSectionIds() != null && !section.getIgnoreConflictWithSectionIds().isEmpty()) {
        Element ignoreEl = sectionEl.addElement("no-conflicts");
        for (Long sectionId : section.getIgnoreConflictWithSectionIds()) ignoreEl.addElement("section").addAttribute("id", getId("section", sectionId));
    }
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Instructor(org.cpsolver.studentsct.model.Instructor) Element(org.dom4j.Element)

Aggregations

RoomLocation (org.cpsolver.coursett.model.RoomLocation)15 Placement (org.cpsolver.coursett.model.Placement)13 HashSet (java.util.HashSet)9 TimeLocation (org.cpsolver.coursett.model.TimeLocation)9 Lecture (org.cpsolver.coursett.model.Lecture)8 ArrayList (java.util.ArrayList)5 BitSet (java.util.BitSet)5 HashMap (java.util.HashMap)5 Section (org.cpsolver.studentsct.model.Section)5 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)4 DistanceConflict (org.cpsolver.studentsct.extension.DistanceConflict)4 Course (org.cpsolver.studentsct.model.Course)4 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)4 Enrollment (org.cpsolver.studentsct.model.Enrollment)4 Request (org.cpsolver.studentsct.model.Request)4 DecimalFormat (java.text.DecimalFormat)3 Map (java.util.Map)3 Set (java.util.Set)3 TreeSet (java.util.TreeSet)3 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)3