All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cpsolver.exam.criteria.PeriodPenalty Maven / Gradle / Ivy

Go to download

The constraint solver library contains a local search based framework that allows modeling of a problem using constraint programming primitives (variables, values, constraints).

The newest version!
package org.cpsolver.exam.criteria;

import java.util.Collection;
import java.util.Set;

import org.cpsolver.exam.criteria.additional.PeriodViolation;
import org.cpsolver.exam.model.Exam;
import org.cpsolver.exam.model.ExamPeriodPlacement;
import org.cpsolver.exam.model.ExamPlacement;
import org.cpsolver.ifs.assignment.Assignment;
import org.cpsolver.ifs.solver.Solver;
import org.cpsolver.ifs.util.DataProperties;


/**
 * Cost for using a period. See {@link ExamPeriodPlacement#getPenalty()} for more details.
 * 

* A weight for period penalty can be set by problem property * Exams.PeriodWeight, or in the input xml file, property periodWeight. * *
* * @author Tomas Muller * @version ExamTT 1.3 (Examination Timetabling)
* Copyright (C) 2008 - 2014 Tomas Muller
* [email protected]
* http://muller.unitime.org
*
* This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public * License along with this library; if not see * http://www.gnu.org/licenses/. */ public class PeriodPenalty extends ExamCriterion { protected Integer iSoftPeriods = null; @Override public boolean init(Solver solver) { if (super.init(solver)) { iSoftPeriods = solver.getProperties().getPropertyInteger("Exam.SoftPeriods", null); if (iSoftPeriods != null) { PeriodViolation pv = new PeriodViolation(); getModel().addCriterion(pv); return pv.init(solver); } } return true; } @Override public String getWeightName() { return "Exams.PeriodWeight"; } @Override public String getXmlWeightName() { return "periodWeight"; } @Override public double getWeightDefault(DataProperties config) { return 1.0; } @Override public double getValue(Assignment assignment, ExamPlacement value, Set conflicts) { return (iSoftPeriods == null || (value.getPeriodPlacement().getExamPenalty() != iSoftPeriods && value.getPeriodPlacement().getPeriod().getPenalty() != iSoftPeriods) ? value.getPeriodPlacement().getPenalty() : 0.0); } @Override public double[] getBounds(Assignment assignment, Collection 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; } @Override public String toString(Assignment assignment) { return "PP:" + sDoubleFormat.format(getValue(assignment)); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy