Search in sources :

Example 6 with TimeLocation

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

the class Test method printClassInfo.

/** Class information 
     * @param pw writer
     * @param model problem model
     **/
public static void printClassInfo(PrintWriter pw, TimetableModel model) {
    pw.println("Class info:");
    pw.println("id, name, min_class_limit, max_class_limit, room2limit_ratio, half_hours");
    for (Lecture lecture : model.variables()) {
        TimeLocation time = lecture.timeLocations().get(0);
        pw.println(lecture.getClassId() + "," + lecture.getName() + "," + lecture.minClassLimit() + "," + lecture.maxClassLimit() + "," + lecture.roomToLimitRatio() + "," + (time.getNrSlotsPerMeeting() * time.getNrMeetings()));
    }
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) TimeLocation(org.cpsolver.coursett.model.TimeLocation)

Example 7 with TimeLocation

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

the class Test method generateReports.

/**
     * Generate a few reports
     * @param outputDir output directory
     * @param assignment current assignments
     * @throws IOException
     */
protected void generateReports(File outputDir, Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) throws IOException {
    PrintWriter out = new PrintWriter(new File(outputDir, "solution-assignments.csv"));
    out.println("Course,Section,Time,Room,Load,Student,Name,Instructor Pref,Course Pref,Attribute Pref,Time Pref,Back-To-Back,Same-Days,Same-Room,Different Lecture,Overlap [h]");
    double diffRoomWeight = getProperties().getPropertyDouble("BackToBack.DifferentRoomWeight", 0.8);
    double diffTypeWeight = getProperties().getPropertyDouble("BackToBack.DifferentTypeWeight", 0.5);
    double diffRoomWeightSD = getProperties().getPropertyDouble("SameDays.DifferentRoomWeight", 0.8);
    double diffTypeWeightSD = getProperties().getPropertyDouble("SameDays.DifferentTypeWeight", 0.5);
    double diffTypeWeightSR = getProperties().getPropertyDouble("SameRoom.DifferentTypeWeight", 0.5);
    for (TeachingRequest.Variable request : variables()) {
        out.print(request.getCourse().getCourseName());
        String sect = "", time = "", room = "";
        for (Iterator<Section> i = request.getSections().iterator(); i.hasNext(); ) {
            Section section = i.next();
            sect += section.getSectionName();
            time += (section.getTime() == null ? "-" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(true));
            room += (section.getRoom() == null ? "-" : section.getRoom());
            if (i.hasNext()) {
                sect += ", ";
                time += ", ";
                room += ", ";
            }
        }
        out.print(",\"" + sect + "\",\"" + time + "\",\"" + room + "\"");
        out.print("," + new DecimalFormat("0.0").format(request.getRequest().getLoad()));
        TeachingAssignment ta = assignment.getValue(request);
        if (ta != null) {
            Instructor instructor = ta.getInstructor();
            out.print("," + instructor.getExternalId());
            out.print(",\"" + instructor.getName() + "\"");
            out.print("," + (ta.getInstructorPreference() == 0 ? "" : ta.getInstructorPreference()));
            out.print("," + (ta.getCoursePreference() == 0 ? "" : ta.getCoursePreference()));
            out.print("," + (ta.getAttributePreference() == 0 ? "" : ta.getAttributePreference()));
            out.print("," + (ta.getTimePreference() == 0 ? "" : ta.getTimePreference()));
            double b2b = instructor.countBackToBacks(assignment, ta, diffRoomWeight, diffTypeWeight);
            out.print("," + (b2b == 0.0 ? "" : new DecimalFormat("0.0").format(b2b)));
            double sd = instructor.countSameDays(assignment, ta, diffRoomWeightSD, diffTypeWeightSD);
            out.print("," + (sd == 0.0 ? "" : new DecimalFormat("0.0").format(sd)));
            double sr = instructor.countSameRooms(assignment, ta, diffTypeWeightSR);
            out.print("," + (sr == 0.0 ? "" : new DecimalFormat("0.0").format(sr)));
            double dl = instructor.differentLectures(assignment, ta);
            out.print("," + (dl == 0.0 ? "" : new DecimalFormat("0.0").format(dl)));
            double sh = instructor.share(assignment, ta);
            out.print("," + (sh == 0 ? "" : new DecimalFormat("0.0").format(sh / 12.0)));
        }
        out.println();
    }
    out.flush();
    out.close();
    out = new PrintWriter(new File(outputDir, "solution-students.csv"));
    out.println("Student,Name,Preference,Not Available,Time Pref,Course Pref,Back-to-Back,Same-Days,Same-Room,Max Load,Assigned Load,Back-To-Back,Same-Days,Same-Room,Different Lecture,Overlap [h],1st Assignment,2nd Assignment, 3rd Assignment");
    for (Instructor instructor : getInstructors()) {
        out.print(instructor.getExternalId());
        out.print(",\"" + instructor.getName() + "\"");
        out.print("," + (instructor.getPreference() == 0 ? "" : instructor.getPreference()));
        out.print(",\"" + instructor.getAvailable() + "\"");
        String timePref = "";
        for (Preference<TimeLocation> p : instructor.getTimePreferences()) {
            if (!p.isProhibited()) {
                if (!timePref.isEmpty())
                    timePref += ", ";
                timePref += p.getTarget().getLongName(true).trim() + ": " + (p.isRequired() ? "R" : p.isProhibited() ? "P" : p.getPreference());
            }
        }
        out.print(",\"" + timePref + "\"");
        String coursePref = "";
        for (Preference<Course> p : instructor.getCoursePreferences()) {
            if (!coursePref.isEmpty())
                coursePref += ", ";
            coursePref += p.getTarget().getCourseName() + ": " + (p.isRequired() ? "R" : p.isProhibited() ? "P" : p.getPreference());
        }
        out.print(",\"" + coursePref + "\"");
        out.print("," + (instructor.getBackToBackPreference() == 0 ? "" : instructor.getBackToBackPreference()));
        out.print("," + (instructor.getSameDaysPreference() == 0 ? "" : instructor.getSameDaysPreference()));
        out.print("," + (instructor.getSameRoomPreference() == 0 ? "" : instructor.getSameRoomPreference()));
        out.print("," + new DecimalFormat("0.0").format(instructor.getMaxLoad()));
        Instructor.Context context = instructor.getContext(assignment);
        out.print("," + new DecimalFormat("0.0").format(context.getLoad()));
        out.print("," + (context.countBackToBackPercentage() == 0.0 ? "" : new DecimalFormat("0.0").format(100.0 * context.countBackToBackPercentage())));
        out.print("," + (context.countSameDaysPercentage() == 0.0 ? "" : new DecimalFormat("0.0").format(100.0 * context.countSameDaysPercentage())));
        out.print("," + (context.countSameRoomPercentage() == 0.0 ? "" : new DecimalFormat("0.0").format(100.0 * context.countSameRoomPercentage())));
        out.print("," + (context.countDifferentLectures() == 0.0 ? "" : new DecimalFormat("0.0").format(100.0 * context.countDifferentLectures())));
        out.print("," + (context.countTimeOverlaps() == 0.0 ? "" : new DecimalFormat("0.0").format(context.countTimeOverlaps() / 12.0)));
        for (TeachingAssignment ta : context.getAssignments()) {
            String sect = "";
            for (Iterator<Section> i = ta.variable().getSections().iterator(); i.hasNext(); ) {
                Section section = i.next();
                sect += section.getSectionName() + (section.getTime() == null ? "" : " " + section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(true));
                if (i.hasNext())
                    sect += ", ";
            }
            out.print(",\"" + ta.variable().getCourse() + " " + sect + "\"");
        }
        out.println();
    }
    out.flush();
    out.close();
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) DecimalFormat(java.text.DecimalFormat) Instructor(org.cpsolver.instructor.model.Instructor) TeachingRequest(org.cpsolver.instructor.model.TeachingRequest) Section(org.cpsolver.instructor.model.Section) TeachingAssignment(org.cpsolver.instructor.model.TeachingAssignment) Course(org.cpsolver.instructor.model.Course) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 8 with TimeLocation

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

