001    package net.sf.cpsolver.studentsct.extension;
002    
003    import net.sf.cpsolver.ifs.extension.ConflictStatistics;
004    import net.sf.cpsolver.ifs.model.Value;
005    import net.sf.cpsolver.ifs.solver.Solver;
006    import net.sf.cpsolver.ifs.util.DataProperties;
007    import net.sf.cpsolver.studentsct.model.Enrollment;
008    import net.sf.cpsolver.studentsct.model.Student;
009    
010    /**
011     * Same as {@link ConflictStatistics}, however, conflict with real students 
012     * can be weighted differently than with last-like students.
013     * 
014     * <br><br>
015     * Parameters:
016     * <br>
017     * <table border='1'><tr><th>Parameter</th><th>Type</th><th>Comment</th></tr>
018     * <tr><td>StudentConflictStatistics.RealStudentWeight</td><td>{@link Double}</td><td>
019     * Weight of a conflict with a real student ({@link Student#isDummy()} is false). 
020     * </td></tr>
021     * <tr><td>StudentConflictStatistics.RealStudentWeight</td><td>{@link Double}</td><td>
022     * Weight of a conflict with a last-like student ({@link Student#isDummy()} is true). 
023     * </td></tr>
024     * </table>
025     *
026     * @version
027     * StudentSct 1.1 (Student Sectioning)<br>
028     * Copyright (C) 2007 Tomáš Müller<br>
029     * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
030     * Lazenska 391, 76314 Zlin, Czech Republic<br>
031     * <br>
032     * This library is free software; you can redistribute it and/or
033     * modify it under the terms of the GNU Lesser General Public
034     * License as published by the Free Software Foundation; either
035     * version 2.1 of the License, or (at your option) any later version.
036     * <br><br>
037     * This library is distributed in the hope that it will be useful,
038     * but WITHOUT ANY WARRANTY; without even the implied warranty of
039     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
040     * Lesser General Public License for more details.
041     * <br><br>
042     * You should have received a copy of the GNU Lesser General Public
043     * License along with this library; if not, write to the Free Software
044     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
045     */
046    public class StudentConflictStatistics extends ConflictStatistics {
047        public double iRealStudentWeight = 2.0;
048        public double iDummyStudentWeight = 0.5;
049    
050        public StudentConflictStatistics(Solver solver, DataProperties properties) {
051            super (solver, properties);
052            iRealStudentWeight = properties.getPropertyDouble("StudentConflictStatistics.RealStudentWeight", iRealStudentWeight);
053            iDummyStudentWeight = properties.getPropertyDouble("StudentConflictStatistics.DummyStudentWeight", iDummyStudentWeight);
054        }
055        
056        public double countRemovals(long iteration, Value conflictValue, Value value) {
057            double ret = super.countRemovals(iteration, conflictValue, value);
058            if (ret==0.0) return ret;
059            Enrollment conflict = (Enrollment)conflictValue;
060            /*
061            Enrollment enrollment = (Enrollment)value;
062            if (enrollment.getRequest().getStudent().isDummy()==conflict.getRequest().getStudent().isDummy())
063                return ret;
064            */
065            return ret * (conflict.getRequest().getStudent().isDummy()?iDummyStudentWeight:iRealStudentWeight); 
066        }
067    }