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 * @author Tomáš Müller 016 * @version IFS 1.3 (Iterative Forward Search)<br> 017 * Copyright (C) 2014 Tomáš Müller<br> 018 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 019 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 020 * <br> 021 * This library is free software; you can redistribute it and/or modify 022 * it under the terms of the GNU Lesser General Public License as 023 * published by the Free Software Foundation; either version 3 of the 024 * License, or (at your option) any later version. <br> 025 * <br> 026 * This library is distributed in the hope that it will be useful, but 027 * WITHOUT ANY WARRANTY; without even the implied warranty of 028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 029 * Lesser General Public License for more details. <br> 030 * <br> 031 * You should have received a copy of the GNU Lesser General Public 032 * License along with this library; if not see <a href='http://www.gnu.org/licenses'>http://www.gnu.org/licenses</a>. 033 * @param <V> Variable 034 * @param <T> Value 035 **/ 036public class DefaultInheritedAssignment<V extends Variable<V, T>, T extends Value<V, T>> extends DefaultParallelAssignment<V, T> implements InheritedAssignment<V, T> { 037 private Assignment<V, T> iParent; 038 private long iVersion = -1; 039 040 public DefaultInheritedAssignment(Solution<V, T> parent, int index) { 041 super(new InheritedAssignmentContextHolder<V, T>(index, parent.getIteration()), index, parent); 042 iParent = parent.getAssignment(); 043 iVersion = parent.getIteration(); 044 } 045 046 @Override 047 public Assignment<V, T> getParentAssignment() { 048 return iParent; 049 } 050 051 @Override 052 public long getVersion() { 053 return iVersion; 054 } 055}