the class OriginalStudentWeights method main.

/**
     * Test case -- run to see the weights for a few courses
     * @param args program arguments
     */
public static void main(String[] args) {
    OriginalStudentWeights pw = new OriginalStudentWeights(new DataProperties());
    DecimalFormat df = new DecimalFormat("0.000");
    Student s = new Student(0l);
    new CourseRequest(1l, 0, false, s, ToolBox.toList(new Course(1, "A", "1", new Offering(0, "A")), new Course(1, "A", "2", new Offering(0, "A")), new Course(1, "A", "3", new Offering(0, "A"))), false, null);
    new CourseRequest(2l, 1, false, s, ToolBox.toList(new Course(1, "B", "1", new Offering(0, "B")), new Course(1, "B", "2", new Offering(0, "B")), new Course(1, "B", "3", new Offering(0, "B"))), false, null);
    new CourseRequest(3l, 2, false, s, ToolBox.toList(new Course(1, "C", "1", new Offering(0, "C")), new Course(1, "C", "2", new Offering(0, "C")), new Course(1, "C", "3", new Offering(0, "C"))), false, null);
    new CourseRequest(4l, 3, false, s, ToolBox.toList(new Course(1, "D", "1", new Offering(0, "D")), new Course(1, "D", "2", new Offering(0, "D")), new Course(1, "D", "3", new Offering(0, "D"))), false, null);
    new CourseRequest(5l, 4, false, s, ToolBox.toList(new Course(1, "E", "1", new Offering(0, "E")), new Course(1, "E", "2", new Offering(0, "E")), new Course(1, "E", "3", new Offering(0, "E"))), false, null);
    new CourseRequest(6l, 5, true, s, ToolBox.toList(new Course(1, "F", "1", new Offering(0, "F")), new Course(1, "F", "2", new Offering(0, "F")), new Course(1, "F", "3", new Offering(0, "F"))), false, null);
    new CourseRequest(7l, 6, true, s, ToolBox.toList(new Course(1, "G", "1", new Offering(0, "G")), new Course(1, "G", "2", new Offering(0, "G")), new Course(1, "G", "3", new Offering(0, "G"))), false, null);
    Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
    Placement p = new Placement(null, new TimeLocation(1, 90, 12, 0, 0, null, null, new BitSet(), 10), new ArrayList<RoomLocation>());
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            w[i] = pw.getWeight(assignment, e, null, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With one distance conflict:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<DistanceConflict.Conflict> dc = new HashSet<DistanceConflict.Conflict>();
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, (Section) sections.iterator().next()));
            w[i] = pw.getWeight(assignment, e, dc, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With two distance conflicts:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<DistanceConflict.Conflict> dc = new HashSet<DistanceConflict.Conflict>();
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, (Section) sections.iterator().next()));
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null)));
            w[i] = pw.getWeight(assignment, e, dc, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With 25% time overlapping conflicts:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<TimeOverlapsCounter.Conflict> toc = new HashSet<TimeOverlapsCounter.Conflict>();
            toc.add(new TimeOverlapsCounter.Conflict(s, 3, e, sections.iterator().next(), e, sections.iterator().next()));
            w[i] = pw.getWeight(assignment, e, null, toc);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) Config(org.cpsolver.studentsct.model.Config) DecimalFormat(java.text.DecimalFormat) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) DataProperties(org.cpsolver.ifs.util.DataProperties) Placement(org.cpsolver.coursett.model.Placement) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) BitSet(java.util.BitSet) Student(org.cpsolver.studentsct.model.Student) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section) TimeOverlapsCounter(org.cpsolver.studentsct.extension.TimeOverlapsCounter) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) Subpart(org.cpsolver.studentsct.model.Subpart) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) SctAssignment(org.cpsolver.studentsct.model.SctAssignment)

