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 * @author  Tomáš Müller
019 * @version IFS 1.3 (Iterative Forward Search)<br>
020 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
021 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
022 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
023 * <br>
024 *          This library is free software; you can redistribute it and/or modify
025 *          it under the terms of the GNU Lesser General Public License as
026 *          published by the Free Software Foundation; either version 3 of the
027 *          License, or (at your option) any later version. <br>
028 * <br>
029 *          This library is distributed in the hope that it will be useful, but
030 *          WITHOUT ANY WARRANTY; without even the implied warranty of
031 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
032 *          Lesser General Public License for more details. <br>
033 * <br>
034 *          You should have received a copy of the GNU Lesser General Public
035 *          License along with this library; if not see
036 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
037 * @param <V> Variable
038 * @param <T> Value
039 */
040public class AssignedValue<V extends Variable<V, T>, T extends Value<V, T>> extends AbstractCriterion<V, T>{
041    
042    @Override
043    public double getWeightDefault(DataProperties config) {
044        return 1.0;
045    }
046
047    @Override
048    public double getValue(Assignment<V, T> assignment, T value, Set<T> conflicts) {
049        double ret = value.toDouble(assignment);
050        if (conflicts != null)
051            for (T conflict: conflicts)
052                ret -= conflict.toDouble(assignment);
053        return ret;
054    }
055
056}