All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.chocosolver.solver.variables.view.IView Maven / Gradle / Ivy

There is a newer version: 4.10.17
Show newest version
/*
 * This file is part of choco-solver, http://choco-solver.org/
 *
 * Copyright (c) 2020, IMT Atlantique. All rights reserved.
 *
 * Licensed under the BSD 4-clause license.
 *
 * See LICENSE file in the project root for full license information.
 */
package org.chocosolver.solver.variables.view;

import org.chocosolver.solver.ICause;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.learn.ExplanationForSignedClause;
import org.chocosolver.solver.learn.Implications;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.Variable;
import org.chocosolver.solver.variables.events.IEventType;
import org.chocosolver.solver.variables.events.IntEventType;
import org.chocosolver.util.objects.ValueSortedMap;
import org.chocosolver.util.objects.setDataStructures.iterable.IntIterableRangeSet;

import static org.chocosolver.util.objects.setDataStructures.iterable.IntIterableSetUtils.unionOf;

/**
 * An interface to define views.
 * A view is a specific variable that does not declare any domain but relies on another variable.
 * It converts getters and setters to ensure that the semantic of the view is respected.
 * 

* This is intend to replace very specific propagator such as equality. *
* * @author Charles Prud'homme * @since 26/08/11 */ public interface IView extends ICause, Variable { /** * Return the basis variable * * @return variable observed */ IntVar getVariable(); /** * This methods is related to explanations, it binds an event occurring on the observed * variable to the view. * @param mask type of modification * @param one an int * @param two an int * @param three an int */ void justifyEvent(IntEventType mask, int one, int two, int three); /** * To notify a view that the variable is observed has been modified. * @param event the event received by the observed variable * @throws ContradictionException if a failure occurs */ void notify(IEventType event) throws ContradictionException; default void explain(ExplanationForSignedClause explanation, ValueSortedMap front, Implications ig, int p) { IntVar pivot = ig.getIntVarAt(p); IntVar other = (this == pivot ? getVariable() : (IntVar)this); IntIterableRangeSet dom = explanation.getComplementSet(other); explanation.addLiteral(other, dom, false); dom = explanation.getComplementSet(pivot); unionOf(dom, ig.getDomainAt(p)); explanation.addLiteral(pivot, dom, true); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy