001package org.cpsolver.ifs.assignment;
002
003import org.cpsolver.ifs.assignment.context.InheritedAssignmentContextHolder;
004import org.cpsolver.ifs.model.Value;
005import org.cpsolver.ifs.model.Variable;
006import org.cpsolver.ifs.solution.Solution;
007
008/**
009 * Default inherited assignment. This assignment is based on {@link DefaultParallelAssignment} and creates
010 * a full copy of the given assignment during its creation. This inherited assignment is slower than
011 * {@link OptimisticInheritedAssignment}, but more reliable. Useful for small problems with a lot of constraints.
012 * 
013 * @see InheritedAssignment
014 * 
015 * @version IFS 1.3 (Iterative Forward Search)<br>
016 *          Copyright (C) 2014 Tomáš Müller<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 <a href='http://www.gnu.org/licenses'>http://www.gnu.org/licenses</a>.
032 * @param <V> Variable
033 * @param <T> Value
034 **/
035public class DefaultInheritedAssignment<V extends Variable<V, T>, T extends Value<V, T>> extends DefaultParallelAssignment<V, T> implements InheritedAssignment<V, T> {
036    private Assignment<V, T> iParent;
037    private long iVersion = -1;
038
039    public DefaultInheritedAssignment(Solution<V, T> parent, int index) {
040        super(new InheritedAssignmentContextHolder<V, T>(index, parent.getIteration()), index, parent);
041        iParent = parent.getAssignment();
042        iVersion = parent.getIteration();
043    }
044
045    @Override
046    public Assignment<V, T> getParentAssignment() {
047        return iParent;
048    }
049
050    @Override
051    public long getVersion() {
052        return iVersion;
053    }
054}