Search in sources :

Example 51 with Exam

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

the class StudentMoreThan1ADayConflicts method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    int ret = 0;
    ExamModel m = (ExamModel) getModel();
    Set<Integer> days = new HashSet<Integer>();
    for (ExamPeriod p : m.getPeriods()) {
        if (days.add(p.getDay())) {
            Map<ExamStudent, Set<Exam>> students = ((ExamModel) getModel()).getStudentsOfDay(assignment, p);
            for (Set<Exam> exams : students.values()) {
                int nrExams = exams.size();
                if (nrExams > 1)
                    ret += nrExams - 1;
            }
        }
    }
    return ret;
}
Also used : ExamPeriod(org.cpsolver.exam.model.ExamPeriod) HashSet(java.util.HashSet) Set(java.util.Set) ExamModel(org.cpsolver.exam.model.ExamModel) ExamStudent(org.cpsolver.exam.model.ExamStudent) Exam(org.cpsolver.exam.model.Exam) HashSet(java.util.HashSet)

Example 52 with Exam

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

the class ExamHillClimbing method selectNeighbour.

/**
 * Select one of the given neighbourhoods randomly, select neighbour, return
 * it if its value is below or equal to zero (continue with the next
 * selection otherwise). Return null when the given number of idle
 * iterations is reached.
 */
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
    Context context = getContext(solution.getAssignment());
    context.activateIfNeeded();
    while (true) {
        if (context.incIter(solution))
            break;
        NeighbourSelection<Exam, ExamPlacement> ns = iNeighbours.get(ToolBox.random(iNeighbours.size()));
        Neighbour<Exam, ExamPlacement> n = ns.selectNeighbour(solution);
        if (n != null) {
            if (n instanceof LazyNeighbour) {
                ((LazyNeighbour<Exam, ExamPlacement>) n).setAcceptanceCriterion(this);
                return n;
            } else if (n.value(solution.getAssignment()) <= 0.0)
                return n;
        }
    }
    context.reset();
    return null;
}
Also used : AssignmentContext(org.cpsolver.ifs.assignment.context.AssignmentContext) NeighbourSelectionWithContext(org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) LazyNeighbour(org.cpsolver.ifs.model.LazyNeighbour) Exam(org.cpsolver.exam.model.Exam)

Example 53 with Exam

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

the class ExamUnassignedVariableSelection method selectVariable.

/**
 * Variable selection
 */
@Override
public Exam selectVariable(Solution<Exam, ExamPlacement> solution) {
    ExamModel model = (ExamModel) solution.getModel();
    Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
    if (model.variables().size() == assignment.nrAssignedVariables())
        return null;
    if (iRandomSelection) {
        int idx = ToolBox.random(model.variables().size() - assignment.nrAssignedVariables());
        for (Exam v : model.variables()) {
            if (assignment.getValue(v) != null)
                continue;
            if (idx == 0)
                return v;
            idx--;
        }
    }
    Exam variable = null;
    for (Exam v : model.variables()) {
        if (assignment.getValue(v) != null)
            continue;
        if (variable == null || v.compareTo(variable) < 0)
            variable = v;
    }
    return variable;
}
Also used : ExamPlacement(org.cpsolver.exam.model.ExamPlacement) ExamModel(org.cpsolver.exam.model.ExamModel) Exam(org.cpsolver.exam.model.Exam)

Example 54 with Exam

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

the class MistaTables method main.

public static void main(String[] args) {
    try {
        ToolBox.configureLogging();
        DataProperties config = new DataProperties();
        Table[] tables = new Table[] { new Problems(), new Rooms() };
        for (int i = 0; i < args.length; i++) {
            File file = new File(args[i]);
            sLog.info("Loading " + file);
            ExamModel model = new ExamModel(config);
            Assignment<Exam, ExamPlacement> assignment = new DefaultSingleAssignment<Exam, ExamPlacement>();
            model.load(new SAXReader().read(file), assignment);
            String name = file.getName();
            if (name.contains("."))
                name = name.substring(0, name.indexOf('.'));
            for (Table table : tables) table.add(name, model);
            Progress.removeInstance(model);
        }
        sLog.info("Saving tables...");
        File output = new File("tables");
        output.mkdir();
        for (Table table : tables) table.save(output);
        sLog.info("All done.");
    } catch (Exception e) {
        sLog.error(e.getMessage(), e);
    }
}
Also used : ExamModel(org.cpsolver.exam.model.ExamModel) SAXReader(org.dom4j.io.SAXReader) DataProperties(org.cpsolver.ifs.util.DataProperties) IOException(java.io.IOException) ExamPlacement(org.cpsolver.exam.model.ExamPlacement) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) File(java.io.File) Exam(org.cpsolver.exam.model.Exam)

Example 55 with Exam

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

the class DistributionPenalty method getValue.

@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    int penalty = 0;
    Set<ExamDistributionConstraint> added = new HashSet<ExamDistributionConstraint>();
    for (Exam exam : variables) {
        for (ExamDistributionConstraint dc : exam.getDistributionConstraints()) {
            if (added.add(dc)) {
                if (dc.isHard() || (iSoftDistributions != null && iSoftDistributions == dc.getWeight()))
                    continue;
                if (!dc.isSatisfied(assignment))
                    penalty += dc.getWeight();
            }
        }
    }
    return penalty;
}
Also used : ExamDistributionConstraint(org.cpsolver.exam.model.ExamDistributionConstraint) ExamDistributionConstraint(org.cpsolver.exam.model.ExamDistributionConstraint) Exam(org.cpsolver.exam.model.Exam) HashSet(java.util.HashSet)

Aggregations

Exam (org.cpsolver.exam.model.Exam)62 ExamPlacement (org.cpsolver.exam.model.ExamPlacement)38 ExamModel (org.cpsolver.exam.model.ExamModel)26 ExamRoomPlacement (org.cpsolver.exam.model.ExamRoomPlacement)21 ExamPeriod (org.cpsolver.exam.model.ExamPeriod)19 ExamStudent (org.cpsolver.exam.model.ExamStudent)18 Set (java.util.Set)15 ArrayList (java.util.ArrayList)13 ExamPeriodPlacement (org.cpsolver.exam.model.ExamPeriodPlacement)12 CSVFile (org.cpsolver.ifs.util.CSVFile)12 CSVField (org.cpsolver.ifs.util.CSVFile.CSVField)12 HashSet (java.util.HashSet)11 ExamInstructor (org.cpsolver.exam.model.ExamInstructor)10 DecimalFormat (java.text.DecimalFormat)6 AssignmentContext (org.cpsolver.ifs.assignment.context.AssignmentContext)6 NeighbourSelectionWithContext (org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext)6 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 ExamOwner (org.cpsolver.exam.model.ExamOwner)4 IOException (java.io.IOException)3