001    package net.sf.cpsolver.coursett.criteria;
002    
003    import java.util.Collection;
004    import java.util.Set;
005    
006    import net.sf.cpsolver.coursett.model.Lecture;
007    import net.sf.cpsolver.coursett.model.Placement;
008    import net.sf.cpsolver.ifs.util.DataProperties;
009    
010    /**
011     * Student committed conflicts. This criterion counts student conflicts between pairs of classes where
012     * one the classes is committed (i.e., fixed in time and room, belonging to another problem).
013     * <br>
014     * 
015     * @version CourseTT 1.2 (University Course Timetabling)<br>
016     *          Copyright (C) 2006 - 2011 Tomas Muller<br>
017     *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
018     *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
019     * <br>
020     *          This library is free software; you can redistribute it and/or modify
021     *          it under the terms of the GNU Lesser General Public License as
022     *          published by the Free Software Foundation; either version 3 of the
023     *          License, or (at your option) any later version. <br>
024     * <br>
025     *          This library is distributed in the hope that it will be useful, but
026     *          WITHOUT ANY WARRANTY; without even the implied warranty of
027     *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
028     *          Lesser General Public License for more details. <br>
029     * <br>
030     *          You should have received a copy of the GNU Lesser General Public
031     *          License along with this library; if not see
032     *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
033     */
034    public class StudentCommittedConflict extends StudentConflict {
035    
036        @Override
037        public double getWeightDefault(DataProperties config) {
038            return config.getPropertyDouble("Comparator.CommitedStudentConflictWeight", 1.0);
039        }
040    
041        @Override
042        public String getPlacementSelectionWeightName() {
043            return "Placement.NrCommitedStudConfsWeight";
044        }
045        
046        @Override
047        public boolean isApplicable(Lecture l1, Lecture l2) {
048            return !ignore(l1, l2) && committed(l1, l2); // only committed student conflicts
049        }
050    
051    
052        @Override
053        public boolean inConflict(Placement p1, Placement p2) {
054            return !ignore(p1, p2) && committed(p1, p2) && super.inConflict(p1, p2);
055        }
056            
057        @Override
058        public double[] getBounds(Collection<Lecture> variables) {
059            double[] bounds = super.getBounds(variables);
060            for (Lecture lecture: variables) {
061                Double max = null;
062                for (Placement placement: lecture.values()) {
063                    if (max == null) { max = new Double(lecture.getCommitedConflicts(placement)); continue; }
064                    max = Math.max(max, lecture.getCommitedConflicts(placement));
065                }
066                if (max != null) bounds[0] += max;
067            }
068            return bounds;
069        }
070        
071        @Override
072        public double getValue(Placement value, Set<Placement> conflicts) {
073            double ret = super.getValue(value, conflicts);
074            ret += value.variable().getCommitedConflicts(value);
075            if (iIncludeConflicts && conflicts != null)
076                for (Placement conflict: conflicts)
077                    ret -= value.variable().getCommitedConflicts(conflict);
078            return ret;
079        }
080        
081        @Override
082        public double getValue(Collection<Lecture> variables) {
083            double ret = super.getValue(variables);
084            for (Lecture lect: variables)
085                if (lect.getAssignment() != null)
086                    ret += lect.getCommitedConflicts(lect.getAssignment());
087            return Math.round(ret);
088        }
089    }