Search in sources :

Example 1 with ExamPlacement

use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.

the class Test method addCSVLine.

private static void addCSVLine(File file, String instance, String config, Solution<Exam, ExamPlacement> solution) {
    try {
        ExamModel model = (ExamModel) solution.getModel();
        Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
        boolean ex = file.exists();
        PrintWriter pw = new PrintWriter(new FileWriter(file, true));
        boolean mpp = ((PerturbationPenalty) model.getCriterion(PerturbationPenalty.class)).isMPP();
        int largeSize = ((LargeExamsPenalty) model.getCriterion(LargeExamsPenalty.class)).getLargeSize();
        RoomSplitDistancePenalty splitDistance = (RoomSplitDistancePenalty) model.getCriterion(RoomSplitDistancePenalty.class);
        ExamSplitter splitter = (ExamSplitter) model.getCriterion(ExamSplitter.class);
        PeriodViolation violPer = (PeriodViolation) model.getCriterion(PeriodViolation.class);
        RoomViolation violRoom = (RoomViolation) model.getCriterion(RoomViolation.class);
        DistributionViolation violDist = (DistributionViolation) model.getCriterion(DistributionViolation.class);
        DistanceToStronglyPreferredRoom distStrPref = (DistanceToStronglyPreferredRoom) model.getCriterion(DistanceToStronglyPreferredRoom.class);
        ExamRotationPenalty rotation = (ExamRotationPenalty) model.getCriterion(ExamRotationPenalty.class);
        DecimalFormat df = new DecimalFormat("0.00");
        if (!ex) {
            pw.println("SEED" + ",NA,DC,M2D,BTB" + (model.getBackToBackDistance() < 0 ? "" : ",dBTB") + ",iNA,iDC,iM2D,iBTB" + (model.getBackToBackDistance() < 0 ? "" : ",diBTB") + ",PP,RP,DP" + // Period Index, Rotation Penalty, Period Size
            ",PI,@P,PS" + // Room Size, Room Split, Room Split Distance
            ",RSz,RSp,RD" + (largeSize >= 0 ? ",LP" : "") + (mpp ? ",IP,IRP" : "") + (distStrPref == null ? "" : ",@D") + (splitter == null ? "" : ",XX") + (violPer == null ? "" : ",!P") + (violRoom == null ? "" : ",!R") + (violDist == null ? "" : ",!D") + ",INSTANCE,CONFIG");
            int nrStudentExams = 0;
            for (ExamStudent student : model.getStudents()) {
                nrStudentExams += student.variables().size();
            }
            int nrInstructorExams = 0;
            for (ExamInstructor instructor : model.getInstructors()) {
                nrInstructorExams += instructor.variables().size();
            }
            pw.println("MIN" + ",#EX,#RM,#PER," + (model.getBackToBackDistance() < 0 ? "" : ",") + ",#STD,#STDX,#INS,#INSX" + (model.getBackToBackDistance() < 0 ? "" : ",") + "," + model.getCriterion(PeriodPenalty.class).getBounds(assignment)[0] + "," + model.getCriterion(RoomPenalty.class).getBounds(assignment)[0] + "," + model.getCriterion(DistributionPenalty.class).getBounds(assignment)[0] + ",," + df.format(rotation.averagePeriod(assignment)) + "," + ",,," + (largeSize >= 0 ? ",0" : "") + (mpp ? ",," : "") + (distStrPref == null ? "" : ",") + (splitter == null ? "" : ",") + (violPer == null ? "" : ",") + (violRoom == null ? "" : ",") + (violDist == null ? "" : ",") + ",,");
            pw.println("MAX" + "," + model.variables().size() + "," + model.getRooms().size() + "," + model.getPeriods().size() + "," + (model.getBackToBackDistance() < 0 ? "" : ",") + "," + model.getStudents().size() + "," + nrStudentExams + "," + model.getInstructors().size() + "," + nrInstructorExams + (model.getBackToBackDistance() < 0 ? "" : ",") + "," + model.getCriterion(PeriodPenalty.class).getBounds(assignment)[1] + "," + model.getCriterion(RoomPenalty.class).getBounds(assignment)[1] + "," + model.getCriterion(DistributionPenalty.class).getBounds(assignment)[1] + ",," + rotation.nrAssignedExamsWithAvgPeriod(assignment) + "," + ",,," + (largeSize >= 0 ? "," + model.getCriterion(LargeExamsPenalty.class).getBounds(assignment)[1] : "") + (mpp ? ",," : "") + (distStrPref == null ? "" : ",") + (splitter == null ? "" : ",") + (violPer == null ? "" : "," + model.getCriterion(PeriodViolation.class).getBounds(assignment)[1]) + (violRoom == null ? "" : "," + model.getCriterion(RoomViolation.class).getBounds(assignment)[1]) + (violDist == null ? "" : "," + model.getCriterion(DistributionViolation.class).getBounds(assignment)[1]) + ",,");
        }
        pw.println(ToolBox.getSeed() + "," + model.getCriterion(StudentNotAvailableConflicts.class).getValue(assignment) + "," + model.getCriterion(StudentDirectConflicts.class).getValue(assignment) + "," + model.getCriterion(StudentMoreThan2ADayConflicts.class).getValue(assignment) + "," + model.getCriterion(StudentBackToBackConflicts.class).getValue(assignment) + (model.getBackToBackDistance() < 0 ? "" : "," + model.getCriterion(StudentDistanceBackToBackConflicts.class).getValue(assignment)) + "," + model.getCriterion(InstructorNotAvailableConflicts.class).getValue(assignment) + "," + model.getCriterion(InstructorDirectConflicts.class).getValue(assignment) + "," + model.getCriterion(InstructorMoreThan2ADayConflicts.class).getValue(assignment) + "," + model.getCriterion(InstructorBackToBackConflicts.class).getValue(assignment) + (model.getBackToBackDistance() < 0 ? "" : "," + model.getCriterion(InstructorDistanceBackToBackConflicts.class).getValue(assignment)) + "," + model.getCriterion(PeriodPenalty.class).getValue(assignment) + "," + model.getCriterion(RoomPenalty.class).getValue(assignment) + "," + model.getCriterion(DistributionPenalty.class).getValue(assignment) + "," + df.format(model.getCriterion(PeriodIndexPenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) + "," + df.format(Math.sqrt(rotation.getValue(assignment) / rotation.nrAssignedExamsWithAvgPeriod(assignment)) - 1) + "," + df.format(model.getCriterion(PeriodSizePenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) + "," + df.format(model.getCriterion(RoomSizePenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) + "," + model.getCriterion(RoomSplitPenalty.class).getValue(assignment) + "," + df.format(splitDistance.nrRoomSplits(assignment) <= 0 ? 0.0 : splitDistance.getValue(assignment) / splitDistance.nrRoomSplits(assignment)) + (largeSize >= 0 ? "," + model.getCriterion(LargeExamsPenalty.class).getValue(assignment) : "") + (mpp ? "," + df.format(model.getCriterion(PerturbationPenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) + "," + df.format(model.getCriterion(RoomPerturbationPenalty.class).getValue(assignment) / assignment.nrAssignedVariables()) : "") + (distStrPref == null ? "" : "," + df.format(distStrPref.getValue(assignment) / assignment.nrAssignedVariables())) + (splitter == null ? "" : "," + df.format(splitter.getValue(assignment))) + (violPer == null ? "" : "," + df.format(violPer.getValue(assignment))) + (violRoom == null ? "" : "," + df.format(violRoom.getValue(assignment))) + (violDist == null ? "" : "," + df.format(violDist.getValue(assignment))) + "," + instance + "," + config);
        pw.flush();
        pw.close();
    } catch (Exception e) {
        sLog.error("Unable to add CSV line to " + file, e);
    }
}
Also used : RoomPerturbationPenalty(org.cpsolver.exam.criteria.RoomPerturbationPenalty) PerturbationPenalty(org.cpsolver.exam.criteria.PerturbationPenalty) InstructorDistanceBackToBackConflicts(org.cpsolver.exam.criteria.InstructorDistanceBackToBackConflicts) ExamModel(org.cpsolver.exam.model.ExamModel) FileWriter(java.io.FileWriter) DecimalFormat(java.text.DecimalFormat) DistanceToStronglyPreferredRoom(org.cpsolver.exam.criteria.additional.DistanceToStronglyPreferredRoom) InstructorBackToBackConflicts(org.cpsolver.exam.criteria.InstructorBackToBackConflicts) DistributionViolation(org.cpsolver.exam.criteria.additional.DistributionViolation) RoomViolation(org.cpsolver.exam.criteria.additional.RoomViolation) ExamStudentConflictsPerExam(org.cpsolver.exam.reports.ExamStudentConflictsPerExam) Exam(org.cpsolver.exam.model.Exam) PrintWriter(java.io.PrintWriter) LargeExamsPenalty(org.cpsolver.exam.criteria.LargeExamsPenalty) ExamInstructor(org.cpsolver.exam.model.ExamInstructor) RoomSplitDistancePenalty(org.cpsolver.exam.criteria.RoomSplitDistancePenalty) PeriodViolation(org.cpsolver.exam.criteria.additional.PeriodViolation) InstructorDirectConflicts(org.cpsolver.exam.criteria.InstructorDirectConflicts) ExamStudent(org.cpsolver.exam.model.ExamStudent) IOException(java.io.IOException) ExamRotationPenalty(org.cpsolver.exam.criteria.ExamRotationPenalty) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) InstructorNotAvailableConflicts(org.cpsolver.exam.criteria.InstructorNotAvailableConflicts) InstructorMoreThan2ADayConflicts(org.cpsolver.exam.criteria.InstructorMoreThan2ADayConflicts) ExamSplitter(org.cpsolver.exam.split.ExamSplitter) RoomPerturbationPenalty(org.cpsolver.exam.criteria.RoomPerturbationPenalty)

Example 2 with ExamPlacement

use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.

the class Test method main.

/**
     * Main program
     * 
     * @param args
     *            problem property file, input file (optional, may be set by
     *            General.Input property), output file (optional, may be set by
     *            General.OutputFile property)
     */
public static void main(String[] args) {
    try {
        DataProperties cfg = new DataProperties();
        cfg.setProperty("Termination.StopWhenComplete", "false");
        cfg.setProperty("Termination.TimeOut", "1800");
        cfg.setProperty("General.SaveBestUnassigned", "-1");
        cfg.setProperty("Neighbour.Class", "org.cpsolver.exam.heuristics.ExamNeighbourSelection");
        if (args.length >= 1) {
            cfg.load(new FileInputStream(args[0]));
            cfg.setProperty("General.Config", new File(args[0]).getName());
        }
        cfg.putAll(System.getProperties());
        File inputFile = new File("c:\\test\\exam\\exam1070.xml");
        if (args.length >= 2) {
            inputFile = new File(args[1]);
        }
        ToolBox.setSeed(cfg.getPropertyLong("General.Seed", Math.round(Long.MAX_VALUE * Math.random())));
        cfg.setProperty("General.Input", inputFile.toString());
        String outName = inputFile.getName();
        if (outName.indexOf('.') >= 0)
            outName = outName.substring(0, outName.lastIndexOf('.')) + "s.xml";
        File outFile = new File(inputFile.getParentFile(), outName);
        if (args.length >= 3) {
            outFile = new File(args[2]);
            if (outFile.exists() && outFile.isDirectory())
                outFile = new File(outFile, outName);
            if (!outFile.exists() && !outFile.getName().endsWith(".xml"))
                outFile = new File(outFile, outName);
        }
        if (outFile.getParentFile() != null)
            outFile.getParentFile().mkdirs();
        cfg.setProperty("General.OutputFile", outFile.toString());
        cfg.setProperty("General.Output", outFile.getParent());
        String logName = outFile.getName();
        if (logName.indexOf('.') >= 0)
            logName = logName.substring(0, logName.lastIndexOf('.')) + ".log";
        setupLogging(new File(outFile.getParent(), logName), "true".equals(System.getProperty("debug", "false")));
        ExamModel model = new ExamModel(cfg);
        Document document = (new SAXReader()).read(new File(cfg.getProperty("General.Input")));
        int nrSolvers = cfg.getPropertyInt("Parallel.NrSolvers", 1);
        Assignment<Exam, ExamPlacement> assignment = (nrSolvers <= 1 ? new DefaultSingleAssignment<Exam, ExamPlacement>() : new DefaultParallelAssignment<Exam, ExamPlacement>());
        model.load(document, assignment);
        Solver<Exam, ExamPlacement> solver = (nrSolvers == 1 ? new Solver<Exam, ExamPlacement>(cfg) : new ParallelSolver<Exam, ExamPlacement>(cfg));
        solver.setInitalSolution(new Solution<Exam, ExamPlacement>(model, assignment));
        solver.currentSolution().addSolutionListener(new SolutionListener<Exam, ExamPlacement>() {

            @Override
            public void solutionUpdated(Solution<Exam, ExamPlacement> solution) {
            }

            @Override
            public void getInfo(Solution<Exam, ExamPlacement> solution, Map<String, String> info) {
            }

            @Override
            public void getInfo(Solution<Exam, ExamPlacement> solution, Map<String, String> info, Collection<Exam> variables) {
            }

            @Override
            public void bestCleared(Solution<Exam, ExamPlacement> solution) {
            }

            @Override
            public void bestSaved(Solution<Exam, ExamPlacement> solution) {
                ExamModel m = (ExamModel) solution.getModel();
                Assignment<Exam, ExamPlacement> a = solution.getAssignment();
                if (sLog.isInfoEnabled()) {
                    sLog.info("**BEST[" + solution.getIteration() + "]** " + (m.variables().size() > a.nrAssignedVariables() ? "V:" + a.nrAssignedVariables() + "/" + m.variables().size() + " - " : "") + "T:" + new DecimalFormat("0.00").format(m.getTotalValue(a)) + " " + m.toString(a) + (solution.getFailedIterations() > 0 ? ", F:" + sDoubleFormat.format(100.0 * solution.getFailedIterations() / solution.getIteration()) + "%" : ""));
                }
            }

            @Override
            public void bestRestored(Solution<Exam, ExamPlacement> solution) {
            }
        });
        Runtime.getRuntime().addShutdownHook(new ShutdownHook(solver));
        solver.start();
        try {
            solver.getSolverThread().join();
        } catch (InterruptedException e) {
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Solver(org.cpsolver.ifs.solver.Solver) ParallelSolver(org.cpsolver.ifs.solver.ParallelSolver) DefaultParallelAssignment(org.cpsolver.ifs.assignment.DefaultParallelAssignment) ExamModel(org.cpsolver.exam.model.ExamModel) SAXReader(org.dom4j.io.SAXReader) DecimalFormat(java.text.DecimalFormat) DataProperties(org.cpsolver.ifs.util.DataProperties) Document(org.dom4j.Document) DefaultParallelAssignment(org.cpsolver.ifs.assignment.DefaultParallelAssignment) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) Assignment(org.cpsolver.ifs.assignment.Assignment) ExamStudentConflictsPerExam(org.cpsolver.exam.reports.ExamStudentConflictsPerExam) Exam(org.cpsolver.exam.model.Exam) ParallelSolver(org.cpsolver.ifs.solver.ParallelSolver) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) File(java.io.File)

Example 3 with ExamPlacement

use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.

the class PerturbationPenalty method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    if (!isMPP())
        return 0;
    Exam exam = value.variable();
    ExamPlacement initial = exam.getInitialAssignment();
    if (initial == null)
        return 0;
    return Math.abs(initial.getPeriod().getIndex() - value.getPeriod().getIndex()) * (1 + exam.getSize());
}
Also used : ExamPlacement(org.cpsolver.exam.model.ExamPlacement) Exam(org.cpsolver.exam.model.Exam)

Example 4 with ExamPlacement

use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.

the class ExamColoringConstruction method selectNeighbour.

@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(final Solution<Exam, ExamPlacement> solution) {
    ExamModel model = (ExamModel) solution.getModel();
    // if (!model.assignedVariables().isEmpty()) return null;
    final HashMap<Exam, Vertex> vertices = new HashMap<Exam, Vertex>();
    for (Exam x : model.variables()) {
        vertices.put(x, new Vertex(x));
    }
    for (ExamStudent s : model.getStudents()) {
        for (Exam x : s.variables()) {
            for (Exam y : s.variables()) {
                if (!x.equals(y)) {
                    vertices.get(x).neighbors().add(vertices.get(y));
                    vertices.get(y).neighbors().add(vertices.get(x));
                }
            }
        }
    }
    for (ExamInstructor i : model.getInstructors()) {
        for (Exam x : i.variables()) {
            for (Exam y : i.variables()) {
                if (!x.equals(y)) {
                    vertices.get(x).neighbors().add(vertices.get(y));
                    vertices.get(y).neighbors().add(vertices.get(x));
                }
            }
        }
    }
    iProgress.setPhase("Graph coloring-based construction", vertices.size());
    iProgress.info("Looking for a conflict-free assignment using " + model.getPeriods().size() + " periods.");
    iT0 = JProf.currentTimeSec();
    iTimeLimitReached = false;
    if (iMode.isGreedy()) {
        iProgress.info("Using greedy heuristics only (no backtracking)...");
    } else if (backTrack(solution, 0, (iMode.isRedundant() ? null : new HashSet<Integer>()), vertices.values())) {
        iProgress.info("Success!");
    } else if (iTimeLimitReached) {
        iProgress.info("There was no conflict-free schedule found during the given time.");
    } else if (iSolver.isStop()) {
        iProgress.info("Solver was stopped.");
    } else {
        if (iMode.isRedundant())
            iProgress.info("There is no conflict-free schedule!");
        else
            iProgress.info("Conflict-free schedule not found.");
    }
    if (iMode.isConstraintCheck())
        solution.restoreBest();
    HashSet<Vertex> remaning = new HashSet<Vertex>();
    for (Vertex v : vertices.values()) if (v.color() < 0)
        remaning.add(v);
    remaining: while (!remaning.isEmpty()) {
        Vertex vertex = null;
        for (Vertex v : remaning) if (vertex == null || v.compareTo(vertex) < 0)
            vertex = v;
        remaning.remove(vertex);
        for (int color : vertex.domain()) if (vertex.colorize(solution.getAssignment(), color))
            continue remaining;
    }
    if (!iMode.isConstraintCheck()) {
        return new Neighbour<Exam, ExamPlacement>() {

            @Override
            public void assign(Assignment<Exam, ExamPlacement> assignment, long iteration) {
                iProgress.info("Using graph coloring solution ...");
                for (Vertex vertex : new TreeSet<Vertex>(vertices.values())) {
                    ExamPeriodPlacement period = vertex.period();
                    if (period == null || !vertex.exam().checkDistributionConstraints(assignment, period))
                        continue;
                    Set<ExamRoomPlacement> rooms = findRooms(assignment, vertex.exam(), period);
                    if (rooms == null)
                        continue;
                    assignment.assign(iteration, new ExamPlacement(vertex.exam(), period, rooms));
                }
                HashSet<Vertex> unassigned = new HashSet<Vertex>();
                for (Vertex vertex : vertices.values()) {
                    if (assignment.getValue(vertex.exam()) == null) {
                        unassigned.add(vertex);
                        vertex.colorize(assignment, -1);
                    }
                }
                solution.saveBest();
                iProgress.info("Extending ...");
                unassigned: while (!unassigned.isEmpty()) {
                    Vertex vertex = null;
                    for (Vertex v : unassigned) if (vertex == null || v.compareTo(vertex) < 0)
                        vertex = v;
                    unassigned.remove(vertex);
                    for (int color : vertex.domain()) {
                        if (!vertex.colorize(assignment, color))
                            continue;
                        ExamPeriodPlacement period = vertex.period(color);
                        if (period == null || !vertex.exam().checkDistributionConstraints(assignment, period))
                            continue;
                        Set<ExamRoomPlacement> rooms = findRooms(assignment, vertex.exam(), period);
                        if (rooms == null)
                            continue;
                        assignment.assign(iteration, new ExamPlacement(vertex.exam(), period, rooms));
                        continue unassigned;
                    }
                    vertex.colorize(assignment, -1);
                }
                solution.saveBest();
                iProgress.info("Construction done.");
            }

            @Override
            public double value(Assignment<Exam, ExamPlacement> assignment) {
                return 0;
            }

            @Override
            public Map<Exam, ExamPlacement> assignments() {
                throw new UnsupportedOperationException();
            }
        };
    }
    return null;
}
Also used : ExamInstructor(org.cpsolver.exam.model.ExamInstructor) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ExamModel(org.cpsolver.exam.model.ExamModel) ExamStudent(org.cpsolver.exam.model.ExamStudent) Assignment(org.cpsolver.ifs.assignment.Assignment) ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) Neighbour(org.cpsolver.ifs.model.Neighbour) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) TreeSet(java.util.TreeSet) ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) Exam(org.cpsolver.exam.model.Exam) HashSet(java.util.HashSet)

