Search in sources :

Example 91 with Lecture

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

the class FixCompleteSolutionNeighbourSelection method selectNeighbour.

/**
     * Try to improve existing solution by backtracking search of very limited
     * depth. See {@link NeighbourSelectionWithSuggestions} for more details.
     */
@Override
public Neighbour<Lecture, Placement> selectNeighbour(Solution<Lecture, Placement> solution) {
    FixCompleteSolutionNeighbourContext context = getContext(solution.getAssignment());
    if (context.getPhase() == 0) {
        if (solution.getModel().nrUnassignedVariables(solution.getAssignment()) == 0) {
            // complete solution was found
            if (iCompleteSolutionFixInterval < 0) {
                // feature disabled
                return iParent.selectNeighbour(solution);
            } else if (iCompleteSolutionFixInterval == 0) {
                // only run first time a complete solution is found
                if (iLastCompleteSolutionFixIteration >= 0)
                    return iParent.selectNeighbour(solution);
            } else {
                // run first time and if not run for a given number of iterations
                if (iLastCompleteSolutionFixIteration >= 0 && solution.getIteration() - iLastCompleteSolutionFixIteration < iCompleteSolutionFixInterval)
                    return iParent.selectNeighbour(solution);
            }
            if (solution.getBestIteration() == solution.getIteration())
                context.incPhase(solution);
        } else if (!solution.isBestComplete()) {
            // complete solution has not been found yet
            if (iIncompleteSolutionFixInterval < 0) {
                // feature disabled
                return iParent.selectNeighbour(solution);
            } else if (iIncompleteSolutionFixInterval == 0) {
                // only run first time a complete solution is found
                if (iLastIncompleteSolutionFixIteration >= 0)
                    return iParent.selectNeighbour(solution);
            } else {
                // run first time and if not run for a given number of iterations
                if (solution.getIteration() - iLastIncompleteSolutionFixIteration < iIncompleteSolutionFixInterval)
                    return iParent.selectNeighbour(solution);
            }
            if (solution.getBestIteration() == solution.getIteration())
                context.incPhase(solution);
        }
    }
    while (context.getPhase() > 0 && !iSolver.isStop()) {
        if (context.hasMoreElements()) {
            Lecture variable = context.nextElement();
            // iProgress.incProgress();
            if (context.getPhase() == 1) {
                Placement bestValue = null;
                double bestVal = 0.0;
                Placement currentValue = solution.getAssignment().getValue(variable);
                if (currentValue == null)
                    continue;
                double currentVal = currentValue.toDouble(solution.getAssignment());
                for (Placement value : variable.values(solution.getAssignment())) {
                    if (value.equals(currentValue))
                        continue;
                    if (solution.getModel().conflictValues(solution.getAssignment(), value).isEmpty()) {
                        double val = value.toDouble(solution.getAssignment());
                        if (bestValue == null || val < bestVal) {
                            bestValue = value;
                            bestVal = val;
                        }
                    }
                }
                if (bestValue != null && bestVal < currentVal)
                    return new SimpleNeighbour<Lecture, Placement>(variable, bestValue);
            } else {
                Neighbour<Lecture, Placement> n = iSuggestions.selectNeighbourWithSuggestions(solution, variable, 2);
                if (n != null && n.value(solution.getAssignment()) <= solution.getModel().getTotalValue(solution.getAssignment()))
                    return n;
            }
        } else {
            context.incPhase(solution);
        }
    }
    return iParent.selectNeighbour(solution);
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement)

Example 92 with Lecture

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

the class DistributionPreferences method getValue.

@Override
public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    double ret = 0;
    Set<GroupConstraint> constraints = new HashSet<GroupConstraint>();
    for (Lecture lect : variables) {
        for (GroupConstraint gc : lect.groupConstraints()) {
            if (!constraints.add(gc))
                continue;
            ret += gc.getContext(assignment).getPreference();
        }
    }
    return ret;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) GroupConstraint(org.cpsolver.coursett.constraint.GroupConstraint) HashSet(java.util.HashSet)

Example 93 with Lecture

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

