Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ NEXT MILESTONE
### Other closed issues and pull requests:
See [milestone 5.0.0-beta.2](https://github.com/chocoteam/choco-solver/milestone/41)

- Performance improvement in PropXPlusYEqZ and PropAbsolute
- Fix bug in ConflictOrderingSearch (monitor not plugged)
- Performance improvement for LastConflict, ConflictOrderingSearch and StrategySequencer.
- Fix bug : regular constraints parsed from XCSP now support negative values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PropAbsolute(IntVar X, IntVar Y) {
super(ArrayUtils.toArray(X, Y), PropagatorPriority.BINARY, true);
this.X = vars[0];
this.Y = vars[1];
bothEnumerated = X.hasEnumeratedDomain() && Y.hasEnumeratedDomain();
bothEnumerated = X.hasUnfixedEnumeratedDomain() && Y.hasUnfixedEnumeratedDomain();
}

@Override
Expand Down Expand Up @@ -101,8 +101,8 @@ public void propagate(int varIdx, int mask) throws ContradictionException {
Y.updateLowerBound(-val, this, lcg() ? Reason.r(X.getValLit()) : Reason.undef());
Y.updateUpperBound(val, this, lcg() ? Reason.r(X.getValLit()) : Reason.undef());
val--;
for (int v = -val; v <= val; v = Y.nextValue(v)) {
Y.removeValue(v, this, lcg() ? Reason.r(X.getValLit()) : Reason.undef());
if (val >= 0) {
removeInterval(Y, -val, val, lcg() ? Reason.r(X.getValLit()) : Reason.undef());
}
setPassive();
} else {
Expand All @@ -124,10 +124,9 @@ private void setBounds() throws ContradictionException {
int min = X.getLB();
Y.updateLowerBound(-max, this, lcg() ? Reason.r(X.getMaxLit()) : Reason.undef());
Y.updateUpperBound(max, this, lcg() ? Reason.r(X.getMaxLit()) : Reason.undef());
for (int v = 1 - min; v <= min - 1; v = Y.nextValue(v)) {
Y.removeValue(v, this, lcg() ? Reason.r(X.getMinLit()) : Reason.undef());
if (1 - min <= min -1) {
removeInterval(Y, 1 - min, min - 1, lcg() ? Reason.r(X.getMinLit()) : Reason.undef());
}
//if (!lcg()) Y.removeInterval(1 - min, min - 1, this);
/////////////////////////////////////////////////
int prevLB = X.getLB();
int prevUB = X.getUB();
Expand Down Expand Up @@ -178,4 +177,13 @@ private void enumeratedFiltering() throws ContradictionException {
// EXPLANATIONS
//***********************************************************************************

private void removeInterval(IntVar intVar, int fromIncl, int toIncl, Reason reason) throws ContradictionException {
if (!lcg()) {
intVar.removeInterval(fromIncl, toIncl, this);
} else {
for (int i=fromIncl; i<=toIncl; i++) {
intVar.removeValue(i, this, reason);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.chocosolver.util.ESat;
import org.chocosolver.util.objects.setDataStructures.iterable.IntIterableRangeSet;

import java.util.Arrays;

/**
* A propagator to ensure that X + Y = Z holds, where X, Y and Z are IntVar.
* This propagator ensures AC when all variables are enumerated, BC otherwise.
Expand All @@ -32,9 +34,10 @@ public class PropXplusYeqZ extends Propagator<IntVar> {

private static final int THRESHOLD = 300;
/**
* Set to <tt>true</tt> if X, Y and Z are bounded
* Set to <tt>true</tt> if at least two variables from X, Y and Z are either fixed or bounded
* Or if LCG is used, as AC is not explained yet
*/
private final boolean allbounded;
private final boolean isRangeOnly;
/**
* Temporary structure to ease filtering
*/
Expand All @@ -49,7 +52,9 @@ public class PropXplusYeqZ extends Propagator<IntVar> {
*/
public PropXplusYeqZ(IntVar X, IntVar Y, IntVar Z) {
super(new IntVar[]{X, Y, Z}, PropagatorPriority.TERNARY, false);
allbounded = (!X.hasEnumeratedDomain() & !Y.hasEnumeratedDomain() & !Z.hasEnumeratedDomain());
isRangeOnly = lcg() || Arrays.stream(vars)
.filter(v -> !v.hasUnfixedEnumeratedDomain())
.count() >= 2;
set = new IntIterableRangeSet();
}

Expand Down Expand Up @@ -77,8 +82,7 @@ private boolean filterPlus() throws ContradictionException {
lcg() ? Reason.r(vars[0].getMinLit(), vars[1].getMinLit()) : Reason.undef());
change |= vars[2].updateUpperBound(ub, this,
lcg() ? Reason.r(vars[0].getMaxLit(), vars[1].getMaxLit()) : Reason.undef());
if (!allbounded) {
if ((long) vars[0].getDomainSize() * vars[1].getDomainSize() > THRESHOLD || lcg()) return change;
if (isAC(vars[0], vars[1])) {
set.clear();
int ub1 = vars[0].getUB();
int ub2 = vars[1].getUB();
Expand Down Expand Up @@ -115,8 +119,7 @@ private boolean filterMinus(int vr) throws ContradictionException {
lcg() ? Reason.r(vars[2].getMinLit(), vars[vo].getMaxLit()) : Reason.undef());
change |= vars[vr].updateUpperBound(ub, this,
lcg() ? Reason.r(vars[2].getMaxLit(), vars[vo].getMinLit()) : Reason.undef());
if (!allbounded) {
if ((long) vars[2].getDomainSize() * vars[vo].getDomainSize() > THRESHOLD || lcg()) return change;
if (isAC(vars[2], vars[vo])) {
set.clear();
int ub1 = vars[2].getUB();
int ub2 = vars[vo].getUB();
Expand All @@ -138,6 +141,10 @@ private boolean filterMinus(int vr) throws ContradictionException {
return change;
}

private boolean isAC(IntVar v1, IntVar v2) {
return !isRangeOnly && (long) v1.getDomainSize() * v2.getDomainSize() < THRESHOLD;
}

@Override
public ESat isEntailed() {
int sumUB = 0, sumLB = 0, i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,14 @@ default int getRange(){
*/
boolean hasEnumeratedDomain();

/**
* Indicates wether (or not) <code>this</code> has an enumerated domain (represented in extension) and is not a single value
* @return <code>true</code> if the domain is enumerated and the variable is not instantiated yet, <code>false</code> otherwise.
*/
default boolean hasUnfixedEnumeratedDomain() {
return !isInstantiated() && hasEnumeratedDomain();
}

/**
* Allow to monitor removed values of <code>this</code>.
*
Expand Down
Loading