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