the class StudentConflict method getValue.

@Override
public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    double ret = 0.0;
    Set<JenrlConstraint> constraints = new HashSet<JenrlConstraint>();
    for (Lecture lect : variables) {
        Placement plac = assignment.getValue(lect);
        if (plac == null)
            continue;
        for (JenrlConstraint jenrl : lect.jenrlConstraints()) {
            if (!constraints.add(jenrl))
                continue;
            Lecture other = jenrl.another(lect);
            if (!other.isCommitted() && !variables.contains(other))
                continue;
            if (!isApplicable(lect, other))
                continue;
            if (inConflict(plac, assignment.getValue(other)))
                ret += jointEnrollment(jenrl);
        }
    }
    return ret;
}
Also used : JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement) HashSet(java.util.HashSet)

Example 94 with Lecture

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

the class StudentConflict method getValue.

@Override
public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    double ret = 0.0;
    for (JenrlConstraint jenrl : value.variable().jenrlConstraints()) {
        Lecture other = jenrl.another(value.variable());
        if (!isApplicable(value.variable(), other))
            continue;
        Placement another = assignment.getValue(other);
        if (another == null)
            continue;
        if (conflicts != null && conflicts.contains(another))
            continue;
        if (inConflict(value, another))
            ret += jointEnrollment(jenrl);
    }
    if (iIncludeConflicts && conflicts != null)
        for (Placement conflict : conflicts) {
            for (JenrlConstraint jenrl : conflict.variable().jenrlConstraints()) {
                Lecture other = jenrl.another(conflict.variable());
                if (!isApplicable(conflict.variable(), other))
                    continue;
                Placement another = assignment.getValue(other);
                if (another == null || another.variable().equals(value.variable()))
                    continue;
                if (conflicts != null && conflicts.contains(another))
                    continue;
                if (inConflict(conflict, another))
                    ret -= jointEnrollment(jenrl);
            }
        }
    return ret;
}
Also used : JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement)

Example 95 with Lecture

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

the class IgnoredCommittedStudentConflict method countCommittedConflicts.

public int countCommittedConflicts(Student student, Placement placement) {
    if (student.getCommitedPlacements() == null)
        return 0;
    int conflicts = 0;
    Lecture lecture = placement.variable();
    for (Placement commitedPlacement : student.getCommitedPlacements()) {
        Lecture commitedLecture = commitedPlacement.variable();
        if (lecture.getSchedulingSubpartId() != null && lecture.getSchedulingSubpartId().equals(commitedLecture.getSchedulingSubpartId()))
            continue;
        if (ignore(lecture, commitedLecture) && (overlaps(placement, commitedPlacement) || distance(getMetrics(), placement, commitedPlacement)))
            conflicts++;
    }
    if (conflicts == 0)
        return 0;
    double w = student.getOfferingWeight((placement.variable()).getConfiguration());
    return (int) Math.round(student.avg(w, 1.0) * conflicts);
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement)

Aggregations

Lecture (org.cpsolver.coursett.model.Lecture)96 Placement (org.cpsolver.coursett.model.Placement)55 HashSet (java.util.HashSet)35 TimetableModel (org.cpsolver.coursett.model.TimetableModel)17 WeakeningConstraint (org.cpsolver.ifs.model.WeakeningConstraint)17 HashMap (java.util.HashMap)16 ArrayList (java.util.ArrayList)14 TimeLocation (org.cpsolver.coursett.model.TimeLocation)14 Constraint (org.cpsolver.ifs.model.Constraint)14 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)13 Student (org.cpsolver.coursett.model.Student)13 BitSet (java.util.BitSet)11 JenrlConstraint (org.cpsolver.coursett.constraint.JenrlConstraint)10 GlobalConstraint (org.cpsolver.ifs.model.GlobalConstraint)9 RoomLocation (org.cpsolver.coursett.model.RoomLocation)8 Set (java.util.Set)7 TreeSet (java.util.TreeSet)7 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)7 StudentGroup (org.cpsolver.coursett.model.StudentGroup)7 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)6