Package org.drools.planner.examples.examination.domain

Examples of org.drools.planner.examples.examination.domain.Exam


        List<ExamInitializationWeight> examInitialWeightList = createExamAssigningScoreList(examination);

        for (ExamInitializationWeight examInitialWeight : examInitialWeightList) {
            Score unscheduledScore = scoreDirector.calculateScore();
            Exam leader = examInitialWeight.getExam();

            List<ExamToHandle> examToHandleList = new ArrayList<ExamToHandle>(5);
            if (leader.getExamCoincidence() == null) {
                examToHandleList.add(new ExamToHandle(leader));
            } else {
                for (Exam coincidenceExam : leader.getExamCoincidence().getCoincidenceExamSet()) {
                    examToHandleList.add(new ExamToHandle(coincidenceExam));
                }
            }

            List<PeriodScoring> periodScoringList = new ArrayList<PeriodScoring>(periodList.size());
            for (Period period : periodList) {
                for (ExamToHandle examToHandle : examToHandleList) {
                    Exam exam = examToHandle.getExam();
                    if (!examToHandle.isAdded()) {
                        scoreDirector.beforeEntityAdded(exam);
                        exam.setPeriod(period);
                        scoreDirector.afterEntityAdded(exam);
                        examToHandle.setAdded(true);
                    } else {
                        scoreDirector.beforeVariableChanged(exam, "period");
                        exam.setPeriod(period);
                        scoreDirector.afterVariableChanged(exam, "period");
                    }
                }
                Score score = scoreDirector.calculateScore();
                periodScoringList.add(new PeriodScoring(period, score));
            }
            Collections.sort(periodScoringList);

            scheduleLeader(periodScoringList, roomList, scoreDirector, unscheduledScore, examToHandleList, leader);
            examList.add(leader);

            // Schedule the non leaders
            for (ExamToHandle examToHandle : examToHandleList) {
                Exam exam = examToHandle.getExam();
                // Leader already has a room
                if (!exam.isCoincidenceLeader()) {
                    scheduleNonLeader(roomList, scoreDirector, exam);
                    examList.add(exam);
                }
            }
        }
View Full Code Here


            if (bestScore.compareTo(periodScoring.getScore()) >= 0) {
                // No need to check the rest
                break;
            }
            for (ExamToHandle examToHandle : examToHandleList) {
                Exam exam = examToHandle.getExam();
                scoreDirector.beforeVariableChanged(exam, "period");
                exam.setPeriod(periodScoring.getPeriod());
                scoreDirector.afterVariableChanged(exam, "period");
            }
            for (Room room : roomList) {
                scoreDirector.beforeVariableChanged(leader, "room");
                leader.setRoom(room);
                scoreDirector.afterVariableChanged(leader, "room");
                Score score = scoreDirector.calculateScore();
                if (score.compareTo(unscheduledScore) < 0) {
                    if (score.compareTo(bestScore) > 0) {
                        bestScore = score;
                        bestPeriod = periodScoring.getPeriod();
                        bestRoom = room;
                    }
                } else if (score.equals(unscheduledScore)) {
                    perfectMatch = true;
                    break;
                } else {
                    throw new IllegalStateException("The score (" + score
                            + ") cannot be higher than unscheduledScore (" + unscheduledScore + ").");
                }
            }
            if (perfectMatch) {
                break;
            }
        }
        if (!perfectMatch) {
            if (bestPeriod == null || bestRoom == null) {
                throw new IllegalStateException("The bestPeriod (" + bestPeriod + ") or the bestRoom ("
                        + bestRoom + ") cannot be null.");
            }
            scoreDirector.beforeVariableChanged(leader, "room");
            leader.setRoom(bestRoom);
            scoreDirector.afterVariableChanged(leader, "room");
            for (ExamToHandle examToHandle : examToHandleList) {
                Exam exam = examToHandle.getExam();
                scoreDirector.beforeVariableChanged(exam, "period");
                exam.setPeriod(bestPeriod);
                scoreDirector.afterVariableChanged(exam, "period");
            }
        }
        logger.debug("    Exam ({}) initialized.", leader);
    }