Example 9 with TimeLocation

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

the class MinimizeNumberOfUsedGroupsOfTime method computeConflicts.

@Override
public void computeConflicts(Assignment<Lecture, Placement> assignment, Placement placement, Set<Placement> conflicts) {
    MinimizeNumberOfUsedGroupsOfTimeContext context = getContext(assignment);
    int overLimit = context.getOverLimit(placement);
    if (overLimit > 0) {
        TimeLocation time = placement.getTimeLocation();
        List<List<Placement>> adepts = new ArrayList<List<Placement>>();
        for (int i = 0; i < iGroupsOfTime.length; i++) {
            GroupOfTime groupOfTime = iGroupsOfTime[i];
            Set<Placement> usage = context.getUsage(i);
            if (groupOfTime.overlap(time) || usage.isEmpty())
                continue;
            boolean canUnassign = true;
            List<Placement> placementsToUnassign = new ArrayList<Placement>(usage.size());
            for (Placement p : usage) {
                Lecture l = p.variable();
                if (l.isCommitted()) {
                    canUnassign = false;
                    break;
                }
                if (!conflicts.contains(p))
                    placementsToUnassign.add(p);
            }
            if (!canUnassign)
                continue;
            adepts.add(placementsToUnassign);
        }
        if (adepts.size() < overLimit) {
            conflicts.add(placement);
        } else {
            Collections.sort(adepts, new Comparator<List<Placement>>() {

                @Override
                public int compare(List<Placement> c1, List<Placement> c2) {
                    return Double.compare(c1.size(), c2.size());
                }
            });
            for (int i = 0; i < overLimit; i++) {
                conflicts.addAll(adepts.get(i));
            }
        }
    }
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) TimeLocation(org.cpsolver.coursett.model.TimeLocation) ArrayList(java.util.ArrayList) WeakeningConstraint(org.cpsolver.ifs.model.WeakeningConstraint) Placement(org.cpsolver.coursett.model.Placement) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with TimeLocation

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

