Search in sources :

Example 11 with Placement

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

the class FlexibleConstraint method mergeToBlocks.

/**
     * Creates a list of blocks from a placements sorted by startSlot
     * 
     * @param sorted list of placements sorted by startSlot
     * @param maxBreakBetweenBTB maximum number of free slots between BTB placements
     * @return groups of BTB placements as a list of blocks
     */
protected List<Block> mergeToBlocks(List<Placement> sorted, int maxBreakBetweenBTB) {
    List<Block> blocks = new ArrayList<Block>();
    // add placements to blocks
    for (int i = 0; i < sorted.size(); i++) {
        Placement placement = sorted.get(i);
        boolean added = false;
        // add placement to a suitable block
        for (int j = 0; j < blocks.size(); j++) {
            if (blocks.get(j).addPlacement(placement)) {
                added = true;
            }
        }
        // create a new block if a lecture does not fit into any block
        if (!added) {
            Block block = new Block(maxBreakBetweenBTB);
            block.addPlacement(placement);
            blocks.add(block);
        }
    }
    return blocks;
}
Also used : Placement(org.cpsolver.coursett.model.Placement) ArrayList(java.util.ArrayList)

Example 12 with Placement

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

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

the class GetInfo method getInfoOfASolution.

public static HashMap<String, String> getInfoOfASolution(File file) {
    try {
        DataProperties properties = new DataProperties();
        properties.setProperty("General.Input", file.getPath());
        TimetableXMLLoader loader = new TimetableXMLLoader(new TimetableModel(properties), new DefaultSingleAssignment<Lecture, Placement>());
        loader.load();
        File newOutputFile = new File(file.getParentFile(), "new-output.csv");
        Test.saveOutputCSV(new Solution<Lecture, Placement>(loader.getModel(), loader.getAssignment()), newOutputFile);
        Progress.removeInstance(loader.getModel());
        System.out.println("  Reading " + newOutputFile + " ...");
        HashMap<String, String> info = getInfo(newOutputFile);
        File outputFile = new File(file.getParentFile(), "output.csv");
        if (outputFile.exists()) {
            System.out.println("  Reading " + outputFile + " ...");
            HashMap<String, String> info2 = getInfo(outputFile);
            if (info2.containsKey("000.002 Time [sec]"))
                info.put("000.002 Time [sec]", info2.get("000.002 Time [sec]"));
        }
        return info;
    } catch (Exception e) {
        System.err.println("Error reading info, message: " + e.getMessage());
        e.printStackTrace();
        return null;
    }
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement) DataProperties(org.cpsolver.ifs.util.DataProperties) TimetableModel(org.cpsolver.coursett.model.TimetableModel) File(java.io.File) CSVFile(org.cpsolver.ifs.util.CSVFile)

Example 14 with Placement

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

the class InstructorFairness method getValue.

@Override
public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    double ret = 0.0;
    InstructorFairnessContext context = (InstructorFairnessContext) getContext(assignment);
    if (context.allInstructorsAssigned(assignment) && !value.variable().getInstructorConstraints().isEmpty()) {
        List<InstructorConstraint> insConstraints = value.variable().getInstructorConstraints();
        ret = (context.getDiffInstrValue(insConstraints, context.fairnessDouble(assignment, value))) / insConstraints.size();
        if (conflicts != null) {
            for (Placement conflict : conflicts) {
                if (!conflict.variable().getInstructorConstraints().isEmpty()) {
                    List<InstructorConstraint> insConstraints2 = conflict.variable().getInstructorConstraints();
                    ret -= (context.getDiffInstrValue(insConstraints2, context.fairnessDouble(assignment, conflict))) / insConstraints2.size();
                }
            }
        }
    }
    return ret;
}
Also used : Placement(org.cpsolver.coursett.model.Placement) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint)

Example 15 with Placement

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

the class SpreadConstraint method getAdepts.

@SuppressWarnings("unchecked")
private Set<Placement>[] getAdepts(Assignment<Lecture, Placement> assignment, Placement placement, int[][] nrCourses, Set<Placement> conflicts) {
    SpreadConstraintContext context = getContext(assignment);
    int firstSlot = placement.getTimeLocation().getStartSlot();
    if (firstSlot > iLastDaySlot)
        return null;
    int endSlot = firstSlot + placement.getTimeLocation().getNrSlotsPerMeeting() - 1;
    if (endSlot < iFirstDaySlot)
        return null;
    HashSet<Placement>[] adepts = new HashSet[] { new HashSet<Placement>(), new HashSet<Placement>() };
    for (int i = Math.max(firstSlot, iFirstDaySlot); i <= Math.min(endSlot, iLastDaySlot); i++) {
        for (int j = iFirstWorkDay; j <= iLastWorkDay; j++) {
            int dayCode = Constants.DAY_CODES[j];
            if ((dayCode & placement.getTimeLocation().getDayCode()) != 0 && nrCourses[i - iFirstDaySlot][j - iFirstWorkDay] >= context.getMaxCourses(i, j)) {
                for (Placement p : context.getCourses(i, j)) {
                    if (conflicts.contains(p))
                        continue;
                    if (p.equals(placement))
                        continue;
                    if (p.variable().equals(placement.variable()))
                        continue;
                    adepts[(p.variable()).isCommitted() ? 1 : 0].add(p);
                }
            }
        }
    }
    return adepts;
// sLogger.debug("  -- adept "+adept+" selected, penalty will be decreased by "+improvement);
}
Also used : Placement(org.cpsolver.coursett.model.Placement) WeakeningConstraint(org.cpsolver.ifs.model.WeakeningConstraint) HashSet(java.util.HashSet)

Aggregations

Placement (org.cpsolver.coursett.model.Placement)72 Lecture (org.cpsolver.coursett.model.Lecture)55 HashSet (java.util.HashSet)24 TimetableModel (org.cpsolver.coursett.model.TimetableModel)18 TimeLocation (org.cpsolver.coursett.model.TimeLocation)17 WeakeningConstraint (org.cpsolver.ifs.model.WeakeningConstraint)17 ArrayList (java.util.ArrayList)16 BitSet (java.util.BitSet)16 Constraint (org.cpsolver.ifs.model.Constraint)15 HashMap (java.util.HashMap)14 RoomLocation (org.cpsolver.coursett.model.RoomLocation)13 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)9 GlobalConstraint (org.cpsolver.ifs.model.GlobalConstraint)9 Student (org.cpsolver.coursett.model.Student)7 List (java.util.List)6 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)6 DataProperties (org.cpsolver.ifs.util.DataProperties)6 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)5 JenrlConstraint (org.cpsolver.coursett.constraint.JenrlConstraint)5 SpreadConstraint (org.cpsolver.coursett.constraint.SpreadConstraint)5