View Full Code Here

    public List<Exam> createExamList(Examination examination) {
        List<Topic> topicList = examination.getTopicList();
        List<Exam> examList = new ArrayList<Exam>(topicList.size());
        Map<Topic, Exam> topicToExamMap = new HashMap<Topic, Exam>(topicList.size());
        for (Topic topic : topicList) {
            Exam exam = new Exam();
            exam.setId(topic.getId());
            exam.setTopic(topic);
            examList.add(exam);
            topicToExamMap.put(topic, exam);
        }
        for (PeriodPenalty periodPenalty : examination.getPeriodPenaltyList()) {
            if (periodPenalty.getPeriodPenaltyType() == PeriodPenaltyType.EXAM_COINCIDENCE) {
                Exam leftExam = topicToExamMap.get(periodPenalty.getLeftSideTopic());
                Exam rightExam = topicToExamMap.get(periodPenalty.getRightSideTopic());

                Set<Exam> newCoincidenceExamSet = new LinkedHashSet<Exam>(4);
                ExamCoincidence leftExamCoincidence = leftExam.getExamCoincidence();
                if (leftExamCoincidence != null) {
                    newCoincidenceExamSet.addAll(leftExamCoincidence.getCoincidenceExamSet());
                } else {
                    newCoincidenceExamSet.add(leftExam);
                }
                ExamCoincidence rightExamCoincidence = rightExam.getExamCoincidence();
                if (rightExamCoincidence != null) {
                    newCoincidenceExamSet.addAll(rightExamCoincidence.getCoincidenceExamSet());
                } else {
                    newCoincidenceExamSet.add(rightExam);
                }
                ExamCoincidence newExamCoincidence = new ExamCoincidence(newCoincidenceExamSet);
                for (Exam exam : newCoincidenceExamSet) {
                    exam.setExamCoincidence(newExamCoincidence);
                }
            } else if (periodPenalty.getPeriodPenaltyType() == PeriodPenaltyType.AFTER) {
                Exam afterExam = topicToExamMap.get(periodPenalty.getLeftSideTopic());
                Exam beforeExam = topicToExamMap.get(periodPenalty.getRightSideTopic());
                ExamBefore examBefore = beforeExam.getExamBefore();
                if (examBefore == null) {
                    examBefore = new ExamBefore(new LinkedHashSet<Exam>(2));
                    beforeExam.setExamBefore(examBefore);
                }
                examBefore.getAfterExamSet().add(afterExam);
            }
        }
        return examList;
View Full Code Here

        private void createExamList(Examination examination) {
            List<Topic> topicList = examination.getTopicList();
            List<Exam> examList = new ArrayList<Exam>(topicList.size());
            Map<Topic, Exam> topicToExamMap = new HashMap<Topic, Exam>(topicList.size());
            for (Topic topic : topicList) {
                Exam exam = new Exam();
                exam.setId(topic.getId());
                exam.setTopic(topic);
                // Notice that we leave the PlanningVariable properties on null
                examList.add(exam);
                topicToExamMap.put(topic, exam);
            }
            for (PeriodPenalty periodPenalty : examination.getPeriodPenaltyList()) {
                if (periodPenalty.getPeriodPenaltyType() == PeriodPenaltyType.EXAM_COINCIDENCE) {
                    Exam leftExam = topicToExamMap.get(periodPenalty.getLeftSideTopic());
                    Exam rightExam = topicToExamMap.get(periodPenalty.getRightSideTopic());

                    Set<Exam> newCoincidenceExamSet = new LinkedHashSet<Exam>(4);
                    ExamCoincidence leftExamCoincidence = leftExam.getExamCoincidence();
                    if (leftExamCoincidence != null) {
                        newCoincidenceExamSet.addAll(leftExamCoincidence.getCoincidenceExamSet());
                    } else {
                        newCoincidenceExamSet.add(leftExam);
                    }
                    ExamCoincidence rightExamCoincidence = rightExam.getExamCoincidence();
                    if (rightExamCoincidence != null) {
                        newCoincidenceExamSet.addAll(rightExamCoincidence.getCoincidenceExamSet());
                    } else {
                        newCoincidenceExamSet.add(rightExam);
                    }
                    ExamCoincidence newExamCoincidence = new ExamCoincidence(newCoincidenceExamSet);
                    for (Exam exam : newCoincidenceExamSet) {
                        exam.setExamCoincidence(newExamCoincidence);
                    }
                } else if (periodPenalty.getPeriodPenaltyType() == PeriodPenaltyType.AFTER) {
                    Exam afterExam = topicToExamMap.get(periodPenalty.getLeftSideTopic());
                    Exam beforeExam = topicToExamMap.get(periodPenalty.getRightSideTopic());
                    ExamBefore examBefore = beforeExam.getExamBefore();
                    if (examBefore == null) {
                        examBefore = new ExamBefore(new LinkedHashSet<Exam>(2));
                        beforeExam.setExamBefore(examBefore);
                    }
                    examBefore.getAfterExamSet().add(afterExam);
                }
            }
            examination.setExamList(examList);
View Full Code Here

    public List<Move> createMoveList(Solution solution) {
        Examination examination = (Examination) solution;
        List<Exam> examList = examination.getExamList();
        List<Move> moveList = new ArrayList<Move>();
        for (ListIterator<Exam> leftIt = examList.listIterator(); leftIt.hasNext();) {
            Exam leftExam = leftIt.next();
            for (ListIterator<Exam> rightIt = examList.listIterator(leftIt.nextIndex()); rightIt.hasNext();) {
                Exam rightExam = rightIt.next();
                moveList.add(new ExamSwapMove(leftExam, rightExam));
            }
        }
        return moveList;
    }
View Full Code Here

TOP

Related Classes of org.drools.planner.examples.examination.domain.Exam

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.