the class InstructorConstraint method inConflict.

@Override
public boolean inConflict(Assignment<Lecture, Placement> assignment, Placement placement) {
    Lecture lecture = placement.variable();
    Placement current = assignment.getValue(lecture);
    BitSet weekCode = placement.getTimeLocation().getWeekCode();
    InstructorConstraintContext context = getContext(assignment);
    for (Enumeration<Integer> e = placement.getTimeLocation().getSlots(); e.hasMoreElements(); ) {
        int slot = e.nextElement();
        for (Placement p : context.getPlacements(slot)) {
            if (!p.equals(current) && p.getTimeLocation().shareWeeks(weekCode)) {
                if (p.canShareRooms(placement) && p.sameRooms(placement))
                    continue;
                return true;
            }
        }
    }
    if (!iIgnoreDistances) {
        for (Enumeration<Integer> e = placement.getTimeLocation().getStartSlots(); e.hasMoreElements(); ) {
            int startSlot = e.nextElement();
            int prevSlot = startSlot - 1;
            if (prevSlot >= 0 && (prevSlot / Constants.SLOTS_PER_DAY) == (startSlot / Constants.SLOTS_PER_DAY)) {
                for (Placement c : context.getPlacements(prevSlot, placement)) {
                    if (lecture.equals(c.variable()))
                        continue;
                    if (c.canShareRooms(placement) && c.sameRooms(placement))
                        continue;
                    if (Placement.getDistanceInMeters(getDistanceMetric(), placement, c) > getDistanceMetric().getInstructorProhibitedLimit())
                        return true;
                }
            }
            int nextSlot = startSlot + placement.getTimeLocation().getLength();
            if ((nextSlot / Constants.SLOTS_PER_DAY) == (startSlot / Constants.SLOTS_PER_DAY)) {
                for (Placement c : context.getPlacements(nextSlot, placement)) {
                    if (lecture.equals(c.variable()))
                        continue;
                    if (c.canShareRooms(placement) && c.sameRooms(placement))
                        continue;
                    if (Placement.getDistanceInMeters(getDistanceMetric(), placement, c) > getDistanceMetric().getInstructorProhibitedLimit())
                        return true;
                }
            }
            if (getDistanceMetric().doComputeDistanceConflictsBetweenNonBTBClasses()) {
                TimeLocation t1 = placement.getTimeLocation();
                for (Lecture other : variables()) {
                    Placement otherPlacement = assignment.getValue(other);
                    if (otherPlacement == null || other.equals(placement.variable()))
                        continue;
                    TimeLocation t2 = otherPlacement.getTimeLocation();
                    if (t1 == null || t2 == null || !t1.shareDays(t2) || !t1.shareWeeks(t2))
                        continue;
                    if (t1.getStartSlot() + t1.getLength() < t2.getStartSlot()) {
                        if (Placement.getDistanceInMinutes(getDistanceMetric(), placement, otherPlacement) > t1.getBreakTime() + Constants.SLOT_LENGTH_MIN * (t2.getStartSlot() - t1.getStartSlot() - t1.getLength()))
                            return true;
                    } else if (t2.getStartSlot() + t2.getLength() < t1.getStartSlot()) {
                        if (Placement.getDistanceInMinutes(getDistanceMetric(), placement, otherPlacement) > t2.getBreakTime() + Constants.SLOT_LENGTH_MIN * (t1.getStartSlot() - t2.getStartSlot() - t2.getLength()))
                            return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) TimeLocation(org.cpsolver.coursett.model.TimeLocation) Placement(org.cpsolver.coursett.model.Placement) BitSet(java.util.BitSet)

Aggregations

TimeLocation (org.cpsolver.coursett.model.TimeLocation)36 Placement (org.cpsolver.coursett.model.Placement)17 Lecture (org.cpsolver.coursett.model.Lecture)14 HashSet (java.util.HashSet)12 RoomLocation (org.cpsolver.coursett.model.RoomLocation)9 Constraint (org.cpsolver.ifs.model.Constraint)9 ArrayList (java.util.ArrayList)8 BitSet (java.util.BitSet)7 HashMap (java.util.HashMap)7 Element (org.dom4j.Element)7 WeakeningConstraint (org.cpsolver.ifs.model.WeakeningConstraint)6 DecimalFormat (java.text.DecimalFormat)5 List (java.util.List)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)4 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)3 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)3 SpreadConstraint (org.cpsolver.coursett.constraint.SpreadConstraint)3 Student (org.cpsolver.coursett.model.Student)3