org.chocosolver.solver.constraints.nary.nvalue.PropNValue 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.nary.nvalue;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.set.hash.TIntHashSet;
import org.chocosolver.solver.constraints.Propagator;
import org.chocosolver.solver.constraints.PropagatorPriority;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.events.IntEventType;
import org.chocosolver.solver.variables.events.PropagatorEventType;
import org.chocosolver.util.ESat;
import org.chocosolver.util.objects.setDataStructures.ISet;
import org.chocosolver.util.objects.setDataStructures.ISetIterator;
import org.chocosolver.util.objects.setDataStructures.SetFactory;
import org.chocosolver.util.objects.setDataStructures.SetType;
import org.chocosolver.util.tools.ArrayUtils;
import java.util.Random;
/**
* @author Arthur Godet
* @since 13/03/2020
*/
public class PropNValue extends Propagator {
private static final int NO_WITNESS = -1;
private final IntVar nValue;
private final int n;
private final int[] concernedValues;
private final int[] witness;
private final ISet mandatoryValues;
private final ISet possibleValues;
private final TIntArrayList listForRandomPick;
private final Random rnd = new Random(vars[0].getModel().getSeed());
public PropNValue(IntVar[] vars, IntVar nvalue) {
super(ArrayUtils.concat(vars, nvalue), PropagatorPriority.LINEAR, true);
this.nValue = nvalue;
n = vars.length;
TIntHashSet set = new TIntHashSet();
int min = Integer.MAX_VALUE;
for(int i = 0; i vars[n].getUB() || countMax < vars[n].getLB()) {
return ESat.FALSE;
} else if (isCompletelyInstantiated() && countMin == nValue.getValue()) {
return ESat.TRUE;
}
return ESat.UNDEFINED;
}
}