org.chocosolver.solver.constraints.set.PropSetIntValuesUnion Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of choco-solver Show documentation
Show all versions of choco-solver Show documentation
Open-source constraint solver.
/*
* This file is part of choco-solver, http://choco-solver.org/
*
* Copyright (c) 2023, 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.constraints.set;
import org.chocosolver.solver.constraints.Propagator;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.SetVar;
import org.chocosolver.solver.variables.Variable;
import org.chocosolver.util.ESat;
import org.chocosolver.util.objects.setDataStructures.ISetIterator;
import org.chocosolver.util.tools.ArrayUtils;
/**
* Maintain a link between a set variable and the union of values taken by an array of
* integer variables
*
* Not idempotent (use two of them)
*
* @author Jean-Guillaume Fages
*/
public class PropSetIntValuesUnion extends Propagator {
//***********************************************************************************
// VARIABLES
//***********************************************************************************
private final IntVar[] X;
private final SetVar values;
//***********************************************************************************
// CONSTRUCTORS
//***********************************************************************************
public PropSetIntValuesUnion(IntVar[] X, SetVar values){
super(ArrayUtils.append(X,new Variable[]{values}));
this.X = X;
this.values = values;
}
//***********************************************************************************
// METHODS
//***********************************************************************************
@Override
public void propagate(int evtmask) throws ContradictionException {
ISetIterator iter = values.getUB().iterator();
while (iter.hasNext()){
int v = iter.nextInt();
int support = -1;
for(int i=0;i