    001package org.cpsolver.ifs.criteria;
    002
    003import java.util.Set;
    004
    005import org.cpsolver.ifs.assignment.Assignment;
    006import org.cpsolver.ifs.model.Model;
    007import org.cpsolver.ifs.model.Value;
    008import org.cpsolver.ifs.model.Variable;
    009import org.cpsolver.ifs.util.DataProperties;
    010
    011
    012/**
    013 * Simple Criterion: Sum of {@link Value#toDouble(Assignment)}. <br>
    014 * <br>
    015 * This criterion only counts a sum of values (see {@link Value#toDouble(Assignment)}) of the assigned variables.
    016 * It is an alternative to the default {@link Model#getTotalValue(Assignment)}.
    017 *
    018 * @version IFS 1.3 (Iterative Forward Search)<br>
    019 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    020 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    021 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    022 * <br>
    023 *          This library is free software; you can redistribute it and/or modify
    024 *          it under the terms of the GNU Lesser General Public License as
    025 *          published by the Free Software Foundation; either version 3 of the
    026 *          License, or (at your option) any later version. <br>
    027 * <br>
    028 *          This library is distributed in the hope that it will be useful, but
    029 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    030 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    031 *          Lesser General Public License for more details. <br>
    032 * <br>
    033 *          You should have received a copy of the GNU Lesser General Public
    034 *          License along with this library; if not see
    035 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    036 * @param <V> Variable
    037 * @param <T> Value
    038 */
    039public class AssignedValue<V extends Variable<V, T>, T extends Value<V, T>> extends AbstractCriterion<V, T>{
    040
    041    @Override
    042    public double getWeightDefault(DataProperties config) {
    043        return 1.0;
    044    }
    045
    046    @Override
    047    public double getValue(Assignment<V, T> assignment, T value, Set<T> conflicts) {
    048        double ret = value.toDouble(assignment);
    049        if (conflicts != null)
    050            for (T conflict: conflicts)
    051                ret -= conflict.toDouble(assignment);
    052        return ret;
    053    }
    054
    055}