001package org.cpsolver.ifs.assignment.context; 002 003import org.cpsolver.ifs.assignment.Assignment; 004import org.cpsolver.ifs.model.Model; 005import org.cpsolver.ifs.model.Value; 006import org.cpsolver.ifs.model.Variable; 007 008/** 009 * An interface holding all assignment contexts associated with one assignment. It also 010 * creates a new assignment context when there is no assignment context associated with the given 011 * reference.<br><br> 012 * 013 * Method {@link AssignmentContextReference#getIndex()} can be used to index stored contexts. 014 * A new assignment context can be created for a reference by calling {@link HasAssignmentContext#createAssignmentContext(Assignment)} 015 * on the {@link AssignmentContextReference#getParent()}. 016 * 017 * @see AssignmentContext 018 * @see AssignmentContextReference 019 * @see HasAssignmentContext 020 * 021 * @version IFS 1.3 (Iterative Forward Search)<br> 022 * Copyright (C) 2014 Tomáš Müller<br> 023 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 024 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 025 * <br> 026 * This library is free software; you can redistribute it and/or modify 027 * it under the terms of the GNU Lesser General Public License as 028 * published by the Free Software Foundation; either version 3 of the 029 * License, or (at your option) any later version. <br> 030 * <br> 031 * This library is distributed in the hope that it will be useful, but 032 * WITHOUT ANY WARRANTY; without even the implied warranty of 033 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 034 * Lesser General Public License for more details. <br> 035 * <br> 036 * You should have received a copy of the GNU Lesser General Public 037 * License along with this library; if not see <a href='http://www.gnu.org/licenses'>http://www.gnu.org/licenses</a>. 038 * @param <V> Variable 039 * @param <T> Value 040 **/ 041public interface AssignmentContextHolder<V extends Variable<V, T>, T extends Value<V, T>> { 042 043 /** 044 * Return assignment context for the given assignment and reference. A new assignment context is created 045 * when there is not assignment context associated with the given reference yet. 046 * @param assignment current assignment (there is only one assignment associated with one holder, but 047 * the assignment is passed so that {@link HasAssignmentContext#createAssignmentContext(Assignment)} can be called if needed 048 * @param reference a reference created by calling {@link Model#createReference(HasAssignmentContext)} 049 * @param <U> assignment context type 050 * @return an assignment context 051 */ 052 public <U extends AssignmentContext> U getAssignmentContext(Assignment<V, T> assignment, AssignmentContextReference<V, T, U> reference); 053 054 /** 055 * Clear an assignment context that is associated with the given a reference. If there is any created for the reference. 056 * @param reference a reference (which can be stored within the model, e.g., as an instance variable of a constraint) 057 * @param <U> assignment context type 058 **/ 059 public <U extends AssignmentContext> void clearContext(AssignmentContextReference<V, T, U> reference); 060 061}