Example 5 with ExamPlacement

use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.

the class ExamConstruction method selectNeighbour.

/**
     * Select a neighbour. While there are exams that are still not assigned:
     * <ul>
     * <li>The worst unassigned exam is selected (using
     * {@link Exam#compareTo(Exam)})
     * <li>The best period that does not break any hard constraint and for which
     * there is a room assignment available is selected together with the set
     * the best available rooms for the exam in the best period (computed using
     * {@link Exam#findBestAvailableRooms(Assignment, ExamPeriodPlacement)}).
     * </ul>
     * Return null when done (all variables are assigned and the problem is
     * locally optimal).
     */
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
    ExamModel model = (ExamModel) solution.getModel();
    Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
    Context context = getContext(assignment);
    if (!iActive) {
        iActive = true;
        // iProgress.setPhase("Construction ...", model.variables().size());
        iProgress.info("[" + Thread.currentThread().getName() + "] Construction ...");
    }
    // iProgress.setProgress(assignment.nrAssignedVariables());
    if (model.variables().size() - assignment.nrAssignedVariables() <= context.skip().size())
        return checkLocalOptimality(assignment, model);
    Exam bestExam = null;
    for (Exam exam : model.variables()) {
        if (assignment.getValue(exam) != null || context.skip().contains(exam))
            continue;
        if (bestExam == null || exam.compareTo(bestExam) < 0)
            bestExam = exam;
    }
    ExamPlacement best = null;
    for (ExamPeriodPlacement period : bestExam.getPeriodPlacements()) {
        if (bestExam.countStudentConflicts(assignment, period) > 0) {
            if (context.assignments().contains(bestExam.getId() + ":" + period.getIndex()))
                continue;
        }
        if (!bestExam.checkDistributionConstraints(assignment, period))
            continue;
        ExamPlacement placement = new ExamPlacement(bestExam, period, null);
        if (best == null || best.getTimeCost(assignment) > placement.getTimeCost(assignment)) {
            Set<ExamRoomPlacement> rooms = bestExam.findBestAvailableRooms(assignment, period);
            if (rooms != null)
                best = new ExamPlacement(bestExam, period, rooms);
        }
    }
    if (best != null) {
        context.assignments().add(bestExam.getId() + ":" + best.getPeriod().getIndex());
        return new ExamSimpleNeighbour(assignment, best);
    }
    /*
           * else { for (Enumeration
           * e=bestExam.getPeriodPlacements().elements();e.hasMoreElements();) {
           * ExamPeriodPlacement period = (ExamPeriodPlacement)e.nextElement();
           * ExamPlacement placement = new ExamPlacement(bestExam, period,
           * null); if (best==null ||
           * best.getTimeCost()>placement.getTimeCost()) { Set rooms =
           * bestExam.findBestAvailableRooms(period); if (rooms!=null) best =
           * new ExamPlacement(bestExam, period, rooms); } } if (best!=null) {
           * bestExam.allowAllStudentConflicts(best.getPeriod());
           * iAssignments.add(bestExam.getId()+":"+best.getPeriod().getIndex());
           * return new ExamSimpleNeighbour(best); } }
           */
    if (!context.skip().contains(bestExam)) {
        context.skip().add(bestExam);
        return selectNeighbour(solution);
    }
    return checkLocalOptimality(assignment, model);
}
Also used : AssignmentContext(org.cpsolver.ifs.assignment.context.AssignmentContext) NeighbourSelectionWithContext(org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext) ExamRoomPlacement(org.cpsolver.exam.model.ExamRoomPlacement) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamModel(org.cpsolver.exam.model.ExamModel) ExamPeriodPlacement(org.cpsolver.exam.model.ExamPeriodPlacement) Exam(org.cpsolver.exam.model.Exam) ExamSimpleNeighbour(org.cpsolver.exam.neighbours.ExamSimpleNeighbour)

Aggregations

ExamPlacement (org.cpsolver.exam.model.ExamPlacement)40 Exam (org.cpsolver.exam.model.Exam)38 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)21 ArrayList (java.util.ArrayList)14 ExamModel (org.cpsolver.exam.model.ExamModel)13 CSVFile (org.cpsolver.ifs.util.CSVFile)12 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)12 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)11 ExamStudent (org.cpsolver.exam.model.ExamStudent)9 DecimalFormat (java.text.DecimalFormat)6 AssignmentContext (org.cpsolver.ifs.assignment.context.AssignmentContext)6 NeighbourSelectionWithContext (org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext)6 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 ExamOwner (org.cpsolver.exam.model.ExamOwner)4 IOException (java.io.IOException)3 TreeSet (java.util.TreeSet)3 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)3 File (java.io.File)2