当前位置: 首页>>代码示例>>Java>>正文


Java ExamPeriodPlacement类代码示例

本文整理汇总了Java中org.cpsolver.exam.model.ExamPeriodPlacement的典型用法代码示例。如果您正苦于以下问题:Java ExamPeriodPlacement类的具体用法?Java ExamPeriodPlacement怎么用?Java ExamPeriodPlacement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExamPeriodPlacement类属于org.cpsolver.exam.model包,在下文中一共展示了ExamPeriodPlacement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPlacement

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
private ExamPlacement getPlacement(Exam exam, ExamPlacement placement) {
    ExamPeriodPlacement period = null;
    for (ExamPeriodPlacement p: exam.getPeriodPlacements()) {
        if (placement.getPeriod().equals(p.getPeriod())) {
            period = p; break;
        }
    }
    if (period==null) {
        iProgress.warn("WARNING: Period "+placement.getPeriod()+" is not available for class "+exam.getName());
        return null;
    }
    Set rooms = new HashSet();
    for (Iterator f=exam.getRoomPlacements().iterator();f.hasNext();) {
        ExamRoomPlacement r = (ExamRoomPlacement)f.next();
        if (r.isAvailable(period.getPeriod()) && placement.contains(r.getRoom())) {
            rooms.add(r);
        }
    }
    if (rooms.size()!=placement.getRoomPlacements().size()) {
        iProgress.warn("WARNING: Room(s) "+placement.getRoomPlacements()+" are not available for exam "+exam.getName());
        return null;
    }
    return new ExamPlacement(exam,period,rooms);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:25,代码来源:ExamSolver.java

示例2: getAssignment

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
@Override
public ExamAssignmentInfo getAssignment(Long examId, Long periodId, Collection<Long> roomIds) {
    Lock lock = currentSolution().getLock().readLock();
    lock.lock();
    try {
        Exam exam = getExam(examId);
        if (exam==null) return null;
        ExamPeriodPlacement period = null;
        for (ExamPeriodPlacement p: exam.getPeriodPlacements()) {
            if (p.getId().equals(periodId)) { period = p; break; }
        }
        if (period==null) return null;
        HashSet rooms = new HashSet();
        for (Long roomId: roomIds) {
            ExamRoomPlacement room = null;
            for (ExamRoomPlacement r: exam.getRoomPlacements()) {
                if (r.getId()==roomId) { room = r; break; }
            }
            if (room!=null) rooms.add(room);
        }
        return new ExamAssignmentInfo(exam, new ExamPlacement(exam, period, rooms), currentSolution().getAssignment());
    } finally {
    	lock.unlock();
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:26,代码来源:ExamSolver.java

示例3: selectNeighbour

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
/**
 * Select an exam randomly, select an available period randomly (from
 * {@link Exam#getPeriodPlacements()}), select rooms using
 * {@link Exam#findBestAvailableRooms(Assignment, ExamPeriodPlacement)}.
 */
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
    ExamModel model = (ExamModel) solution.getModel();
    Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
    Exam exam = ToolBox.random(model.variables());
    int px = ToolBox.random(exam.getPeriodPlacements().size());
    for (int p = 0; p < exam.getPeriodPlacements().size(); p++) {
        ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
        if (iCheckStudentConflicts && exam.countStudentConflicts(assignment, period) > 0)
            continue;
        if (iCheckDistributionConstraints && !exam.checkDistributionConstraints(assignment, period))
            continue;
        Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
        if (rooms == null)
            continue;
        return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, rooms));
    }
    return null;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:25,代码来源:ExamRandomMove.java

示例4: getBounds

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    double[] bounds = new double[] { 0.0, 0.0 };
    for (Exam exam : variables) {
        if (!exam.getPeriodPlacements().isEmpty()) {
            int minSizePenalty = Integer.MAX_VALUE, maxSizePenalty = Integer.MIN_VALUE;
            for (ExamPeriodPlacement periodPlacement : exam.getPeriodPlacements()) {
                minSizePenalty = Math.min(minSizePenalty, periodPlacement.getPenalty() * (exam.getSize() + 1));
                maxSizePenalty = Math.max(maxSizePenalty, periodPlacement.getPenalty() * (exam.getSize() + 1));
            }
            bounds[0] += minSizePenalty;
            bounds[1] += maxSizePenalty;
        }
    }
    return bounds;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:17,代码来源:PeriodSizePenalty.java

示例5: getBounds

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    double[] bounds = new double[] { 0.0, 0.0 };
    for (Exam exam : variables) {
        if (!exam.getPeriodPlacements().isEmpty()) {
            int minPenalty = Integer.MAX_VALUE, maxPenalty = Integer.MIN_VALUE;
            for (ExamPeriodPlacement periodPlacement : exam.getPeriodPlacements()) {
                if (iSoftPeriods != null && (periodPlacement.getExamPenalty() == iSoftPeriods || periodPlacement.getPeriod().getPenalty() == iSoftPeriods)) continue;
                minPenalty = Math.min(minPenalty, periodPlacement.getPenalty());
                maxPenalty = Math.max(maxPenalty, periodPlacement.getPenalty());
            }
            bounds[0] += minPenalty;
            bounds[1] += maxPenalty;
        }
    }
    return bounds;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:18,代码来源:PeriodPenalty.java

示例6: findRooms

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
public Set<ExamRoomPlacement> findRooms(Assignment<Exam, ExamPlacement> assignment, Exam exam, ExamPeriodPlacement period) {
    Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
    if (rooms != null) return rooms;
    
    rooms = new HashSet<ExamRoomPlacement>();
    int size = 0;
    while (size < exam.getSize()) {
        ExamRoomPlacement bestRoom = null; int bestSize = 0;
        for (ExamRoomPlacement r: exam.getRoomPlacements()) {
            if (!r.isAvailable(period.getPeriod())) continue;
            if (rooms.contains(r)) continue;
            if (!r.getRoom().getPlacements(assignment, period.getPeriod()).isEmpty()) continue;
            int s = r.getSize(exam.hasAltSeating());
            if (bestRoom == null || s > bestSize) {
                bestRoom = r;
                bestSize = s;
            }
        }
        if (bestRoom == null) return rooms;
        rooms.add(bestRoom); size += bestSize;
    }
    
    return rooms;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:25,代码来源:ExamColoringConstruction.java

示例7: bestSplit

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
/**
 * Find a best split for the given exam. Only improving neighbors are considered. 
 * @param assignment current assignment
 * @param exam an exam to be split
 * @return best neighbor that will do the split
 */
public ExamSplitNeighbour bestSplit(Assignment<Exam, ExamPlacement> assignment, Exam exam) {
    ExamSplitNeighbour split = null;
    ExamPlacement placement = assignment.getValue(exam);
    int px = ToolBox.random(exam.getPeriodPlacements().size());
    for (int p = 0; p < exam.getPeriodPlacements().size(); p++) { // Iterate over possible periods
        ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
        if (placement != null && placement.getPeriod().equals(period)) continue;
        // Try to create a neighbor
        ExamSplitNeighbour s = new ExamSplitNeighbour(assignment, exam, new ExamPlacement(exam, period, null));
        if (split == null || s.value(assignment) < split.value(assignment)) {
            // If improving, try to find available rooms
            Set<ExamRoomPlacement> rooms = findBestAvailableRooms(assignment, exam, period, s.nrStudents());
            if (rooms != null) {
                // Remember as best split
                s.placement().getRoomPlacements().addAll(rooms);
                split = s;
            }
        }
    }
    return split;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:28,代码来源:ExamSplitMoves.java

示例8: getPlacement

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
public ExamPlacement getPlacement(ExamAssignment assignment) {
    Lock lock = currentSolution().getLock().readLock();
    lock.lock();
    try {
        Exam exam = getExam(assignment.getExamId());
        if (exam==null) return null;
        ExamPeriodPlacement period = null;
        for (ExamPeriodPlacement p: exam.getPeriodPlacements()) {
            if (p.getId().equals(assignment.getPeriodId())) { period = p; break; }
        }
        if (period==null) return null;
        HashSet rooms = new HashSet();
        for (ExamRoomInfo roomInfo : assignment.getRooms()) {
            Long roomId = roomInfo.getLocationId();
            ExamRoomPlacement room = null;
            for (ExamRoomPlacement r: exam.getRoomPlacements()) {
                if (r.getId()==roomId) { room = r; break; }
            }
            if (room!=null) rooms.add(room);
        }
        return new ExamPlacement(exam, period, rooms);
    } finally {
    	lock.unlock();
    }
}
 
开发者ID:UniTime,项目名称:unitime,代码行数:26,代码来源:ExamSolver.java

示例9: checkConsistency

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
protected void checkConsistency() {
    iProgress.setPhase("Checking consistency...", getModel().variables().size());
    for (Exam exam: getModel().variables()) {
        iProgress.incProgress();
       if (exam.getPeriodPlacements().isEmpty()) {
            iProgress.error("Exam "+getExamLabel(exam)+" has no period available.");
            continue;
        }
        if (exam.getMaxRooms()>0) {
            int capacity = 0;
            for (int i = 0; i < Math.min(exam.getMaxRooms(), exam.getRoomPlacements().size()); i++) {
                ExamRoomPlacement r = (ExamRoomPlacement)exam.getRoomPlacements().get(i);
                capacity += r.getSize(exam.hasAltSeating());
            }
            if (capacity<exam.getSize()) {
                iProgress.error("Exam "+getExamLabel(exam)+" has no room placement available.");
                continue;
            }
            boolean hasValue = false;
            for (Iterator<ExamPeriodPlacement> f=exam.getPeriodPlacements().iterator();!hasValue && f.hasNext();) {
                ExamPeriodPlacement period = f.next();
                if (exam.findBestAvailableRooms(getAssignment(), period)!=null) hasValue = true;
            }
            if (!hasValue) {
                iProgress.error("Exam "+getExamLabel(exam)+" has no assignment available.");
                continue;
            }
        }
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:31,代码来源:ExamDatabaseLoader.java

示例10: findBestAvailableRooms

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
public Set findBestAvailableRooms(Exam exam, ExamPeriodPlacement period, boolean checkConstraints) {
    if (exam.getMaxRooms()==0) return new HashSet();
    ExamRoomSharing sharing = iModel.getRoomSharing();
    loop: for (int nrRooms=1;nrRooms<=exam.getMaxRooms();nrRooms++) {
        HashSet rooms = new HashSet(); int size = 0;
        while (rooms.size()<nrRooms && size<exam.getSize()) {
            int minSize = (exam.getSize()-size)/(nrRooms-rooms.size());
            ExamRoomPlacement best = null; int bestSize = 0, bestPenalty = 0;
            for (ExamRoomPlacement room: exam.getRoomPlacements()) {
                if (!room.isAvailable(period.getPeriod())) continue;
                if (checkConstraints) {
                    if (nrRooms == 1 && sharing != null) {
                        if (sharing.inConflict(exam, room.getRoom().getPlacements(iAssignment, period.getPeriod()), room.getRoom()))
                            continue;
                    } else {
                        if (!room.getRoom().getPlacements(iAssignment, period.getPeriod()).isEmpty())
                            continue;
                    }
                }
                if (rooms.contains(room)) continue;
                if (checkConstraints && !exam.checkDistributionConstraints(iAssignment, room)) continue;
                int s = room.getSize(exam.hasAltSeating());
                if (s<minSize) break;
                int p = room.getPenalty(period.getPeriod());
                if (best==null || bestPenalty>p || (bestPenalty==p && bestSize>s)) {
                    best = room;
                    bestSize = s;
                    bestPenalty = p;
                }
            }
            if (best==null) continue loop;
            rooms.add(best); size+=bestSize;
        }
        if (size>=exam.getSize()) return rooms;
    }
    return null;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:38,代码来源:ExamSuggestions.java

示例11: backtrack

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
private void backtrack(int depth) {
    if (iDepth>depth && iConflictsToResolve.isEmpty()) {
        if (iSuggestions.size()==iLimit && iSuggestions.last().isBetter(iModel, iAssignment)) return;
        iSuggestions.add(new ExamProposedChange(iModel, iAssignment, iInitialAssignment, iInitialInfo, iConflictsToResolve.values(), iResolvedExams));
        iNrSolutions++;
        if (iSuggestions.size()>iLimit) iSuggestions.remove(iSuggestions.last());
        return;
    }
    if (depth<=0) return;
    if (iTimeOut>0 && System.currentTimeMillis()-iStartTime>iTimeOut) {
        iTimeoutReached = true;
        return;
    }
    Exam exam = (iDepth==depth && !iResolvedExams.contains(iExam)?iExam:iConflictsToResolve.keys().nextElement());
    if (iResolvedExams.contains(exam)) return;
    iResolvedExams.add(exam);
    for (ExamPeriodPlacement period: exam.getPeriodPlacements()) {
        //if (exam.equals(iExam) && !match(period.getPeriod().toString())) continue;
        Set rooms = findBestAvailableRooms(exam, period, true);
        if (rooms!=null) {
            tryPlacement(new ExamPlacement(exam, period, rooms), depth);
        } else {
            rooms = findBestAvailableRooms(exam, period, false);
            if (rooms!=null) tryPlacement(new ExamPlacement(exam, period, rooms), depth);
        }
    }
    iResolvedExams.remove(exam);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:29,代码来源:ExamSuggestions.java

示例12: getBounds

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
    double[] bounds = new double[] { 0.0, 0.0 };
    for (Exam exam : variables) {
        if (!exam.getPeriodPlacements().isEmpty()) {
            for (ExamPeriodPlacement periodPlacement : exam.getPeriodPlacements()) {
                if (periodPlacement.getExamPenalty() == getWeight() || periodPlacement.getPeriod().getPenalty() == getWeight()) {
                    bounds[1] ++; break;
                }
            }
        }
    }
    return bounds;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:15,代码来源:PeriodViolation.java

示例13: checkDistributionConstraints

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
public boolean checkDistributionConstraints(Assignment<Exam, ExamPlacement> assignment, Exam exam, ExamPeriodPlacement period, Map<Exam, ExamPlacement> placements) {
    for (ExamDistributionConstraint dc : exam.getDistributionConstraints()) {
        if (!dc.isHard())
            continue;
        boolean before = true;
        for (Exam other : dc.variables()) {
            if (other.equals(this)) {
                before = false;
                continue;
            }
            ExamPlacement placement = (placements.containsKey(other) ? placements.get(other) : assignment.getValue(other));
            if (placement == null) continue;
            switch (dc.getType()) {
                case ExamDistributionConstraint.sDistSamePeriod:
                    if (period.getIndex() != placement.getPeriod().getIndex())
                        return false;
                    break;
                case ExamDistributionConstraint.sDistDifferentPeriod:
                    if (period.getIndex() == placement.getPeriod().getIndex())
                        return false;
                    break;
                case ExamDistributionConstraint.sDistPrecedence:
                    if (before) {
                        if (period.getIndex() <= placement.getPeriod().getIndex())
                            return false;
                    } else {
                        if (period.getIndex() >= placement.getPeriod().getIndex())
                            return false;
                    }
                    break;
                case ExamDistributionConstraint.sDistPrecedenceRev:
                    if (before) {
                        if (period.getIndex() >= placement.getPeriod().getIndex())
                            return false;
                    } else {
                        if (period.getIndex() <= placement.getPeriod().getIndex())
                            return false;
                    }
                    break;
            }
        }
    }
    return true;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:45,代码来源:ExamPeriodSwapMove.java

示例14: Vertex

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
public Vertex(Exam exam) {
    iExam = exam;
    for (ExamPeriodPlacement period: exam.getPeriodPlacements())
        iDomain.put(period.getIndex(), period);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:6,代码来源:ExamColoringConstruction.java

示例15: findBestAvailableRooms

import org.cpsolver.exam.model.ExamPeriodPlacement; //导入依赖的package包/类
/**
 * Find best available rooms for a new exam (that is to be split from the given one),
 * if is is assigned into the given examination period.
 * 
 * @param assignment current assignment
 * @param exam an exam to be split
 * @param period a period to be assigned to the new exam
 * @param examSize size of the new exam (i.e., the number of students that will be moved from the given exam to the new one)
 * @return best room placement for the given exam and period 
 */
public Set<ExamRoomPlacement> findBestAvailableRooms(Assignment<Exam, ExamPlacement> assignment, Exam exam, ExamPeriodPlacement period, int examSize) {
    if (exam.getMaxRooms() == 0) return new HashSet<ExamRoomPlacement>();
    double sw = exam.getModel().getCriterion(RoomSizePenalty.class).getWeight();
    double pw = exam.getModel().getCriterion(RoomPenalty.class).getWeight();
    loop: for (int nrRooms = 1; nrRooms <= exam.getMaxRooms(); nrRooms++) {
        HashSet<ExamRoomPlacement> rooms = new HashSet<ExamRoomPlacement>();
        int size = 0;
        while (rooms.size() < nrRooms && size < examSize) {
            int minSize = (examSize - size) / (nrRooms - rooms.size());
            ExamRoomPlacement best = null;
            double bestWeight = 0;
            int bestSize = 0;
            for (ExamRoomPlacement room : exam.getRoomPlacements()) {
                if (!room.isAvailable(period.getPeriod()))
                    continue;
                if (!room.getRoom().getPlacements(assignment, period.getPeriod()).isEmpty())
                    continue;
                if (rooms.contains(room))
                    continue;
                int s = room.getSize(exam.hasAltSeating());
                if (s < minSize)
                    break;
                int p = room.getPenalty(period.getPeriod());
                double w = pw * p + sw * (s - minSize);
                double d = 0;
                if (!rooms.isEmpty()) {
                    for (ExamRoomPlacement r : rooms) {
                        d += r.getDistanceInMeters(room);
                    }
                    w += d / rooms.size();
                }
                if (best == null || bestWeight > w) {
                    best = room;
                    bestSize = s;
                    bestWeight = w;
                }
            }
            if (best == null)
                continue loop;
            rooms.add(best);
            size += bestSize;
        }
        if (size >= examSize)
            return rooms;
    }
    return null;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:58,代码来源:ExamSplitMoves.java


注:本文中的org.cpsolver.exam.model.ExamPeriodPlacement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。