diff --git a/CHANGELOG b/CHANGELOG
index 9273fcb1e..9fb832bf9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,34 @@
+Version 4.4
+===========
+
+1. New selection for search variables in minizinc. Only output
+ variables are selected by default.
+
+2. Adding additional pass to the flatzinc compiler. bool2int does not
+ generate the equality constraints on both variables. Only the first
+ variable is used in the model and the second one as the alias for
+ the first one. Decreases the number of generated constraints.
+
+3. Sum and SumWeight are deprecated and SumInt, SumBool or LinearInt
+ should be used instead.
+
+4. New circuit and subcircuit constraint definitions in minizinc that
+ accept arbitrary indexes (not always starting from 1).
+
+5. New constraint SumBool.
+
+6. Correcting a bug in OrBool constraint.
+
+7. Xor of Linear constraint corrected. Linear is deprecated and
+ LinearInt should be used instead.
+
+8. Correcting a bug in GCC.
+
+9. Improvements and corrections in Linear, LinearInt, SumInt,
+ LinearIntDom and LinearFloat.
+
+10. Bug fixes and improvements.
+
Version 4.3
===========
1. Implementation of constraints ArgMin and ArgMax as well connection to
diff --git a/README.md b/README.md
index c38277346..a3cc8e5af 100644
--- a/README.md
+++ b/README.md
@@ -43,5 +43,4 @@ us to perform extensive testing with the help of other solvers as we can compare
JaCoP is an ongoing activity. We are working on it in our free time. The most recent addition is Scala based DSL so
it is easier to create your own constraint programs even in more intuitive manner.
-Currently, our focus is on providing a simple Java API for JaCoP as well as integrate it well with industrial quality
-technologies like OSGi and Spring.
+JaCoP is also available from maven repository. For details, please check INSTALL file.
diff --git a/change.bash b/change.bash
index c3325a37a..05ee20dbd 100644
--- a/change.bash
+++ b/change.bash
@@ -1,7 +1,7 @@
#!/bin/bash
echo changing file $1;
mv $1 $1.bak;
-sed -e "s/@version 4.2/@version 4.3/g" < $1.bak > $1;
+sed -e "s/@version 4.3/@version 4.4/g" < $1.bak > $1;
rm $1.bak;
# command to be executed
# find src/ -name "*.java" -exec change.bash {} \;
diff --git a/pom.xml b/pom.xml
index 4adb941d0..484621ab4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.jacopjacop
- 4.3.0
+ 4.4.0jarJaCoP
@@ -143,10 +143,32 @@ setup to run configuration. -->
maven-surefire-report-plugin2.18.1
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.3
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.3
+
+
+ 1.7
+ -Xlint:all
+
+
+
+
org.scala-tools
@@ -247,7 +269,7 @@ setup to run configuration. -->
-
+
org.apache.maven.plugins
@@ -255,7 +277,21 @@ setup to run configuration. -->
2.10.3
- -Xdoclint:none
+
+
diff --git a/src/main/java/org/jacop/constraints/AbsXeqY.java b/src/main/java/org/jacop/constraints/AbsXeqY.java
index 17f7423b5..1c5be58a3 100644
--- a/src/main/java/org/jacop/constraints/AbsXeqY.java
+++ b/src/main/java/org/jacop/constraints/AbsXeqY.java
@@ -48,7 +48,7 @@
* Domain and bounds consistency can be used; third parameter of constructor controls this.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class AbsXeqY extends PrimitiveConstraint {
@@ -273,9 +273,15 @@ else if (x.max() < 0) {
y.domain.in(store.level, y, -x.max(), -x.min());
}
else { // x.min() < 0 && x.max() >= 0
- // int xBound = Math.max(y.min(), y.max());
- int xBound = y.max(); // y is always >= 0
- x.domain.in(store.level, x, -xBound, xBound);
+ IntervalDomain xBound;
+ if (y.min() == 0)
+ xBound = new IntervalDomain(-y.max(), y.max());
+ else {
+ xBound = new IntervalDomain(-y.max(), -y.min());
+ xBound.unionAdapt(new Interval(y.min(), y.max()));
+ }
+
+ x.domain.in(store.level, x, xBound);
store.propagationHasOccurred = false;
diff --git a/src/main/java/org/jacop/constraints/Alldiff.java b/src/main/java/org/jacop/constraints/Alldiff.java
index d1e7259b4..f638f806e 100644
--- a/src/main/java/org/jacop/constraints/Alldiff.java
+++ b/src/main/java/org/jacop/constraints/Alldiff.java
@@ -55,7 +55,7 @@
* It extends basic functionality of Alldifferent constraint.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Alldiff extends Alldifferent {
diff --git a/src/main/java/org/jacop/constraints/Alldifferent.java b/src/main/java/org/jacop/constraints/Alldifferent.java
index f8e8a2f18..d0b048945 100644
--- a/src/main/java/org/jacop/constraints/Alldifferent.java
+++ b/src/main/java/org/jacop/constraints/Alldifferent.java
@@ -50,7 +50,7 @@
* partial consistency technique.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Alldifferent extends Constraint {
diff --git a/src/main/java/org/jacop/constraints/Alldistinct.java b/src/main/java/org/jacop/constraints/Alldistinct.java
index ec182ec84..3ee13dbed 100644
--- a/src/main/java/org/jacop/constraints/Alldistinct.java
+++ b/src/main/java/org/jacop/constraints/Alldistinct.java
@@ -61,7 +61,7 @@
* 0..1000000 will make it use few MB already and kill the efficiency.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class Alldistinct extends Constraint {
diff --git a/src/main/java/org/jacop/constraints/Among.java b/src/main/java/org/jacop/constraints/Among.java
index bc111ef7d..317d4056b 100644
--- a/src/main/java/org/jacop/constraints/Among.java
+++ b/src/main/java/org/jacop/constraints/Among.java
@@ -53,7 +53,7 @@
* backtracking) to improve the constraint further.
*
* @author Polina Makeeva and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Among extends Constraint {
@@ -221,16 +221,25 @@ public void consistency(Store store) {
System.out.println("lbS = " + currentLB);
System.out.println("ubS = " + currentUB);
System.out.println(" domain of N " + n.domain + " is in [ "
- + Math.max(n.min(), currentLB) + ", "
- + Math.min(n.max(), currentUB) + " ]");
+ + currentLB + ", "
+ + currentUB + " ]");
}
// ----------------------------------------------------------
- if (Math.max(n.min(), currentLB) > Math.min(n.max(), currentUB))
- throw Store.failException;
+ // Changed KK, 2015-10-17;
+ // Not needed, in method will fail in such case
+ // if (Math.max(n.min(), currentLB) > Math.min(n.max(), currentUB))
+ // throw Store.failException;
+ if (currentLB > currentUB)
+ throw Store.failException;
- n.domain.in(store.level, n, Math.max(n.min(), currentLB), Math.min(n.max(),
- currentUB));
+ // n.domain.in(store.level, n, Math.max(n.min(), currentLB), Math.min(n.max(),
+ // currentUB));
+
+ // Changed KK, 2015-10-17;
+ // Math.max is not needed since method in is doing
+ // intersection between new domain and original domain
+ n.domain.in(store.level, n, currentLB, currentUB);
// Just in case LB or UB have changed.
upperBorder.update(currentUB);
@@ -310,10 +319,16 @@ public void impose(Store store) {
int pos = 0;
position = new HashMap();
for (IntVar var : list) {
- position.put(var, pos);
+ Integer varPosition = position.put(var, pos);
+ if (varPosition == null) {
var.putConstraint(this);
queueVariable(level, var);
pos++;
+ }
+ else {
+ System.err.println("ERROR: Constraint " + toString() + " must have different variables on the list");
+ System.exit(0);
+ }
}
n.putConstraint(this);
@@ -352,13 +367,15 @@ public String toString() {
StringBuffer result = new StringBuffer( id () );
- result.append(" Among(");
+ result.append(": Among([");
for(IntVar var : this.list)
- result.append("variable").append(var.id).append(" : ").append(var.domain).append(" ");
+ // result.append("variable").append(var.id).append(" : ").append(var.domain).append(" ");
+ result.append(var).append(" ");
- result.append(")\n Kset : ").append(this.kSet).append("\n");
- result.append("variable ").append(n.id).append(" : ").append(n.domain).append(")\n");
+ result.append("], ").append(this.kSet).append(", ");
+ // result.append("variable ").append(n.id).append(" : ").append(n.domain).append(")\n");
+ result.append(n).append(")\n");
return result.toString();
}
diff --git a/src/main/java/org/jacop/constraints/AmongVar.java b/src/main/java/org/jacop/constraints/AmongVar.java
index 5ef950612..7ee2bbf80 100644
--- a/src/main/java/org/jacop/constraints/AmongVar.java
+++ b/src/main/java/org/jacop/constraints/AmongVar.java
@@ -63,7 +63,7 @@
* function. The strength of propagation algorithm is incomporable to BC.
*
* @author Polina Makeeva and Radoslaw Szymanek
-* @version 4.3
+* @version 4.4
*/
public class AmongVar extends Constraint {
@@ -284,7 +284,7 @@ public void consistencyForX(Store store) {
* 1) If there are not enough of y to cover future domain then fail
* 2)
*
- * @param store
+ * @param store a constraint store in which context all prunings are executed.
*/
public void consistencyWhen_LB0_EQ_UB0(Store store) {
@@ -1120,18 +1120,34 @@ public void impose(Store store) {
for (i = 0; i < listOfX.length; i++) {
x = listOfX[i];
- x.putConstraint(this);
- xIndex.put(x, i);
- if (x.singleton()) gx++;
+
+ Integer varPosition = xIndex.put(x, i);
+ if (varPosition == null) {
+ x.putConstraint(this);
+ // xIndex.put(x, i);
+ if (x.singleton()) gx++;
+ }
+ else {
+ System.err.println("ERROR: Constraint " + toString() + " must have different variables on the list");
+ System.exit(0);
+ }
}
yIndex = new HashMap();
for (i = 0; i < listOfY.length; i++) {
y = listOfY[i];
- y.putConstraint(this);
- variableQueueY.add(i);
- yIndex.put(y, i);
+
+ Integer varPosition = yIndex.put(y, i);
+ if (varPosition == null) {
+ y.putConstraint(this);
+ variableQueueY.add(i);
+ // yIndex.put(y, i);
+ }
+ else {
+ System.err.println("ERROR: Constraint " + toString() + " must have different variables on the list");
+ System.exit(0);
+ }
}
n.putConstraint(this);
diff --git a/src/main/java/org/jacop/constraints/And.java b/src/main/java/org/jacop/constraints/And.java
index 753191e48..8a32101b1 100644
--- a/src/main/java/org/jacop/constraints/And.java
+++ b/src/main/java/org/jacop/constraints/And.java
@@ -44,7 +44,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class And extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/AndBool.java b/src/main/java/org/jacop/constraints/AndBool.java
index 0cbe810a1..d5835b29a 100644
--- a/src/main/java/org/jacop/constraints/AndBool.java
+++ b/src/main/java/org/jacop/constraints/AndBool.java
@@ -33,410 +33,134 @@
import java.util.ArrayList;
-import org.jacop.core.IntDomain;
import org.jacop.core.IntVar;
-import org.jacop.core.IntervalDomain;
import org.jacop.core.Store;
import org.jacop.core.Var;
-import org.jacop.core.TimeStamp;
/**
- * If all x's are equal 1 then result variable is equal 1 too. Otherwise, result variable
- * is equal to zero. It restricts the domain of all x as well as result to be between 0 and 1.
+ * AndBool constraint implements logic and operation on its arguments
+ * and returns result.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class AndBool extends PrimitiveConstraint {
- static int counter = 1;
+ PrimitiveConstraint c = null;
/**
- * It specifies a list of variables which all must be equal to 1 to set result variable to 1.
+ * It constructs and constraint on variables.
+ * @param a parameters variable.
+ * @param result variable.
*/
- public IntVar [] list;
-
- /**
- * It specifies the length of the list.
- */
- final int l;
-
- /**
- * It specifies variable result, storing the result of and function performed a list of variables.
- */
- public IntVar result;
-
- /**
- * It specifies the arguments required to be saved by an XML format as well as
- * the constructor being called to recreate an object from an XML format.
- */
- public static String[] xmlAttributes = {"list", "result"};
-
- /*
- * Defines first position of the variable that is not ground to 1
- */
- private TimeStamp position;
-
- /**
- * It constructs AndBool.
- *
- * @param list list of x's which must all be equal 1 to make result equal 1.
- * @param result variable which is equal 0 if any of x is equal to zero.
- */
- public AndBool(IntVar [] list, IntVar result) {
-
- assert ( list != null ) : "List variable is null";
- assert ( result != null ) : "Result variable is null";
-
- this.numberId = counter++;
- this.l = list.length;
- this.numberArgs = (short)(l + 1);
-
- this.list = new IntVar[l];
- for (int i = 0; i < l; i++) {
- assert (list[i] != null) : i + "-th element in the list is null";
- this.list[i] = list[i];
- }
-
- this.result = result;
-
- assert ( checkInvariants() == null) : checkInvariants();
-
- if (l > 2)
- queueIndex = 1;
+ public AndBool(IntVar[] a, IntVar result) {
+ if (a.length == 2)
+ c = new AndBoolSimple(a[0], a[1], result);
else
- queueIndex = 0;
-
+ c = new AndBoolVector(a, result);
}
/**
- * It constructs AndBool.
- *
- * @param list list of x's which must all be equal 1 to make result equal 1.
- * @param result variable which is equal 0 if any of x is equal to zero.
+ * It constructs and constraint on variables.
+ * @param a parameters variable.
+ * @param result variable.
*/
- public AndBool(ArrayList list, IntVar result) {
+ public AndBool(ArrayList a, IntVar result) {
- this(list.toArray(new IntVar[list.size()]), result);
+ if (a.size() == 2)
+ c = new AndBoolSimple(a.get(0), a.get(1), result);
+ else
+ c = new AndBoolVector(a.toArray(new IntVar[a.size()]), result);
}
/**
- * It checks invariants required by the constraint. Namely that
- * boolean variables have boolean domain.
- *
- * @return the string describing the violation of the invariant, null otherwise.
+ * It constructs and constraint on variables.
+ * @param a parameter variable.
+ * @param b parameter variable.
+ * @param result variable.
*/
- public String checkInvariants() {
-
- for (IntVar var : list)
- if (var.min() < 0 || var.max() > 1)
- return "Variable " + var + " does not have boolean domain";
-
- return null;
+ public AndBool(IntVar a, IntVar b, IntVar result) {
+ c = new AndBoolSimple(a, b, result);
}
@Override
public ArrayList arguments() {
- ArrayList variables = new ArrayList(l + 1);
-
- variables.add(result);
- for (int i = 0; i < l; i++)
- variables.add(list[i]);
- return variables;
+ return c.arguments();
}
@Override
- public int getConsistencyPruningEvent(Var var) {
-
- // If consistency function mode
- if (consistencyPruningEvents != null) {
- Integer possibleEvent = consistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.BOUND;
+ public void consistency(Store store) {
+ c.consistency(store);
}
@Override
- public int getNotConsistencyPruningEvent(Var var) {
-
- // If notConsistency function mode
- if (notConsistencyPruningEvents != null) {
- Integer possibleEvent = notConsistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.GROUND;
+ public void notConsistency(Store store) {
+ c.consistency(store);
}
@Override
- public int getNestedPruningEvent(Var var, boolean mode) {
+ public int getConsistencyPruningEvent(Var var) {
+ return c.getConsistencyPruningEvent(var);
- // If consistency function mode
- if (mode) {
- if (consistencyPruningEvents != null) {
- Integer possibleEvent = consistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.ANY;
- }
- // If notConsistency function mode
- else {
- if (notConsistencyPruningEvents != null) {
- Integer possibleEvent = notConsistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.GROUND;
- }
}
-
- // registers the constraint in the constraint store
@Override
- public void impose(Store store) {
-
- result.putModelConstraint(this, getConsistencyPruningEvent(result));
-
- position = new TimeStamp(store, 0);
-
- for (Var V : list)
- V.putModelConstraint(this, getConsistencyPruningEvent(V));
-
- store.addChanged(this);
- store.countConstraint();
-
+ public int getNestedPruningEvent(Var var, boolean mode) {
+ return c.getNestedPruningEvent(var, mode);
}
@Override
- public void include(Store store) {
-
- position = new TimeStamp(store, 0);
-
- }
-
- public void consistency(Store store) {
-
- int start = position.value();
- int index_01=l-1;
-
- if (result.min() == 1) {
- for (int i=start; i constraints;
-
@Override
- public ArrayList decompose(Store store) {
-
- constraints = new ArrayList();
-
- PrimitiveConstraint [] andConstraints = new PrimitiveConstraint[l];
-
- IntervalDomain booleanDom = new IntervalDomain(0, 1);
-
- for (int i = 0; i < andConstraints.length; i++) {
- andConstraints[0] = new XeqC(list[i], 1);
- constraints.add(new In(list[i], booleanDom));
- }
-
- constraints.add( new In(result, booleanDom));
-
- constraints.add( new Eq(new And(andConstraints), new XeqC(result, 1)) );
-
- return constraints;
+ public boolean notSatisfied() {
+ return c.satisfied();
}
@Override
- public void imposeDecomposition(Store store) {
-
- if (constraints == null)
- decompose(store);
-
- for (Constraint c : constraints)
- store.impose(c, queueIndex);
-
+ public String toString() {
+ return c.toString();
}
@Override
public void increaseWeight() {
- if (increaseWeight) {
- result.weight++;
- for (Var v : list) v.weight++;
- }
+ c.increaseWeight();
}
}
diff --git a/src/main/java/org/jacop/constraints/AndBoolSimple.java b/src/main/java/org/jacop/constraints/AndBoolSimple.java
new file mode 100644
index 000000000..294374b16
--- /dev/null
+++ b/src/main/java/org/jacop/constraints/AndBoolSimple.java
@@ -0,0 +1,195 @@
+/**
+ * AndBoolSimple.java
+ * This file is part of JaCoP.
+ *
+ * JaCoP is a Java Constraint Programming solver.
+ *
+ * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * Notwithstanding any other provision of this License, the copyright
+ * owners of this work supplement the terms of this License with terms
+ * prohibiting misrepresentation of the origin of this work and requiring
+ * that modified versions of this work be marked in reasonable ways as
+ * different from the original version. This supplement of the license
+ * terms is in accordance with Section 7 of GNU Affero General Public
+ * License version 3.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package org.jacop.constraints;
+
+import java.util.ArrayList;
+
+import org.jacop.core.IntDomain;
+import org.jacop.core.IntVar;
+import org.jacop.core.IntervalDomain;
+import org.jacop.core.Store;
+import org.jacop.core.Var;
+
+/**
+ * If both a and b are equal 1 then result variable is equal 1 too. Otherwise, result variable
+ * is equal to zero. It restricts the domain of all x as well as result to be between 0 and 1.
+ *
+ * @author Krzysztof Kuchcinski and Radoslaw Szymanek
+ * @version 4.4
+ */
+
+public class AndBoolSimple extends AndBoolVector {
+
+ static int counter = 1;
+
+ /**
+ * It specifies variables which all must be equal to 1 to set result variable to 1.
+ */
+ public IntVar a, b;
+
+ /**
+ * It specifies variable result, storing the result of and function performed a list of variables.
+ */
+ public IntVar result;
+
+ /**
+ * It specifies the arguments required to be saved by an XML format as well as
+ * the constructor being called to recreate an object from an XML format.
+ */
+ public static String[] xmlAttributes = {"a", "b", "result"};
+
+
+ /**
+ * It constructs AndBoolSimple.
+ *
+ * @param a parameter to predicate.
+ * @param b parameter to predicate.
+ * @param result variable which is equal 0 if any of x is equal to zero.
+ */
+ public AndBoolSimple(IntVar a, IntVar b, IntVar result) {
+
+ super(new IntVar[] {a,b}, result);
+
+ assert ( a != null ) : "First variable is null";
+ assert ( b != null ) : "Second variable is null";
+ assert ( result != null ) : "Result variable is null";
+
+ this.numberId = counter++;
+ this.numberArgs = 3;
+
+ this.a = a;
+ this.b = b;
+ this.result = result;
+
+ assert ( checkInvariants() == null) : checkInvariants();
+
+ queueIndex = 0;
+
+ }
+
+
+ @Override
+ public ArrayList arguments() {
+
+ ArrayList variables = new ArrayList(l + 1);
+
+ variables.add(a);
+ variables.add(b);
+ variables.add(result);
+ return variables;
+ }
+
+ // registers the constraint in the constraint store
+ @Override
+ public void impose(Store store) {
+
+ a.putModelConstraint(this, getConsistencyPruningEvent(a));
+ b.putModelConstraint(this, getConsistencyPruningEvent(b));
+ result.putModelConstraint(this, getConsistencyPruningEvent(result));
+
+ store.addChanged(this);
+ store.countConstraint();
+ }
+
+ @Override
+ public void include(Store store) {
+ }
+
+ public void consistency(Store store) {
+ if (a.max() == 0 || b.max() == 0) {
+ result.domain.in(store.level, result, 0,0);
+ removeConstraint();
+ }
+ else if (a.min() == 1 && b.min() == 1)
+ result.domain.in(store.level, result, 1,1);
+ else if (result.min() == 1) {
+ a.domain.in(store.level, a, 1,1);
+ b.domain.in(store.level, b, 1,1);
+ }
+ else if (result.max() == 0)
+ if (a.min() == 1)
+ b.domain.in(store.level, b, 0,0);
+ else if (b.min() == 1)
+ a.domain.in(store.level, a, 0,0);
+ }
+
+ @Override
+ public void notConsistency(Store store) {
+ // result = not a OR not b
+ if (a.max() == 0 || b.max() == 0) {
+ result.domain.in(store.level, result, 1,1);
+ removeConstraint();
+ }
+ else if (a.min() == 1 && b.min() == 1)
+ result.domain.in(store.level, result, 0,0);
+ else if (result.max() == 0) {
+ a.domain.in(store.level, a, 1,1);
+ b.domain.in(store.level, b, 1,1);
+ }
+ else if (result.min() == 1)
+ if (a.max() == 1)
+ b.domain.in(store.level, b, 0,0);
+ else if (b.max() == 1)
+ a.domain.in(store.level, a, 0,0);
+ }
+
+ @Override
+ public boolean satisfied() {
+ return (result.min() == 1 && a.min() == 1 && b.min() == 1) || (result.max() == 0 && (a.max() == 0 || b.max() == 0));
+ }
+
+ @Override
+ public boolean notSatisfied() {
+ return (result.min() == 1 && (a.max() == 0 || b.max() == 0) || (result.max() == 0 && a.min() == 1 && b.min() == 1));
+ }
+
+ @Override
+ public void removeConstraint() {
+ a.removeConstraint(this);
+ b.removeConstraint(this);
+ result.removeConstraint(this);
+ }
+
+ @Override
+ public String toString() {
+
+ StringBuffer resultString = new StringBuffer( id() );
+
+ resultString.append(" : andBoolSimple([ ");
+ resultString.append( a + ", " + b);
+
+ resultString.append("], ");
+ resultString.append(result);
+ resultString.append(")");
+ return resultString.toString();
+ }
+}
diff --git a/src/main/java/org/jacop/constraints/AndBoolVector.java b/src/main/java/org/jacop/constraints/AndBoolVector.java
new file mode 100644
index 000000000..80c0e2794
--- /dev/null
+++ b/src/main/java/org/jacop/constraints/AndBoolVector.java
@@ -0,0 +1,448 @@
+/**
+ * AndBoolVector.java
+ * This file is part of JaCoP.
+ *
+ * JaCoP is a Java Constraint Programming solver.
+ *
+ * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * Notwithstanding any other provision of this License, the copyright
+ * owners of this work supplement the terms of this License with terms
+ * prohibiting misrepresentation of the origin of this work and requiring
+ * that modified versions of this work be marked in reasonable ways as
+ * different from the original version. This supplement of the license
+ * terms is in accordance with Section 7 of GNU Affero General Public
+ * License version 3.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package org.jacop.constraints;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import org.jacop.core.IntDomain;
+import org.jacop.core.IntVar;
+import org.jacop.core.IntervalDomain;
+import org.jacop.core.Store;
+import org.jacop.core.Var;
+import org.jacop.core.TimeStamp;
+
+/**
+ * If all x's are equal 1 then result variable is equal 1 too. Otherwise, result variable
+ * is equal to zero. It restricts the domain of all x as well as result to be between 0 and 1.
+ *
+ * @author Krzysztof Kuchcinski and Radoslaw Szymanek
+ * @version 4.2
+ */
+
+public class AndBoolVector extends PrimitiveConstraint {
+
+ static int counter = 1;
+
+ /**
+ * It specifies a list of variables which all must be equal to 1 to set result variable to 1.
+ */
+ public IntVar [] list;
+
+ /**
+ * It specifies the length of the list.
+ */
+ final int l;
+
+ /**
+ * It specifies variable result, storing the result of and function performed a list of variables.
+ */
+ public IntVar result;
+
+ /**
+ * It specifies the arguments required to be saved by an XML format as well as
+ * the constructor being called to recreate an object from an XML format.
+ */
+ public static String[] xmlAttributes = {"list", "result"};
+
+ /*
+ * Defines first position of the variable that is not ground to 1
+ */
+ private TimeStamp position;
+
+ /**
+ * It constructs AndBoolVector.
+ *
+ * @param list list of x's which must all be equal 1 to make result equal 1.
+ * @param result variable which is equal 0 if any of x is equal to zero.
+ */
+ public AndBoolVector(IntVar [] list, IntVar result) {
+
+ assert ( list != null ) : "List variable is null";
+ assert ( result != null ) : "Result variable is null";
+
+ this.numberId = counter++;
+
+ HashSet varSet = new HashSet();
+ for (IntVar var : list) {
+ assert (var != null) : "element in the list is null";
+ varSet.add(var);
+ }
+ this.l = varSet.size();
+ this.numberArgs = (short)(l + 1);
+
+ this.list = new IntVar[l];
+ int i = 0;
+ for (IntVar v : varSet) {
+ this.list[i++] = v;
+ }
+
+ this.result = result;
+ assert ( checkInvariants() == null) : checkInvariants();
+
+ if (l > 2)
+ queueIndex = 1;
+ else
+ queueIndex = 0;
+
+ }
+
+ /**
+ * It constructs AndBoolVector.
+ *
+ * @param list list of x's which must all be equal 1 to make result equal 1.
+ * @param result variable which is equal 0 if any of x is equal to zero.
+ */
+ public AndBoolVector(ArrayList list, IntVar result) {
+
+ this(list.toArray(new IntVar[list.size()]), result);
+
+ }
+
+ /**
+ * It checks invariants required by the constraint. Namely that
+ * boolean variables have boolean domain.
+ *
+ * @return the string describing the violation of the invariant, null otherwise.
+ */
+ public String checkInvariants() {
+
+ for (IntVar var : list)
+ if (var.min() < 0 || var.max() > 1)
+ return "Variable " + var + " does not have boolean domain";
+
+ return null;
+ }
+
+ @Override
+ public ArrayList arguments() {
+
+ ArrayList variables = new ArrayList(l + 1);
+
+ variables.add(result);
+ for (int i = 0; i < l; i++)
+ variables.add(list[i]);
+ return variables;
+ }
+
+ @Override
+ public int getConsistencyPruningEvent(Var var) {
+
+ // If consistency function mode
+ if (consistencyPruningEvents != null) {
+ Integer possibleEvent = consistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.BOUND;
+ }
+
+ @Override
+ public int getNotConsistencyPruningEvent(Var var) {
+
+ // If notConsistency function mode
+ if (notConsistencyPruningEvents != null) {
+ Integer possibleEvent = notConsistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.GROUND;
+ }
+
+ @Override
+ public int getNestedPruningEvent(Var var, boolean mode) {
+
+ // If consistency function mode
+ if (mode) {
+ if (consistencyPruningEvents != null) {
+ Integer possibleEvent = consistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.ANY;
+ }
+ // If notConsistency function mode
+ else {
+ if (notConsistencyPruningEvents != null) {
+ Integer possibleEvent = notConsistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.GROUND;
+ }
+ }
+
+
+ // registers the constraint in the constraint store
+ @Override
+ public void impose(Store store) {
+
+ result.putModelConstraint(this, getConsistencyPruningEvent(result));
+
+ position = new TimeStamp(store, 0);
+
+ for (Var V : list)
+ V.putModelConstraint(this, getConsistencyPruningEvent(V));
+
+ store.addChanged(this);
+ store.countConstraint();
+
+ }
+
+ @Override
+ public void include(Store store) {
+
+ position = new TimeStamp(store, 0);
+
+ }
+
+ public void consistency(Store store) {
+
+ int start = position.value();
+ int index_01=l-1;
+
+ if (result.min() == 1) {
+ for (int i=start; i constraints;
+
+ @Override
+ public ArrayList decompose(Store store) {
+
+ constraints = new ArrayList();
+
+ PrimitiveConstraint [] andConstraints = new PrimitiveConstraint[l];
+
+ IntervalDomain booleanDom = new IntervalDomain(0, 1);
+
+ for (int i = 0; i < andConstraints.length; i++) {
+ andConstraints[0] = new XeqC(list[i], 1);
+ constraints.add(new In(list[i], booleanDom));
+ }
+
+ constraints.add( new In(result, booleanDom));
+
+ constraints.add( new Eq(new And(andConstraints), new XeqC(result, 1)) );
+
+ return constraints;
+ }
+
+ @Override
+ public void imposeDecomposition(Store store) {
+
+ if (constraints == null)
+ decompose(store);
+
+ for (Constraint c : constraints)
+ store.impose(c, queueIndex);
+
+ }
+
+ @Override
+ public void increaseWeight() {
+ if (increaseWeight) {
+ result.weight++;
+ for (Var v : list) v.weight++;
+ }
+ }
+
+}
diff --git a/src/main/java/org/jacop/constraints/ArgMax.java b/src/main/java/org/jacop/constraints/ArgMax.java
index 03e1e1bcc..72f478263 100644
--- a/src/main/java/org/jacop/constraints/ArgMax.java
+++ b/src/main/java/org/jacop/constraints/ArgMax.java
@@ -47,7 +47,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ArgMax extends Constraint {
@@ -73,7 +73,7 @@ public class ArgMax extends Constraint {
public int indexOffset;
/**
- * tirbreak == true --> select element with the lowest index if exist several
+ * tirbreak == true {@literal -->} select element with the lowest index if exist several
*/
public boolean tiebreak = true;
@@ -88,7 +88,7 @@ public class ArgMax extends Constraint {
* @param maxIndex variable denoting the index of the maximum value
* @param list the array of variables for which the index of the maximum value is imposed.
* @param indexOffset the offset for the index that is computed from 1 by default (if needed from 0, use -1 for this parameter)
- * @param tiebreak defines if tie breaking sgould be used (returning the least index if several maximum elements
+ * @param tiebreak defines if tie breaking should be used (returning the least index if several maximum elements
*/
public ArgMax(IntVar[] list, IntVar maxIndex, int indexOffset, boolean tiebreak) {
@@ -119,6 +119,8 @@ public ArgMax(IntVar[] list, IntVar maxIndex) {
* It constructs max constraint.
* @param maxIndex variable denoting index of the maximum value
* @param variables the array of variables for which the maximum value is imposed.
+ * @param indexOffset the offset for the index that is computed from 1 by default (if needed from 0, use -1 for this parameter)
+ * @param tiebreak defines if tie breaking sgould be used (returning the least index if several maximum elements
*/
public ArgMax(ArrayList extends IntVar> variables, IntVar maxIndex, int indexOffset, boolean tiebreak) {
this(variables, maxIndex);
diff --git a/src/main/java/org/jacop/constraints/ArgMin.java b/src/main/java/org/jacop/constraints/ArgMin.java
index 9eb0cdefb..974b66d28 100644
--- a/src/main/java/org/jacop/constraints/ArgMin.java
+++ b/src/main/java/org/jacop/constraints/ArgMin.java
@@ -47,7 +47,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ArgMin extends Constraint {
@@ -73,7 +73,7 @@ public class ArgMin extends Constraint {
public int indexOffset;
/**
- * tirbreak == true --> select element with the lowest index if exist several
+ * tirbreak == true {@literal -->} select element with the lowest index if exist several
*/
public boolean tiebreak = true;
@@ -88,7 +88,7 @@ public class ArgMin extends Constraint {
* @param minIndex variable denoting the index of the maximum value
* @param list the array of variables for which the index of the maximum value is imposed.
* @param indexOffset the offset for the index that is computed from 1 by default (if needed from 0, use -1 for this parameter)
- * @param tiebreak defines if tie breaking sgould be used (returning the least index if several maximum elements
+ * @param tiebreak defines if tie breaking should be used (returning the least index if several maximum elements
*/
public ArgMin(IntVar[] list, IntVar minIndex, int indexOffset, boolean tiebreak) {
@@ -119,6 +119,8 @@ public ArgMin(IntVar[] list, IntVar minIndex) {
* It constructs max constraint.
* @param minIndex variable denoting the index of minimum value
* @param variables the array of variables for which the minimum value is imposed.
+ * @param indexOffset the offset for the index that is computed from 1 by default (if needed from 0, use -1 for this parameter)
+ * @param tiebreak defines if tie breaking sgould be used (returning the least index if several maximum elements
*/
public ArgMin(ArrayList extends IntVar> variables, IntVar minIndex, int indexOffset, boolean tiebreak) {
this(variables, minIndex);
diff --git a/src/main/java/org/jacop/constraints/Assignment.java b/src/main/java/org/jacop/constraints/Assignment.java
index c0284452f..731e7f7c2 100644
--- a/src/main/java/org/jacop/constraints/Assignment.java
+++ b/src/main/java/org/jacop/constraints/Assignment.java
@@ -49,7 +49,7 @@
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
*
- * @version 4.3
+ * @version 4.4
*/
public class Assignment extends Constraint {
@@ -130,8 +130,8 @@ public Assignment(IntVar[] xs, IntVar[] ds, int shiftX, int shiftD) {
* d[x[i]-shiftD]=i+shiftX.
* @param xs arraylist of variables x
* @param ds arraylist of variables d
- * @param shiftX
- * @param shiftD
+ * @param shiftX shift for parameter xs
+ * @param shiftD shift for parameter ds
*/
public Assignment(ArrayList extends IntVar> xs,
ArrayList extends IntVar> ds,
@@ -437,7 +437,8 @@ public String toString() {
if (i < d.length - 1)
result.append(", ");
}
- result.append("])");
+ result.append("], ");
+ result.append(shiftX + ", " + shiftD + ")");
return result.toString();
}
diff --git a/src/main/java/org/jacop/constraints/BoolClause.java b/src/main/java/org/jacop/constraints/BoolClause.java
index f75fd77a9..f76c583a9 100644
--- a/src/main/java/org/jacop/constraints/BoolClause.java
+++ b/src/main/java/org/jacop/constraints/BoolClause.java
@@ -48,7 +48,7 @@
* It restricts the domain of all x as well as result to be between 0 and 1.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class BoolClause extends PrimitiveConstraint {
@@ -300,7 +300,7 @@ public void notConsistency(Store store) {
for (int i = 0; i < lx; i++)
x[i].domain.in(store.level, x[i], 0, 0);
- for (int i = 0; i < lx; i++)
+ for (int i = 0; i < ly; i++)
y[i].domain.in(store.level, y[i], 1, 1);
removeConstraint();
diff --git a/src/main/java/org/jacop/constraints/Circuit.java b/src/main/java/org/jacop/constraints/Circuit.java
index f5f5b9a2c..c57bfcb62 100644
--- a/src/main/java/org/jacop/constraints/Circuit.java
+++ b/src/main/java/org/jacop/constraints/Circuit.java
@@ -48,7 +48,7 @@
* the circuit. Variables create one circuit.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Circuit extends Alldiff {
diff --git a/src/main/java/org/jacop/constraints/CircuitVar.java b/src/main/java/org/jacop/constraints/CircuitVar.java
index 7ebf174b3..338fa0951 100644
--- a/src/main/java/org/jacop/constraints/CircuitVar.java
+++ b/src/main/java/org/jacop/constraints/CircuitVar.java
@@ -40,7 +40,7 @@
* keeps current next node and previous node for the circuit
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class CircuitVar implements MutableVar {
diff --git a/src/main/java/org/jacop/constraints/CircuitVarValue.java b/src/main/java/org/jacop/constraints/CircuitVarValue.java
index aaa0ebded..c52cfd92e 100644
--- a/src/main/java/org/jacop/constraints/CircuitVarValue.java
+++ b/src/main/java/org/jacop/constraints/CircuitVarValue.java
@@ -37,7 +37,7 @@
* Defines a current value of the CircuitVar and related operations on it.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class CircuitVarValue implements MutableVarValue {
diff --git a/src/main/java/org/jacop/constraints/Constraint.java b/src/main/java/org/jacop/constraints/Constraint.java
index 4aa362f0b..c7cc82eab 100644
--- a/src/main/java/org/jacop/constraints/Constraint.java
+++ b/src/main/java/org/jacop/constraints/Constraint.java
@@ -58,13 +58,6 @@ public abstract class Constraint extends DecomposedConstraint {
*/
public int numberId;
- /**
- * It specifies the string id of the constraint. If it is null then
- * the string id is created from string associated for the constraint
- * type and the numberId of the constraint.
- */
- public String id;
-
/**
* It returns the variables in a scope of the constraint.
* @return variables in a scope of the constraint.
@@ -114,10 +107,7 @@ public void removeLevelLate(int level) {
* @return string id of the constraint.
*/
public String id() {
- if (id != null)
- return id;
- else
- return this.getClass().getSimpleName() + numberId;
+ return this.getClass().getSimpleName() + numberId;
}
/**
diff --git a/src/main/java/org/jacop/constraints/Count.java b/src/main/java/org/jacop/constraints/Count.java
index 8d106c5ae..65f46b240 100644
--- a/src/main/java/org/jacop/constraints/Count.java
+++ b/src/main/java/org/jacop/constraints/Count.java
@@ -45,7 +45,7 @@
* specified by variable counter.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Count extends Constraint {
diff --git a/src/main/java/org/jacop/constraints/Cumulative.java b/src/main/java/org/jacop/constraints/Cumulative.java
index 22e04173e..fea3c5576 100644
--- a/src/main/java/org/jacop/constraints/Cumulative.java
+++ b/src/main/java/org/jacop/constraints/Cumulative.java
@@ -49,7 +49,7 @@
* algorithm and profile information on the resource use.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Cumulative extends Constraint {
diff --git a/src/main/java/org/jacop/constraints/CumulativeProfiles.java b/src/main/java/org/jacop/constraints/CumulativeProfiles.java
index ca15f95bd..da50f413e 100644
--- a/src/main/java/org/jacop/constraints/CumulativeProfiles.java
+++ b/src/main/java/org/jacop/constraints/CumulativeProfiles.java
@@ -38,7 +38,7 @@
* value.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class CumulativeProfiles {
diff --git a/src/main/java/org/jacop/constraints/DecomposedConstraint.java b/src/main/java/org/jacop/constraints/DecomposedConstraint.java
index 8da359760..8cb1e6fbf 100644
--- a/src/main/java/org/jacop/constraints/DecomposedConstraint.java
+++ b/src/main/java/org/jacop/constraints/DecomposedConstraint.java
@@ -41,7 +41,7 @@
* Defines how to construct a constraint out of other constraints.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public abstract class DecomposedConstraint {
diff --git a/src/main/java/org/jacop/constraints/Diff.java b/src/main/java/org/jacop/constraints/Diff.java
index d64c073c5..de20c29d9 100644
--- a/src/main/java/org/jacop/constraints/Diff.java
+++ b/src/main/java/org/jacop/constraints/Diff.java
@@ -545,14 +545,6 @@ Rectangle[] getRectangles() {
return rectangles;
}
- @Override
- public String id() {
- if (id != null)
- return id;
- else
- return this.getClass().getSimpleName() + numberId;
- }
-
// registers the constraint in the constraint store
@Override
public void impose(Store store) {
diff --git a/src/main/java/org/jacop/constraints/Diff2.java b/src/main/java/org/jacop/constraints/Diff2.java
index bae0fbc15..06a0880d4 100644
--- a/src/main/java/org/jacop/constraints/Diff2.java
+++ b/src/main/java/org/jacop/constraints/Diff2.java
@@ -46,7 +46,7 @@
* Zero-width rectangles can be packed anywhere.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Diff2 extends Diff {
diff --git a/src/main/java/org/jacop/constraints/Diff2Var.java b/src/main/java/org/jacop/constraints/Diff2Var.java
index c923fa908..f7769d478 100644
--- a/src/main/java/org/jacop/constraints/Diff2Var.java
+++ b/src/main/java/org/jacop/constraints/Diff2Var.java
@@ -40,7 +40,7 @@
* keeps current recatngles for evaluation ([[R2, R3], [R1, R3], ...]
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class Diff2Var implements MutableVar {
diff --git a/src/main/java/org/jacop/constraints/Diff2VarValue.java b/src/main/java/org/jacop/constraints/Diff2VarValue.java
index 9d7c3bd1a..7454a0639 100644
--- a/src/main/java/org/jacop/constraints/Diff2VarValue.java
+++ b/src/main/java/org/jacop/constraints/Diff2VarValue.java
@@ -39,7 +39,7 @@
* Defines a current value of the Diff2Var and related operations on it.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class Diff2VarValue implements MutableVarValue {
diff --git a/src/main/java/org/jacop/constraints/DiffnProfile.java b/src/main/java/org/jacop/constraints/DiffnProfile.java
index b7a768c56..07dff9c90 100644
--- a/src/main/java/org/jacop/constraints/DiffnProfile.java
+++ b/src/main/java/org/jacop/constraints/DiffnProfile.java
@@ -42,7 +42,7 @@
* value.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class DiffnProfile extends Profile {
diff --git a/src/main/java/org/jacop/constraints/Disjoint.java b/src/main/java/org/jacop/constraints/Disjoint.java
index 36a5488fe..b2d98dcbb 100644
--- a/src/main/java/org/jacop/constraints/Disjoint.java
+++ b/src/main/java/org/jacop/constraints/Disjoint.java
@@ -46,7 +46,7 @@
* Zero-width rectangles does not overlap with any other rectangle.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Disjoint extends Diff {
diff --git a/src/main/java/org/jacop/constraints/DisjointCondVar.java b/src/main/java/org/jacop/constraints/DisjointCondVar.java
index 3e6a7f647..68968f417 100644
--- a/src/main/java/org/jacop/constraints/DisjointCondVar.java
+++ b/src/main/java/org/jacop/constraints/DisjointCondVar.java
@@ -43,7 +43,7 @@
* keeps current recatngles for evaluation ([[R2, R3], [R1, R3], ...]
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class DisjointCondVar implements MutableVar {
diff --git a/src/main/java/org/jacop/constraints/DisjointCondVarValue.java b/src/main/java/org/jacop/constraints/DisjointCondVarValue.java
index cca777061..7cc8ad71f 100644
--- a/src/main/java/org/jacop/constraints/DisjointCondVarValue.java
+++ b/src/main/java/org/jacop/constraints/DisjointCondVarValue.java
@@ -40,7 +40,7 @@
* Defines a current value of the Diff2Var and related operations on it.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class DisjointCondVarValue implements MutableVarValue {
diff --git a/src/main/java/org/jacop/constraints/DisjointConditional.java b/src/main/java/org/jacop/constraints/DisjointConditional.java
index a14fa4451..97377a2de 100644
--- a/src/main/java/org/jacop/constraints/DisjointConditional.java
+++ b/src/main/java/org/jacop/constraints/DisjointConditional.java
@@ -211,8 +211,8 @@ public DisjointConditional(IntVar[] o1,
* @param o2 variables specifying the origin in the second dimension.
* @param l1 variables specifying the length in the first dimension.
* @param l2 variables specifying the length in the second dimension.
- * @param exceptionIndices
- * @param exceptionCondition
+ * @param exceptionIndices list of rectangles that may not be considered
+ * @param exceptionCondition conditions for rectangles that may not be considered
* @param profile it specifies if the profiles are being used and computed within that constraint.
*/
public DisjointConditional(IntVar[] o1,
@@ -229,8 +229,8 @@ public DisjointConditional(IntVar[] o1,
/**
* It creates Disjoint conditional constraint.
* @param rectangles the rectangles within a constraint.
- * @param exceptionIndices
- * @param exceptionCondition
+ * @param exceptionIndices list of rectangles that may not be considered
+ * @param exceptionCondition conditions for rectangles that may not be considered
*/
public DisjointConditional(IntVar[][] rectangles,
ArrayList> exceptionIndices,
@@ -250,8 +250,8 @@ public DisjointConditional(IntVar[][] rectangles,
/**
* It creates Disjoint conditional constraint.
* @param rectangles the rectangles within a constraint.
- * @param exceptionIndices
- * @param exceptionCondition
+ * @param exceptionIndices list of rectangles that may not be considered
+ * @param exceptionCondition conditions for rectangles that may not be considered
* @param profile it specifies if the profiles are being computed and used within that constraint.
*/
public DisjointConditional(IntVar[][] rectangles,
diff --git a/src/main/java/org/jacop/constraints/DisjointConditionalProfile.java b/src/main/java/org/jacop/constraints/DisjointConditionalProfile.java
index c1904c006..e11e23935 100644
--- a/src/main/java/org/jacop/constraints/DisjointConditionalProfile.java
+++ b/src/main/java/org/jacop/constraints/DisjointConditionalProfile.java
@@ -42,7 +42,7 @@
* value.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class DisjointConditionalProfile extends ProfileConditional {
diff --git a/src/main/java/org/jacop/constraints/Distance.java b/src/main/java/org/jacop/constraints/Distance.java
index cbf217ba5..e5ca94f7c 100644
--- a/src/main/java/org/jacop/constraints/Distance.java
+++ b/src/main/java/org/jacop/constraints/Distance.java
@@ -47,7 +47,7 @@
*
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class Distance extends PrimitiveConstraint {
@@ -83,9 +83,10 @@ public class Distance extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "y", "z"};
/**
- * @param x
- * @param y
- * @param z
+ * Distance between x and y |x-y| = z
+ * @param x first parameter
+ * @param y second parameter
+ * @param z result
*/
public Distance(IntVar x, IntVar y, IntVar z) {
@@ -409,7 +410,9 @@ public void notConsistency(Store store) {
do {
- if (x.singleton()) {
+ store.propagationHasOccurred = false;
+
+ if (x.singleton()) {
if (z.singleton()) {
diff --git a/src/main/java/org/jacop/constraints/Element.java b/src/main/java/org/jacop/constraints/Element.java
index 1b3b9ca10..b208247d6 100644
--- a/src/main/java/org/jacop/constraints/Element.java
+++ b/src/main/java/org/jacop/constraints/Element.java
@@ -44,7 +44,7 @@
* The first index in the variables list is equal to 1.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Element extends Constraint {
@@ -98,9 +98,10 @@ public Element(IntVar index, int[] values, IntVar value, int shift) {
}
/**
- * @param index
- * @param variables
- * @param value
+ * It constructs element constraint based on variables. The default shift value is equal 0.
+ * @param index index variable.
+ * @param variables list of integers.
+ * @param value variable to which index variable is equal to.
*/
public Element(IntVar index, IntVar[] variables, IntVar value) {
queueIndex = 1;
diff --git a/src/main/java/org/jacop/constraints/ElementInteger.java b/src/main/java/org/jacop/constraints/ElementInteger.java
index cdee8fcc4..2cab65e5a 100644
--- a/src/main/java/org/jacop/constraints/ElementInteger.java
+++ b/src/main/java/org/jacop/constraints/ElementInteger.java
@@ -54,7 +54,7 @@
* make addressing of list array starting from 1.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class ElementInteger extends Constraint {
@@ -93,7 +93,7 @@ public class ElementInteger extends Constraint {
/**
* It specifies list of variables within an element constraint list[index-indexOffset] = value.
- * The list is addressed by positive integers (>=1) if indexOffset is equal to 0.
+ * The list is addressed by positive integers ({@code >=1}) if indexOffset is equal to 0.
*/
public int list[];
diff --git a/src/main/java/org/jacop/constraints/ElementIntegerFast.java b/src/main/java/org/jacop/constraints/ElementIntegerFast.java
index 0ad900f3c..6f96e32db 100644
--- a/src/main/java/org/jacop/constraints/ElementIntegerFast.java
+++ b/src/main/java/org/jacop/constraints/ElementIntegerFast.java
@@ -57,7 +57,7 @@
* make addressing of list array starting from 1.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ElementIntegerFast extends Constraint {
@@ -83,7 +83,7 @@ public class ElementIntegerFast extends Constraint {
/**
* It specifies list of variables within an element constraint list[index - indexOffset] = value.
- * The list is addressed by positive integers (>=1) if indexOffset is equal to 0.
+ * The list is addressed by positive integers ({@code >=1}) if indexOffset is equal to 0.
*/
public int list[];
@@ -201,123 +201,123 @@ public void consistency(Store store) {
index.domain.in(store.level, index, 1 + this.indexOffset, list.length + this.indexOffset);
firstConsistencyCheck = false;
}
- else
- do {
- store.propagationHasOccurred = false;
+ do {
- short sort = order.value();
+ store.propagationHasOccurred = false;
- if (sort == ascending || sort == descending) {
- int minIndex = index.min();
- int maxIndex = index.max();
+ short sort = order.value();
- if (sort == ascending)
- value.domain.in(store.level, value, list[minIndex - 1 - indexOffset], list[maxIndex - 1 - indexOffset]);
- else
- value.domain.in(store.level, value, list[maxIndex - 1 - indexOffset], list[minIndex - 1 - indexOffset]);
+ if (sort == ascending || sort == descending) {
+ int minIndex = index.min();
+ int maxIndex = index.max();
+
+ if (sort == ascending)
+ value.domain.in(store.level, value, list[minIndex - 1 - indexOffset], list[maxIndex - 1 - indexOffset]);
+ else
+ value.domain.in(store.level, value, list[maxIndex - 1 - indexOffset], list[minIndex - 1 - indexOffset]);
- IntervalDomain indexDom = new IntervalDomain(5); // create with size 5 ;)
- for (ValueEnumeration e = index.domain.valueEnumeration(); e.hasMoreElements();) {
- int position = e.nextElement() - 1 - indexOffset;
- int val = list[position];
+ IntervalDomain indexDom = new IntervalDomain(5); // create with size 5 ;)
+ for (ValueEnumeration e = index.domain.valueEnumeration(); e.hasMoreElements();) {
+ int position = e.nextElement() - 1 - indexOffset;
+ int val = list[position];
- if (disjoint(value, val))
- if (indexDom.size == 0)
- indexDom.unionAdapt(position + 1 + indexOffset);
- else
- // indexes are in ascending order and can be added at the end if the last element
- // plus 1 is not equal a new value. In such case the max must be changed.
- indexDom.addLastElement(position + 1 + indexOffset);
+ if (disjoint(value, val))
+ if (indexDom.size == 0)
+ indexDom.unionAdapt(position + 1 + indexOffset);
else
- if (val == list[maxIndex - 1 - indexOffset])
- break;
- }
+ // indexes are in ascending order and can be added at the end if the last element
+ // plus 1 is not equal a new value. In such case the max must be changed.
+ indexDom.addLastElement(position + 1 + indexOffset);
+ else
+ if (val == list[maxIndex - 1 - indexOffset])
+ break;
+ }
- index.domain.in(store.level, index, indexDom.complement());
+ index.domain.in(store.level, index, indexDom.complement());
- }
- else if (sort == detect) {
+ }
+ else if (sort == detect) {
- IntDomain vals = new IntervalDomain(5);
+ IntDomain vals = new IntervalDomain(5);
- int min = IntDomain.MaxInt;
- int max = IntDomain.MinInt;
- IntervalDomain indexDom = new IntervalDomain(5); // create with size 5 ;)
- boolean asc = true, desc = true;
- int previous = list[index.min() - 1 - indexOffset];
-
- for (ValueEnumeration e = index.domain.valueEnumeration(); e.hasMoreElements();) {
- int position = e.nextElement() - 1 - indexOffset;
- int val = list[position];
+ int min = IntDomain.MaxInt;
+ int max = IntDomain.MinInt;
+ IntervalDomain indexDom = new IntervalDomain(5); // create with size 5 ;)
+ boolean asc = true, desc = true;
+ int previous = list[index.min() - 1 - indexOffset];
+
+ for (ValueEnumeration e = index.domain.valueEnumeration(); e.hasMoreElements();) {
+ int position = e.nextElement() - 1 - indexOffset;
+ int val = list[position];
- if (disjoint(value, val))
- if (indexDom.size == 0)
- indexDom.unionAdapt(position + 1 + indexOffset);
- else
- // indexes are in ascending order and can be added at the end if the last element
- // plus 1 is not equal a new value. In such case the max must be changed.
- indexDom.addLastElement(position + 1 + indexOffset);
- else {
- min = Math.min(min, val);
- max = Math.max(max, val);
- }
-
- if (val > previous)
- desc = false;
- if (val < previous)
- asc = false;
-
- previous = val;
+ if (disjoint(value, val))
+ if (indexDom.size == 0)
+ indexDom.unionAdapt(position + 1 + indexOffset);
+ else
+ // indexes are in ascending order and can be added at the end if the last element
+ // plus 1 is not equal a new value. In such case the max must be changed.
+ indexDom.addLastElement(position + 1 + indexOffset);
+ else {
+ min = Math.min(min, val);
+ max = Math.max(max, val);
}
- if (desc)
- order.update(descending);
- if (asc)
- order.update(ascending);
+
+ if (val > previous)
+ desc = false;
+ if (val < previous)
+ asc = false;
+
+ previous = val;
+ }
+ if (desc)
+ order.update(descending);
+ if (asc)
+ order.update(ascending);
- index.domain.in(store.level, index, indexDom.complement());
- value.domain.in(store.level, value, min, max);
+ index.domain.in(store.level, index, indexDom.complement());
+ value.domain.in(store.level, value, min, max);
- if (index.singleton()) {
- int position = index.value() - 1 - indexOffset;
- value.domain.in(store.level, value, list[position], list[position]);
- removeConstraint();
- }
+ if (index.singleton()) {
+ int position = index.value() - 1 - indexOffset;
+ value.domain.in(store.level, value, list[position], list[position]);
+ removeConstraint();
}
- else {// sort == none
+ }
+ else {// sort == none
- IntDomain vals = new IntervalDomain(5);
+ IntDomain vals = new IntervalDomain(5);
- int min = IntDomain.MaxInt;
- int max = IntDomain.MinInt;
- IntervalDomain indexDom = new IntervalDomain(5); // create with size 5 ;)
- for (ValueEnumeration e = index.domain.valueEnumeration(); e.hasMoreElements();) {
- int position = e.nextElement() - 1 - indexOffset;
- int val = list[position];
-
- if (disjoint(value, val))
- if (indexDom.size == 0)
- indexDom.unionAdapt(position + 1 + indexOffset);
- else
- // indexes are in ascending order and can be added at the end if the last element
- // plus 1 is not equal a new value. In such case the max must be changed.
- indexDom.addLastElement(position + 1 + indexOffset);
- else {
- min = Math.min(min, val);
- max = Math.max(max, val);
- }
+ int min = IntDomain.MaxInt;
+ int max = IntDomain.MinInt;
+ IntervalDomain indexDom = new IntervalDomain(5); // create with size 5 ;)
+ for (ValueEnumeration e = index.domain.valueEnumeration(); e.hasMoreElements();) {
+ int position = e.nextElement() - 1 - indexOffset;
+ int val = list[position];
+
+ if (disjoint(value, val))
+ if (indexDom.size == 0)
+ indexDom.unionAdapt(position + 1 + indexOffset);
+ else
+ // indexes are in ascending order and can be added at the end if the last element
+ // plus 1 is not equal a new value. In such case the max must be changed.
+ indexDom.addLastElement(position + 1 + indexOffset);
+ else {
+ min = Math.min(min, val);
+ max = Math.max(max, val);
}
+ }
- index.domain.in(store.level, index, indexDom.complement());
- value.domain.in(store.level, value, min, max);
+ index.domain.in(store.level, index, indexDom.complement());
+ value.domain.in(store.level, value, min, max);
- if (index.singleton()) {
- int position = index.value() - 1 - indexOffset;
- value.domain.in(store.level, value, list[position], list[position]);
- removeConstraint();
- }
+ if (index.singleton()) {
+ int position = index.value() - 1 - indexOffset;
+ value.domain.in(store.level, value, list[position], list[position]);
+ removeConstraint();
}
- } while (store.propagationHasOccurred);
+ }
+ } while (store.propagationHasOccurred);
}
boolean disjoint(IntVar v1, int v2) {
diff --git a/src/main/java/org/jacop/constraints/ElementVariable.java b/src/main/java/org/jacop/constraints/ElementVariable.java
index 97016fd9f..04388878f 100644
--- a/src/main/java/org/jacop/constraints/ElementVariable.java
+++ b/src/main/java/org/jacop/constraints/ElementVariable.java
@@ -56,7 +56,7 @@
* make addressing of list array starting from 1.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ElementVariable extends Constraint {
@@ -83,7 +83,7 @@ public class ElementVariable extends Constraint {
/**
* It specifies list of variables within an element constraint list[index - indexOffset] = value.
- * The list is addressed by positive integers (>=1) if indexOffset is equal to 0.
+ * The list is addressed by positive integers ({@code >=1}) if indexOffset is equal to 0.
*/
public IntVar list[];
diff --git a/src/main/java/org/jacop/constraints/ElementVariableFast.java b/src/main/java/org/jacop/constraints/ElementVariableFast.java
index 93b901202..629dc262e 100644
--- a/src/main/java/org/jacop/constraints/ElementVariableFast.java
+++ b/src/main/java/org/jacop/constraints/ElementVariableFast.java
@@ -56,7 +56,7 @@
* make addressing of list array starting from 1.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ElementVariableFast extends Constraint {
@@ -82,7 +82,7 @@ public class ElementVariableFast extends Constraint {
/**
* It specifies list of variables within an element constraint list[index - indexOffset] = value.
- * The list is addressed by positive integers (>=1) if indexOffset is equal to 0.
+ * The list is addressed by positive integers ({@code >=1}) if indexOffset is equal to 0.
*/
public IntVar list[];
@@ -187,36 +187,37 @@ public void consistency(Store store) {
index.domain.in(store.level, index, 1 + this.indexOffset, list.length + this.indexOffset);
firstConsistencyCheck = false;
}
- else {
- int min = IntDomain.MaxInt;
- int max = IntDomain.MinInt;
- IntervalDomain indexDom = new IntervalDomain(5); // create with size 5 ;)
- for (ValueEnumeration e = index.domain.valueEnumeration(); e.hasMoreElements();) {
- int position = e.nextElement() - 1 - indexOffset;
+ int min = IntDomain.MaxInt;
+ int max = IntDomain.MinInt;
+ IntervalDomain indexDom = new IntervalDomain(5); // create with size 5 ;)
+ for (ValueEnumeration e = index.domain.valueEnumeration(); e.hasMoreElements();) {
+ int position = e.nextElement() - 1 - indexOffset;
- if (disjoint(value, list[position]))
+ if (disjoint(value, list[position]))
+ if (indexDom.size == 0)
indexDom.unionAdapt(position + 1 + indexOffset);
- else {
- min = Math.min(min, list[position].min());
- max = Math.max(max, list[position].max());
- }
+ else
+ indexDom.addLastElement(position + 1 + indexOffset);
+ else {
+ min = Math.min(min, list[position].min());
+ max = Math.max(max, list[position].max());
}
+ }
- index.domain.in(store.level, index, indexDom.complement());
- value.domain.in(store.level, value, min, max);
+ index.domain.in(store.level, index, indexDom.complement());
+ value.domain.in(store.level, value, min, max);
- if (index.singleton()) {
- int position = index.value() - 1 - indexOffset;
- value.domain.in(store.level, value, list[position].domain);
- list[ position].domain.in(store.level, list[position], value.domain);
+ if (index.singleton()) {
+ int position = index.value() - 1 - indexOffset;
+ value.domain.in(store.level, value, list[position].domain);
+ list[ position].domain.in(store.level, list[position], value.domain);
- }
- if (value.singleton() && index.singleton()) {
- IntVar v = list[index.value() - 1 - indexOffset];
- v.domain.in(store.level, v, value.value(), value.value());
- removeConstraint();
- }
+ }
+ if (value.singleton() && index.singleton()) {
+ IntVar v = list[index.value() - 1 - indexOffset];
+ v.domain.in(store.level, v, value.value(), value.value());
+ removeConstraint();
}
}
diff --git a/src/main/java/org/jacop/constraints/Eq.java b/src/main/java/org/jacop/constraints/Eq.java
index b950948af..5ad3ec472 100644
--- a/src/main/java/org/jacop/constraints/Eq.java
+++ b/src/main/java/org/jacop/constraints/Eq.java
@@ -40,11 +40,11 @@
import org.jacop.util.SimpleHashSet;
/**
- * Constraint "constraint1" #<=> "constraint2"
+ * Constraint "constraint1"{@literal #<=>} "constraint2"
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Eq extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/EqBool.java b/src/main/java/org/jacop/constraints/EqBool.java
index 1181b35fc..0a46a0aeb 100644
--- a/src/main/java/org/jacop/constraints/EqBool.java
+++ b/src/main/java/org/jacop/constraints/EqBool.java
@@ -44,7 +44,7 @@
* is equal to zero. It restricts the domains of all variables to be either 0 or 1.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class EqBool extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/ExclusiveItem.java b/src/main/java/org/jacop/constraints/ExclusiveItem.java
index 05202e3ce..bd2dcef5d 100644
--- a/src/main/java/org/jacop/constraints/ExclusiveItem.java
+++ b/src/main/java/org/jacop/constraints/ExclusiveItem.java
@@ -38,7 +38,7 @@
* DisjointConditional
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class ExclusiveItem {
diff --git a/src/main/java/org/jacop/constraints/ExclusiveList.java b/src/main/java/org/jacop/constraints/ExclusiveList.java
index 99b0ea675..a50f2d4a0 100644
--- a/src/main/java/org/jacop/constraints/ExclusiveList.java
+++ b/src/main/java/org/jacop/constraints/ExclusiveList.java
@@ -39,7 +39,7 @@
* Defines a list of exclusive items.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class ExclusiveList extends ArrayList {
diff --git a/src/main/java/org/jacop/constraints/ExtensionalConflictVA.java b/src/main/java/org/jacop/constraints/ExtensionalConflictVA.java
index c163dbecc..728ea139a 100644
--- a/src/main/java/org/jacop/constraints/ExtensionalConflictVA.java
+++ b/src/main/java/org/jacop/constraints/ExtensionalConflictVA.java
@@ -55,7 +55,7 @@
* efficiency.
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ExtensionalConflictVA extends Constraint {
@@ -107,7 +107,7 @@ public class ExtensionalConflictVA extends Constraint {
* Partial constructor which stores variables involved in a constraint but
* does not get information about tuples yet. The tuples must set separately.
*
- * @param list
+ * @param list list of variables for constraint
*/
public ExtensionalConflictVA(IntVar[] list) {
@@ -127,8 +127,8 @@ public ExtensionalConflictVA(IntVar[] list) {
* tuples parameter will be reflected in the constraint behavior. Changes to
* tuples should not performed under any circumstances. The tuples array is
* not copied to save memory and time.
- * @param list
- * @param tuples
+ * @param list list of variables for the conflict constraint
+ * @param tuples list of forbidden tuples
*/
public ExtensionalConflictVA(IntVar[] list, int[][] tuples) {
@@ -821,7 +821,7 @@ public String toString() {
* specified in xmlAttributes.
*
* @param tf a place to write the content of the object.
- * @throws SAXException
+ * @throws SAXException exception from org.xml.sax package
*/
public void toXML(TransformerHandler tf) throws SAXException {
diff --git a/src/main/java/org/jacop/constraints/ExtensionalSupportSTR.java b/src/main/java/org/jacop/constraints/ExtensionalSupportSTR.java
index 5b58c8a15..4a0bf5e0c 100644
--- a/src/main/java/org/jacop/constraints/ExtensionalSupportSTR.java
+++ b/src/main/java/org/jacop/constraints/ExtensionalSupportSTR.java
@@ -56,7 +56,7 @@
* available, which helped to create our own version of this algorithm.
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
@@ -751,7 +751,7 @@ public String toString() {
* specified in xmlAttributes.
*
* @param tf a place to write the content of the object.
- * @throws SAXException
+ * @throws SAXException exception from org.xml.sax package
*/
public void toXML(TransformerHandler tf) throws SAXException {
diff --git a/src/main/java/org/jacop/constraints/ExtensionalSupportVA.java b/src/main/java/org/jacop/constraints/ExtensionalSupportVA.java
index 08a10f9f3..92d74eb17 100644
--- a/src/main/java/org/jacop/constraints/ExtensionalSupportVA.java
+++ b/src/main/java/org/jacop/constraints/ExtensionalSupportVA.java
@@ -55,7 +55,7 @@
* efficiency.
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ExtensionalSupportVA extends Constraint {
@@ -238,7 +238,7 @@ public int seekInvalidPosition(int[] t) {
* Partial constructor which stores variables involved in a constraint but
* does not get information about tuples yet. The tuples must set separately.
*
- * @param list
+ * @param list list of variables for the constraint
*/
public ExtensionalSupportVA(IntVar[] list) {
@@ -716,7 +716,7 @@ public String toString() {
* specified in xmlAttributes.
*
* @param tf a place to write the content of the object.
- * @throws SAXException
+ * @throws SAXException exception from org.xml.sax
*/
public void toXML(TransformerHandler tf) throws SAXException {
diff --git a/src/main/java/org/jacop/constraints/GCC.java b/src/main/java/org/jacop/constraints/GCC.java
index 92bb42537..a140ac897 100644
--- a/src/main/java/org/jacop/constraints/GCC.java
+++ b/src/main/java/org/jacop/constraints/GCC.java
@@ -58,7 +58,7 @@
*
* @author Jocelyne Lotfi and Radoslaw Szymanek.
*
-* @version 4.3
+* @version 4.4
*/
public class GCC extends Constraint {
@@ -295,8 +295,10 @@ public void consistency(Store store) {
while (k < stamp.value()) {
if (x[k].singleton()){
+ if (stamp.value() > 0) {
stamp.update(stamp.value() - 1);
putToTheEnd(x, k);
+ }
} else {
// no incrementation if there is a modification in the
// xNodes table. The variable in the i position is no more
@@ -328,15 +330,17 @@ public void consistency(Store store) {
// if v is singleton and is an X variable
if (var.singleton() && xNodesHash.containsKey(var)) {
// if
- if (xNodesHash.get(var) <= stamp.value()) {
+ if (xNodesHash.get(var) < stamp.value()) { // changing '<=' to '<' (KK)
if (debug)
System.out.println(" in xVariableToChange: " + var);
- stamp.update(stamp.value() - 1);
- putToTheEnd(x, xNodesHash.get(var));
+ if (stamp.value() > 0) {
+ stamp.update(stamp.value() - 1);
+ putToTheEnd(x, xNodesHash.get(var));
+ }
}
}
}
-
+
assert checkXorder() : "Inconsistent X variable order: " + Arrays.toString(this.x);
if (debug) {
@@ -484,14 +488,6 @@ public int getConsistencyPruningEvent(Var var) {
return IntDomain.BOUND;
}
- @Override
- public String id() {
- if (id != null)
- return id;
- else
- return this.getClass().getSimpleName() + numberId;
- }
-
@Override
public void impose(Store store) {
@@ -499,9 +495,18 @@ public void impose(Store store) {
// first I will put all the xNodes in a hashTable to be able to use
// it with the queueVariable function
- for (int i = 0; i < xSize; i++)
- xNodesHash.put(x[i], i);
-
+ // KK, 2015-10-18
+ // only non ground variables need to be added
+ // no duplicates allowed
+ for (int i = 0; i < xSize; i++)
+ if (!x[i].singleton()) {
+ Integer varPosition = xNodesHash.put(x[i], i);
+ if (varPosition != null) {
+ System.err.println("ERROR: Constraint " + toString() + " must have different non ground variables on the list");
+ System.exit(0);
+ }
+ }
+
// here I will put normalization
IntervalDomain d = new IntervalDomain();
diff --git a/src/main/java/org/jacop/constraints/IfThen.java b/src/main/java/org/jacop/constraints/IfThen.java
index a6d8c235c..d062659f4 100644
--- a/src/main/java/org/jacop/constraints/IfThen.java
+++ b/src/main/java/org/jacop/constraints/IfThen.java
@@ -42,7 +42,7 @@
* Constraint if constraint1 then constraint2
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class IfThen extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/IfThenBool.java b/src/main/java/org/jacop/constraints/IfThenBool.java
index d80c9ff2a..dcdbe4e78 100644
--- a/src/main/java/org/jacop/constraints/IfThenBool.java
+++ b/src/main/java/org/jacop/constraints/IfThenBool.java
@@ -40,11 +40,11 @@
import org.jacop.core.Var;
/**
- * Constraint ( X => Y ) <=> Z.
+ * Constraint ( X {@literal =>} Y ) {@literal <=>} Z.
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class IfThenBool extends PrimitiveConstraint {
@@ -60,17 +60,17 @@ public class IfThenBool extends PrimitiveConstraint {
static int counter = 1;
/**
- * It specifies variable x in constraint ( X => Y ) <=> Z.
+ * It specifies variable x in constraint ( X {@literal =>} Y ) {@literal <=>} Z.
*/
public IntVar x;
/**
- * It specifies variable y in constraint ( X => Y ) <=> Z.
+ * It specifies variable y in constraint ( X {@literal =>} Y ) {@literal <=>} Z.
*/
public IntVar y;
/**
- * It specifies variable z in constraint ( X => Y ) <=> Z.
+ * It specifies variable z in constraint ( X {@literal =>} Y ) {@literal <=>} Z.
*/
public IntVar z;
@@ -81,7 +81,7 @@ public class IfThenBool extends PrimitiveConstraint {
*/
public static String[] xmlAttributes = {"x", "y", "z"};
- /** It constructs constraint ( X => Y ) <=> Z.
+ /** It constructs constraint ( X {@literal =>} Y ) {@literal <=>} Z.
* @param x variable x.
* @param y variable y.
* @param z variable z.
diff --git a/src/main/java/org/jacop/constraints/IfThenElse.java b/src/main/java/org/jacop/constraints/IfThenElse.java
index 4f5f152ea..b046c1d56 100644
--- a/src/main/java/org/jacop/constraints/IfThenElse.java
+++ b/src/main/java/org/jacop/constraints/IfThenElse.java
@@ -41,7 +41,7 @@
* Constraint if constraint1 then constraint2 else constraint3
* *
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class IfThenElse extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/In.java b/src/main/java/org/jacop/constraints/In.java
index ed88d92d3..e6cff6979 100644
--- a/src/main/java/org/jacop/constraints/In.java
+++ b/src/main/java/org/jacop/constraints/In.java
@@ -45,7 +45,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class In extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/IntRectangle.java b/src/main/java/org/jacop/constraints/IntRectangle.java
index 837440e6b..60a43ac1d 100644
--- a/src/main/java/org/jacop/constraints/IntRectangle.java
+++ b/src/main/java/org/jacop/constraints/IntRectangle.java
@@ -40,7 +40,7 @@
* constraint.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class IntRectangle {
diff --git a/src/main/java/org/jacop/constraints/IntTask.java b/src/main/java/org/jacop/constraints/IntTask.java
index 8bb7c1907..733c6f87b 100644
--- a/src/main/java/org/jacop/constraints/IntTask.java
+++ b/src/main/java/org/jacop/constraints/IntTask.java
@@ -36,7 +36,7 @@
* cumulative constraint
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class IntTask {
diff --git a/src/main/java/org/jacop/constraints/Lex.java b/src/main/java/org/jacop/constraints/Lex.java
index 12847fbc5..ffdff4f33 100644
--- a/src/main/java/org/jacop/constraints/Lex.java
+++ b/src/main/java/org/jacop/constraints/Lex.java
@@ -47,11 +47,13 @@
* It constructs a Lex (lexicographical order) constraint.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Lex extends DecomposedConstraint {
+ static int idNumber = 1;
+
/**
* A two dimensional array containing arrays which have to be lexicographically ordered.
*/
@@ -69,11 +71,11 @@ public class Lex extends DecomposedConstraint {
/**
* It creates a lexicographical order for vectors x[i], i.e.
- * forall i, exists j : x[i][k] = x[i+1][k] for k < j and x[i][k] <= x[i+1][k]
- * for k >= j
+ * forall i, exists j : x[i][k] = x[i+1][k] for k {@literal <} j and x[i][k] {@literal <=} x[i+1][k]
+ * for k {@literal >=} j
*
* vectors x[i] does not need to be of the same size.
- * boolea lt defines if we require Lex_{<} (lt = false) or Lex_{=<} (lt = true)
+ * boolea lt defines if we require Lex_{{@literal <}} (lt = false) or Lex_{{@literal =<}} (lt = true)
*
* @param x vector of vectors which assignment is constrained by Lex constraint.
*/
@@ -89,6 +91,8 @@ public Lex(IntVar[][] x, boolean lt) {
assert (x != null) : "x list is null.";
this.x = new IntVar[x.length][];
+ idNumber += 1;
+
lexLT = lt;
for (int i = 0; i < x.length; i++) {
@@ -414,7 +418,7 @@ public ArrayList decomposeLT(Store store) {
BooleanVar[] b = new BooleanVar[sizeToCompare+1];
for (int i=0; i < b.length; i++)
- b[i] = new BooleanVar(store, "_b["+i+"]");
+ b[i] = new BooleanVar(store, "_b"+idNumber+"["+i+"]");
constraints.add(new XeqC(b[0], 1));
@@ -442,7 +446,7 @@ public ArrayList decomposeLE(Store store) {
BooleanVar[] b = new BooleanVar[sizeToCompare];
for (int i=0; i < b.length; i++)
- b[i] = new BooleanVar(store, "_b["+i+"]");
+ b[i] = new BooleanVar(store, "_b"+idNumber+"["+i+"]");
constraints.add(new XeqC(b[0], 1));
diff --git a/src/main/java/org/jacop/constraints/LexOrder.java b/src/main/java/org/jacop/constraints/LexOrder.java
index 7e8745b9e..6123a5e7b 100644
--- a/src/main/java/org/jacop/constraints/LexOrder.java
+++ b/src/main/java/org/jacop/constraints/LexOrder.java
@@ -32,14 +32,14 @@
package org.jacop.constraints;
import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.Hashtable;
+import java.util.HashMap;
import org.jacop.core.Var;
import org.jacop.core.IntVar;
import org.jacop.core.IntDomain;
import org.jacop.core.IntervalDomain;
import org.jacop.core.Store;
+import org.jacop.util.SimpleHashSet;
// import org.jacop.core.TimeStamp;
/**
@@ -53,11 +53,13 @@
* Artificial Intelligence 170 (2006) 803–834.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class LexOrder extends Constraint {
+ static int idNumber = 1;
+
final static boolean debug = false;
/**
@@ -67,7 +69,7 @@ public class LexOrder extends Constraint {
public IntVar[] y;
/**
- * Is Lex enforcing "<" relationship?
+ * Is Lex enforcing "{@literal <}" relationship?
*/
public boolean lexLT;
@@ -85,20 +87,24 @@ public class LexOrder extends Constraint {
private int alpha;
private int beta;
- LinkedHashSet indexQueue = new LinkedHashSet();
- Hashtable varToIndex = new Hashtable();
+ SimpleHashSet indexQueue = new SimpleHashSet();
+ HashMap varXToIndex = new HashMap();
+ HashMap varYToIndex = new HashMap();
/**
* It creates a lexicographical order for vectors x and y,
*
* vectors x and y does not need to be of the same size.
- * boolean lt defines if we require strict order, Lex_{<} (lt = true) or Lex_{=<} (lt = false)
+ * boolean lt defines if we require strict order, Lex_{{@literal <}} (lt = true) or Lex_{{@literal =<}} (lt = false)
*
- * @param x vector of vectors which assignment is constrained by LexOrder constraint.
+ * @param x first vector constrained by LexOrder constraint.
+ * @param y second vector constrained by LexOrder constraint.
*/
public LexOrder(IntVar[] x, IntVar[] y) {
this(x, y, true);
+
+ numberId = idNumber++;
}
@@ -107,7 +113,8 @@ public LexOrder(IntVar[] x, IntVar[] y, boolean lt) {
assert (x != null) : "x list is null.";
assert (y != null) : "y list is null.";
- queueIndex = 1;
+ queueIndex = 2;
+ numberId = idNumber++;
lexLT = lt;
@@ -141,23 +148,46 @@ public ArrayList arguments() {
public void impose(Store store) {
this.store = store;
-
+
// alpha = new TimeStamp(store, 0);
// beta = new TimeStamp(store, 0);
alpha = 0;
beta = 0;
- store.registerRemoveLevelLateListener(this);
-
for (int i = 0; i < n; i++) {
- varToIndex.put(x[i], i);
+ int[] varPositions = varXToIndex.get(x[i]);
+ if (varPositions == null) {
+ int[] p = new int[1];
+ p[0] = i;
+ varXToIndex.put(x[i], p);
+ }
+ else {
+ int[] newPos = new int[varPositions.length+1];
+ System.arraycopy(varPositions, 0, newPos, 0, varPositions.length);
+ newPos[varPositions.length] = i;
+ varXToIndex.put(x[i], varPositions);
+ }
x[i].putModelConstraint(this, getConsistencyPruningEvent(x[i]));
}
+
for (int i = 0; i < n; i++) {
- varToIndex.put(y[i], i);
+ int[] varPositions = varYToIndex.get(y[i]);
+ if (varPositions == null) {
+ int[] p = new int[1];
+ p[0] = i;
+ varYToIndex.put(y[i], p);
+ }
+ else {
+ int[] newPos = new int[varPositions.length+1];
+ System.arraycopy(varPositions, 0, newPos, 0, varPositions.length);
+ newPos[varPositions.length] = i;
+ varYToIndex.put(y[i], varPositions);
+ }
y[i].putModelConstraint(this, getConsistencyPruningEvent(y[i]));
}
+ store.registerRemoveLevelLateListener(this);
+
store.addChanged(this);
store.countConstraint();
}
@@ -184,10 +214,11 @@ public void consistency(Store store) {
store.propagationHasOccurred = false;
- LinkedHashSet index = indexQueue;
- indexQueue = new LinkedHashSet();
+ SimpleHashSet index = indexQueue;
+ indexQueue = new SimpleHashSet();
- for (int i : index) {
+ while (!index.isEmpty()) {
+ int i = index.removeFirst();
// if ( !( i >= beta.value() || satisfied) )
if ( !( i >= beta || satisfied) )
@@ -250,10 +281,16 @@ public void increaseWeight() {
@Override
public void queueVariable(int level, Var var) {
- int i = varToIndex.get(var);
-
- indexQueue.add(i);
+ int[] iValX = varXToIndex.get(var);
+ int[] iValY = varYToIndex.get(var);
+ if (iValX != null)
+ for (int i : iValX)
+ indexQueue.add(i);
+ if (iValY != null)
+ for (int i : iValY)
+ indexQueue.add(i);
+
}
@Override
@@ -286,6 +323,10 @@ public String toString() {
if (i < y.length - 1)
result.append(", ");
}
+ if (lexLT)
+ result.append("], <");
+ else
+ result.append("], <=");
result.append(");");
diff --git a/src/main/java/org/jacop/constraints/Linear.java b/src/main/java/org/jacop/constraints/Linear.java
index c7b7074ba..5e6474d49 100644
--- a/src/main/java/org/jacop/constraints/Linear.java
+++ b/src/main/java/org/jacop/constraints/Linear.java
@@ -45,11 +45,17 @@
* variables . It provides the weighted sum from all variables on the list.
* The weights are integers.
*
+ * This version works as argument for Reified and Xor constraints.
+ * For other constraints (And, Or, Not, Eq, IfThen, IfThenElse) use LinearInt.
+ *
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
* @version 3.1
*/
-public class Linear extends PrimitiveConstraint {
+/**
+ * @deprecated As of release 4.3.1 replaced by LinearInt constraint.
+ */
+@Deprecated public class Linear extends Constraint {
Store store;
static int counter = 1;
@@ -121,9 +127,12 @@ public class Linear extends PrimitiveConstraint {
public static String[] xmlAttributes = {"list", "weights", "sum"};
/**
- * @param list
- * @param weights
- * @param sum
+ * It constructs the constraint Linear.
+ * @param store current store
+ * @param list variables which are being multiplied by weights.
+ * @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
+ * @param sum variable containing the sum of weighted variables.
*/
public Linear(Store store, IntVar[] list, int[] weights, String rel, int sum) {
@@ -208,8 +217,10 @@ private void commonInitialization(Store store, IntVar[] list, int[] weights, int
/**
* It constructs the constraint Linear.
+ * @param store current store
* @param variables variables which are being multiplied by weights.
* @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
* @param sum variable containing the sum of weighted variables.
*/
public Linear(Store store, ArrayList extends IntVar> variables,
@@ -256,16 +267,16 @@ public void consistency(Store store) {
removeConstraint();
}
- @Override
- public void notConsistency(Store store) {
+ // @Override
+ // public void notConsistency(Store store) {
- pruneRelation(store, negRel[relationType]);
+ // pruneRelation(store, negRel[relationType]);
- if (negRel[relationType] != eq)
- if (notSatisfied())
- removeConstraint();
+ // if (negRel[relationType] != eq)
+ // if (notSatisfied())
+ // removeConstraint();
- }
+ // }
private void pruneRelation(Store store, byte rel) {
@@ -369,20 +380,16 @@ private void pruneRelation(Store store, byte rel) {
break;
case ne : //=============================================
- d1 = ((float)(min + lMaxArray[i]) / weights[i]);
- d2 = ((float)(max + lMinArray[i]) / weights[i]);
+ int rem1 = (min + lMaxArray[i]) % weights[i];
+ int rem2 = (max + lMinArray[i]) % weights[i];
+ if (rem1 != 0 || rem2 != 0)
+ break;
- if (d1 <= d2) {
- divMin = (int)( Math.round( Math.ceil ( d1 ) ) );
- divMax = (int)( Math.round( Math.floor( d2 ) ) );
- }
- else {
- divMin = (int)( Math.round( Math.ceil ( d2 ) ) );
- divMax = (int)( Math.round( Math.floor( d1 ) ) );
- }
+ divMin = (min + lMaxArray[i]) / weights[i];
+ divMax = (max + lMinArray[i]) / weights[i];
- if ( divMin == divMax)
- v.domain.inComplement(store.level, v, divMin);
+ if (divMin == divMax)
+ v.domain.inComplement(store.level, v,divMin);
break;
case gt : //=============================================
@@ -457,43 +464,43 @@ public int getConsistencyPruningEvent(Var var) {
return IntDomain.BOUND;
}
- @Override
- public int getNestedPruningEvent(Var var, boolean mode) {
-
- // If consistency function mode
- if (mode) {
- if (consistencyPruningEvents != null) {
- Integer possibleEvent = consistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.BOUND;
- }
-
- // If notConsistency function mode
- else {
- if (notConsistencyPruningEvents != null) {
- Integer possibleEvent = notConsistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.BOUND;
- }
-
- }
-
- @Override
- public int getNotConsistencyPruningEvent(Var var) {
-
- // If notConsistency function mode
- if (notConsistencyPruningEvents != null) {
- Integer possibleEvent = notConsistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.BOUND;
+ // @Override
+ // public int getNestedPruningEvent(Var var, boolean mode) {
+
+ // // If consistency function mode
+ // if (mode) {
+ // if (consistencyPruningEvents != null) {
+ // Integer possibleEvent = consistencyPruningEvents.get(var);
+ // if (possibleEvent != null)
+ // return possibleEvent;
+ // }
+ // return IntDomain.BOUND;
+ // }
+
+ // // If notConsistency function mode
+ // else {
+ // if (notConsistencyPruningEvents != null) {
+ // Integer possibleEvent = notConsistencyPruningEvents.get(var);
+ // if (possibleEvent != null)
+ // return possibleEvent;
+ // }
+ // return IntDomain.BOUND;
+ // }
+
+ // }
+
+ // @Override
+ // public int getNotConsistencyPruningEvent(Var var) {
+
+ // // If notConsistency function mode
+ // if (notConsistencyPruningEvents != null) {
+ // Integer possibleEvent = notConsistencyPruningEvents.get(var);
+ // if (possibleEvent != null)
+ // return possibleEvent;
+ // }
+ // return IntDomain.BOUND;
- }
+ // }
@Override
public void impose(Store store) {
@@ -631,19 +638,19 @@ public boolean satisfied() {
}
- @Override
- public boolean notSatisfied() {
+ // @Override
+ // public boolean notSatisfied() {
- if (reified && backtrackHasOccured) {
+ // if (reified && backtrackHasOccured) {
- backtrackHasOccured = false;
+ // backtrackHasOccured = false;
- recomputeBounds();
- }
+ // recomputeBounds();
+ // }
- return entailed(negRel[relationType]);
+ // return entailed(negRel[relationType]);
- }
+ // }
private boolean entailed(byte rel) {
diff --git a/src/main/java/org/jacop/constraints/LinearInt.java b/src/main/java/org/jacop/constraints/LinearInt.java
index 6119539e8..9e5268bb0 100644
--- a/src/main/java/org/jacop/constraints/LinearInt.java
+++ b/src/main/java/org/jacop/constraints/LinearInt.java
@@ -53,7 +53,7 @@
* by Warwick Harvey and Joachim Schimpf
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class LinearInt extends PrimitiveConstraint {
@@ -128,9 +128,11 @@ public class LinearInt extends PrimitiveConstraint {
public static String[] xmlAttributes = {"list", "weights", "sum"};
/**
- * @param list
- * @param weights
- * @param sum
+ * @param store current store
+ * @param list variables which are being multiplied by weights.
+ * @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
+ * @param sum variable containing the sum of weighted variables.
*/
public LinearInt(Store store, IntVar[] list, int[] weights, String rel, int sum) {
@@ -142,8 +144,10 @@ public LinearInt(Store store, IntVar[] list, int[] weights, String rel, int sum)
/**
* It constructs the constraint LinearInt.
+ * @param store current store
* @param variables variables which are being multiplied by weights.
* @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
* @param sum variable containing the sum of weighted variables.
*/
public LinearInt(Store store, ArrayList extends IntVar> variables,
@@ -171,8 +175,7 @@ private void commonInitialization(Store store, IntVar[] list, int[] weights, int
for (int i = 0; i < list.length; i++) {
assert (list[i] != null) : i + "-th element of list in Propagations constraint is null";
-
- if (weights[i] != 0) {
+ if (weights[i] != 0) {
if (list[i].singleton())
this.b -= list[i].value() * weights[i];
else
@@ -187,9 +190,13 @@ private void commonInitialization(Store store, IntVar[] list, int[] weights, int
}
}
+ int size=0;
+ for (IntVar e : parameters.keySet())
+ if (parameters.get(e) != 0)
+ size++;
- this.x = new IntVar[parameters.size()];
- this.a = new int[parameters.size()];
+ this.x = new IntVar[size];//parameters.size()];
+ this.a = new int[size];//parameters.size()];
int i = 0;
for (IntVar var : parameters.keySet()) {
@@ -209,6 +216,11 @@ private void commonInitialization(Store store, IntVar[] list, int[] weights, int
i++;
}
}
+ // for (IntVar var : parameters.keySet()) {
+ // int coeff = parameters.get(var);
+ // if (coeff == 0)
+ // System.out.println("%% " + id() + " : " + var);;
+ // }
this.l = x.length;
this.I = new int[l];
@@ -233,95 +245,38 @@ public ArrayList arguments() {
return variables;
}
-
@Override
public void consistency(Store store) {
-
- computeInit();
-
- do {
-
- store.propagationHasOccurred = false;
-
- switch (relationType) {
- case eq:
-
- pruneLtEq();
- pruneGtEq();
-
- if (!reified)
- if (sumMax <= b && sumMin >= b)
- removeConstraint();
-
- break;
-
- case le:
- pruneLtEq();
-
- if (!reified)
- if (sumMax <= b)
- removeConstraint();
- break;
-
- case lt:
- pruneLt();
-
- if (!reified)
- if (sumMax < b)
- removeConstraint();
- break;
- case ne:
- pruneNeq();
-
- if (!reified)
- if (sumMin == sumMax && sumMin != b)
- removeConstraint();
- break;
- case gt:
-
- pruneGt();
-
- if (!reified)
- if (sumMin > b)
- removeConstraint();
- break;
- case ge:
-
- pruneGtEq();
-
- if (!reified)
- if (sumMin >= b)
- removeConstraint();
-
- break;
- }
-
- } while (store.propagationHasOccurred);
+ propagate(relationType);
}
@Override
public void notConsistency(Store store) {
-
+ propagate(negRel[relationType]);
+ }
+
+ public void propagate(int rel) {
+
computeInit();
do {
store.propagationHasOccurred = false;
- switch (negRel[relationType]) {
+ switch (rel) {
case eq:
- pruneLtEq();
- pruneGtEq();
-
- if (!reified)
- if (sumMax <= b && sumMin >= b)
- removeConstraint();
+ pruneLtEq(b);
+ pruneGtEq(b);
+
+ // if (!reified)
+ // if (sumMax <= b && sumMin >= b)
+ // removeConstraint();
break;
case le:
- pruneLtEq();
+ pruneLtEq(b);
if (!reified)
if (sumMax <= b)
@@ -329,7 +284,7 @@ public void notConsistency(Store store) {
break;
case lt:
- pruneLt();
+ pruneLtEq(b-1);
if (!reified)
if (sumMax < b)
@@ -339,12 +294,13 @@ public void notConsistency(Store store) {
pruneNeq();
if (!reified)
+ // if (sumMin == sumMax && (sumMin > b || sumMax < b))
if (sumMin > b || sumMax < b)
removeConstraint();
break;
case gt:
- pruneGt();
+ pruneGtEq(b+1);
if (!reified)
if (sumMin > b)
@@ -352,7 +308,7 @@ public void notConsistency(Store store) {
break;
case ge:
- pruneGtEq();
+ pruneGtEq(b);
if (!reified)
if (sumMin >= b)
@@ -433,16 +389,18 @@ void computeInit() {
int i = 0;
// positive weights
for (; i < pos; i++) {
- min = x[i].min() * a[i];
- max = x[i].max() * a[i];
+ IntDomain xd = x[i].dom();
+ min = xd.min() * a[i];
+ max = xd.max() * a[i];
f += min;
e += max;
I[i] = (max - min);
}
// negative weights
for (; i < l; i++) {
- min = x[i].max() * a[i];
- max = x[i].min() * a[i];
+ IntDomain xd = x[i].dom();
+ min = xd.max() * a[i];
+ max = xd.min() * a[i];
f += min;
e += max;
I[i] = (max - min);
@@ -451,7 +409,8 @@ void computeInit() {
sumMax = e;
}
- void pruneLtEq() {
+
+ void pruneLtEq(int b) {
if (sumMin > b)
throw store.failException;
@@ -472,7 +431,7 @@ void pruneLtEq() {
}
// negative weights
for (; i < l; i++) {
- if (I[i] > b - sumMax) {
+ if (I[i] > b - sumMin) {
min = x[i].max() * a[i];
max = min + I[i];
if (pruneMin(x[i], divRoundUp(-(b - sumMin + min), -a[i]))) {
@@ -484,7 +443,7 @@ void pruneLtEq() {
}
}
- void pruneGtEq() {
+ void pruneGtEq(int b) {
if (sumMax < b)
throw store.failException;
@@ -517,74 +476,6 @@ void pruneGtEq() {
}
}
- private void pruneLt() {
-
- if (sumMin >= b)
- throw store.failException;
-
- int min, max;
- int i = 0;
- // positive weights
- for (; i < pos; i++) {
- if (I[i] >= b - sumMin) {
- min = x[i].min() * a[i];
- max = min + I[i];
- if (pruneMax(x[i], divRoundUp(b - sumMin + min, a[i]) - 1)) {
- int newMax = x[i].max() * a[i];
- sumMax -= max - newMax;
- I[i] = newMax - min;
- }
- }
- }
- // negative weights
- for (; i < l; i++) {
- if (I[i] >= b - sumMax) {
- min = x[i].max() * a[i];
- max = min + I[i];
- if (pruneMin(x[i], divRoundDown(-(b - sumMin + min), -a[i]) + 1)) {
- int newMax = x[i].min() * a[i];
- sumMax -= max - newMax;
- I[i] = newMax - min;
- }
- }
- }
- }
-
- private void pruneGt() {
-
- if (sumMax <= b)
- throw store.failException;
-
- int min, max;
- int i = 0;
- // positive weights
- for (; i < pos; i++) {
- if (I[i] >= -(b - sumMax)) {
- max = x[i].max() * a[i];
- min = max - I[i];
-
- if (pruneMin(x[i], divRoundDown(b - sumMax + max, a[i]) + 1)) {
- int nmin = x[i].min() * a[i];
- sumMin += nmin - min;
- I[i] = max - nmin;
- }
- }
- }
- // negative weights
- for (; i < l; i++) {
- if (I[i] >= - (b - sumMax)) {
- max = x[i].min() * a[i];
- min = max - I[i];
-
- if (pruneMax(x[i], divRoundUp(-(b - sumMax + max), -a[i]) - 1)) {
- int newMin = x[i].max() * a[i];
- sumMin += newMin - min;
- I[i] = max - newMin;
- }
- }
- }
- }
-
void pruneNeq() {
if (sumMin == sumMax && b == sumMin)
@@ -610,7 +501,7 @@ void pruneNeq() {
min = x[i].max() * a[i];
max = min + I[i];
- if (pruneNe(x[i], -(b - sumMin + min), -(b - sumMax + max), a[i])) {
+ if (pruneNe(x[i], b - sumMin + min, b - sumMax + max, a[i])) {
int newMin = x[i].max() * a[i];
int newMax = x[i].min() * a[i];
sumMin += newMin - min;
@@ -640,20 +531,19 @@ private boolean pruneMax(IntVar x, int max) {
private boolean pruneNe(IntVar x, int min, int max, int a) {
- if (min == max) {
- int low = divRoundUp(min, a);
- int high = divRoundDown(max, a);
- if (low == high) {
- boolean boundsChanged = false;
- if (low == x.min() || high == x.max())
- boundsChanged = true;
+ if (min == max && min % a == 0) {
- x.domain.inComplement(store.level, x, low);
+ int d = min/a;
- return boundsChanged;
- }
- }
+ boolean boundsChanged = false;
+
+ if (d == x.min() || d == x.max())
+ boundsChanged = true;
+
+ x.domain.inComplement(store.level, x, d);
+ return boundsChanged;
+ }
return false;
}
@@ -689,7 +579,7 @@ public boolean satisfiedNeq() {
return sMin > b || sMax < b;
}
- public boolean satisfiedLtEq() {
+ public boolean satisfiedLtEq(int b) {
int sMax = 0;
int i = 0;
@@ -703,21 +593,7 @@ public boolean satisfiedLtEq() {
return sMax <= b;
}
- public boolean satisfiedLt() {
-
- int sMax = 0;
- int i = 0;
- for (; i < pos; i++) {
- sMax += x[i].max() * a[i];
- }
- for (; i < l; i++) {
- sMax += x[i].min() * a[i];
- }
-
- return sMax < b;
- }
-
- public boolean satisfiedGtEq() {
+ public boolean satisfiedGtEq(int b) {
int sMin = 0;
int i = 0;
@@ -731,20 +607,6 @@ public boolean satisfiedGtEq() {
return sMin >= b;
}
- public boolean satisfiedGt() {
-
- int sMin = 0;
- int i = 0;
- for (; i < pos; i++) {
- sMin += x[i].min() * a[i];
- }
- for (; i < l; i++) {
- sMin += x[i].max() * a[i];
- }
-
- return sMin > b;
- }
-
@Override
public void removeConstraint() {
for (Var v : x)
@@ -771,15 +633,15 @@ private boolean entailed(int rel) {
case eq:
return satisfiedEq();
case le:
- return satisfiedLtEq();
+ return satisfiedLtEq(b);
case lt:
- return satisfiedLt();
+ return satisfiedLtEq(b-1);
case ne:
return satisfiedNeq();
case gt:
- return satisfiedGt();
+ return satisfiedGtEq(b+1);
case ge:
- return satisfiedGtEq();
+ return satisfiedGtEq(b);
}
return false;
diff --git a/src/main/java/org/jacop/constraints/LinearIntDom.java b/src/main/java/org/jacop/constraints/LinearIntDom.java
index 126a1678d..11d2a929d 100644
--- a/src/main/java/org/jacop/constraints/LinearIntDom.java
+++ b/src/main/java/org/jacop/constraints/LinearIntDom.java
@@ -53,7 +53,7 @@
*
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class LinearIntDom extends LinearInt {
@@ -77,9 +77,12 @@ public class LinearIntDom extends LinearInt {
double limitDomainPruning = 1e+7;
/**
- * @param list
- * @param weights
- * @param sum
+ * It constructs the constraint LinearIntDom.
+ * @param store current store
+ * @param list variables which are being multiplied by weights.
+ * @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
+ * @param sum variable containing the sum of weighted variables.
*/
public LinearIntDom(Store store, IntVar[] list, int[] weights, String rel, int sum) {
@@ -89,8 +92,10 @@ public LinearIntDom(Store store, IntVar[] list, int[] weights, String rel, int s
/**
* It constructs the constraint LinearIntDom.
+ * @param store current store
* @param variables variables which are being multiplied by weights.
* @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
* @param sum variable containing the sum of weighted variables.
*/
public LinearIntDom(Store store, ArrayList extends IntVar> variables,
@@ -103,48 +108,15 @@ public LinearIntDom(Store store, ArrayList extends IntVar> variables,
@Override
public void consistency(Store store) {
-
- computeInit();
-
- do {
-
- store.propagationHasOccurred = false;
-
- switch (relationType) {
- case eq:
-
- if (domainSize() < limitDomainPruning)
- pruneEq(); // domain consistency
- else {
- // bound consistency
- pruneLtEq();
- pruneGtEq();
- }
-
- if (sumMax <= b && sumMin >= b)
- removeConstraint();
-
- break;
-
- case ne:
- if (domainSize() < limitDomainPruning)
- pruneNeq();
- else
- super.pruneNeq();
-
- if (sumMin == sumMax && sumMin != b)
- removeConstraint();
- break;
- default:
- System.out.println("Not implemented relation in LinearIntDom; implemented == and != only.");
- break;
- }
-
- } while (store.propagationHasOccurred);
+ propagate(relationType);
}
@Override
public void notConsistency(Store store) {
+ propagate(negRel[relationType]);
+ }
+
+ public void propagate(int rel) {
computeInit();
@@ -152,28 +124,30 @@ public void notConsistency(Store store) {
store.propagationHasOccurred = false;
- switch (negRel[relationType]) {
+ switch (rel) {
case eq:
+
if (domainSize() < limitDomainPruning)
- pruneEq();
+ pruneEq(); // domain consistency
else {
- pruneLtEq();
- pruneGtEq();
+ // bound consistency
+ pruneLtEq(b);
+ pruneGtEq(b);
}
- if (sumMax <= b && sumMin >= b)
+ if (!reified && sumMax <= b && sumMin >= b)
removeConstraint();
break;
case ne:
-
if (domainSize() < limitDomainPruning)
pruneNeq();
else
super.pruneNeq();
- if (sumMin > b || sumMax < b)
+ // if (!reified && sumMin == sumMax && sumMin != b)
+ if (!reified && (sumMin > b || sumMax < b))
removeConstraint();
break;
default:
@@ -197,6 +171,9 @@ public void notConsistency(Store store) {
void pruneEq() {
+ if (sumMin > b || sumMax < b)
+ throw store.failException;
+
// System.out.println("check " + this);
assignments = new int[l];
support = new IntervalDomain[l];
@@ -205,7 +182,7 @@ void pruneEq() {
findSupport(0, 0);
- // System.out.println("valid assignments: " + java.util.Arrays.asList(support));
+ // System.out.println("Variables: "+java.util.Arrays.asList(x)+" have valid assignments: " + java.util.Arrays.asList(support));
int f = 0, e = 0;
for (int i = 0; i < pos; i++) {
x[i].domain.in(store.level, x[i], support[i]);
@@ -273,12 +250,13 @@ void findSupportPositive(int index, int partialSum) {
// store assignments
for (int i = 0; i < l; i++) {
+ int a = assignments[i];
if (support[i].getSize() == 0)
- support[i] = new IntervalDomain(assignments[i], assignments[i]);
- else if (support[i].max() < assignments[i])
- support[i].addLastElement(assignments[i]);
- else if (support[i].max() > assignments[i])
- support[i].unionAdapt(assignments[i], assignments[i]);
+ support[i] = new IntervalDomain(a, a);
+ else if (support[i].max() < a)
+ support[i].addLastElement(a);
+ else if (support[i].max() > a)
+ support[i].unionAdapt(a, a);
}
}
return;
@@ -300,13 +278,7 @@ else if (support[i].max() > assignments[i])
int eMin = e.min();
int eMax = e.max();
- // if (eMax*w < lb)
- // continue; // value too low
- // else if (eMin*w > ub) // value too large
- // break;
-
- for (int j = eMin; j <= eMax; j++) {
- int element = j;
+ for (int element = eMin; element <= eMax; element++) {
int elementValue = element*w;
if (elementValue < lb)
@@ -362,12 +334,13 @@ void findSupportNegative(int index, int partialSum) {
// store assignments
for (int i = 0; i < l; i++) {
+ int a = assignments[i];
if (support[i].getSize() == 0)
- support[i] = new IntervalDomain(assignments[i], assignments[i]);
- else if (support[i].max() < assignments[i])
- support[i].addLastElement(assignments[i]);
- else if (support[i].max() > assignments[i])
- support[i].unionAdapt(assignments[i], assignments[i]);
+ support[i] = new IntervalDomain(a, a);
+ else if (support[i].max() < a)
+ support[i].addLastElement(a);
+ else if (support[i].max() > a)
+ support[i].unionAdapt(a, a);
}
}
return;
@@ -388,14 +361,8 @@ else if (support[i].max() > assignments[i])
Interval e = ((IntervalDomain)currentDom).intervals[k];
int eMin = e.min();
int eMax = e.max();
-
- // if (eMin*w < lb)
- // break; // value too low
- // else if (eMax*w > ub) // value too large
- // continue;
- for (int j = eMin; j <= eMax; j++) {
- int element = j;
+ for (int element = eMin; element <= eMax; element++) {
int elementValue = element*w;
if (elementValue < lb)
diff --git a/src/main/java/org/jacop/constraints/Max.java b/src/main/java/org/jacop/constraints/Max.java
index d2f1051fb..69e2188ca 100644
--- a/src/main/java/org/jacop/constraints/Max.java
+++ b/src/main/java/org/jacop/constraints/Max.java
@@ -46,7 +46,7 @@
* max(list) = max.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Max extends Constraint {
diff --git a/src/main/java/org/jacop/constraints/Min.java b/src/main/java/org/jacop/constraints/Min.java
index c047c247b..f66782d40 100644
--- a/src/main/java/org/jacop/constraints/Min.java
+++ b/src/main/java/org/jacop/constraints/Min.java
@@ -44,7 +44,7 @@
* varable from all FD varaibles on the list.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Min extends Constraint {
diff --git a/src/main/java/org/jacop/constraints/NoGood.java b/src/main/java/org/jacop/constraints/NoGood.java
index cc5bda17c..a0aa7e9ac 100644
--- a/src/main/java/org/jacop/constraints/NoGood.java
+++ b/src/main/java/org/jacop/constraints/NoGood.java
@@ -56,7 +56,7 @@
* master search.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class NoGood extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/Not.java b/src/main/java/org/jacop/constraints/Not.java
index d14d5436f..64f85fe38 100644
--- a/src/main/java/org/jacop/constraints/Not.java
+++ b/src/main/java/org/jacop/constraints/Not.java
@@ -42,7 +42,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Not extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/Or.java b/src/main/java/org/jacop/constraints/Or.java
index 594820723..efe284bd9 100644
--- a/src/main/java/org/jacop/constraints/Or.java
+++ b/src/main/java/org/jacop/constraints/Or.java
@@ -43,7 +43,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Or extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/OrBool.java b/src/main/java/org/jacop/constraints/OrBool.java
index 8bcf65ec8..bef9fc06b 100644
--- a/src/main/java/org/jacop/constraints/OrBool.java
+++ b/src/main/java/org/jacop/constraints/OrBool.java
@@ -33,401 +33,133 @@
import java.util.ArrayList;
-import org.jacop.core.IntDomain;
import org.jacop.core.IntVar;
-import org.jacop.core.IntervalDomain;
import org.jacop.core.Store;
import org.jacop.core.Var;
-import org.jacop.core.TimeStamp;
/**
- * If at least one variable from the list is equal 1 then result variable is equal 1 too.
- * Otherwise, result variable is equal to zero.
- * It restricts the domain of all x as well as result to be between 0 and 1.
- *
+ * OrBool constraint implements logic and operation on its arguments
+ * and returns result.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class OrBool extends PrimitiveConstraint {
- static int counter = 1;
-
- /**
- * It specifies a list of variables among which one must be equal to 1 to set result variable to 1.
- */
- public IntVar [] list;
-
- /**
- * It specifies variable result, storing the result of or function performed a list of variables.
- */
- public IntVar result;
+ PrimitiveConstraint c = null;
/**
- * It specifies the length of the list of variables.
+ * It constructs and constraint on variables.
+ * @param a parameters
+ * @param result result variable.
*/
- final int l;
- /**
- * It specifies the arguments required to be saved by an XML format as well as
- * the constructor being called to recreate an object from an XML format.
- */
- public static String[] xmlAttributes = {"list", "result"};
-
- /*
- * Defines first position of the variable that is not ground to 0
- */
- private TimeStamp position;
-
- /**
- * It constructs orBool.
- *
- * @param list list of x's which one of them must be equal 1 to make result equal 1.
- * @param result variable which is equal 0 if none of x is equal to zero.
- */
- public OrBool(IntVar [] list, IntVar result) {
-
- assert ( list != null ) : "List variable is null";
- assert ( result != null ) : "Result variable is null";
-
- this.numberId = counter++;
- this.l = list.length;
- this.numberArgs = (short)(l + 1);
-
- this.list = new IntVar[l];
- for (int i = 0; i < l; i++) {
- assert (list[i] != null) : i + "-th element in the list is null";
- this.list[i] = list[i];
- }
-
- this.result = result;
- assert ( checkInvariants() == null) : checkInvariants();
-
- if (l > 2)
- queueIndex = 1;
+ public OrBool(IntVar[] a, IntVar result) {
+ if (a.length == 2)
+ c = new OrBoolSimple(a[0], a[1], result);
else
- queueIndex = 0;
+ c = new OrBoolVector(a, result);
}
/**
- * It constructs orBool.
- *
- * @param list list of x's which one of them must be equal 1 to make result equal 1.
- * @param result variable which is equal 0 if none of x is equal to zero.
+ * It constructs and constraint on variables.
+ * @param a parameters
+ * @param result result variable.
*/
- public OrBool(ArrayList extends IntVar> list, IntVar result) {
-
- this(list.toArray(new IntVar[list.size()]), result);
-
+ public OrBool(ArrayList a, IntVar result) {
+
+ if (a.size() == 2)
+ c = new OrBoolSimple(a.get(0), a.get(1), result);
+ else
+ c = new OrBoolVector(a.toArray(new IntVar[a.size()]), result);
}
/**
- * It checks invariants required by the constraint. Namely that
- * boolean variables have boolean domain.
- *
- * @return the string describing the violation of the invariant, null otherwise.
+ * It constructs and constraint on variables.
+ * @param a a parameter
+ * @param b b parameter
+ * @param result result variable.
*/
- public String checkInvariants() {
-
- for (IntVar var : list)
- if (var.min() < 0 || var.max() > 1)
- return "Variable " + var + " does not have boolean domain";
-
- return null;
+ public OrBool(IntVar a, IntVar b, IntVar result) {
+ c = new OrBoolSimple(a, b, result);
}
@Override
public ArrayList arguments() {
- ArrayList variables = new ArrayList(l + 1);
-
- variables.add(result);
- for (int i = 0; i < l; i++)
- variables.add(list[i]);
- return variables;
+ return c.arguments();
}
@Override
- public int getConsistencyPruningEvent(Var var) {
+ public void consistency(Store store) {
+ c.consistency(store);
+ }
- // If consistency function mode
- if (consistencyPruningEvents != null) {
- Integer possibleEvent = consistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.BOUND;
+ @Override
+ public void notConsistency(Store store) {
+ c.consistency(store);
}
@Override
- public int getNotConsistencyPruningEvent(Var var) {
+ public int getConsistencyPruningEvent(Var var) {
+ return c.getConsistencyPruningEvent(var);
- // If notConsistency function mode
- if (notConsistencyPruningEvents != null) {
- Integer possibleEvent = notConsistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.GROUND;
}
@Override
public int getNestedPruningEvent(Var var, boolean mode) {
-
- // If consistency function mode
- if (mode) {
- if (consistencyPruningEvents != null) {
- Integer possibleEvent = consistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.ANY;
- }
- // If notConsistency function mode
- else {
- if (notConsistencyPruningEvents != null) {
- Integer possibleEvent = notConsistencyPruningEvents.get(var);
- if (possibleEvent != null)
- return possibleEvent;
- }
- return IntDomain.GROUND;
- }
+ return c.getNestedPruningEvent(var, mode);
}
- // registers the constraint in the constraint store
@Override
- public void impose(Store store) {
-
- result.putModelConstraint(this, getConsistencyPruningEvent(result));
-
- position = new TimeStamp(store, 0);
-
- for (Var V : list)
- V.putModelConstraint(this, getConsistencyPruningEvent(V));
-
- store.addChanged(this);
- store.countConstraint();
-
+ public int getNotConsistencyPruningEvent(Var var) {
+ return c.getNotConsistencyPruningEvent(var);
}
+
@Override
- public void include(Store store) {
-
- position = new TimeStamp(store, 0);
-
+ public String id() {
+ return c.id();
}
- public void consistency(Store store) {
-
- int start = position.value();
- int index_01 = l-1;
-
- for (int i = start; i < l; i++) {
- if (list[i].min() == 1) {
- result.domain.in(store.level, result, 1, 1);
- removeConstraint();
- return;
- }
- else
- if (list[i].max() == 0) {
- swap(start, i);
- start++;
- position.update(start);
- }
- }
-
- if (start == l)
- result.domain.in(store.level, result, 0, 0);
-
- // for case >, then the in() will fail as the constraint should.
- if (result.min() == 1 && start >= l - 1)
- list[index_01].domain.in(store.level, list[index_01], 1, 1);
-
- if (result.max() == 0 && start < l)
- for (int i = start; i < l; i++)
- list[i].domain.in(store.level, list[i], 0, 0);
-
- if (l < 3)
- queueIndex = 0;
-
+ @Override
+ public void impose(Store store) {
+ c.impose(store);
}
- private void swap(int i, int j) {
- if ( i != j) {
- IntVar tmp = list[i];
- list[i] = list[j];
- list[j] = tmp;
- }
+ @Override
+ public void queueVariable(int level, Var V) {
+ c.queueVariable(level, V);
}
@Override
- public void notConsistency(Store store) {
-
- do {
-
- store.propagationHasOccurred = false;
-
- int start = position.value();
- int index_01 = l-1;
-
- for (int i = start; i < l; i++) {
- if (list[i].min() == 1) {
- result.domain.in(store.level, result, 0, 0);
- return;
- }
- else
- if (list[i].max() == 0) {
- swap(start, i);
- start++;
- position.update(start);
- }
- // else
- // index_01 = i;
- }
-
- if (start == l)
- result.domain.in(store.level, result, 1, 1);
-
- // for case >, then the in() will fail as the constraint should.
- if (result.min() == 1 && start < l)
- for (int i = 0; i < l; i++)
- list[i].domain.in(store.level, list[i], 0, 0);
-
- if (result.max() == 0 && start >= l - 1)
- list[index_01].domain.in(store.level, list[index_01], 1, 1);
-
- } while (store.propagationHasOccurred);
-
- if (l < 3)
- queueIndex = 0;
+ public void removeConstraint() {
+ c.removeConstraint();
}
@Override
public boolean satisfied() {
-
- int start = position.value();
-
- if (result.max() == 0) {
-
- for (int i = start; i < l; i++)
- if (list[i].max() != 0)
- return false;
- else {
- swap(start, i);
- start++;
- position.update(start);
- }
-
- return true;
-
- }
- else {
-
- if (result.min() == 1) {
-
- for (int i = start; i < l; i++)
- if (list[i].min() == 1)
- return true;
- else if (list[i].max() == 0) {
- swap(start, i);
- start++;
- position.update(start);
- }
-
- }
- }
-
- return false;
-
+ return c.satisfied();
}
@Override
public boolean notSatisfied() {
-
- int start = position.value();
-
- int x1 = 0, x0 = start;
-
- for (int i = start; i < l; i++) {
- if (list[i].min() == 1)
- x1++;
- else if (list[i].max() == 0) {
- x0++;
- swap(start, i);
- start++;
- position.update(start);
- }
- }
-
- return (x0 == l && result.min() == 1) || (x1 != 0 && result.max() == 0);
-
+ return c.satisfied();
}
@Override
- public void removeConstraint() {
- result.removeConstraint(this);
- for (int i = 0; i < l; i++) {
- list[i].removeConstraint(this);
- }
+ public void include(Store store) {
+ c.include(store);
}
@Override
public String toString() {
-
- StringBuffer resultString = new StringBuffer( id() );
-
- resultString.append(" : orBool([ ");
- for (int i = 0; i < l; i++) {
- resultString.append( list[i] );
- if (i < l - 1)
- resultString.append(", ");
- }
- resultString.append("], ");
- resultString.append(result);
- resultString.append(")");
- return resultString.toString();
- }
-
- ArrayList constraints;
-
- @Override
- public ArrayList decompose(Store store) {
-
- constraints = new ArrayList();
-
- PrimitiveConstraint [] orConstraints = new PrimitiveConstraint[l];
-
- IntervalDomain booleanDom = new IntervalDomain(0, 1);
-
- for (int i = 0; i < orConstraints.length; i++) {
- orConstraints[0] = new XeqC(list[i], 1);
- constraints.add(new In(list[i], booleanDom));
- }
-
- constraints.add( new In(result, booleanDom));
-
- constraints.add( new Eq(new Or(orConstraints), new XeqC(result, 1)) );
-
- return constraints;
- }
-
- @Override
- public void imposeDecomposition(Store store) {
-
- if (constraints == null)
- decompose(store);
-
- for (Constraint c : constraints)
- store.impose(c, queueIndex);
-
+ return c.toString();
}
@Override
public void increaseWeight() {
- if (increaseWeight) {
- result.weight++;
- for (Var v : list) v.weight++;
- }
+ c.increaseWeight();
}
}
diff --git a/src/main/java/org/jacop/constraints/OrBoolSimple.java b/src/main/java/org/jacop/constraints/OrBoolSimple.java
new file mode 100644
index 000000000..5ecaef8c1
--- /dev/null
+++ b/src/main/java/org/jacop/constraints/OrBoolSimple.java
@@ -0,0 +1,195 @@
+/**
+ * OrBoolSimple.java
+ * This file is part of JaCoP.
+ *
+ * JaCoP is a Java Constraint Programming solver.
+ *
+ * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * Notwithstanding any other provision of this License, the copyright
+ * owners of this work supplement the terms of this License with terms
+ * prohibiting misrepresentation of the origin of this work and requiring
+ * that modified versions of this work be marked in reasonable ways as
+ * different from the original version. This supplement of the license
+ * terms is in accordance with Section 7 of GNU Affero General Public
+ * License version 3.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package org.jacop.constraints;
+
+import java.util.ArrayList;
+
+import org.jacop.core.IntDomain;
+import org.jacop.core.IntVar;
+import org.jacop.core.IntervalDomain;
+import org.jacop.core.Store;
+import org.jacop.core.Var;
+
+/**
+ * If at least one variable is equal 1 then result variable is equal 1 too.
+ * Otherwise, result variable is equal to zero.
+ * It restricts the domain of a and b as well as result to be between 0 and 1.
+ *
+ *
+ * @author Krzysztof Kuchcinski and Radoslaw Szymanek
+ * @version 4.4
+ */
+
+public class OrBoolSimple extends OrBoolVector {
+
+ static int counter = 1;
+
+ /**
+ * It specifies variables which all must be equal to 1 to set result variable to 1.
+ */
+ public IntVar a, b;
+
+ /**
+ * It specifies variable result, storing the result of or function performed a list of variables.
+ */
+ public IntVar result;
+
+ /**
+ * It specifies the arguments required to be saved by an XML format as well as
+ * the constructor being called to recreate an object from an XML format.
+ */
+ public static String[] xmlAttributes = {"a", "b", "result"};
+
+ /**
+ * It constructs orBool.
+ *
+ * @param a a parameter
+ * @param b b parameter
+ * @param result variable which is equal 0 if none of x is equal to zero.
+ */
+ public OrBoolSimple(IntVar a, IntVar b, IntVar result) {
+
+ super(new IntVar[] {a,b}, result);
+
+ assert ( a != null ) : "First variable is null";
+ assert ( b != null ) : "Second variable is null";
+ assert ( result != null ) : "Result variable is null";
+
+ this.numberId = counter++;
+ this.numberArgs = (short)(l + 1);
+
+ this.a = a;
+ this.b = b;
+ this.result = result;
+
+ assert ( checkInvariants() == null) : checkInvariants();
+
+ queueIndex = 0;
+ }
+
+ @Override
+ public ArrayList arguments() {
+
+ ArrayList variables = new ArrayList(l + 1);
+
+ variables.add(a);
+ variables.add(b);
+ variables.add(result);
+ return variables;
+ }
+
+ // registers the constraint in the constraint store
+ @Override
+ public void impose(Store store) {
+
+ a.putModelConstraint(this, getConsistencyPruningEvent(a));
+ b.putModelConstraint(this, getConsistencyPruningEvent(b));
+ result.putModelConstraint(this, getConsistencyPruningEvent(result));
+
+ store.addChanged(this);
+ store.countConstraint();
+ }
+
+ @Override
+ public void include(Store store) {
+ }
+
+ public void consistency(Store store) {
+ // a OR b = result
+ if (a.max() == 0 && b.max() == 0)
+ result.domain.in(store.level, result, 0,0);
+ else if (a.min() == 1 || b.min() == 1) {
+ result.domain.in(store.level, result, 1,1);
+ removeConstraint();
+ }
+ else if (result.max() == 0) {
+ a.domain.in(store.level, a, 0,0);
+ b.domain.in(store.level, b, 0,0);
+ }
+ else if (result.min() == 1)
+ if (a.max() == 0)
+ b.domain.in(store.level, b, 1,1);
+ else if (b.max() == 0)
+ a.domain.in(store.level, a, 1,1);
+ }
+
+ @Override
+ public void notConsistency(Store store) {
+ // not(a OR b) = not a and not b = result
+ if (a.min() == 1 || b.min() == 1) {
+ result.domain.in(store.level, result, 0,0);
+ removeConstraint();
+ }
+ else if (a.max() == 0 && b.max() == 0)
+ result.domain.in(store.level, result, 1,1);
+ else if (result.min() == 1) {
+ a.domain.in(store.level, a, 0,0);
+ b.domain.in(store.level, b, 0,0);
+ }
+ else if (result.max() == 0)
+ if (a.max() == 0)
+ b.domain.in(store.level, b, 1,1);
+ else if (b.max() == 0)
+ a.domain.in(store.level, a, 1,1);
+ }
+
+ @Override
+ public boolean satisfied() {
+ return (result.max() == 0 && a.max() == 0 && b.max() == 0) || (result.min() == 1 && (a.min() == 1 || b.min() == 1));
+ }
+
+ @Override
+ public boolean notSatisfied() {
+ return (result.min() == 1 && a.max() == 0 && b.max() == 0) || (result.max() == 0 && (a.min() == 1 || b.min() == 1));
+ }
+
+ @Override
+ public void removeConstraint() {
+ a.removeConstraint(this);
+ b.removeConstraint(this);
+ result.removeConstraint(this);
+ }
+
+ @Override
+ public String toString() {
+
+ StringBuffer resultString = new StringBuffer( id() );
+
+ resultString.append(" : orBoolSimple([ ");
+ resultString.append( a + ", " + b);
+
+ resultString.append("], ");
+ resultString.append(result);
+ resultString.append(")");
+ return resultString.toString();
+ }
+}
diff --git a/src/main/java/org/jacop/constraints/OrBoolVector.java b/src/main/java/org/jacop/constraints/OrBoolVector.java
new file mode 100644
index 000000000..d82e929ee
--- /dev/null
+++ b/src/main/java/org/jacop/constraints/OrBoolVector.java
@@ -0,0 +1,437 @@
+/**
+ * OrBoolVector.java
+ * This file is part of JaCoP.
+ *
+ * JaCoP is a Java Constraint Programming solver.
+ *
+ * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * Notwithstanding any other provision of this License, the copyright
+ * owners of this work supplement the terms of this License with terms
+ * prohibiting misrepresentation of the origin of this work and requiring
+ * that modified versions of this work be marked in reasonable ways as
+ * different from the original version. This supplement of the license
+ * terms is in accordance with Section 7 of GNU Affero General Public
+ * License version 3.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package org.jacop.constraints;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import org.jacop.core.IntDomain;
+import org.jacop.core.IntVar;
+import org.jacop.core.IntervalDomain;
+import org.jacop.core.Store;
+import org.jacop.core.Var;
+import org.jacop.core.TimeStamp;
+
+/**
+ * If at least one variable from the list is equal 1 then result variable is equal 1 too.
+ * Otherwise, result variable is equal to zero.
+ * It restricts the domain of all x as well as result to be between 0 and 1.
+ *
+ *
+ * @author Krzysztof Kuchcinski and Radoslaw Szymanek
+ * @version 4.2
+ */
+
+public class OrBoolVector extends PrimitiveConstraint {
+
+ static int counter = 1;
+
+ /**
+ * It specifies a list of variables among which one must be equal to 1 to set result variable to 1.
+ */
+ public IntVar [] list;
+
+ /**
+ * It specifies variable result, storing the result of or function performed a list of variables.
+ */
+ public IntVar result;
+
+ /**
+ * It specifies the length of the list of variables.
+ */
+ final int l;
+ /**
+ * It specifies the arguments required to be saved by an XML format as well as
+ * the constructor being called to recreate an object from an XML format.
+ */
+ public static String[] xmlAttributes = {"list", "result"};
+
+ /*
+ * Defines first position of the variable that is not ground to 0
+ */
+ private TimeStamp position;
+
+ /**
+ * It constructs orBool.
+ *
+ * @param list list of x's which one of them must be equal 1 to make result equal 1.
+ * @param result variable which is equal 0 if none of x is equal to zero.
+ */
+ public OrBoolVector(IntVar [] list, IntVar result) {
+
+ assert ( list != null ) : "List variable is null";
+ assert ( result != null ) : "Result variable is null";
+
+ this.numberId = counter++;
+
+ HashSet varSet = new HashSet();
+ for (IntVar var : list) {
+ assert (var != null) : "element in the list is null";
+ varSet.add(var);
+ }
+ this.l = varSet.size();
+ this.numberArgs = (short)(l + 1);
+
+ this.list = new IntVar[l];
+ int i = 0;
+ for (IntVar v : varSet) {
+ this.list[i++] = v;
+ }
+
+ this.result = result;
+ assert ( checkInvariants() == null) : checkInvariants();
+
+ if (l > 2)
+ queueIndex = 1;
+ else
+ queueIndex = 0;
+ }
+
+ /**
+ * It constructs orBool.
+ *
+ * @param list list of x's which one of them must be equal 1 to make result equal 1.
+ * @param result variable which is equal 0 if none of x is equal to zero.
+ */
+ public OrBoolVector(ArrayList extends IntVar> list, IntVar result) {
+
+ this(list.toArray(new IntVar[list.size()]), result);
+
+ }
+
+ /**
+ * It checks invariants required by the constraint. Namely that
+ * boolean variables have boolean domain.
+ *
+ * @return the string describing the violation of the invariant, null otherwise.
+ */
+ public String checkInvariants() {
+
+ for (IntVar var : list)
+ if (var.min() < 0 || var.max() > 1)
+ return "Variable " + var + " does not have boolean domain";
+
+ return null;
+ }
+
+ @Override
+ public ArrayList arguments() {
+
+ ArrayList variables = new ArrayList(l + 1);
+
+ variables.add(result);
+ for (int i = 0; i < l; i++)
+ variables.add(list[i]);
+ return variables;
+ }
+
+ @Override
+ public int getConsistencyPruningEvent(Var var) {
+
+ // If consistency function mode
+ if (consistencyPruningEvents != null) {
+ Integer possibleEvent = consistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.BOUND;
+ }
+
+ @Override
+ public int getNotConsistencyPruningEvent(Var var) {
+
+ // If notConsistency function mode
+ if (notConsistencyPruningEvents != null) {
+ Integer possibleEvent = notConsistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.GROUND;
+ }
+
+ @Override
+ public int getNestedPruningEvent(Var var, boolean mode) {
+
+ // If consistency function mode
+ if (mode) {
+ if (consistencyPruningEvents != null) {
+ Integer possibleEvent = consistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.ANY;
+ }
+ // If notConsistency function mode
+ else {
+ if (notConsistencyPruningEvents != null) {
+ Integer possibleEvent = notConsistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.GROUND;
+ }
+ }
+
+ // registers the constraint in the constraint store
+ @Override
+ public void impose(Store store) {
+
+ result.putModelConstraint(this, getConsistencyPruningEvent(result));
+
+ position = new TimeStamp(store, 0);
+
+ for (Var V : list)
+ V.putModelConstraint(this, getConsistencyPruningEvent(V));
+
+ store.addChanged(this);
+ store.countConstraint();
+
+ }
+
+ @Override
+ public void include(Store store) {
+
+ position = new TimeStamp(store, 0);
+
+ }
+
+ public void consistency(Store store) {
+
+ int start = position.value();
+ int index_01 = l-1;
+
+ for (int i = start; i < l; i++) {
+ if (list[i].min() == 1) {
+ result.domain.in(store.level, result, 1, 1);
+ removeConstraint();
+ return;
+ }
+ else
+ if (list[i].max() == 0) {
+ swap(start, i);
+ start++;
+ }
+ }
+ position.update(start);
+
+ if (start == l)
+ result.domain.in(store.level, result, 0, 0);
+
+ // for case >, then the in() will fail as the constraint should.
+ if (result.min() == 1 && start >= l - 1)
+ list[index_01].domain.in(store.level, list[index_01], 1, 1);
+
+ if (result.max() == 0 && start < l)
+ for (int i = start; i < l; i++)
+ list[i].domain.in(store.level, list[i], 0, 0);
+
+ if ((l-start) < 3)
+ queueIndex = 0;
+
+ }
+
+ private void swap(int i, int j) {
+ if ( i != j) {
+ IntVar tmp = list[i];
+ list[i] = list[j];
+ list[j] = tmp;
+ }
+ }
+
+ @Override
+ public void notConsistency(Store store) {
+
+ // do {
+
+ // store.propagationHasOccurred = false;
+
+ int start = position.value();
+ int index_01 = l-1;
+
+ for (int i = start; i < l; i++) {
+ if (list[i].min() == 1) {
+ result.domain.in(store.level, result, 0, 0);
+ return;
+ }
+ else
+ if (list[i].max() == 0) {
+ swap(start, i);
+ start++;
+ }
+ }
+ position.update(start);
+
+ if (start == l)
+ result.domain.in(store.level, result, 1, 1);
+
+ // for case >, then the in() will fail as the constraint should.
+ if (result.min() == 1 && start < l)
+ for (int i = 0; i < l; i++)
+ list[i].domain.in(store.level, list[i], 0, 0);
+
+ if (result.max() == 0 && start >= l - 1)
+ list[index_01].domain.in(store.level, list[index_01], 1, 1);
+
+ // } while (store.propagationHasOccurred);
+
+ if ((l-start) < 3)
+ queueIndex = 0;
+ }
+
+ @Override
+ public boolean satisfied() {
+
+ int start = position.value();
+
+ if (result.max() == 0) {
+
+ for (int i = start; i < l; i++)
+ if (list[i].max() != 0)
+ return false;
+ else {
+ swap(start, i);
+ start++;
+ }
+ position.update(start);
+
+ return true;
+
+ }
+ else {
+
+ if (result.min() == 1) {
+
+ for (int i = start; i < l; i++)
+ if (list[i].min() == 1)
+ return true;
+ else if (list[i].max() == 0) {
+ swap(start, i);
+ start++;
+ }
+ }
+ position.update(start);
+ }
+
+ return false;
+
+ }
+
+ @Override
+ public boolean notSatisfied() {
+
+ int start = position.value();
+
+ int x1 = 0, x0 = start;
+
+ for (int i = start; i < l; i++) {
+ if (list[i].min() == 1)
+ x1++;
+ else if (list[i].max() == 0) {
+ x0++;
+ swap(start, i);
+ start++;
+ }
+ }
+ position.update(start);
+
+ return (x0 == l && result.min() == 1) || (x1 != 0 && result.max() == 0);
+
+ }
+
+ @Override
+ public void removeConstraint() {
+ result.removeConstraint(this);
+ for (int i = 0; i < l; i++) {
+ list[i].removeConstraint(this);
+ }
+ }
+
+ @Override
+ public String toString() {
+
+ StringBuffer resultString = new StringBuffer( id() );
+
+ resultString.append(" : orBool([ ");
+ for (int i = 0; i < l; i++) {
+ resultString.append( list[i] );
+ if (i < l - 1)
+ resultString.append(", ");
+ }
+ resultString.append("], ");
+ resultString.append(result);
+ resultString.append(")");
+ return resultString.toString();
+ }
+
+ ArrayList constraints;
+
+ @Override
+ public ArrayList decompose(Store store) {
+
+ constraints = new ArrayList();
+
+ PrimitiveConstraint [] orConstraints = new PrimitiveConstraint[l];
+
+ IntervalDomain booleanDom = new IntervalDomain(0, 1);
+
+ for (int i = 0; i < orConstraints.length; i++) {
+ orConstraints[0] = new XeqC(list[i], 1);
+ constraints.add(new In(list[i], booleanDom));
+ }
+
+ constraints.add( new In(result, booleanDom));
+
+ constraints.add( new Eq(new Or(orConstraints), new XeqC(result, 1)) );
+
+ return constraints;
+ }
+
+ @Override
+ public void imposeDecomposition(Store store) {
+
+ if (constraints == null)
+ decompose(store);
+
+ for (Constraint c : constraints)
+ store.impose(c, queueIndex);
+
+ }
+
+ @Override
+ public void increaseWeight() {
+ if (increaseWeight) {
+ result.weight++;
+ for (Var v : list) v.weight++;
+ }
+ }
+
+}
diff --git a/src/main/java/org/jacop/constraints/PrimitiveConstraint.java b/src/main/java/org/jacop/constraints/PrimitiveConstraint.java
index 01d08f2b9..7f2fccfa1 100644
--- a/src/main/java/org/jacop/constraints/PrimitiveConstraint.java
+++ b/src/main/java/org/jacop/constraints/PrimitiveConstraint.java
@@ -43,7 +43,7 @@
* arguments to constraints Not, And, Or, etc.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public abstract class PrimitiveConstraint extends Constraint {
diff --git a/src/main/java/org/jacop/constraints/Profile.java b/src/main/java/org/jacop/constraints/Profile.java
index 0a4be4b0d..22721d569 100644
--- a/src/main/java/org/jacop/constraints/Profile.java
+++ b/src/main/java/org/jacop/constraints/Profile.java
@@ -40,7 +40,7 @@
* current value.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Profile extends ArrayList {
@@ -64,7 +64,7 @@ public Profile() {
/**
* It constructs the profile of a given type (e.g. for cumulative).
- * @param type
+ * @param type type of the profile (cumul=0, diffn=1)
*/
public Profile(short type) {
this.type = type;
diff --git a/src/main/java/org/jacop/constraints/ProfileConditional.java b/src/main/java/org/jacop/constraints/ProfileConditional.java
index 25d8bd943..fc921a4e0 100644
--- a/src/main/java/org/jacop/constraints/ProfileConditional.java
+++ b/src/main/java/org/jacop/constraints/ProfileConditional.java
@@ -39,7 +39,7 @@
* disjointConditonal/2
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class ProfileConditional extends ArrayList {
diff --git a/src/main/java/org/jacop/constraints/ProfileItem.java b/src/main/java/org/jacop/constraints/ProfileItem.java
index c6126c8d8..2fc5899e2 100644
--- a/src/main/java/org/jacop/constraints/ProfileItem.java
+++ b/src/main/java/org/jacop/constraints/ProfileItem.java
@@ -38,7 +38,7 @@
* belongs to it nad b does not) and the value.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ProfileItem {
@@ -246,7 +246,7 @@ public void set(int a, int b, int val) {
/**
* It sets the ending point of the profile item.
- * @param b
+ * @param b the ending point of the profile item
*/
public void setMax(int b) {
max = b;
@@ -254,7 +254,7 @@ public void setMax(int b) {
/**
* It sets the starting point of the profile item.
- * @param a
+ * @param a the starting point of the profile item.
*/
public void setMin(int a) {
min = a;
@@ -262,7 +262,7 @@ public void setMin(int a) {
/**
* It sets the amount by which this profile item is contributing towards the profile.
- * @param val
+ * @param val amount by which this profile item is contributing towards the profile
*/
public void setValue(int val) {
value = val;
diff --git a/src/main/java/org/jacop/constraints/ProfileItemCondition.java b/src/main/java/org/jacop/constraints/ProfileItemCondition.java
index e0acdf1fd..df2297165 100644
--- a/src/main/java/org/jacop/constraints/ProfileItemCondition.java
+++ b/src/main/java/org/jacop/constraints/ProfileItemCondition.java
@@ -40,7 +40,7 @@
* some rectangles can share the same place.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class ProfileItemCondition extends ProfileItem {
diff --git a/src/main/java/org/jacop/constraints/Rectangle.java b/src/main/java/org/jacop/constraints/Rectangle.java
index 8c5dbd794..d4c6886a1 100644
--- a/src/main/java/org/jacop/constraints/Rectangle.java
+++ b/src/main/java/org/jacop/constraints/Rectangle.java
@@ -41,7 +41,7 @@
* Defines a rectangle used in the diffn constraint.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Rectangle {
diff --git a/src/main/java/org/jacop/constraints/RectangleWithCondition.java b/src/main/java/org/jacop/constraints/RectangleWithCondition.java
index 675ad23f4..10f29fbff 100644
--- a/src/main/java/org/jacop/constraints/RectangleWithCondition.java
+++ b/src/main/java/org/jacop/constraints/RectangleWithCondition.java
@@ -39,7 +39,7 @@
* Defines a rectangle used in the diffn constraint.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class RectangleWithCondition extends Rectangle {
diff --git a/src/main/java/org/jacop/constraints/Reified.java b/src/main/java/org/jacop/constraints/Reified.java
index a056230ef..0819f6259 100644
--- a/src/main/java/org/jacop/constraints/Reified.java
+++ b/src/main/java/org/jacop/constraints/Reified.java
@@ -41,11 +41,11 @@
import org.jacop.util.SimpleHashSet;
/**
- * Reified constraints "constraint" #<=> B
+ * Reified constraints "constraint" {@literal <=>} B
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Reified extends Constraint {
@@ -66,7 +66,7 @@ public class Reified extends Constraint {
boolean needQueueVariable = false;
boolean needRemoveLevelLate = false;
-
+
/**
* It specifies the arguments required to be saved by an XML format as well as
* the constructor being called to recreate an object from an XML format.
@@ -124,14 +124,18 @@ public ArrayList arguments() {
@Override
public void consistency(Store store) {
- if (b.max() == 0) // C must be false
- c.notConsistency(store);
- else if (b.min() == 1) // C must be true
- c.consistency(store);
- else if (c.satisfied())
- b.domain.in(store.level, b, 1, 1);
- else if (c.notSatisfied())
- b.domain.in(store.level, b, 0, 0);
+ if (c.satisfied()) {
+ b.domain.in(store.level, b, 1, 1);
+ removeSatConstraint();
+ }
+ else if (c.notSatisfied()) {
+ b.domain.in(store.level, b, 0, 0);
+ removeSatConstraint();
+ }
+ else if (b.max() == 0) // C must be false
+ c.notConsistency(store);
+ else if (b.min() == 1) // C must be true
+ c.consistency(store);
}
@@ -182,7 +186,8 @@ public void impose(Store store) {
while (!variables.isEmpty()) {
Var V = variables.removeFirst();
V.putModelConstraint(this, getConsistencyPruningEvent(V));
- queueVariable(store.level, V);
+ if (needQueueVariable)
+ queueVariable(store.level, V);
}
c.include(store);
@@ -196,10 +201,22 @@ public void impose(Store store) {
@Override
public void removeConstraint() {
- b.removeConstraint(this);
+ b.removeConstraint(this);
- for (Var V : c.arguments())
- V.removeConstraint(this);
+ for (Var v : c.arguments())
+ v.removeConstraint(this);
+
+ }
+
+ private void removeSatConstraint() {
+
+ // b must be gound here and it is not needed to remove
+ // this constraint from b
+ // b.removeConstraint(this);
+
+ for (Var v : c.arguments())
+ if (! v.singleton())
+ v.removeConstraint(this);
}
diff --git a/src/main/java/org/jacop/constraints/Sequence.java b/src/main/java/org/jacop/constraints/Sequence.java
index 60add8543..77cd7ffea 100644
--- a/src/main/java/org/jacop/constraints/Sequence.java
+++ b/src/main/java/org/jacop/constraints/Sequence.java
@@ -52,7 +52,7 @@
* contains between min and max values from the given set.
*
* @author Radoslaw Szymanek and Polina Makeeva
- * @version 4.3
+ * @version 4.4
*/
public class Sequence extends DecomposedConstraint {
diff --git a/src/main/java/org/jacop/constraints/SoftAlldifferent.java b/src/main/java/org/jacop/constraints/SoftAlldifferent.java
index ec1108c01..cecfe99f2 100644
--- a/src/main/java/org/jacop/constraints/SoftAlldifferent.java
+++ b/src/main/java/org/jacop/constraints/SoftAlldifferent.java
@@ -49,7 +49,7 @@
* either into a network flow constraint or a set of primitive constraints.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
@@ -86,7 +86,7 @@ public ArrayList primitiveDecomposition(Store store) {
decomposition.add(new Reified(new XeqY(xVars[i], xVars[j]), v));
}
}
- decomposition.add(new Sum(costs, costVar));
+ decomposition.add(new SumInt(store, costs, "==", costVar));
} else {
throw new UnsupportedOperationException("Unsupported violation measure " + violationMeasure);
@@ -109,7 +109,7 @@ public ArrayList primitiveDecomposition(Store store) {
result.add(new Reified(new XeqY(xVars[i], xVars[j]), v));
}
}
- result.add(new Sum(costs, costVar));
+ result.add(new SumInt(store, costs, "==", costVar));
} else {
throw new UnsupportedOperationException("Unsupported violation measure " + violationMeasure);
diff --git a/src/main/java/org/jacop/constraints/SoftGCC.java b/src/main/java/org/jacop/constraints/SoftGCC.java
index 5a297ab24..282d21808 100644
--- a/src/main/java/org/jacop/constraints/SoftGCC.java
+++ b/src/main/java/org/jacop/constraints/SoftGCC.java
@@ -56,7 +56,7 @@
* hardCounter. It uses value based violation metric.
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
@@ -412,7 +412,7 @@ public ArrayList primitiveDecomposition(Store store) {
}
- decomposition.add(new Sum(costs, costVar));
+ decomposition.add(new SumInt(store, costs, "==", costVar));
} else {
throw new UnsupportedOperationException("Unsupported violation measure " + violationMeasure);
@@ -503,7 +503,7 @@ public ArrayList primitiveDecomposition(Store store) {
}
- result.add(new Sum(costs, costVar));
+ result.add(new SumInt(store, costs, "==", costVar));
} else {
throw new UnsupportedOperationException("Unsupported violation measure " + violationMeasure);
diff --git a/src/main/java/org/jacop/constraints/Stretch.java b/src/main/java/org/jacop/constraints/Stretch.java
index ef50b5985..1ad87fdfc 100644
--- a/src/main/java/org/jacop/constraints/Stretch.java
+++ b/src/main/java/org/jacop/constraints/Stretch.java
@@ -51,7 +51,7 @@
* sequence of values 2 has to be of length between 2 and 3.
*
* @author Radoslaw Szymanek and Polina Makeeva
- * @version 4.3
+ * @version 4.4
*/
public class Stretch extends DecomposedConstraint {
diff --git a/src/main/java/org/jacop/constraints/Subcircuit.java b/src/main/java/org/jacop/constraints/Subcircuit.java
index 226e66d65..cc02d0f92 100644
--- a/src/main/java/org/jacop/constraints/Subcircuit.java
+++ b/src/main/java/org/jacop/constraints/Subcircuit.java
@@ -49,7 +49,7 @@
* its position, i.e., x[i] = i.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Subcircuit extends Alldiff {
diff --git a/src/main/java/org/jacop/constraints/Sum.java b/src/main/java/org/jacop/constraints/Sum.java
index b08c0512f..6317128a4 100644
--- a/src/main/java/org/jacop/constraints/Sum.java
+++ b/src/main/java/org/jacop/constraints/Sum.java
@@ -44,10 +44,13 @@
* the sum from all Variable's on the list.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
-public class Sum extends Constraint {
+/**
+ * @deprecated As of release 4.3.1 replaced by SumInt constraint.
+ */
+@Deprecated public class Sum extends Constraint {
static int counter = 1;
@@ -79,8 +82,8 @@ public class Sum extends Constraint {
/**
* It constructs sum constraint which sums all variables and makes it equal to variable sum.
- * @param list
- * @param sum
+ * @param list list of variables to be added
+ * @param sum the resulting sum
*/
public Sum(IntVar[] list, IntVar sum) {
diff --git a/src/main/java/org/jacop/constraints/SumBool.java b/src/main/java/org/jacop/constraints/SumBool.java
new file mode 100644
index 000000000..580833afd
--- /dev/null
+++ b/src/main/java/org/jacop/constraints/SumBool.java
@@ -0,0 +1,490 @@
+/**
+ * SumBool.java
+ * This file is part of JaCoP.
+ *
+ * JaCoP is a Java Constraint Programming solver.
+ *
+ * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * Notwithstanding any other provision of this License, the copyright
+ * owners of this work supplement the terms of this License with terms
+ * prohibiting misrepresentation of the origin of this work and requiring
+ * that modified versions of this work be marked in reasonable ways as
+ * different from the original version. This supplement of the license
+ * terms is in accordance with Section 7 of GNU Affero General Public
+ * License version 3.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package org.jacop.constraints;
+
+import java.util.ArrayList;
+
+import org.jacop.core.IntVar;
+import org.jacop.core.IntDomain;
+import org.jacop.core.Store;
+import org.jacop.core.Var;
+import org.jacop.core.TimeStamp;
+
+/**
+ * SumBool constraint implements the summation over several
+ * 0/1 variables.
+ *
+ * sum(i in 1..N)(xi) = sum
+ *
+ * It provides the sum from all variables on the list.
+ *
+ * @author Krzysztof Kuchcinski
+ * @version 4.4
+ */
+
+public class SumBool extends PrimitiveConstraint {
+
+ Store store;
+
+ static int idNumber = 1;
+
+ boolean reified = true;
+
+ /**
+ * Defines relations
+ */
+ final static byte eq=0, le=1, lt=2, ne=3, gt=4, ge=5;
+
+ /**
+ * Defines negated relations
+ */
+ final static byte[] negRel= {ne, //eq=0,
+ gt, //le=1,
+ ge, //lt=2,
+ eq, //ne=3,
+ le, //gt=4,
+ lt //ge=5;
+ };
+
+ /**
+ * It specifies what relations is used by this constraint
+ */
+ public byte relationType;
+
+ /**
+ * It specifies a list of variables being summed.
+ */
+ IntVar x[];
+
+ /**
+ * It specifies variable for the overall sum.
+ */
+ IntVar sum;
+
+ /**
+ * It specifies the number of variables.
+ */
+ int l;
+
+ /**
+ * It specifies the arguments required to be saved by an XML format as well as
+ * the constructor being called to recreate an object from an XML format.
+ */
+ public static String[] xmlAttributes = {"list", "sum"};
+
+ /**
+ * @param store current store
+ * @param list variables which are being multiplied by weights.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
+ * @param sum variable containing the sum of weighted variables.
+ */
+ public SumBool(Store store, IntVar[] list, String rel, IntVar sum) {
+
+ commonInitialization(store, list, sum);
+ this.relationType = relation(rel);
+
+ }
+
+ /**
+ * It constructs the constraint SumBool.
+ * @param store current store
+ * @param variables variables which are being multiplied by weights.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
+ * @param sum variable containing the sum of weighted variables.
+ */
+ public SumBool(Store store, ArrayList extends IntVar> variables,
+ String rel, IntVar sum) {
+
+ commonInitialization(store, variables.toArray(new IntVar[variables.size()]), sum);
+ this.relationType = relation(rel);
+ }
+
+
+ private void commonInitialization(Store store, IntVar[] list, IntVar sum) {
+
+
+ this.store = store;
+ this.sum = sum;
+ x = new IntVar[list.length];
+ System.arraycopy(list, 0, x, 0, list.length);
+ numberId = idNumber++;
+
+ for (IntVar v : list)
+ if (v.min() < 0 || v.max() > 1)
+ throw new IllegalArgumentException("\nArguments of SumBool must have domains 0/1; variable "+v+" is incorrect.");
+
+ this.l = x.length;
+
+ checkForOverflow();
+
+ if (l <= 2)
+ queueIndex = 0;
+ else
+ queueIndex = 1;
+
+ }
+
+ @Override
+ public ArrayList arguments() {
+
+ ArrayList variables = new ArrayList(x.length+1);
+
+ for (Var v : x)
+ variables.add(v);
+
+ variables.add(sum);
+
+ return variables;
+ }
+
+
+ @Override
+ public void consistency(Store store) {
+ prune(relationType);
+ }
+
+ @Override
+ public void notConsistency(Store store) {
+ prune(negRel[relationType]);
+ }
+
+ private void prune(byte rel) {
+
+ int min = 0;
+ int max = 0;
+
+ for (int i = 0; i < l; i++) {
+ IntDomain xd = x[i].dom();
+ min += xd.min();
+ max += xd.max();
+ }
+
+ switch (rel) {
+ case eq:
+
+ sum.domain.in(store.level, sum, min, max);
+
+ if (sum.singleton() && min != max) {
+ int sumValue = sum.value();
+ if (sumValue == min)
+ for (int i = 0; i < l; i++)
+ if (! x[i].singleton())
+ x[i].domain.in(store.level, x[i], 0, 0);
+
+ if (sumValue == max)
+ for (int i = 0; i < l; i++)
+ if (! x[i].singleton())
+ x[i].domain.in(store.level, x[i], 1, 1);
+ }
+ break;
+ case le:
+
+ sum.domain.inMin(store.level, sum, min);
+
+ if (!reified)
+ if (max <= sum.min())
+ removeConstraint();
+
+ if (sum.singleton() && min != max) {
+ int sumValue = sum.value();
+ if (sumValue == min)
+ for (int i = 0; i < l; i++)
+ if (! x[i].singleton())
+ x[i].domain.in(store.level, x[i], 0, 0);
+ }
+ break;
+ case lt:
+
+ sum.domain.inMin(store.level, sum, min + 1);
+
+ if (!reified)
+ if (max < sum.min())
+ removeConstraint();
+
+ if (sum.singleton() && min != max) {
+ int sumValue = sum.value();
+ if (sumValue - 1 == min)
+ for (int i = 0; i < l; i++)
+ if (! x[i].singleton())
+ x[i].domain.in(store.level, x[i], 0, 0);
+
+ }
+ break;
+ case ne:
+
+ if (min == max )
+ sum.domain.inComplement(store.level, sum, min);
+
+ int sumMin = sum.min() - max, sumMax = sum.max() - min;
+ if (sumMax - sumMin == 1)
+ for (int i = 0; i < l; i++)
+ if (!x[i].singleton())
+ x[i].domain.inComplement(store.level, x[i], sumMin + x[i].max());
+ break;
+ case gt:
+
+ sum.domain.inMax(store.level, sum, max - 1);
+
+ if (!reified)
+ if (min > sum.max())
+ removeConstraint();
+
+ if (sum.singleton() && min != max) {
+ int sumValue = sum.value();
+
+ if (sumValue + 1 == max)
+ for (int i = 0; i < l; i++)
+ if (! x[i].singleton())
+ x[i].domain.in(store.level, x[i], 1, 1);
+ }
+ break;
+ case ge:
+
+ sum.domain.inMax(store.level, sum, max);
+
+ if (!reified)
+ if (min >= sum.max())
+ removeConstraint();
+
+ if (sum.singleton() && min != max) {
+ int sumValue = sum.value();
+
+ if (sumValue == max)
+ for (int i = 0; i < l; i++)
+ if (! x[i].singleton())
+ x[i].domain.in(store.level, x[i], 1, 1);
+ }
+ break;
+ }
+ }
+
+ @Override
+ public int getConsistencyPruningEvent(Var var) {
+
+ // If consistency function mode
+ if (consistencyPruningEvents != null) {
+ Integer possibleEvent = consistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.BOUND;
+ }
+
+ @Override
+ public int getNestedPruningEvent(Var var, boolean mode) {
+
+ // If consistency function mode
+ if (mode) {
+ if (consistencyPruningEvents != null) {
+ Integer possibleEvent = consistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.BOUND;
+ }
+
+ // If notConsistency function mode
+ else {
+ if (notConsistencyPruningEvents != null) {
+ Integer possibleEvent = notConsistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.BOUND;
+ }
+ }
+
+ @Override
+ public int getNotConsistencyPruningEvent(Var var) {
+
+ // If notConsistency function mode
+ if (notConsistencyPruningEvents != null) {
+ Integer possibleEvent = notConsistencyPruningEvents.get(var);
+ if (possibleEvent != null)
+ return possibleEvent;
+ }
+ return IntDomain.BOUND;
+ }
+
+ @Override
+ public void impose(Store store) {
+
+ if (x == null)
+ return;
+
+ reified = false;
+
+ for (Var V : x)
+ V.putModelConstraint(this, getConsistencyPruningEvent(V));
+
+ sum.putModelConstraint(this, getConsistencyPruningEvent(sum));
+
+ store.addChanged(this);
+ store.countConstraint();
+ }
+
+ @Override
+ public void removeConstraint() {
+ for (Var v : x)
+ v.removeConstraint(this);
+ sum.removeConstraint(this);
+ }
+
+ @Override
+ public boolean satisfied() {
+
+ return entailed(relationType);
+
+ }
+
+ @Override
+ public boolean notSatisfied() {
+
+ return entailed(negRel[relationType]);
+
+ }
+
+ private boolean entailed(byte rel) {
+
+ int min=0, max=0;
+
+ for (int i = 0; i < l; i++) {
+ IntDomain xd = x[i].dom();
+ min += xd.min();
+ max += xd.max();
+ }
+
+ switch (rel) {
+ case eq : return sum.singleton(min) && min == max;
+ case lt : return max < sum.min();
+ case le : return max <= sum.min();
+ case ne : return sum.min() > max || sum.max() < min; //sum.singleton() && min == max && sum.min() != min;
+ case gt : return min > sum.max();
+ case ge : return min >= sum.max();
+ }
+
+ return false;
+
+ }
+
+ public byte relation(String r) {
+ if (r.equals("=="))
+ return eq;
+ else if (r.equals("="))
+ return eq;
+ else if (r.equals("<"))
+ return lt;
+ else if (r.equals("<="))
+ return le;
+ else if (r.equals("=<"))
+ return le;
+ else if (r.equals("!="))
+ return ne;
+ else if (r.equals(">"))
+ return gt;
+ else if (r.equals(">="))
+ return ge;
+ else if (r.equals("=>"))
+ return ge;
+ else {
+ System.err.println ("Wrong relation symbol in SumInt constraint " + r + "; assumed ==");
+ return eq;
+ }
+ }
+
+ public String rel2String() {
+ switch (relationType) {
+ case eq : return "==";
+ case lt : return "<";
+ case le : return "<=";
+ case ne : return "!=";
+ case gt : return ">";
+ case ge : return ">=";
+ }
+
+ return "?";
+ }
+
+ void checkForOverflow() {
+
+ int sMin=0, sMax=0;
+ for (int i=0; i}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
+ * @param sum variable containing the sum of weighted variables.
*/
public SumInt(Store store, IntVar[] list, String rel, IntVar sum) {
@@ -132,8 +131,9 @@ public SumInt(Store store, IntVar[] list, String rel, IntVar sum) {
/**
* It constructs the constraint SumInt.
+ * @param store current store
* @param variables variables which are being multiplied by weights.
- * @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
* @param sum variable containing the sum of weighted variables.
*/
public SumInt(Store store, ArrayList extends IntVar> variables,
@@ -149,7 +149,8 @@ private void commonInitialization(Store store, IntVar[] list, IntVar sum) {
this.store = store;
this.sum = sum;
- this.x = list;
+ x = new IntVar[list.length];
+ System.arraycopy(list, 0, x, 0, list.length);
numberId = idNumber++;
this.l = x.length;
@@ -180,115 +181,71 @@ public ArrayList arguments() {
@Override
public void consistency(Store store) {
-
- computeInit();
-
- do {
-
- store.propagationHasOccurred = false;
-
- switch (relationType) {
- case eq:
-
- pruneLtEq();
- pruneGtEq();
-
- if (sumXmax == sumXmin && sum.singleton() && sum.value() == sumXmin)
- removeConstraint();
-
- break;
-
- case le:
- pruneLtEq();
-
- if (sumXmax <= sum.min())
- removeConstraint();
- break;
-
- case lt:
- pruneLt();
-
- if (sumXmax < sum.min())
- removeConstraint();
- break;
- case ne:
- pruneNeq();
-
- if (sumXmin == sumXmax && sum.singleton() && sumXmin != sum.value())
- removeConstraint();
- break;
- case gt:
-
- pruneGt();
-
- if (sumXmin > sum.max())
- removeConstraint();
- break;
- case ge:
-
- pruneGtEq();
-
- if (sumXmin >= sum.max())
- removeConstraint();
-
- break;
- }
-
- } while (store.propagationHasOccurred);
+ propagate(relationType);
}
@Override
public void notConsistency(Store store) {
-
+ propagate(negRel[relationType]);
+ }
+
+ public void propagate(int rel) {
+
computeInit();
do {
store.propagationHasOccurred = false;
- switch (negRel[relationType]) {
+ switch (rel) {
case eq:
- pruneLtEq();
- pruneGtEq();
+ pruneLtEq(0);
+ pruneGtEq(0);
- if (sumXmax == sumXmin && sum.singleton() && sumXmin == sum.value())
- removeConstraint();
+ // if (sumXmax == sumXmin && sum.singleton() && sum.value() == sumXmin)
+ // removeConstraint();
break;
case le:
- pruneLtEq();
+ pruneLtEq(0);
- if (sumXmax <= sum.min())
- removeConstraint();
+ if (!reified)
+ if (sumXmax <= sum.min())
+ removeConstraint();
break;
case lt:
- pruneLt();
+ pruneLtEq(1);
- if (sumXmax < sum.min())
- removeConstraint();
+ if (!reified)
+ if (sumXmax < sum.min())
+ removeConstraint();
break;
case ne:
pruneNeq();
- if (sumXmin == sumXmax && sum.singleton() && sumXmin == sum.value())
- removeConstraint();
+ if (!reified)
+ // if (sumXmin == sumXmax && sum.singleton() && sumXmin != sum.value())
+ if (sumXmin > sum.max() || sumXmax < sum.min())
+ removeConstraint();
break;
case gt:
- pruneGt();
+ pruneGtEq(1);
- if (sumXmin > sum.max())
- removeConstraint();
+ if (!reified)
+ if (sumXmin > sum.max())
+ removeConstraint();
break;
case ge:
- pruneGtEq();
+ pruneGtEq(0);
- if (sumXmin >= sum.max())
- removeConstraint();
+ if (!reified)
+ if (sumXmin >= sum.max())
+ removeConstraint();
break;
}
@@ -366,8 +323,9 @@ private void computeInit() {
int min, max;
for (int i = 0; i < l; i++) {
- min = x[i].min();
- max = x[i].max();
+ IntDomain xd = x[i].dom();
+ min = xd.min();
+ max = xd.max();
f += min;
e += max;
I[i] = (max - min);
@@ -377,18 +335,19 @@ private void computeInit() {
sumXmax = e;
}
- private void pruneLtEq() {
+ private void pruneLtEq(int b) {
- sum.domain.inMin(store.level, sum, sumXmin);
+ sum.domain.inMin(store.level, sum, sumXmin + b);
+ store.propagationHasOccurred = false;
int min, max;
int sMax = sum.max();
for (int i = 0; i < l; i++) {
- if (I[i] > (sMax - sumXmin)) {
+ if (I[i] > (sMax - sumXmin - b)) {
min = x[i].min();
max = min + I[i];
- if (pruneMax(x[i], sMax - sumXmin + min)) {
+ if (pruneMax(x[i], sMax - sumXmin + min - b)) {
int newMax = x[i].max();
sumXmax -= max - newMax;
I[i] = newMax - min;
@@ -397,18 +356,19 @@ private void pruneLtEq() {
}
}
- private void pruneGtEq() {
+ private void pruneGtEq(int b) {
- sum.domain.inMax(store.level, sum, sumXmax);
+ sum.domain.inMax(store.level, sum, sumXmax - b);
+ store.propagationHasOccurred = false;
int min, max;
int sMin = sum.min();
for (int i = 0; i < l; i++) {
- if (I[i] > -(sMin - sumXmax)) {
+ if (I[i] > -(sMin - sumXmax + b)) {
max = x[i].max();
min = max - I[i];
- if (pruneMin(x[i], (sMin - sumXmax + max))) {
+ if (pruneMin(x[i], (sMin - sumXmax + max + b))) {
int newMin = x[i].min();
sumXmin += newMin - min;
I[i] = max - newMin;
@@ -417,50 +377,11 @@ private void pruneGtEq() {
}
}
- private void pruneLt() {
-
- sum.domain.inMin(store.level, sum, sumXmin + 1);
-
- int min, max;
- int sMax = sum.max();
-
- for (int i = 0; i < l; i++) {
- if (I[i] >= sMax - sumXmin) {
- min = x[i].min();
- max = min + I[i];
- if (pruneMax(x[i], sMax - sumXmin + min - 1)) {
- int newMax = x[i].max();
- sumXmax -= max - newMax;
- I[i] = newMax - min;
- }
- }
- }
- }
-
- private void pruneGt() {
-
- sum.domain.inMax(store.level, sum, sumXmax - 1);
-
- int min, max;
- int sMin = sum.min();
-
- for (int i = 0; i < l; i++) {
- if (I[i] >= -(sMin - sumXmax)) {
- max = x[i].max();
- min = max - I[i];
- if (pruneMin(x[i], sMin - sumXmax + max + 1)) {
- int nmin = x[i].min();
- sumXmin += nmin - min;
- I[i] = max - nmin;
- }
- }
- }
- }
-
private void pruneNeq() {
if (sumXmin == sumXmax)
sum.domain.inComplement(store.level, sum, sumXmin);
+ store.propagationHasOccurred = false;
int min, max;
@@ -520,7 +441,7 @@ public boolean satisfiedEq() {
sMax += x[i].max();
}
- return sMin == sMax && sMin == sum.min() && sMin == sum.max();
+ return sMax <= sum.min() && sMin >= sum.max(); //sMin == sMax && sMin == sum.min() && sMin == sum.max();
}
public boolean satisfiedNeq() {
@@ -535,7 +456,7 @@ public boolean satisfiedNeq() {
return sMin > sum.max() || sMax < sum.min();
}
- public boolean satisfiedLtEq() {
+ public boolean satisfiedLtEq(int b) {
int sMax = 0;
@@ -543,21 +464,10 @@ public boolean satisfiedLtEq() {
sMax += x[i].max();
}
- return sMax <= sum.min();
+ return sMax <= sum.min() - b;
}
- public boolean satisfiedLt() {
-
- int sMax = 0;
-
- for (int i = 0; i < l; i++) {
- sMax += x[i].max();
- }
-
- return sMax < sum.min();
- }
-
- public boolean satisfiedGtEq() {
+ public boolean satisfiedGtEq(int b) {
int sMin = 0;
@@ -565,18 +475,7 @@ public boolean satisfiedGtEq() {
sMin += x[i].min();
}
- return sMin >= sum.max();
- }
-
- public boolean satisfiedGt() {
-
- int sMin = 0;
-
- for (int i = 0; i < l; i++) {
- sMin += x[i].min();
- }
-
- return sMin > sum.max();
+ return sMin >= sum.max() + b;
}
@Override
@@ -606,15 +505,15 @@ private boolean entailed(int rel) {
case eq:
return satisfiedEq();
case le:
- return satisfiedLtEq();
+ return satisfiedLtEq(0);
case lt:
- return satisfiedLt();
+ return satisfiedLtEq(1);
case ne:
return satisfiedNeq();
case gt:
- return satisfiedGt();
+ return satisfiedGtEq(1);
case ge:
- return satisfiedGtEq();
+ return satisfiedGtEq(0);
}
return false;
@@ -689,6 +588,65 @@ public String toString() {
}
+
+ @Override
+ public Constraint getGuideConstraint() {
+
+ IntVar proposedVariable = (IntVar)getGuideVariable();
+ if (proposedVariable != null)
+ return new XeqC(proposedVariable, guideValue);
+ else
+ return null;
+ }
+
+ @Override
+ public int getGuideValue() {
+ return guideValue;
+ }
+
+ int guideValue = 0;
+
+
+ @Override
+ public Var getGuideVariable() {
+
+ int regret = 1;
+ Var proposedVariable = null;
+
+ for (IntVar v : x) {
+
+ IntDomain listDom = v.dom();
+
+ if (v.singleton())
+ continue;
+
+ int currentRegret = listDom.nextValue(listDom.min()) - listDom.min();
+
+ if (currentRegret > regret) {
+ regret = currentRegret;
+ proposedVariable = v;
+ guideValue = listDom.min();
+ }
+
+ currentRegret = listDom.max() - listDom.previousValue(listDom.max());
+
+ if (currentRegret > regret) {
+ regret = currentRegret;
+ proposedVariable = v;
+ guideValue = listDom.max();
+ }
+
+ }
+
+ return proposedVariable;
+
+ }
+
+
+ @Override
+ public void supplyGuideFeedback(boolean feedback) {
+ }
+
@Override
public void increaseWeight() {
if (increaseWeight) {
diff --git a/src/main/java/org/jacop/constraints/SumWeight.java b/src/main/java/org/jacop/constraints/SumWeight.java
index 9955c4ce2..21f0365c0 100644
--- a/src/main/java/org/jacop/constraints/SumWeight.java
+++ b/src/main/java/org/jacop/constraints/SumWeight.java
@@ -49,7 +49,10 @@
* @version 3.1
*/
-public class SumWeight extends Constraint {
+/**
+ * @deprecated As of release 4.3.1 replaced by LinearInt constraint.
+ */
+@Deprecated public class SumWeight extends Constraint {
static int counter = 1;
@@ -75,9 +78,9 @@ public class SumWeight extends Constraint {
public static String[] xmlAttributes = {"list", "weights", "sum"};
/**
- * @param list
- * @param weights
- * @param sum
+ * @param list the list of varibales
+ * @param weights the list of weights
+ * @param sum the resulting sum
*/
public SumWeight(IntVar[] list, int[] weights, IntVar sum) {
diff --git a/src/main/java/org/jacop/constraints/SumWeightDom.java b/src/main/java/org/jacop/constraints/SumWeightDom.java
index d04a50f24..76162ab7a 100644
--- a/src/main/java/org/jacop/constraints/SumWeightDom.java
+++ b/src/main/java/org/jacop/constraints/SumWeightDom.java
@@ -55,7 +55,10 @@
* @version 3.1
*/
-public class SumWeightDom extends Constraint {
+/**
+ * @deprecated As of release 4.3.1 replaced by LinearIntDom constraint.
+ */
+@Deprecated public class SumWeightDom extends Constraint {
static int counter = 1;
diff --git a/src/main/java/org/jacop/constraints/Task.java b/src/main/java/org/jacop/constraints/Task.java
index fbcb8c2ca..0b9bdda5c 100644
--- a/src/main/java/org/jacop/constraints/Task.java
+++ b/src/main/java/org/jacop/constraints/Task.java
@@ -39,7 +39,7 @@
* Represents tasks for cumulative constraint
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class Task {
diff --git a/src/main/java/org/jacop/constraints/Values.java b/src/main/java/org/jacop/constraints/Values.java
index 8f446885a..ce220cac9 100644
--- a/src/main/java/org/jacop/constraints/Values.java
+++ b/src/main/java/org/jacop/constraints/Values.java
@@ -51,7 +51,7 @@
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
*
- * @version 4.3
+ * @version 4.4
*/
public class Values extends Constraint {
diff --git a/src/main/java/org/jacop/constraints/ViolationMeasure.java b/src/main/java/org/jacop/constraints/ViolationMeasure.java
index 58e7bb657..4a7a4e3bd 100644
--- a/src/main/java/org/jacop/constraints/ViolationMeasure.java
+++ b/src/main/java/org/jacop/constraints/ViolationMeasure.java
@@ -35,7 +35,7 @@
/**
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/XdivYeqZ.java b/src/main/java/org/jacop/constraints/XdivYeqZ.java
index b09198bc8..f8815aec0 100644
--- a/src/main/java/org/jacop/constraints/XdivYeqZ.java
+++ b/src/main/java/org/jacop/constraints/XdivYeqZ.java
@@ -37,6 +37,7 @@
import org.jacop.core.IntDomain;
import org.jacop.core.IntVar;
import org.jacop.core.IntervalDomain;
+import org.jacop.core.Interval;
import org.jacop.core.Store;
import org.jacop.core.Var;
@@ -91,6 +92,8 @@ public XdivYeqZ(IntVar x, IntVar y, IntVar z) {
this.y = y;
this.z = z;
+ checkForOverflow();
+
}
@Override
@@ -131,17 +134,17 @@ else if (x.max() < 0) {
}
// Bounds for Z
- IntervalDomain zBounds = IntDomain.divBounds(x.min(), x.max(), y.min(), y.max());
+ Interval zBounds = IntDomain.divBounds(x.min(), x.max(), y.min(), y.max());
- z.domain.in(store.level, z, zBounds);
+ z.domain.in(store.level, z, zBounds.min(), zBounds.max());
// Bounds for Y
- IntervalDomain yBounds = IntDomain.divBounds(x.min()-reminderMax, x.max()-reminderMin, z.min(), z.max());
+ Interval yBounds = IntDomain.divBounds(x.min()-reminderMax, x.max()-reminderMin, z.min(), z.max());
- y.domain.in(store.level, y, yBounds);
+ y.domain.in(store.level, y, yBounds.min(), yBounds.max());
// Bounds for X
- IntervalDomain xBounds = IntDomain.mulBounds(z.min(), z.max(), y.min(), y.max());
+ Interval xBounds = IntDomain.mulBounds(z.min(), z.max(), y.min(), y.max());
int xMin = xBounds.min();
int xMax = xBounds.max();
@@ -212,6 +215,15 @@ public void increaseWeight() {
}
}
+ private void checkForOverflow() {
+
+ int n = IntDomain.multiply(z.min(), y.min());
+ n = IntDomain.multiply(z.min(), y.max());
+ n = IntDomain.multiply(z.max(), y.min());
+ n = IntDomain.multiply(z.max(), y.max());
+
+ }
+
int div(int a, int b) {
return (int)Math.floor((float)a / (float)b);
}
diff --git a/src/main/java/org/jacop/constraints/XeqC.java b/src/main/java/org/jacop/constraints/XeqC.java
index ac2811637..ce1b49591 100644
--- a/src/main/java/org/jacop/constraints/XeqC.java
+++ b/src/main/java/org/jacop/constraints/XeqC.java
@@ -45,7 +45,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XeqC extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/XeqY.java b/src/main/java/org/jacop/constraints/XeqY.java
index f8a8de7f3..0884057c4 100644
--- a/src/main/java/org/jacop/constraints/XeqY.java
+++ b/src/main/java/org/jacop/constraints/XeqY.java
@@ -44,7 +44,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XeqY extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/XgtC.java b/src/main/java/org/jacop/constraints/XgtC.java
index 674e564f9..3b51c8865 100644
--- a/src/main/java/org/jacop/constraints/XgtC.java
+++ b/src/main/java/org/jacop/constraints/XgtC.java
@@ -40,10 +40,10 @@
import org.jacop.core.Var;
/**
- * Constraint X #> C
+ * Constraint X {@literal >} C
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XgtC extends PrimitiveConstraint {
@@ -67,7 +67,7 @@ public class XgtC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "c"};
/**
- * It constructs constraint X > C.
+ * It constructs constraint X {@literal >} C.
* @param x variable x.
* @param c constant c.
*/
diff --git a/src/main/java/org/jacop/constraints/XgtY.java b/src/main/java/org/jacop/constraints/XgtY.java
index 3c7a739d2..7bf57e5a9 100644
--- a/src/main/java/org/jacop/constraints/XgtY.java
+++ b/src/main/java/org/jacop/constraints/XgtY.java
@@ -39,10 +39,10 @@
import org.jacop.core.Var;
/**
- * Constraint X #> Y
+ * Constraint X {@literal >} Y
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XgtY extends PrimitiveConstraint {
@@ -66,7 +66,7 @@ public class XgtY extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "y"};
/**
- * It constructs a constraint X > Y.
+ * It constructs a constraint X {@literal >} Y.
* @param x variable x.
* @param y variable y.
*/
diff --git a/src/main/java/org/jacop/constraints/XgteqC.java b/src/main/java/org/jacop/constraints/XgteqC.java
index 75ce4f9aa..6f90724a3 100644
--- a/src/main/java/org/jacop/constraints/XgteqC.java
+++ b/src/main/java/org/jacop/constraints/XgteqC.java
@@ -40,10 +40,10 @@
import org.jacop.core.Var;
/**
- * Constraints X #>= C
+ * Constraints X {@literal >=} C
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XgteqC extends PrimitiveConstraint {
@@ -67,7 +67,7 @@ public class XgteqC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "c"};
/**
- * It constructs constraint X >= C.
+ * It constructs constraint X {@literal >=} C.
* @param x variable x.
* @param c constant c.
*/
diff --git a/src/main/java/org/jacop/constraints/XgteqY.java b/src/main/java/org/jacop/constraints/XgteqY.java
index d9dfa00f2..e555db801 100644
--- a/src/main/java/org/jacop/constraints/XgteqY.java
+++ b/src/main/java/org/jacop/constraints/XgteqY.java
@@ -39,10 +39,10 @@
import org.jacop.core.Var;
/**
- * Constraints X #>= Y
+ * Constraints X {@literal >=} Y
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XgteqY extends PrimitiveConstraint {
@@ -66,7 +66,7 @@ public class XgteqY extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "y"};
/**
- * It constructs constraint X >= Y.
+ * It constructs constraint X {@literal >=} Y.
* @param x variable x.
* @param y variable y.
*/
diff --git a/src/main/java/org/jacop/constraints/XltC.java b/src/main/java/org/jacop/constraints/XltC.java
index c31cbcfe7..2c9f8e644 100644
--- a/src/main/java/org/jacop/constraints/XltC.java
+++ b/src/main/java/org/jacop/constraints/XltC.java
@@ -40,10 +40,10 @@
import org.jacop.core.Var;
/**
- * Constraint X #< C
+ * Constraint X {@literal <} C
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XltC extends PrimitiveConstraint {
@@ -67,7 +67,7 @@ public class XltC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "c"};
/**
- * It constructs constraint X < C.
+ * It constructs constraint X {@literal <} C.
* @param x variable x.
* @param c constant c.
*/
diff --git a/src/main/java/org/jacop/constraints/XltY.java b/src/main/java/org/jacop/constraints/XltY.java
index b54c1900e..d92e0e3ba 100644
--- a/src/main/java/org/jacop/constraints/XltY.java
+++ b/src/main/java/org/jacop/constraints/XltY.java
@@ -39,10 +39,10 @@
import org.jacop.core.Var;
/**
- * Constraint X #< Y
+ * Constraint X {@literal <} Y
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XltY extends PrimitiveConstraint {
@@ -50,12 +50,12 @@ public class XltY extends PrimitiveConstraint {
static int idNumber = 1;
/**
- * It specifies x variable in constraint x < y.
+ * It specifies x variable in constraint x {@literal <} y.
*/
public IntVar x;
/**
- * It specifies y variable in constraint x < y.
+ * It specifies y variable in constraint x {@literal <} y.
*/
public IntVar y;
@@ -66,7 +66,7 @@ public class XltY extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "y"};
/**
- * It constructs the constraint X < Y.
+ * It constructs the constraint X {@literal <} Y.
* @param x variable x.
* @param y variable y.
*/
diff --git a/src/main/java/org/jacop/constraints/XlteqC.java b/src/main/java/org/jacop/constraints/XlteqC.java
index a68016d24..bd53b161d 100644
--- a/src/main/java/org/jacop/constraints/XlteqC.java
+++ b/src/main/java/org/jacop/constraints/XlteqC.java
@@ -40,11 +40,11 @@
import org.jacop.core.Var;
/**
- * Constraint X #<= C
+ * Constraint X {@literal <=} C
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XlteqC extends PrimitiveConstraint {
@@ -68,7 +68,7 @@ public class XlteqC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "c"};
/**
- * It constructs constraint X <= C.
+ * It constructs constraint X {@literal <=} C.
* @param x variable x.
* @param c constant c.
*/
diff --git a/src/main/java/org/jacop/constraints/XlteqY.java b/src/main/java/org/jacop/constraints/XlteqY.java
index ad0bbf671..0e086ec79 100644
--- a/src/main/java/org/jacop/constraints/XlteqY.java
+++ b/src/main/java/org/jacop/constraints/XlteqY.java
@@ -39,10 +39,10 @@
import org.jacop.core.Var;
/**
- * Constraint X #<= Y
+ * Constraint X {@literal <=} Y
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XlteqY extends PrimitiveConstraint {
@@ -50,12 +50,12 @@ public class XlteqY extends PrimitiveConstraint {
static int idNumber = 1;
/**
- * It specifies variable x in the constraint x <= y.
+ * It specifies variable x in the constraint x {@literal <=} y.
*/
public IntVar x;
/**
- * It specifies variable y in the constraint x <= y.
+ * It specifies variable y in the constraint x {@literal <=} y.
*/
public IntVar y;
@@ -66,7 +66,7 @@ public class XlteqY extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "y"};
/**
- * It constructs the constraint X <= Y.
+ * It constructs the constraint X {@literal <=} Y.
* @param x variable x.
* @param y variable y.
*/
diff --git a/src/main/java/org/jacop/constraints/XmodYeqZ.java b/src/main/java/org/jacop/constraints/XmodYeqZ.java
index 75eb1f00e..4aa223707 100644
--- a/src/main/java/org/jacop/constraints/XmodYeqZ.java
+++ b/src/main/java/org/jacop/constraints/XmodYeqZ.java
@@ -36,6 +36,7 @@
import org.jacop.core.IntDomain;
import org.jacop.core.IntVar;
import org.jacop.core.IntervalDomain;
+import org.jacop.core.Interval;
import org.jacop.core.Store;
import org.jacop.core.Var;
@@ -136,7 +137,7 @@ else if (x.max() < 0) {
// Bounds for result
int oldResultMin = resultMin, oldResultMax = resultMax;
- IntervalDomain result = IntDomain.divBounds(x.min(), x.max(), y.min(), y.max());
+ Interval result = IntDomain.divBounds(x.min(), x.max(), y.min(), y.max());
resultMin = result.min();
resultMax = result.max();
@@ -145,12 +146,12 @@ else if (x.max() < 0) {
store.propagationHasOccurred = true;
// Bounds for Y
- IntervalDomain yBounds = IntDomain.divBounds(x.min()-reminderMax, x.max()-reminderMin, resultMin, resultMax);
+ Interval yBounds = IntDomain.divBounds(x.min()-reminderMax, x.max()-reminderMin, resultMin, resultMax);
- y.domain.in(store.level, y, yBounds);
+ y.domain.in(store.level, y, yBounds.min(), yBounds.max());
// Bounds for Z and reminder
- IntervalDomain reminder = IntDomain.mulBounds(resultMin, resultMax, y.min(), y.max());
+ Interval reminder = IntDomain.mulBounds(resultMin, resultMax, y.min(), y.max());
int zMin = reminder.min(), zMax = reminder.max();
reminderMin = x.min() - zMax;
diff --git a/src/main/java/org/jacop/constraints/XmulCeqZ.java b/src/main/java/org/jacop/constraints/XmulCeqZ.java
index f77b3d1fd..9f23fd4f5 100644
--- a/src/main/java/org/jacop/constraints/XmulCeqZ.java
+++ b/src/main/java/org/jacop/constraints/XmulCeqZ.java
@@ -36,6 +36,7 @@
import org.jacop.core.IntDomain;
import org.jacop.core.IntVar;
import org.jacop.core.IntervalDomain;
+import org.jacop.core.Interval;
import org.jacop.core.Store;
import org.jacop.core.Var;
import org.jacop.core.FailException;
@@ -91,6 +92,8 @@ public XmulCeqZ(IntVar x, int c, IntVar z) {
this.x = x;
this.c = c;
this.z = z;
+
+ checkForOverflow();
}
@Override
@@ -112,14 +115,14 @@ public void consistency (Store store) {
store.propagationHasOccurred = false;
// Bounds for X
- IntervalDomain xBounds = IntDomain.divIntBounds(z.min(), z.max(), c, c);
+ Interval xBounds = IntDomain.divIntBounds(z.min(), z.max(), c, c);
- x.domain.in(store.level, x, xBounds);
+ x.domain.in(store.level, x, xBounds.min(), xBounds.max());
// Bounds for Z
- IntervalDomain zBounds = IntDomain.mulBounds(x.min(), x.max(), c, c);
+ Interval zBounds = IntDomain.mulBounds(x.min(), x.max(), c, c);
- z.domain.in(store.level, z, zBounds);
+ z.domain.in(store.level, z, zBounds.min(), zBounds.max());
} while (store.propagationHasOccurred);
else
@@ -136,7 +139,7 @@ public void notConsistency (Store store) {
z.domain.inComplement(store.level, z, x.value()*c);
if ( z.singleton() ) {
- IntervalDomain xBounds;
+ Interval xBounds;
try {
xBounds = IntDomain.divIntBounds(z.min(), z.max(), c, c);
@@ -145,7 +148,7 @@ public void notConsistency (Store store) {
return;
}
- x.domain.inComplement(store.level, x, xBounds.value());
+ x.domain.inComplement(store.level, x, xBounds.min());
}
}
@@ -163,7 +166,8 @@ public boolean satisfied() {
@Override
public boolean notSatisfied() {
- return ! z.domain.isIntersecting(IntDomain.mulBounds(x.min(), x.max(), c, c));
+ Interval r = IntDomain.mulBounds(x.min(), x.max(), c, c);
+ return ! z.domain.isIntersecting(r.min(), r.max());
// IntDomain Xdom = x.dom();
// IntDomain Zdom = z.dom();
@@ -242,6 +246,13 @@ public String toString() {
return id() + " : XmulCeqZ(" + x + ", " + c + ", " + z + " )";
}
+ private void checkForOverflow() {
+
+ int n = IntDomain.multiply(x.min(), c);
+ n = IntDomain.multiply(x.max(), c);
+
+ }
+
@Override
public void increaseWeight() {
if (increaseWeight) {
diff --git a/src/main/java/org/jacop/constraints/XmulYeqC.java b/src/main/java/org/jacop/constraints/XmulYeqC.java
index 92eb5113d..a64af4caf 100644
--- a/src/main/java/org/jacop/constraints/XmulYeqC.java
+++ b/src/main/java/org/jacop/constraints/XmulYeqC.java
@@ -36,6 +36,7 @@
import org.jacop.core.IntDomain;
import org.jacop.core.IntVar;
import org.jacop.core.IntervalDomain;
+import org.jacop.core.Interval;
import org.jacop.core.Store;
import org.jacop.core.Var;
@@ -141,17 +142,17 @@ public void consistency (Store store) {
store.propagationHasOccurred = false;
// Bounds for X
- IntervalDomain xBounds = IntDomain.divIntBounds(c, c, y.min(), y.max());
+ Interval xBounds = IntDomain.divIntBounds(c, c, y.min(), y.max());
- x.domain.in(store.level, x, xBounds);
+ x.domain.in(store.level, x, xBounds.min(), xBounds.max());
// Bounds for Y
- IntervalDomain yBounds = IntDomain.divIntBounds(c, c, x.min(), x.max());
+ Interval yBounds = IntDomain.divIntBounds(c, c, x.min(), x.max());
- y.domain.in(store.level, y, yBounds);
+ y.domain.in(store.level, y, yBounds.min(), yBounds.max());
// check bounds, if C is covered.
- IntervalDomain cBounds = IntDomain.mulBounds(x.min(), x.max(), y.min(), y.max());
+ Interval cBounds = IntDomain.mulBounds(x.min(), x.max(), y.min(), y.max());
if ( c < cBounds.min() || c > cBounds.max() )
throw Store.failException;
diff --git a/src/main/java/org/jacop/constraints/XmulYeqZ.java b/src/main/java/org/jacop/constraints/XmulYeqZ.java
index 953c55425..7ee328dd6 100644
--- a/src/main/java/org/jacop/constraints/XmulYeqZ.java
+++ b/src/main/java/org/jacop/constraints/XmulYeqZ.java
@@ -37,6 +37,7 @@
import org.jacop.core.IntDomain;
import org.jacop.core.IntVar;
import org.jacop.core.IntervalDomain;
+import org.jacop.core.Interval;
import org.jacop.core.Store;
import org.jacop.core.Var;
@@ -96,6 +97,8 @@ public XmulYeqZ(IntVar x, IntVar y, IntVar z) {
this.x = x;
this.y = y;
this.z = z;
+
+ checkForOverflow();
}
@Override
@@ -115,11 +118,11 @@ public void consistency (Store store) {
if (xSquare) // X^2 = Z
do {
- store.propagationHasOccurred = false;
-
// Bounds for Z
- IntervalDomain zBounds = IntDomain.mulBounds(x.min(), x.max(), x.min(), x.max());
- z.domain.in(store.level, z, zBounds);
+ Interval zBounds = IntDomain.mulBounds(x.min(), x.max(), x.min(), x.max());
+ z.domain.in(store.level, z, zBounds.min(), zBounds.max());
+
+ store.propagationHasOccurred = false;
// Bounds for X
@@ -137,27 +140,29 @@ public void consistency (Store store) {
} while(store.propagationHasOccurred);
else // X*Y=Z
do {
-
- store.propagationHasOccurred = false;
// Bounds for X
- IntervalDomain xBounds = IntDomain.divIntBounds(z.min(), z.max(), y.min(), y.max());
+ Interval xBounds = IntDomain.divIntBounds(z.min(), z.max(), y.min(), y.max());
- x.domain.in(store.level, x, xBounds);
+ x.domain.in(store.level, x, xBounds.min(), xBounds.max());
+
+ store.propagationHasOccurred = false;
// Bounds for Y
- IntervalDomain yBounds = IntDomain.divIntBounds(z.min(), z.max(), x.min(), x.max());
+ Interval yBounds = IntDomain.divIntBounds(z.min(), z.max(), x.min(), x.max());
- y.domain.in(store.level, y, yBounds);
+ y.domain.in(store.level, y, yBounds.min(), yBounds.max());
// Bounds for Z
- IntervalDomain zBounds = IntDomain.mulBounds(x.min(), x.max(), y.min(), y.max());
+ Interval zBounds = IntDomain.mulBounds(x.min(), x.max(), y.min(), y.max());
- z.domain.in(store.level, z, zBounds);
+ z.domain.in(store.level, z, zBounds.min(), zBounds.max());
} while (store.propagationHasOccurred);
-
+
+ if (x.singleton(0) || y.singleton(0))
+ removeConstraint();
}
@Override
@@ -201,7 +206,15 @@ public String toString() {
return id() + " : XmulYeqZ(" + x + ", " + y + ", " + z + " )";
}
+ private void checkForOverflow() {
+
+ int n = IntDomain.multiply(x.min(), y.min());
+ n = IntDomain.multiply(x.min(), y.max());
+ n = IntDomain.multiply(x.max(), y.min());
+ n = IntDomain.multiply(x.max(), y.max());
+ }
+
@Override
public void increaseWeight() {
if (increaseWeight) {
diff --git a/src/main/java/org/jacop/constraints/XneqC.java b/src/main/java/org/jacop/constraints/XneqC.java
index e4cdb192c..1abfd7a29 100644
--- a/src/main/java/org/jacop/constraints/XneqC.java
+++ b/src/main/java/org/jacop/constraints/XneqC.java
@@ -43,7 +43,7 @@
* Constraints X #\= C
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XneqC extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/XneqY.java b/src/main/java/org/jacop/constraints/XneqY.java
index ae4d56e0d..1242e3806 100644
--- a/src/main/java/org/jacop/constraints/XneqY.java
+++ b/src/main/java/org/jacop/constraints/XneqY.java
@@ -44,7 +44,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XneqY extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/Xor.java b/src/main/java/org/jacop/constraints/Xor.java
index b0e052373..32a36aba4 100644
--- a/src/main/java/org/jacop/constraints/Xor.java
+++ b/src/main/java/org/jacop/constraints/Xor.java
@@ -45,7 +45,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Xor extends PrimitiveConstraint {
@@ -62,6 +62,10 @@ public class Xor extends PrimitiveConstraint {
*/
public IntVar b;
+ boolean needQueueVariable = false;
+
+ boolean needRemoveLevelLate = false;
+
/**
* It specifies the arguments required to be saved by an XML format as well as
* the constructor being called to recreate an object from an XML format.
@@ -88,6 +92,20 @@ public Xor(PrimitiveConstraint c, IntVar b) {
this.c = c;
this.b = b;
+ try {
+ c.getClass().getDeclaredMethod("queueVariable", int.class, Var.class);
+ needQueueVariable = true;
+ } catch (NoSuchMethodException e) {
+ needQueueVariable = false;
+ }
+
+
+ try {
+ c.getClass().getDeclaredMethod("removeLevelLate", int.class);
+ needRemoveLevelLate = true;
+ } catch (NoSuchMethodException e) {
+ needRemoveLevelLate = false;
+ }
}
@Override
@@ -208,6 +226,7 @@ public void impose(Store store) {
while (!variables.isEmpty()) {
Var V = variables.removeFirst();
V.putModelConstraint(this, getConsistencyPruningEvent(V));
+ queueVariable(store.level, V);
}
c.include(store);
@@ -267,7 +286,21 @@ public boolean notSatisfied() {
|| (bDom.max() == 0 && c.notSatisfied());
}
- @Override
+ @Override
+ public void queueVariable(int level, Var variable) {
+
+ if (needQueueVariable)
+ if (!variable.equals(b))
+ c.queueVariable(level, variable);
+
+ }
+
+ public void removeLevelLate(int level) {
+ if (needRemoveLevelLate)
+ c.removeLevelLate(level);
+ }
+
+ @Override
public void increaseWeight() {
if (increaseWeight) {
b.weight++;
diff --git a/src/main/java/org/jacop/constraints/XorBool.java b/src/main/java/org/jacop/constraints/XorBool.java
index c1d85aee4..f16f4a69b 100644
--- a/src/main/java/org/jacop/constraints/XorBool.java
+++ b/src/main/java/org/jacop/constraints/XorBool.java
@@ -40,10 +40,10 @@
import org.jacop.core.Var;
/**
- * Constraint ( x_0 xor x_1 xor ... xor x_n ) <=> y
+ * Constraint ( x_0 xor x_1 xor ... xor x_n ){@literal <=>} y
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XorBool extends PrimitiveConstraint {
@@ -79,7 +79,7 @@ public class XorBool extends PrimitiveConstraint {
*/
public static String[] xmlAttributes = {"x", "y"};
- /** It constructs constraint (x_0 xor x_1 xor ... xor x_n ) <=> y.
+ /** It constructs constraint (x_0 xor x_1 xor ... xor x_n ) {@literal <=>} y.
* @param x variables x.
* @param y variable y.
*/
diff --git a/src/main/java/org/jacop/constraints/XplusCeqZ.java b/src/main/java/org/jacop/constraints/XplusCeqZ.java
index f56aa447a..63ba21776 100644
--- a/src/main/java/org/jacop/constraints/XplusCeqZ.java
+++ b/src/main/java/org/jacop/constraints/XplusCeqZ.java
@@ -43,7 +43,7 @@
* Constraint X + C #= Z.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XplusCeqZ extends PrimitiveConstraint {
@@ -106,10 +106,10 @@ public void consistency(Store store) {
do {
- store.propagationHasOccurred = false;
-
x.domain.inShift(store.level, x, z.domain, -c);
+ store.propagationHasOccurred = false;
+
z.domain.inShift(store.level, z, x.domain, c);
} while (store.propagationHasOccurred);
diff --git a/src/main/java/org/jacop/constraints/XplusClteqZ.java b/src/main/java/org/jacop/constraints/XplusClteqZ.java
index f8f3de2f9..e06782cc1 100644
--- a/src/main/java/org/jacop/constraints/XplusClteqZ.java
+++ b/src/main/java/org/jacop/constraints/XplusClteqZ.java
@@ -39,12 +39,12 @@
import org.jacop.core.Var;
/**
- * Constraints X + C #<= Z.
+ * Constraints X + C{@literal <=} Z.
*
* Boundary consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XplusClteqZ extends PrimitiveConstraint {
@@ -52,17 +52,17 @@ public class XplusClteqZ extends PrimitiveConstraint {
static int idNumber = 1;
/**
- * It specifies variable x in constraint x+c<=z.
+ * It specifies variable x in constraint x+c{@literal <=}z.
*/
public IntVar x;
/**
- * It specifies constant c in constraint x+c<=z.
+ * It specifies constant c in constraint x+c{@literal <=} z.
*/
public int c;
/**
- * It specifies variable z in constraint x+c<=z.
+ * It specifies variable z in constraint x+c{@literal <=} z.
*/
public IntVar z;
@@ -73,7 +73,7 @@ public class XplusClteqZ extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "c", "z"};
/**
- * It constructs constraint X+C<=Z.
+ * It constructs constraint X+C{@literal <=} Z.
* @param x variable x.
* @param c constant c.
* @param z variable z.
diff --git a/src/main/java/org/jacop/constraints/XplusYeqC.java b/src/main/java/org/jacop/constraints/XplusYeqC.java
index 741deb55f..a8133843a 100644
--- a/src/main/java/org/jacop/constraints/XplusYeqC.java
+++ b/src/main/java/org/jacop/constraints/XplusYeqC.java
@@ -45,7 +45,7 @@
* Constraint X + Y #= C
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class XplusYeqC extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/XplusYeqZ.java b/src/main/java/org/jacop/constraints/XplusYeqZ.java
index ab51129e0..032469acc 100644
--- a/src/main/java/org/jacop/constraints/XplusYeqZ.java
+++ b/src/main/java/org/jacop/constraints/XplusYeqZ.java
@@ -39,12 +39,12 @@
import org.jacop.core.Var;
/**
- * Constraint X + Y #= Z
+ * Constraint X + Y = Z
*
* Bound consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XplusYeqZ extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/XplusYgtC.java b/src/main/java/org/jacop/constraints/XplusYgtC.java
index 75308fbeb..102400751 100644
--- a/src/main/java/org/jacop/constraints/XplusYgtC.java
+++ b/src/main/java/org/jacop/constraints/XplusYgtC.java
@@ -39,11 +39,11 @@
import org.jacop.core.Var;
/**
- * Constraint X + Y #> C
+ * Constraint X + Y{@literal >} C
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XplusYgtC extends PrimitiveConstraint {
@@ -51,17 +51,17 @@ public class XplusYgtC extends PrimitiveConstraint {
static int idNumber = 1;
/**
- * It specifies variable x in constraint x + y > c.
+ * It specifies variable x in constraint x + y{@literal >} c.
*/
public IntVar x;
/**
- * It specifies variable y in constraint x + y > c.
+ * It specifies variable y in constraint x + y{@literal >} c.
*/
public IntVar y;
/**
- * It specifies constant c in constraint x + y > c.
+ * It specifies constant c in constraint x + y{@literal >} c.
*/
public int c;
@@ -72,7 +72,7 @@ public class XplusYgtC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "y", "c"};
/**
- * It constructs X+Y>C constraint.
+ * It constructs X+Y{@literal >} C constraint.
* @param x variable x.
* @param y variable y.
* @param c variable c.
diff --git a/src/main/java/org/jacop/constraints/XplusYlteqZ.java b/src/main/java/org/jacop/constraints/XplusYlteqZ.java
index f3756423a..0b210211d 100644
--- a/src/main/java/org/jacop/constraints/XplusYlteqZ.java
+++ b/src/main/java/org/jacop/constraints/XplusYlteqZ.java
@@ -39,12 +39,12 @@
import org.jacop.core.Var;
/**
- * Constraint X + Y =< Z
+ * Constraint X + Y{@literal =<} Z
*
* Bound consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XplusYlteqZ extends PrimitiveConstraint {
@@ -52,17 +52,17 @@ public class XplusYlteqZ extends PrimitiveConstraint {
static int counter = 1;
/**
- * It specifies variable x in constraint x + y <= z.
+ * It specifies variable x in constraint x + y{@literal <=} z.
*/
public IntVar x;
/**
- * It specifies variable x in constraint x + y <= z.
+ * It specifies variable x in constraint x + y{@literal <=} z.
*/
public IntVar y;
/**
- * It specifies variable x in constraint x + y <= z.
+ * It specifies variable x in constraint x + y{@literal <=} z.
*/
public IntVar z;
@@ -73,7 +73,7 @@ public class XplusYlteqZ extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "y", "z"};
/**
- * It constructs X + Y <= Z constraint.
+ * It constructs X + Y{@literal <=} Z constraint.
* @param x variable x.
* @param y variable y.
* @param z variable z.
diff --git a/src/main/java/org/jacop/constraints/XplusYplusCeqZ.java b/src/main/java/org/jacop/constraints/XplusYplusCeqZ.java
index 5d19ae623..32ab7b3ea 100644
--- a/src/main/java/org/jacop/constraints/XplusYplusCeqZ.java
+++ b/src/main/java/org/jacop/constraints/XplusYplusCeqZ.java
@@ -44,7 +44,7 @@
* Bound consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XplusYplusCeqZ extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/XplusYplusQeqZ.java b/src/main/java/org/jacop/constraints/XplusYplusQeqZ.java
index 0dbb8e4c8..c796cbe5d 100644
--- a/src/main/java/org/jacop/constraints/XplusYplusQeqZ.java
+++ b/src/main/java/org/jacop/constraints/XplusYplusQeqZ.java
@@ -44,7 +44,7 @@
* Bound consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XplusYplusQeqZ extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/constraints/XplusYplusQgtC.java b/src/main/java/org/jacop/constraints/XplusYplusQgtC.java
index ab233ca3b..e83556659 100644
--- a/src/main/java/org/jacop/constraints/XplusYplusQgtC.java
+++ b/src/main/java/org/jacop/constraints/XplusYplusQgtC.java
@@ -39,10 +39,10 @@
import org.jacop.core.Var;
/**
- * Constraint X + Y + Q > C
+ * Constraint X + Y + Q {@literal >} C
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XplusYplusQgtC extends PrimitiveConstraint {
@@ -50,17 +50,17 @@ public class XplusYplusQgtC extends PrimitiveConstraint {
static int counter = 1;
/**
- * It specifies variable x in constraint x+y+q > c.
+ * It specifies variable x in constraint x+y+q {@literal >} c.
*/
public IntVar x;
/**
- * It specifies variable y in constraint x+y+q > c.
+ * It specifies variable y in constraint x+y+q {@literal >} c.
*/
public IntVar y;
/**
- * It specifies variable q in constraint x+y+q > c.
+ * It specifies variable q in constraint x+y+q {@literal >} c.
*/
public IntVar q;
@@ -76,7 +76,7 @@ public class XplusYplusQgtC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"x", "y", "q", "c"};
/**
- * It creates X+Y+Q>=C constraint.
+ * It creates X+Y+Q{@literal >=} C constraint.
* @param x variable x.
* @param y variable y.
* @param q variable q.
diff --git a/src/main/java/org/jacop/constraints/binpacking/BinItem.java b/src/main/java/org/jacop/constraints/binpacking/BinItem.java
index e56fef163..a0056ec99 100644
--- a/src/main/java/org/jacop/constraints/binpacking/BinItem.java
+++ b/src/main/java/org/jacop/constraints/binpacking/BinItem.java
@@ -38,7 +38,7 @@
* and its weight.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
class BinItem {
diff --git a/src/main/java/org/jacop/constraints/binpacking/Binpacking.java b/src/main/java/org/jacop/constraints/binpacking/Binpacking.java
index a2c7e40dc..a4bcbc732 100644
--- a/src/main/java/org/jacop/constraints/binpacking/Binpacking.java
+++ b/src/main/java/org/jacop/constraints/binpacking/Binpacking.java
@@ -54,7 +54,7 @@
* Paul Shaw, CP 2004.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Binpacking extends Constraint {
@@ -125,13 +125,17 @@ public Binpacking(IntVar[] bin, IntVar[] load, int[] w) {
assert (load[i] != null) : i + "-th element in load list is null";
this.load[i] = load[i];
- binMap.put(this.load[i], i);
-
+ Integer varPosition = binMap.put(this.load[i], i);
+ if (varPosition != null) {
+ System.err.println("ERROR: Constraint " + toString() + " must have different variables on the list");
+ System.exit(0);
+ }
}
Arrays.sort(item, new WeightComparator());
for (int i = 0; i < item.length; i++)
itemMap.put(item[i].bin, i);
+
}
/**
@@ -150,6 +154,35 @@ public Binpacking(ArrayList extends IntVar> bin,
w);
}
+ /**
+ * It constructs the binpacking constraint for the supplied variable.
+ * @param bin which are constrained to define bin for item i.
+ * @param load which are constrained to define load for bin i.
+ * @param w which define size ofitem i.
+ * @param minBin minimal index of a bin; ovewrite the value provided by minimal index of variable bin
+ */
+ public Binpacking(IntVar[] bin, IntVar[] load, int[] w, int minBin) {
+ this(bin, load, w);
+ minBinNumber = minBin;
+ }
+
+ /**
+ * It constructs the binpacking constraint for the supplied variable.
+ * @param bin which are constrained to define bin for item i.
+ * @param load which are constrained to define load for bin i.
+ * @param w which define size ofitem i.
+ * @param minBin minimal index of a bin; ovewrite the value provided by minimal index of variable bin
+ */
+ public Binpacking(ArrayList extends IntVar> bin,
+ ArrayList extends IntVar> load,
+ int[] w, int minBin) {
+
+ this(bin.toArray(new IntVar[bin.size()]),
+ load.toArray(new IntVar[load.size()]),
+ w);
+ minBinNumber = minBin;
+ }
+
@Override
public ArrayList arguments() {
@@ -171,7 +204,7 @@ public void consistency(Store store) {
if (firstConsistencyCheck) {
for (int i = 0; i < item.length; i++)
item[i].bin.domain.in(store.level, item[i].bin, minBinNumber, load.length - 1 + minBinNumber);
-
+
firstConsistencyCheck = false;
}
diff --git a/src/main/java/org/jacop/constraints/geost/BoxDisplay.java b/src/main/java/org/jacop/constraints/geost/BoxDisplay.java
index bc439bff5..7a4e88094 100644
--- a/src/main/java/org/jacop/constraints/geost/BoxDisplay.java
+++ b/src/main/java/org/jacop/constraints/geost/BoxDisplay.java
@@ -100,7 +100,7 @@ public BoxDisplay(int pixelsPerUnit) {
* It creates a display to visualize 2D geost constraint.
*
* @param pixelsPerUnit number of pixels per unit of object length.
- * @param title
+ * @param title the title of the display
* @param geost geost constraint to visualize
*/
public void displayState(int pixelsPerUnit, String title, Geost geost){
@@ -120,7 +120,7 @@ public void displayState(int pixelsPerUnit, String title, Geost geost){
/**
* It displays the state of the geost constraint.
*
- * @param domainWidth
+ * @param domainWidth the width of the domain
* @param groundedOnly only grounded objects should be displayed.
* @param withFrames should frames describing non-overlapping constraint be displayed too?
* @param geost geost constraint being displayed.
diff --git a/src/main/java/org/jacop/constraints/geost/DBox.java b/src/main/java/org/jacop/constraints/geost/DBox.java
index 45e3fb370..a53f33a1b 100644
--- a/src/main/java/org/jacop/constraints/geost/DBox.java
+++ b/src/main/java/org/jacop/constraints/geost/DBox.java
@@ -84,7 +84,7 @@ public class DBox {
*
* It has to be called at least once before using newBox() and dispatchBox().
*
- * @param dimension
+ * @param dimension the number of dimensions
*/
public static final void supportDimension(int dimension) {
@@ -183,7 +183,7 @@ public static final DBox newBox(int dimension) {
/**
* It returns an instance of DBox of the corresponding dimension,
* using a previously allocated one if possible
- * @param dimension
+ * @param dimension the number of dimensions
*
* @return it returns a preallocated DBox of a given dimensions.
*/
@@ -469,7 +469,7 @@ public Collection subtract(DBox hole, Collection difference){
/**
* computes the bounding box of the given collection of boxes
- * @param boxes
+ * @param boxes collection of boxes
* @return a temporary DBox that represents the bounding box of the given boxes.
* clone it if you need to reuse it.
*/
diff --git a/src/main/java/org/jacop/constraints/geost/ExternalConstraint.java b/src/main/java/org/jacop/constraints/geost/ExternalConstraint.java
index 46c3f7b1d..b608bdca4 100644
--- a/src/main/java/org/jacop/constraints/geost/ExternalConstraint.java
+++ b/src/main/java/org/jacop/constraints/geost/ExternalConstraint.java
@@ -100,7 +100,7 @@ public interface ExternalConstraint {
* Handler method called by the Geost kernel when the domain of the object changes.
* Use this method to make changes to the state of the constraint (and of its relative internal
* constraints) if needed.
- * @param o
+ * @param o the object
*/
public void onObjectUpdate(GeostObject o);
diff --git a/src/main/java/org/jacop/constraints/geost/Geost.java b/src/main/java/org/jacop/constraints/geost/Geost.java
index 01b699c7b..734588564 100644
--- a/src/main/java/org/jacop/constraints/geost/Geost.java
+++ b/src/main/java/org/jacop/constraints/geost/Geost.java
@@ -476,7 +476,7 @@ public Geost(Collection objects,
* @param shapes the list of different shapes used by the objects in scope of the geost.
*
*/
- @SuppressWarnings("all")
+ @SuppressWarnings("unchecked")
public Geost(GeostObject[] objects,
ExternalConstraint[] constraints,
Shape[] shapes) {
@@ -794,6 +794,7 @@ protected void genInternalConstraints() {
* If any data structure is updated here, make sure that it is done carefully enough.
* @param store the store
* @param o the object to prune
+ * @param currentShape the shape of the object
* @param d the current most significant dimension
* @param limit stop pruning if going beyond this value
* @return the bound found if there is one, and Constants.MaxInt if there is no feasible placement.
@@ -905,6 +906,7 @@ protected int pruneMin(Store store,
* @param store the store
* @param o the object to prune
* @param d the current most significant dimension
+ * @param currentShape the shape of the object
* @param limit stop pruning if going beyond this value
* @return the bound found if there is one, and Constants.MinInt if there is no feasible placement.
*/
@@ -1492,7 +1494,7 @@ protected void updateInternalConstraintsGeneratingOutboxes(GeostObject o) {
/**
* It does the processing needed given the set of variables that was updated
* between two consecutive calls to the consistency function.
- * @param variables
+ * @param variables variables in the queue
*/
protected void flushQueue(Collection variables){
@@ -1635,16 +1637,6 @@ public int getConsistencyPruningEvent(Var var) {
}
- @Override
- public String id() {
-
- if (id != null)
- return id;
- else
- return this.getClass().getSimpleName() + numberId;
-
- }
-
@Override
public void impose(Store store) {
diff --git a/src/main/java/org/jacop/constraints/geost/GeostObject.java b/src/main/java/org/jacop/constraints/geost/GeostObject.java
index 925ed9711..50261670c 100644
--- a/src/main/java/org/jacop/constraints/geost/GeostObject.java
+++ b/src/main/java/org/jacop/constraints/geost/GeostObject.java
@@ -126,7 +126,7 @@ public class GeostObject {
* @param shapeID the variable specifying the shape finite domain variable.
* @param start it determines the start time of the geost object in terms of time.
* @param duration finite domain variable specifying the duration of the geost object in terms of time.
- * @param end
+ * @param end finite domain variable specifying the end of the geost object in terms of time.
*/
public GeostObject(int no, IntVar[] coords, IntVar shapeID, IntVar start,
IntVar duration, IntVar end) {
@@ -231,7 +231,7 @@ public TimeBoundConstraint() {
/**
* It evaluates part of the constraint that ensures that start + duration = end
- * @param store
+ * @param store current store
* @return true if some variable was changed, false otherwise
*/
public boolean consistencyStartPlusDurationEqEnd(Store store) {
@@ -274,7 +274,7 @@ public boolean consistencyStartPlusDurationEqEnd(Store store) {
}
/**
- * It applies constraint enforcing that duration > 0
+ * It applies constraint enforcing that duration {@literal >} 0
*
* @param store constraint store in which the geost constraint is imposed at.
* @return true if a variable was updated, false otherwise
diff --git a/src/main/java/org/jacop/constraints/geost/LexicographicalOrder.java b/src/main/java/org/jacop/constraints/geost/LexicographicalOrder.java
index 99a4dba51..bc76e545a 100644
--- a/src/main/java/org/jacop/constraints/geost/LexicographicalOrder.java
+++ b/src/main/java/org/jacop/constraints/geost/LexicographicalOrder.java
@@ -42,8 +42,8 @@ public interface LexicographicalOrder {
/**
* It compares two k-dimensional points.
*
- * @param p1
- * @param p2
+ * @param p1 point 1
+ * @param p2 point 2
* @return comparison result: a negative value if p1 is smaller than p2,
* 0 if p1 is equal to p2, and a positive value if p1 is larger than p2.
*/
@@ -52,7 +52,7 @@ public interface LexicographicalOrder {
/**
* It provides the precedence level of the given dimension. 0 is the most significant.
*
- * @param dimension
+ * @param dimension the given dimension
* @return integer value of the precedence level.
*/
public int precedenceOf(int dimension);
@@ -60,7 +60,7 @@ public interface LexicographicalOrder {
/**
* It provides the dimension corresponding to the given precedence level
*
- * @param precedenceLevel
+ * @param precedenceLevel the given precedence level
* @return an integer value of the dimension.
*/
public int dimensionAt(int precedenceLevel);
diff --git a/src/main/java/org/jacop/constraints/geost/PredefinedOrder.java b/src/main/java/org/jacop/constraints/geost/PredefinedOrder.java
index d3f9c1e9f..7479de2b9 100644
--- a/src/main/java/org/jacop/constraints/geost/PredefinedOrder.java
+++ b/src/main/java/org/jacop/constraints/geost/PredefinedOrder.java
@@ -70,7 +70,7 @@ public class PredefinedOrder implements LexicographicalOrder {
* the dimension ordering and the most significant dimension.
*
* @param ordering how dimensions are stored within each compared point.
- * @param mostSignificantDimension
+ * @param mostSignificantDimension the most significant dimension
*/
public PredefinedOrder(int[] ordering, int mostSignificantDimension) {
diff --git a/src/main/java/org/jacop/constraints/knapsack/Knapsack.java b/src/main/java/org/jacop/constraints/knapsack/Knapsack.java
index ff2ecc72d..67846c9e9 100644
--- a/src/main/java/org/jacop/constraints/knapsack/Knapsack.java
+++ b/src/main/java/org/jacop/constraints/knapsack/Knapsack.java
@@ -262,7 +262,7 @@ public Knapsack(KnapsackItem[] items, IntVar knapsackCapacity, IntVar knapsackPr
* @param weights the list of weights, each for the corresponding item no.
* @param quantity finite domain variable specifying allowed values for the vars.
* @param knapsackCapacity finite domain variable specifying the capacity limit of the knapsack.
- * @param knapsackProfit
+ * @param knapsackProfit finite domain variable defining the profit
*/
public Knapsack(int[] profits,
int[] weights,
@@ -873,14 +873,6 @@ public int getConsistencyPruningEvent(Var var) {
return IntDomain.BOUND;
}
- @Override
- public String id() {
- if (id != null)
- return id;
- else
- return this.getClass().getSimpleName() + numberId;
- }
-
@Override
public void removeConstraint() {
for (TreeLeaf leaf : leaves)
diff --git a/src/main/java/org/jacop/constraints/knapsack/Tree.java b/src/main/java/org/jacop/constraints/knapsack/Tree.java
index dd549afab..a69aa04c9 100644
--- a/src/main/java/org/jacop/constraints/knapsack/Tree.java
+++ b/src/main/java/org/jacop/constraints/knapsack/Tree.java
@@ -122,7 +122,7 @@ public Tree(TreeNode node) {
/**
* It creates a tree by making a shallow copy.
- * @param tree
+ * @param tree tree to be constructed
*/
public Tree(Tree tree) {
this.root = tree.root;
diff --git a/src/main/java/org/jacop/constraints/netflow/ArcCompanion.java b/src/main/java/org/jacop/constraints/netflow/ArcCompanion.java
index 2f0083aef..05539b8e4 100644
--- a/src/main/java/org/jacop/constraints/netflow/ArcCompanion.java
+++ b/src/main/java/org/jacop/constraints/netflow/ArcCompanion.java
@@ -53,7 +53,7 @@
* also provides a hook for S-variables of any
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/netflow/Arithmetic.java b/src/main/java/org/jacop/constraints/netflow/Arithmetic.java
index d49a256e0..3d5be1602 100644
--- a/src/main/java/org/jacop/constraints/netflow/Arithmetic.java
+++ b/src/main/java/org/jacop/constraints/netflow/Arithmetic.java
@@ -39,7 +39,7 @@
import org.jacop.constraints.Constraint;
import org.jacop.constraints.DecomposedConstraint;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.netflow.simplex.Node;
import org.jacop.core.IntVar;
import org.jacop.core.Store;
@@ -47,7 +47,7 @@
/**
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
@@ -137,7 +137,7 @@ public ArrayList primitiveDecomposition(Store store) {
decomposition = new ArrayList();
- final IntVar ZERO = new IntVar(store, "Zero", 0, 0);
+ // final IntVar ZERO = new IntVar(store, "Zero", 0, 0);
for (int[] eqn : eqns) {
ArrayList variables = new ArrayList();
@@ -149,7 +149,9 @@ public ArrayList primitiveDecomposition(Store store) {
weights.add(eqn[i]);
}
- decomposition.add(new SumWeight(variables, weights, ZERO));
+
+ decomposition.add(new LinearInt(store, variables, weights, "==", 0));
+ // decomposition.add(new SumWeight(variables, weights, ZERO));
}
return decomposition;
@@ -158,7 +160,7 @@ public ArrayList primitiveDecomposition(Store store) {
ArrayList result = new ArrayList();
- final IntVar ZERO = new IntVar(store, "Zero", 0, 0);
+ // final IntVar ZERO = new IntVar(store, "Zero", 0, 0);
for (int[] eqn : eqns) {
ArrayList variables = new ArrayList();
@@ -170,7 +172,8 @@ public ArrayList primitiveDecomposition(Store store) {
weights.add(eqn[i]);
}
- result.add(new SumWeight(variables, weights, ZERO));
+ result.add(new LinearInt(store, variables, weights, "==", 0));
+ // result.add(new SumWeight(variables, weights, ZERO));
}
return result;
diff --git a/src/main/java/org/jacop/constraints/netflow/Assert.java b/src/main/java/org/jacop/constraints/netflow/Assert.java
index d69c8a5c4..0e3288bb8 100644
--- a/src/main/java/org/jacop/constraints/netflow/Assert.java
+++ b/src/main/java/org/jacop/constraints/netflow/Assert.java
@@ -42,7 +42,7 @@
/**
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/netflow/DomainStructure.java b/src/main/java/org/jacop/constraints/netflow/DomainStructure.java
index c017e9d27..458041e85 100644
--- a/src/main/java/org/jacop/constraints/netflow/DomainStructure.java
+++ b/src/main/java/org/jacop/constraints/netflow/DomainStructure.java
@@ -51,7 +51,7 @@
* sub-domain and it is inactive otherwise.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
@@ -75,9 +75,9 @@ public enum Behavior {
/**
* Creates an S-variable
*
- * @param variable
- * @param domList
- * @param arcList
+ * @param variable variable to create for
+ * @param domList list of domains
+ * @param arcList list of arcs
*/
public DomainStructure(IntVar variable, List domList, List arcList) {
diff --git a/src/main/java/org/jacop/constraints/netflow/MultiVarHandler.java b/src/main/java/org/jacop/constraints/netflow/MultiVarHandler.java
index 25be7fa54..ba8d0bbff 100644
--- a/src/main/java/org/jacop/constraints/netflow/MultiVarHandler.java
+++ b/src/main/java/org/jacop/constraints/netflow/MultiVarHandler.java
@@ -44,7 +44,7 @@
/**
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/netflow/MutableNetwork.java b/src/main/java/org/jacop/constraints/netflow/MutableNetwork.java
index 0ca533dd1..74e278bac 100644
--- a/src/main/java/org/jacop/constraints/netflow/MutableNetwork.java
+++ b/src/main/java/org/jacop/constraints/netflow/MutableNetwork.java
@@ -37,7 +37,7 @@
* Interface to the network used by VarHandlers.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/netflow/Network.java b/src/main/java/org/jacop/constraints/netflow/Network.java
index 4c4773a75..958b3bb88 100644
--- a/src/main/java/org/jacop/constraints/netflow/Network.java
+++ b/src/main/java/org/jacop/constraints/netflow/Network.java
@@ -51,7 +51,7 @@
* data structures for removal and modification of arcs.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/netflow/NetworkBuilder.java b/src/main/java/org/jacop/constraints/netflow/NetworkBuilder.java
index 41cc4ee10..49a9e5c4d 100644
--- a/src/main/java/org/jacop/constraints/netflow/NetworkBuilder.java
+++ b/src/main/java/org/jacop/constraints/netflow/NetworkBuilder.java
@@ -38,8 +38,8 @@
import org.jacop.constraints.Eq;
import org.jacop.constraints.In;
import org.jacop.constraints.Not;
-import org.jacop.constraints.Sum;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.SumInt;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XeqY;
import org.jacop.constraints.XmulYeqZ;
@@ -56,7 +56,7 @@
* inherit from this class to build a network.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
@@ -172,6 +172,11 @@ public Arc addArc(Node from, Node to) {
/**
* Returns two arrays containing the nodes for each variable and the nodes
* for each domain, respectively.
+ *
+ * @param vars varibales for nodes
+ * @param domains nodes for each variable
+ * @return two arrays containing the nodes for each variable and the nodes
+ * for each domain, respectively
*/
public Node[][] valueGraph(IntVar[] vars, IntDomain[] domains) {
@@ -232,7 +237,8 @@ public NetworkFlow build() {
* solutions is not practically achievable in all cases it is possible
* that decomposition will have more solutions due to the fact that
* decomposition may use more expensive arcs to transfer the flow.
- * @param store
+ * @param store current store
+ * @return decomposed network using primitive constraints
*/
public ArrayList primitiveDecomposition(Store store) {
@@ -337,9 +343,19 @@ public ArrayList primitiveDecomposition(Store store) {
// @TODO, SumWeight could be used instead of Sum and auxiliary variables weight above.
if (simpleSum)
sumC(result, store, vars, costVariable);
- else
- result.add(new SumWeight(vars, weights, costVariable));
-
+ else {
+ int n = vars.size();
+ IntVar[] vs = new IntVar[n + 1];
+ int[] ws = new int[n + 1];
+ for (int i = 0; i < n; i++) {
+ vs[i] = vars.get(i);
+ ws[i] = weights.get(i);
+ }
+ vs[n] = costVariable;
+ ws[n] = -1;
+ result.add(new LinearInt(store, vs, ws, "==", 0));
+ // result.add(new SumWeight(vars, weights, costVariable)); deprecated
+ }
return result;
}
@@ -354,7 +370,8 @@ private void sumC(ArrayList list, Store store, ArrayList var
} else if (vars.size() == 1) {
list.add(new XeqY(result, vars.iterator().next()));
} else {
- list.add(new Sum(vars, result));
+ list.add(new SumInt(store, vars, "==", result));
+ // list.add(new Sum(vars, result)); deprecated
}
}
diff --git a/src/main/java/org/jacop/constraints/netflow/NetworkFlow.java b/src/main/java/org/jacop/constraints/netflow/NetworkFlow.java
index ca806343e..f40187d94 100644
--- a/src/main/java/org/jacop/constraints/netflow/NetworkFlow.java
+++ b/src/main/java/org/jacop/constraints/netflow/NetworkFlow.java
@@ -54,7 +54,7 @@
* instantiate the network.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
@@ -160,7 +160,7 @@ public void impose(Store store) {
}
/***************************/
- /** Search & Backtracking **/
+ /** Search {@literal &} Backtracking **/
@Override
public void queueVariable(int level, Var variable) {
diff --git a/src/main/java/org/jacop/constraints/netflow/Pruning.java b/src/main/java/org/jacop/constraints/netflow/Pruning.java
index e25d23097..5cc81e178 100644
--- a/src/main/java/org/jacop/constraints/netflow/Pruning.java
+++ b/src/main/java/org/jacop/constraints/netflow/Pruning.java
@@ -50,7 +50,7 @@
/**
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/netflow/Statistics.java b/src/main/java/org/jacop/constraints/netflow/Statistics.java
index f7a6e59d1..330b02574 100644
--- a/src/main/java/org/jacop/constraints/netflow/Statistics.java
+++ b/src/main/java/org/jacop/constraints/netflow/Statistics.java
@@ -38,7 +38,7 @@
* This class stores all the statistics gather during the execution of the network flow constraint.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/netflow/VarHandler.java b/src/main/java/org/jacop/constraints/netflow/VarHandler.java
index 46203feab..6014839be 100644
--- a/src/main/java/org/jacop/constraints/netflow/VarHandler.java
+++ b/src/main/java/org/jacop/constraints/netflow/VarHandler.java
@@ -43,7 +43,7 @@
* network flow constraint.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public interface VarHandler {
diff --git a/src/main/java/org/jacop/constraints/netflow/simplex/Arc.java b/src/main/java/org/jacop/constraints/netflow/simplex/Arc.java
index d2e7b85bb..39dd42fbc 100644
--- a/src/main/java/org/jacop/constraints/netflow/simplex/Arc.java
+++ b/src/main/java/org/jacop/constraints/netflow/simplex/Arc.java
@@ -38,7 +38,7 @@
* A directed, residual arc in the graph.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
@@ -165,8 +165,8 @@ public boolean isInCut(boolean forward) {
/**
* Initializes an artificial arc
*
- * @param newCost
- * @param newCapacity
+ * @param newCost new cost for the arc
+ * @param newCapacity new capacity for the arc
*/
public void set(int newCost, int newCapacity) {
diff --git a/src/main/java/org/jacop/constraints/netflow/simplex/Danzig.java b/src/main/java/org/jacop/constraints/netflow/simplex/Danzig.java
index 5c628c602..5581ec7b9 100644
--- a/src/main/java/org/jacop/constraints/netflow/simplex/Danzig.java
+++ b/src/main/java/org/jacop/constraints/netflow/simplex/Danzig.java
@@ -37,7 +37,7 @@
* might be large.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/netflow/simplex/NetworkSimplex.java b/src/main/java/org/jacop/constraints/netflow/simplex/NetworkSimplex.java
index 6fb5fe65d..27e151ec3 100644
--- a/src/main/java/org/jacop/constraints/netflow/simplex/NetworkSimplex.java
+++ b/src/main/java/org/jacop/constraints/netflow/simplex/NetworkSimplex.java
@@ -49,7 +49,7 @@
/**
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
@@ -202,7 +202,9 @@ private void decrementDegree(Node node) {
/******************/
/** Graph update **/
-
+ /**
+ * @param arc the network arc being added
+ */
protected void addArc(Arc arc) {
assert (arc.index == DELETED_ARC) : arc;
int index = numArcs++;
@@ -277,7 +279,7 @@ public void removeArc(Arc arc) {
/**
*
- * @param maxPivots
+ * @param maxPivots max value of the pivot
* @return the number of pivots performed until optimality was reached, or
* -1 if the maximum number of pivots was reached.
*/
@@ -600,9 +602,9 @@ public void treeSwap(Node a, Node b, Node c) {
* detected due to the fact that we have 'artificial' arcs going to the
* root.
*
- * @param source
- * @param sink
- * @param balance
+ * @param source source node
+ * @param sink sink node
+ * @param balance difference between in flow and out flow
* the flow to send from the source to the sink
* @param maxPivots
* limits the number of dual pivots
diff --git a/src/main/java/org/jacop/constraints/netflow/simplex/Node.java b/src/main/java/org/jacop/constraints/netflow/simplex/Node.java
index 21310458d..47c6062ec 100644
--- a/src/main/java/org/jacop/constraints/netflow/simplex/Node.java
+++ b/src/main/java/org/jacop/constraints/netflow/simplex/Node.java
@@ -1,175 +1,175 @@
-/**
- * Node.java
- * This file is part of JaCoP.
- *
- * JaCoP is a Java Constraint Programming solver.
- *
- * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * Notwithstanding any other provision of this License, the copyright
- * owners of this work supplement the terms of this License with terms
- * prohibiting misrepresentation of the origin of this work and requiring
- * that modified versions of this work be marked in reasonable ways as
- * different from the original version. This supplement of the license
- * terms is in accordance with Section 7 of GNU Affero General Public
- * License version 3.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-package org.jacop.constraints.netflow.simplex;
-
-/**
- * A node (vertex) in the network.
- *
- * @author Robin Steiger and Radoslaw Szymanek
- * @version 4.2
- *
- */
-
-public final class Node {
-
- /** for debug only */
- public final int initialBalance;
-
- /** a label, great for debugging */
- public final String name;
-
- /** the potential (or dual variable) of the network simplex */
- public int potential;
-
- /** balance of the last feasible flow */
- public int balance;
-
- /** change in balance for the next flow computation */
- public int deltaBalance;
-
- /** connects this node to the root */
- public Arc artificial;
-
- // we use the parent-thread-depth data structure to store the spanning tree
- public Arc toParent;
- public Node parent; // TODO useful (?) redundancy: parent == toParent.head
- public Node thread;
- public int depth;
-
- /** marks the cut (S,T) for dual pivot */
- boolean marked;
-
- /** number of connected arcs */
- public int degree;
-
- /** adjacency list (recorded when degree reaches 2) */
- public Arc[] adjacencyList;
-
- public Node(String name, int balance) {
- this.name = name;
- this.balance = 0;
- this.deltaBalance = balance;
- this.initialBalance = balance;
- this.degree = 0;
- this.adjacencyList = new Arc[2];
- }
-
- /**
- * Finds the root of the smallest subtree that contains both this node and
- * that node.
- *
- * @param that
- * another node
- * @return the least common ancestor of this & that
- */
- public Node lca(Node that) {
- Node i = this;
- Node j = that;
- while (i != j) {
- int delta = i.depth - j.depth;
- if (delta >= 0)
- i = i.parent;
- if (delta <= 0)
- j = j.parent;
- }
- return i;
- }
-
- /**
- * Finds the last node on the thread that has a larger depth than this node.
- * Note that if this node is a leaf node then 'this' is returned.
- *
- * @return the last node on the thread that is in the subtree of this node
- */
- public Node rightMostLeaf() {
- Node i = this;
- while (i.thread.depth > depth)
- i = i.thread;
- return i;
- }
-
- /**
- * Finds the predecessor of this node on the thread. It uses the parent node
- * as starting point of the search. (Hence, this method cannot be invoked on
- * the root)
- *
- * @return the node i with i.thread == this
- */
- public Node predecessorOnThread() {
- Node i = parent;
- while (i.thread != this)
- i = i.thread;
- return i;
- }
-
- /**
- * Sets or clears a mark on a subtree rooted at this node
- *
- * @param setMark
- * whether to set or clear the mark
- */
- public void markTree(boolean setMark) {
- Node i = this;
- do {
- i.marked = setMark;
- i = i.thread;
- } while (i.depth > depth);
- }
-
- /**
- * Recomputes the potential & depth values in the subtree rooted at this
- * node.
- */
- void computePotentials() {
- for (Node i = thread; true; i = i.thread) {
- // the depth value of i might be wrong so we use its parent's depth
- Node j = i.parent;
- if (j == null || j.depth < depth)
- break;
-
- // arc from i to j
- // c_ij^pi = 0 implies that pi_i = c_ij + pi_j
- Arc ij = i.toParent;
- i.depth = j.depth + 1;
- i.potential = ij.cost + j.potential;
- }
- }
-
- // a string representation of the state
- public String toString() {
- // TODO only for debugging, otherwise we would use StringBuilder
- return "[node: " + name + ", balance=" + balance + ", delta="
- + deltaBalance + ", potential=" + potential + ", depth="
- + depth + ", parent=" + (parent == null ? null : parent.name)
- + ", thread=" + (thread == null ? null : thread.name) + "]";
- }
-}
+/**
+ * Node.java
+ * This file is part of JaCoP.
+ *
+ * JaCoP is a Java Constraint Programming solver.
+ *
+ * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * Notwithstanding any other provision of this License, the copyright
+ * owners of this work supplement the terms of this License with terms
+ * prohibiting misrepresentation of the origin of this work and requiring
+ * that modified versions of this work be marked in reasonable ways as
+ * different from the original version. This supplement of the license
+ * terms is in accordance with Section 7 of GNU Affero General Public
+ * License version 3.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package org.jacop.constraints.netflow.simplex;
+
+/**
+ * A node (vertex) in the network.
+ *
+ * @author Robin Steiger and Radoslaw Szymanek
+ * @version 4.2
+ *
+ */
+
+public final class Node {
+
+ /** for debug only */
+ public final int initialBalance;
+
+ /** a label, great for debugging */
+ public final String name;
+
+ /** the potential (or dual variable) of the network simplex */
+ public int potential;
+
+ /** balance of the last feasible flow */
+ public int balance;
+
+ /** change in balance for the next flow computation */
+ public int deltaBalance;
+
+ /** connects this node to the root */
+ public Arc artificial;
+
+ // we use the parent-thread-depth data structure to store the spanning tree
+ public Arc toParent;
+ public Node parent; // TODO useful (?) redundancy: parent == toParent.head
+ public Node thread;
+ public int depth;
+
+ /** marks the cut (S,T) for dual pivot */
+ boolean marked;
+
+ /** number of connected arcs */
+ public int degree;
+
+ /** adjacency list (recorded when degree reaches 2) */
+ public Arc[] adjacencyList;
+
+ public Node(String name, int balance) {
+ this.name = name;
+ this.balance = 0;
+ this.deltaBalance = balance;
+ this.initialBalance = balance;
+ this.degree = 0;
+ this.adjacencyList = new Arc[2];
+ }
+
+ /**
+ * Finds the root of the smallest subtree that contains both this node and
+ * that node.
+ *
+ * @param that
+ * another node
+ * @return the least common ancestor of this {@literal &} that
+ */
+ public Node lca(Node that) {
+ Node i = this;
+ Node j = that;
+ while (i != j) {
+ int delta = i.depth - j.depth;
+ if (delta >= 0)
+ i = i.parent;
+ if (delta <= 0)
+ j = j.parent;
+ }
+ return i;
+ }
+
+ /**
+ * Finds the last node on the thread that has a larger depth than this node.
+ * Note that if this node is a leaf node then 'this' is returned.
+ *
+ * @return the last node on the thread that is in the subtree of this node
+ */
+ public Node rightMostLeaf() {
+ Node i = this;
+ while (i.thread.depth > depth)
+ i = i.thread;
+ return i;
+ }
+
+ /**
+ * Finds the predecessor of this node on the thread. It uses the parent node
+ * as starting point of the search. (Hence, this method cannot be invoked on
+ * the root)
+ *
+ * @return the node i with i.thread == this
+ */
+ public Node predecessorOnThread() {
+ Node i = parent;
+ while (i.thread != this)
+ i = i.thread;
+ return i;
+ }
+
+ /**
+ * Sets or clears a mark on a subtree rooted at this node
+ *
+ * @param setMark
+ * whether to set or clear the mark
+ */
+ public void markTree(boolean setMark) {
+ Node i = this;
+ do {
+ i.marked = setMark;
+ i = i.thread;
+ } while (i.depth > depth);
+ }
+
+ /**
+ * Recomputes the potential & depth values in the subtree rooted at this
+ * node.
+ */
+ void computePotentials() {
+ for (Node i = thread; true; i = i.thread) {
+ // the depth value of i might be wrong so we use its parent's depth
+ Node j = i.parent;
+ if (j == null || j.depth < depth)
+ break;
+
+ // arc from i to j
+ // c_ij^pi = 0 implies that pi_i = c_ij + pi_j
+ Arc ij = i.toParent;
+ i.depth = j.depth + 1;
+ i.potential = ij.cost + j.potential;
+ }
+ }
+
+ // a string representation of the state
+ public String toString() {
+ // TODO only for debugging, otherwise we would use StringBuilder
+ return "[node: " + name + ", balance=" + balance + ", delta="
+ + deltaBalance + ", potential=" + potential + ", depth="
+ + depth + ", parent=" + (parent == null ? null : parent.name)
+ + ", thread=" + (thread == null ? null : thread.name) + "]";
+ }
+}
diff --git a/src/main/java/org/jacop/constraints/netflow/simplex/PivotRule.java b/src/main/java/org/jacop/constraints/netflow/simplex/PivotRule.java
index 1d2426830..1df260734 100644
--- a/src/main/java/org/jacop/constraints/netflow/simplex/PivotRule.java
+++ b/src/main/java/org/jacop/constraints/netflow/simplex/PivotRule.java
@@ -35,7 +35,7 @@
* A pivot selection rule for the primal network simplex algorithm.
*
* @author Robin Steiger and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/constraints/regular/RegEdge.java b/src/main/java/org/jacop/constraints/regular/RegEdge.java
index 86760c74a..f414f07c9 100644
--- a/src/main/java/org/jacop/constraints/regular/RegEdge.java
+++ b/src/main/java/org/jacop/constraints/regular/RegEdge.java
@@ -40,7 +40,7 @@
* of Regular constraint.
*
* @author Polina Makeeva and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class RegEdge {
diff --git a/src/main/java/org/jacop/constraints/regular/RegState.java b/src/main/java/org/jacop/constraints/regular/RegState.java
index d2b6a2384..a2087961c 100644
--- a/src/main/java/org/jacop/constraints/regular/RegState.java
+++ b/src/main/java/org/jacop/constraints/regular/RegState.java
@@ -43,7 +43,7 @@
* within Regular constraint.
*
* @author Polina Makeeva and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public abstract class RegState {
diff --git a/src/main/java/org/jacop/constraints/regular/RegStateDom.java b/src/main/java/org/jacop/constraints/regular/RegStateDom.java
index 4f85a4712..ca7161f23 100644
--- a/src/main/java/org/jacop/constraints/regular/RegStateDom.java
+++ b/src/main/java/org/jacop/constraints/regular/RegStateDom.java
@@ -45,7 +45,7 @@
* to the given successor state.
*
* @author Polina Makeeva and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class RegStateDom extends RegState {
diff --git a/src/main/java/org/jacop/constraints/regular/RegStateInt.java b/src/main/java/org/jacop/constraints/regular/RegStateInt.java
index 5c7423a43..50d4f127c 100644
--- a/src/main/java/org/jacop/constraints/regular/RegStateInt.java
+++ b/src/main/java/org/jacop/constraints/regular/RegStateInt.java
@@ -45,7 +45,7 @@
* same successor.
*
* @author Polina Makeeva and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class RegStateInt extends RegState {
diff --git a/src/main/java/org/jacop/constraints/regular/Regular.java b/src/main/java/org/jacop/constraints/regular/Regular.java
index ddd1dc9e1..9a74d31cc 100644
--- a/src/main/java/org/jacop/constraints/regular/Regular.java
+++ b/src/main/java/org/jacop/constraints/regular/Regular.java
@@ -142,7 +142,7 @@
* backtracking) to improve the constraint further.
*
* @author Polina Makeeva and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Regular extends Constraint {
@@ -665,7 +665,7 @@ public int unreachBackwardLoop(int sucPrevLimit, int level) {
/**
* Forward part deletes the outgoing edges of the damaged state and watch whether
- * the successors are still active (in-degree > 0 ), otherwise we collect it and
+ * the successors are still active (in-degree {@literal >} 0 ), otherwise we collect it and
* continue the loop.
*
* TODO return value is not used.
@@ -1088,7 +1088,11 @@ public void impose(Store store) {
for (int i = list.length - 1; i >= 0; i--) {
list[i].putConstraint(this);
- mapping.put(list[i], i);
+ Integer varPosition = mapping.put(list[i], i);
+ if (!list[i].singleton() && varPosition != null) {
+ System.err.println("ERROR: Constraint " + toString() + " must have different variables on the list");
+ System.exit(0);
+ }
}
store.addChanged(this);
@@ -1160,15 +1164,6 @@ public int getConsistencyPruningEvent(Var var) {
return IntDomain.ANY;
}
- @Override
- public String id() {
- if (id != null)
- return id;
- else
- return this.getClass().getSimpleName() + numberId;
- }
-
-
@Override
public void removeConstraint() {
for (Var var : list)
@@ -1340,7 +1335,7 @@ else if (curState.isActive(activeLevels))
/**
* It saves the constraint latex description into file.
- * @param desc
+ * @param desc description of the constraint
*/
public void saveLatexToFile(String desc) {
String fileName = this.latexFile + (calls++)+".tex";
@@ -1363,7 +1358,7 @@ public void saveLatexToFile(String desc) {
/**
* It sets the filename for the file which is used to save latex descriptions.
- * @param filename
+ * @param filename the name of the file
*/
public void setLatexBaseFileName(String filename) {
this.latexFile = filename;
diff --git a/src/main/java/org/jacop/core/BooleanVar.java b/src/main/java/org/jacop/core/BooleanVar.java
index bbd017233..e94480b02 100644
--- a/src/main/java/org/jacop/core/BooleanVar.java
+++ b/src/main/java/org/jacop/core/BooleanVar.java
@@ -39,7 +39,7 @@
* Defines a variable and related operations on it.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class BooleanVar extends IntVar {
diff --git a/src/main/java/org/jacop/core/BoundDomain.java b/src/main/java/org/jacop/core/BoundDomain.java
index e83441fb2..6663e0136 100644
--- a/src/main/java/org/jacop/core/BoundDomain.java
+++ b/src/main/java/org/jacop/core/BoundDomain.java
@@ -43,7 +43,7 @@
*
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class BoundDomain extends IntDomain {
@@ -98,7 +98,7 @@ public BoundDomain(int min, int max) {
/**
- * @param i
+ * @param i interval for union operation
*
*/
@Override
diff --git a/src/main/java/org/jacop/core/BoundDomainIntervalEnumeration.java b/src/main/java/org/jacop/core/BoundDomainIntervalEnumeration.java
index a4550e0ab..d3ce288b5 100644
--- a/src/main/java/org/jacop/core/BoundDomainIntervalEnumeration.java
+++ b/src/main/java/org/jacop/core/BoundDomainIntervalEnumeration.java
@@ -39,7 +39,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class BoundDomainIntervalEnumeration extends IntervalEnumeration {
diff --git a/src/main/java/org/jacop/core/BoundDomainValueEnumeration.java b/src/main/java/org/jacop/core/BoundDomainValueEnumeration.java
index 3166439de..fe9e30b0d 100644
--- a/src/main/java/org/jacop/core/BoundDomainValueEnumeration.java
+++ b/src/main/java/org/jacop/core/BoundDomainValueEnumeration.java
@@ -35,7 +35,7 @@
* Defines a methods for enumerating values contained in the BoundDomain.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class BoundDomainValueEnumeration extends ValueEnumeration {
diff --git a/src/main/java/org/jacop/core/Domain.java b/src/main/java/org/jacop/core/Domain.java
index 4268fa7d4..05d0f1c2a 100644
--- a/src/main/java/org/jacop/core/Domain.java
+++ b/src/main/java/org/jacop/core/Domain.java
@@ -39,7 +39,7 @@
* Defines a Domain and related operations on it.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public abstract class Domain {
diff --git a/src/main/java/org/jacop/core/IntDomain.java b/src/main/java/org/jacop/core/IntDomain.java
index a2cc91eb4..c6d53d60e 100644
--- a/src/main/java/org/jacop/core/IntDomain.java
+++ b/src/main/java/org/jacop/core/IntDomain.java
@@ -1268,27 +1268,27 @@ public int getRandomValue() {
/*
* Finds result interval for multiplication of {a..b} * {c..d}
*/
- public final static IntervalDomain mulBounds(int a, int b, int c, int d) {
+ public final static Interval mulBounds(int a, int b, int c, int d) {
int min = Math.min(Math.min(multiply(a,c),multiply(a,d)), Math.min(multiply(b,c),multiply(b,d)));
int max = Math.max(Math.max(multiply(a,c),multiply(a,d)), Math.max(multiply(b,c),multiply(b,d)));
- return new IntervalDomain(min, max);
+ return new Interval(min, max);
}
/*
* Finds result interval for division of {a..b} / {c..d} for div and mod constraints
*/
- public final static IntervalDomain divBounds (int a, int b, int c, int d) {
+ public final static Interval divBounds (int a, int b, int c, int d) {
int min=0, max=0;
- IntervalDomain result = null;
+ Interval result = null;
if (a <= 0 && b >= 0 && c <= 0 && d >= 0) { // case 1
min = IntDomain.MinInt;
max = IntDomain.MaxInt;
- result = new IntervalDomain(min, max);
+ result = new Interval(min, max);
}
else if (c == 0 && d == 0 && (a > 0 || b < 0)) // case 2
@@ -1297,7 +1297,7 @@ else if (c == 0 && d == 0 && (a > 0 || b < 0)) // case 2
else if ( c < 0 && d > 0 && (a > 0 || b < 0)) { // case 3
max = Math.max(Math.abs(a), Math.abs(b));
min = -max;
- result = new IntervalDomain(min, max);
+ result = new Interval(min, max);
}
else if (c == 0 && d != 0 && (a > 0 || b < 0)) // case 4 a
@@ -1309,7 +1309,7 @@ else if (c != 0 && d == 0 && (a > 0 || b < 0)) // case 4 b
int ac = a/c, ad = a/d, bc = b/c, bd =b/d;
min = Math.min(Math.min(ac, ad), Math.min(bc, bd));
max = Math.max(Math.max(ac, ad), Math.max(bc, bd));
- result = new IntervalDomain(min, max);
+ result = new Interval(min, max);
}
return result;
@@ -1318,15 +1318,15 @@ else if (c != 0 && d == 0 && (a > 0 || b < 0)) // case 4 b
/*
* Finds result interval for division of {a..b} / {c..d} for mul constraints
*/
- public final static IntervalDomain divIntBounds (int a, int b, int c, int d) {
+ public final static Interval divIntBounds (int a, int b, int c, int d) {
int min=0, max=0;
- IntervalDomain result=null;
+ Interval result=null;
if (a <= 0 && b >= 0 && c <= 0 && d >= 0) { // case 1
min = IntDomain.MinInt;
max = IntDomain.MaxInt;
- result = new IntervalDomain(min, max);
+ result = new Interval(min, max);
}
else if (c == 0 && d == 0 && (a > 0 || b < 0)) // case 2
@@ -1335,7 +1335,7 @@ else if (c == 0 && d == 0 && (a > 0 || b < 0)) // case 2
else if ( c < 0 && d > 0 && (a > 0 || b < 0)) { // case 3
max = Math.max(Math.abs(a), Math.abs(b));
min = -max;
- result = new IntervalDomain(min, max);
+ result = new Interval(min, max);
}
else if (c == 0 && d != 0 && (a > 0 || b < 0)) // case 4 a
@@ -1351,7 +1351,7 @@ else if (c != 0 && d == 0 && (a > 0 || b < 0)) // case 4 b
min = (int)Math.round( Math.ceil( low ) );
max = (int)Math.round( Math.floor( high ));
if (min > max) throw Store.failException;
- result = new IntervalDomain(min, max);
+ result = new Interval(min, max);
}
return result;
diff --git a/src/main/java/org/jacop/core/IntVar.java b/src/main/java/org/jacop/core/IntVar.java
index ef3a180c5..1af980207 100644
--- a/src/main/java/org/jacop/core/IntVar.java
+++ b/src/main/java/org/jacop/core/IntVar.java
@@ -41,7 +41,7 @@
* Defines a Finite Domain Variable (FDV) and related operations on it.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class IntVar extends Var {
diff --git a/src/main/java/org/jacop/core/Interval.java b/src/main/java/org/jacop/core/Interval.java
index 23dad7836..bc5c7f1d6 100644
--- a/src/main/java/org/jacop/core/Interval.java
+++ b/src/main/java/org/jacop/core/Interval.java
@@ -37,7 +37,7 @@
*
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public final class Interval {
diff --git a/src/main/java/org/jacop/core/IntervalDomain.java b/src/main/java/org/jacop/core/IntervalDomain.java
index c1b5a8e45..895942e65 100644
--- a/src/main/java/org/jacop/core/IntervalDomain.java
+++ b/src/main/java/org/jacop/core/IntervalDomain.java
@@ -50,7 +50,7 @@
*
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class IntervalDomain extends IntDomain {
@@ -94,7 +94,7 @@ public IntervalDomain() {
* specified in xmlAttributes.
*
* @param tf a place to write the content of the object.
- * @throws SAXException
+ * @throws SAXException exception from package org.xml.sax
*/
public void toXML(TransformerHandler tf) throws SAXException {
@@ -240,8 +240,8 @@ public void unionAdapt(Interval i) {
/**
* It adds a value to the domain. It adds at the end without
* checks for the correctness of domain representation.
+ * @param i the element to be added as the lase element of the domain
*/
-
public void addLastElement(int i) {
assert checkInvariants() == null : checkInvariants() ;
diff --git a/src/main/java/org/jacop/core/IntervalDomainIntervalEnumeration.java b/src/main/java/org/jacop/core/IntervalDomainIntervalEnumeration.java
index 1ba81ea64..3fb243ec5 100644
--- a/src/main/java/org/jacop/core/IntervalDomainIntervalEnumeration.java
+++ b/src/main/java/org/jacop/core/IntervalDomainIntervalEnumeration.java
@@ -38,7 +38,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class IntervalDomainIntervalEnumeration extends IntervalEnumeration {
diff --git a/src/main/java/org/jacop/core/IntervalDomainValueEnumeration.java b/src/main/java/org/jacop/core/IntervalDomainValueEnumeration.java
index 845147a6b..e05f0dd8a 100644
--- a/src/main/java/org/jacop/core/IntervalDomainValueEnumeration.java
+++ b/src/main/java/org/jacop/core/IntervalDomainValueEnumeration.java
@@ -35,7 +35,7 @@
* Defines a methods for enumerating values contain in the domain.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class IntervalDomainValueEnumeration extends ValueEnumeration {
diff --git a/src/main/java/org/jacop/core/IntervalEnumeration.java b/src/main/java/org/jacop/core/IntervalEnumeration.java
index a20bb67b9..598b6fdd1 100644
--- a/src/main/java/org/jacop/core/IntervalEnumeration.java
+++ b/src/main/java/org/jacop/core/IntervalEnumeration.java
@@ -40,7 +40,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public abstract class IntervalEnumeration implements Enumeration{
diff --git a/src/main/java/org/jacop/core/MutableDomain.java b/src/main/java/org/jacop/core/MutableDomain.java
index bf035edbe..052ef90eb 100644
--- a/src/main/java/org/jacop/core/MutableDomain.java
+++ b/src/main/java/org/jacop/core/MutableDomain.java
@@ -33,7 +33,7 @@
/**
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class MutableDomain implements MutableVar {
diff --git a/src/main/java/org/jacop/core/MutableDomainValue.java b/src/main/java/org/jacop/core/MutableDomainValue.java
index 8f31a3bbe..df7ce0861 100644
--- a/src/main/java/org/jacop/core/MutableDomainValue.java
+++ b/src/main/java/org/jacop/core/MutableDomainValue.java
@@ -34,7 +34,7 @@
/**
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class MutableDomainValue implements MutableVarValue {
diff --git a/src/main/java/org/jacop/core/MutableVar.java b/src/main/java/org/jacop/core/MutableVar.java
index f64af9053..33ec6c824 100644
--- a/src/main/java/org/jacop/core/MutableVar.java
+++ b/src/main/java/org/jacop/core/MutableVar.java
@@ -35,7 +35,7 @@
* Standard mutable variable definition
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public interface MutableVar {
diff --git a/src/main/java/org/jacop/core/MutableVarValue.java b/src/main/java/org/jacop/core/MutableVarValue.java
index e5c7e715f..9965ecebb 100644
--- a/src/main/java/org/jacop/core/MutableVarValue.java
+++ b/src/main/java/org/jacop/core/MutableVarValue.java
@@ -35,7 +35,7 @@
* Standard mutable variable's value definition
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public interface MutableVarValue {
diff --git a/src/main/java/org/jacop/core/SimpleBacktrackableManager.java b/src/main/java/org/jacop/core/SimpleBacktrackableManager.java
index e0a18653a..949bf3864 100644
--- a/src/main/java/org/jacop/core/SimpleBacktrackableManager.java
+++ b/src/main/java/org/jacop/core/SimpleBacktrackableManager.java
@@ -40,7 +40,7 @@
* store level.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class SimpleBacktrackableManager implements BacktrackableManager {
diff --git a/src/main/java/org/jacop/core/SmallDenseDomain.java b/src/main/java/org/jacop/core/SmallDenseDomain.java
index 06fac8717..495b8bafc 100644
--- a/src/main/java/org/jacop/core/SmallDenseDomain.java
+++ b/src/main/java/org/jacop/core/SmallDenseDomain.java
@@ -40,7 +40,7 @@
* Defines small dense domain based on bits within a long number.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class SmallDenseDomain extends IntDomain {
@@ -126,8 +126,8 @@ public SmallDenseDomain(int min, long bits) {
/**
* It creates a domain with values between min and max inclusive.
- * @param min
- * @param max
+ * @param min min element in the domain
+ * @param max max element in the domain
*/
public SmallDenseDomain(int min, int max) {
diff --git a/src/main/java/org/jacop/core/SmallDenseDomainValueEnumeration.java b/src/main/java/org/jacop/core/SmallDenseDomainValueEnumeration.java
index de2ea2333..f76490dce 100644
--- a/src/main/java/org/jacop/core/SmallDenseDomainValueEnumeration.java
+++ b/src/main/java/org/jacop/core/SmallDenseDomainValueEnumeration.java
@@ -35,7 +35,7 @@
* Defines a methods for enumerating values contain in the domain.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class SmallDenseDomainValueEnumeration extends ValueEnumeration {
diff --git a/src/main/java/org/jacop/core/Store.java b/src/main/java/org/jacop/core/Store.java
index 24d1bbdcf..e6c628328 100644
--- a/src/main/java/org/jacop/core/Store.java
+++ b/src/main/java/org/jacop/core/Store.java
@@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Set;
import org.jacop.constraints.Constraint;
import org.jacop.constraints.DecomposedConstraint;
@@ -44,11 +45,15 @@
* It is an abstract class to describe all necessary functions of any store.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class Store {
+ // data structures to collect fail constraint statistics
+ // public HashMap failConstraintsStatistics = new HashMap();
+ // public HashMap failConstraintsIdStatistics = new HashMap();
+
/**
* It creates a logger for this class. It seeks properties in the file
* log4j.properties. It needs to be placed in the classpath. In eclipse
@@ -542,7 +547,9 @@ public boolean consistency() {
if (currentConstraint != null) {
- currentConstraint.cleanAfterFailure();
+ // collectFailStatistics(currentConstraint);
+
+ currentConstraint.cleanAfterFailure();
if (variableWeightManagement)
currentConstraint.increaseWeight();
@@ -560,7 +567,27 @@ public boolean consistency() {
return true;
}
+ /*
+ void collectFailStatistics(Constraint currentConstraint) {
+ //======== add fail constraints classes to list of fails
+ Integer n = failConstraintsStatistics.get(currentConstraint.getClass());
+ if (n != null ) {
+ failConstraintsStatistics.put(currentConstraint.getClass(), ++n);
+ }
+ else
+ failConstraintsStatistics.put(currentConstraint.getClass(), 1);
+
+ //======== add fail constraints id's to list of fails
+ Integer k = failConstraintsIdStatistics.get(currentConstraint.id());
+ if (k != null ) {
+ failConstraintsIdStatistics.put(currentConstraint.id(), ++k);
+ }
+ else
+ failConstraintsIdStatistics.put(currentConstraint.id(), 1);
+ //========
+ }
+ */
/**
* This function is called when a counter of constraints should be
@@ -1071,7 +1098,7 @@ public void setCheckSatisfiability(boolean value) {
/**
* This function sets the long description of the store.
- * @param description
+ * @param description description of the store
*/
public void setDescription(String description) {
this.description = description;
@@ -1176,6 +1203,9 @@ public String toString() {
result.append(var.value()).append("\n");
}
+ for (Constraint c : getConstraints())
+ result.append("*** Constraint:\n").append(c+"\n" );
+
result.append("\n*** Constraints for evaluation:\n{").append( toStringChangedEl() )
.append(" }");
@@ -1183,6 +1213,20 @@ public String toString() {
}
+ public HashSet getConstraints() {
+
+ HashSet constraints = new HashSet();
+
+ Set ids = variablesHashMap.keySet();
+ for (String s : ids) {
+ Domain d = variablesHashMap.get(s).dom();
+ ArrayList c = d.constraints();
+ constraints.addAll(c);
+ }
+
+ return constraints;
+ }
+
/**
* This function returns a string representation of the constraints pending
* for re-evaluation.
diff --git a/src/main/java/org/jacop/core/SwitchesPruningLogging.java b/src/main/java/org/jacop/core/SwitchesPruningLogging.java
index 009784976..2c40d93b6 100644
--- a/src/main/java/org/jacop/core/SwitchesPruningLogging.java
+++ b/src/main/java/org/jacop/core/SwitchesPruningLogging.java
@@ -37,7 +37,7 @@
* on debugging information.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public final class SwitchesPruningLogging {
diff --git a/src/main/java/org/jacop/core/TimeStamp.java b/src/main/java/org/jacop/core/TimeStamp.java
index 06d3d08cc..291ab07eb 100644
--- a/src/main/java/org/jacop/core/TimeStamp.java
+++ b/src/main/java/org/jacop/core/TimeStamp.java
@@ -44,7 +44,7 @@
* timestamp may ask for the level at which the timestamp was recently updated.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
* @param a class being stored at different time stamps.
*/
@@ -85,7 +85,7 @@ final void addLast(T input, int level) {
/**
* Specify least number of different values to be used by Timestamp.
- * @param minCapacity
+ * @param minCapacity capacity that will be ensured
*/
@SuppressWarnings("unchecked")
public void ensureCapacity(int minCapacity) {
diff --git a/src/main/java/org/jacop/core/ValueEnumeration.java b/src/main/java/org/jacop/core/ValueEnumeration.java
index ea1a95fbe..fff97517f 100644
--- a/src/main/java/org/jacop/core/ValueEnumeration.java
+++ b/src/main/java/org/jacop/core/ValueEnumeration.java
@@ -35,7 +35,7 @@
* Defines a methods for enumerating values contained in the domain.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public abstract class ValueEnumeration {
diff --git a/src/main/java/org/jacop/core/Var.java b/src/main/java/org/jacop/core/Var.java
index b9513de16..c48731295 100644
--- a/src/main/java/org/jacop/core/Var.java
+++ b/src/main/java/org/jacop/core/Var.java
@@ -37,7 +37,7 @@
* Defines a variable and related operations on it.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public abstract class Var implements Backtrackable {
diff --git a/src/main/java/org/jacop/core/XMLSaveSupport.java b/src/main/java/org/jacop/core/XMLSaveSupport.java
index 0f0646ac1..40800d39b 100644
--- a/src/main/java/org/jacop/core/XMLSaveSupport.java
+++ b/src/main/java/org/jacop/core/XMLSaveSupport.java
@@ -46,6 +46,7 @@
* 10. Save constraints, variables, search definition.
*/
+@SuppressWarnings("unchecked")
public class XMLSaveSupport {
private static final String toXMLfunction = "toXML";
diff --git a/src/main/java/org/jacop/examples/RunExample.java b/src/main/java/org/jacop/examples/RunExample.java
index 3c3df2f5b..12879d824 100644
--- a/src/main/java/org/jacop/examples/RunExample.java
+++ b/src/main/java/org/jacop/examples/RunExample.java
@@ -43,7 +43,7 @@
* the arguments for the executed example.
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
diff --git a/src/main/java/org/jacop/examples/cpviz/CPvizNetworkFlow.java b/src/main/java/org/jacop/examples/cpviz/CPvizNetworkFlow.java
index 525a9eda5..a98914a83 100644
--- a/src/main/java/org/jacop/examples/cpviz/CPvizNetworkFlow.java
+++ b/src/main/java/org/jacop/examples/cpviz/CPvizNetworkFlow.java
@@ -19,7 +19,7 @@
* It is used for test purpose only.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class CPvizNetworkFlow{
Store store;
diff --git a/src/main/java/org/jacop/examples/cpviz/CPvizSendMoreMoney.java b/src/main/java/org/jacop/examples/cpviz/CPvizSendMoreMoney.java
index abc14c1c0..a492022cf 100644
--- a/src/main/java/org/jacop/examples/cpviz/CPvizSendMoreMoney.java
+++ b/src/main/java/org/jacop/examples/cpviz/CPvizSendMoreMoney.java
@@ -5,8 +5,7 @@
import java.util.ArrayList;
import org.jacop.constraints.Alldifferent;
-import org.jacop.constraints.SumWeight;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XmulCeqZ;
import org.jacop.constraints.XneqC;
import org.jacop.constraints.XneqY;
@@ -184,11 +183,15 @@ public void modelGlobal() {
IntVar r = new IntVar(store, "R", 0, 9);
IntVar y = new IntVar(store, "Y", 0, 9);
+ IntVar valueSEND = new IntVar(store, "v(SEND)", 0, 9999);
+ IntVar valueMORE = new IntVar(store, "v(MORE)", 0, 9999);
+ IntVar valueMONEY = new IntVar(store, "v(MONEY)", 0, 99999);
+
// Creating arrays for IntVars
IntVar digits[] = { s, e, n, d, m, o, r, y };
- IntVar send[] = { s, e, n, d };
- IntVar more[] = { m, o, r, e };
- IntVar money[] = { m, o, n, e, y };
+ IntVar send[] = { s, e, n, d, valueSEND };
+ IntVar more[] = { m, o, r, e, valueMORE };
+ IntVar money[] = { m, o, n, e, y, valueMONEY };
for (IntVar v : digits)
vars.add(v);
@@ -197,20 +200,19 @@ public void modelGlobal() {
// Only one global constraint
store.impose(new Alldifferent(digits));
- int[] weights5 = { 10000, 1000, 100, 10, 1 };
- int[] weights4 = { 1000, 100, 10, 1 };
-
- IntVar valueSEND = new IntVar(store, "v(SEND)", 0, 9999);
- IntVar valueMORE = new IntVar(store, "v(MORE)", 0, 9999);
- IntVar valueMONEY = new IntVar(store, "v(MONEY)", 0, 99999);
+ int[] weights5 = { 10000, 1000, 100, 10, 1, -1 };
+ int[] weights4 = { 1000, 100, 10, 1, -1 };
// Constraints for getting value for words
// SEND = 1000 * S + 100 * E + N * 10 + D * 1
// MORE = 1000 * M + 100 * O + R * 10 + E * 1
// MONEY = 10000 * M + 1000 * O + 100 * N + E * 10 + Y * 1
- store.impose(new SumWeight(send, weights4, valueSEND));
- store.impose(new SumWeight(more, weights4, valueMORE));
- store.impose(new SumWeight(money, weights5, valueMONEY));
+ store.impose(new LinearInt(store, send, weights4, "==", 0));
+ // store.impose(new SumWeight(send, weights4, valueSEND));
+ // store.impose(new SumWeight(more, weights4, valueMORE));
+ store.impose(new LinearInt(store, more, weights4, "==", 0));
+ // store.impose(new SumWeight(money, weights5, valueMONEY));
+ store.impose(new LinearInt(store, money, weights5, "==", 0));
// Main equation of the problem SEND + MORE = MONEY
store.impose(new XplusYeqZ(valueSEND, valueMORE, valueMONEY));
diff --git a/src/main/java/org/jacop/examples/cpviz/CPvizSudoku.java b/src/main/java/org/jacop/examples/cpviz/CPvizSudoku.java
index 3edc006e9..4f945b6b7 100644
--- a/src/main/java/org/jacop/examples/cpviz/CPvizSudoku.java
+++ b/src/main/java/org/jacop/examples/cpviz/CPvizSudoku.java
@@ -48,7 +48,7 @@
/**
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class CPvizSudoku {
diff --git a/src/main/java/org/jacop/examples/fd/BIBD.java b/src/main/java/org/jacop/examples/fd/BIBD.java
index 93d710fa1..f287a850f 100644
--- a/src/main/java/org/jacop/examples/fd/BIBD.java
+++ b/src/main/java/org/jacop/examples/fd/BIBD.java
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import org.jacop.constraints.AndBool;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.core.BooleanVar;
import org.jacop.core.IntVar;
import org.jacop.core.Store;
@@ -44,7 +44,7 @@
* It models and solves Balanced Incomplete Block Design (BIBD) problem (CSPLIB-P28).
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class BIBD extends ExampleFD {
@@ -92,14 +92,14 @@ public void model() {
IntVar lambdaVar = new IntVar(store, "lambda", lambda, lambda);
for (int i = 0; i < v; i++) {
- store.impose(new Sum(x[i], rVar), 1);
+ store.impose(new SumInt(store, x[i], "==", rVar), 1);
}
for (int j = 0; j < b; j++) {
IntVar[] column = new IntVar[v];
for (int i = 0; i < v; i++)
column[i] = x[i][j];
- store.impose(new Sum(column, kVar), 1);
+ store.impose(new SumInt(store, column, "==", kVar), 1);
}
for (int i = 0; i - 1 < v; i++)
@@ -114,7 +114,7 @@ public void model() {
result.add(product);
}
- store.impose(new Sum(result, lambdaVar), 1);
+ store.impose(new SumInt(store, result, "==", lambdaVar), 1);
}
}
diff --git a/src/main/java/org/jacop/examples/fd/BasicLogicPascal.java b/src/main/java/org/jacop/examples/fd/BasicLogicPascal.java
index ba421b207..0644bf803 100644
--- a/src/main/java/org/jacop/examples/fd/BasicLogicPascal.java
+++ b/src/main/java/org/jacop/examples/fd/BasicLogicPascal.java
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import org.jacop.constraints.Alldifferent;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XneqC;
import org.jacop.constraints.XplusYeqZ;
import org.jacop.core.IntVar;
@@ -51,7 +51,7 @@
* different letters represent different digits
*
* BASIC 9567
- * +LOGIC =======> +1085
+ * +LOGIC{@literal =======>} +1085
* PASCAL 10652
*
*/
@@ -76,11 +76,15 @@ public void model() {
IntVar c = new IntVar(store, "C", 0, 9);
IntVar p = new IntVar(store, "P", 0, 9);
+ IntVar valueBASIC = new IntVar(store, "v(BASIC)", 0, 99999);
+ IntVar valueLOGIC = new IntVar(store, "v(LOGIC)", 0, 99999);
+ IntVar valuePASCAL = new IntVar(store, "v(PASCAL)", 0, 999999);
+
// Creating arrays for FDVs
IntVar digits[] = { b, a, s, i, l, o, g, c, p };
- IntVar basic[] = { b, a, s, i, c };
- IntVar logic[] = { l, o, g, i, c };
- IntVar pascal[] = { p, a, s, c, a, l };
+ IntVar basic[] = { b, a, s, i, c, valueBASIC };
+ IntVar logic[] = { l, o, g, i, c, valueLOGIC };
+ IntVar pascal[] = { p, a, s, c, a, l, valuePASCAL };
for (IntVar v : digits) vars.add(v);
@@ -88,20 +92,19 @@ public void model() {
// Only one global constraint
store.impose(new Alldifferent(digits));
- int[] weights5 = { 10000, 1000, 100, 10, 1 };
- int[] weights6 = { 100000, 10000, 1000, 100, 10, 1 };
-
- IntVar valueBASIC = new IntVar(store, "v(BASIC)", 0, 99999);
- IntVar valueLOGIC = new IntVar(store, "v(LOGIC)", 0, 99999);
- IntVar valuePASCAL = new IntVar(store, "v(PASCAL)", 0, 999999);
+ int[] weights5 = { 10000, 1000, 100, 10, 1, -1 };
+ int[] weights6 = { 100000, 10000, 1000, 100, 10, 1, -1 };
// Constraints for getting value for words
// BASIC = 10000 * B + 1000 * A + 100 * S + I * 10 + C * 1
// LOGIC = 10000 * L + 1000 * O + 100 * G + I * 10 + C * 1
// PASCAL = 100000 * P + 10000 * A + 1000 * S + 100 * C + 10 * A + L * 1
- store.impose(new SumWeight(basic, weights5, valueBASIC));
- store.impose(new SumWeight(logic, weights5, valueLOGIC));
- store.impose(new SumWeight(pascal, weights6, valuePASCAL));
+ store.impose(new LinearInt(store, basic, weights5, "==", 0));
+ // store.impose(new SumWeight(basic, weights5, valueBASIC));
+ store.impose(new LinearInt(store, logic, weights5, "==", 0));
+ // store.impose(new SumWeight(logic, weights5, valueLOGIC));
+ store.impose(new LinearInt(store, pascal, weights6, "==", 0));
+ // store.impose(new SumWeight(pascal, weights6, valuePASCAL));
// Main equation of the problem BASIC+ LOGIC = PASCAL
store.impose(new XplusYeqZ(valueBASIC, valueLOGIC, valuePASCAL));
diff --git a/src/main/java/org/jacop/examples/fd/BuildingBlocks.java b/src/main/java/org/jacop/examples/fd/BuildingBlocks.java
index 87f0af177..623a536c5 100644
--- a/src/main/java/org/jacop/examples/fd/BuildingBlocks.java
+++ b/src/main/java/org/jacop/examples/fd/BuildingBlocks.java
@@ -156,7 +156,7 @@ public void model() {
/**
* It executes the program to solve this logic puzzle.
- * @param args
+ * @param args args for the program (none)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/Cryptogram.java b/src/main/java/org/jacop/examples/fd/Cryptogram.java
index 01024b337..fa5b44951 100644
--- a/src/main/java/org/jacop/examples/fd/Cryptogram.java
+++ b/src/main/java/org/jacop/examples/fd/Cryptogram.java
@@ -40,8 +40,8 @@
import java.util.regex.Pattern;
import org.jacop.constraints.Alldistinct;
-import org.jacop.constraints.Sum;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.SumInt;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XneqC;
import org.jacop.core.IntDomain;
import org.jacop.core.IntVar;
@@ -221,15 +221,23 @@ public void model() {
currentChar));
}
- store.impose(new SumWeight(lettersWithinCurrentWord,
- createWeights(currentWord.length(), base),
- fdv4words[j]));
+ int n = lettersWithinCurrentWord.length;
+ IntVar[] vs = new IntVar[n+1];
+ int[] ws = new int[n+1];
+ System.arraycopy(lettersWithinCurrentWord, 0, vs, 0, n);
+ System.arraycopy(createWeights(currentWord.length(), base), 0, ws, 0, n);
+ vs[n] = fdv4words[j];
+ ws[n] = -1;
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight(lettersWithinCurrentWord,
+ // createWeights(currentWord.length(), base),
+ // fdv4words[j]));
store.impose(new XneqC(lettersWithinCurrentWord[0], 0));
}
- store.impose(new Sum(terms, fdv4words[noWords - 1]));
+ store.impose(new SumInt(store, terms, "==", fdv4words[noWords - 1]));
}
}
diff --git a/src/main/java/org/jacop/examples/fd/DeBruijn.java b/src/main/java/org/jacop/examples/fd/DeBruijn.java
index 0d50ee110..4cad708cb 100644
--- a/src/main/java/org/jacop/examples/fd/DeBruijn.java
+++ b/src/main/java/org/jacop/examples/fd/DeBruijn.java
@@ -35,7 +35,7 @@
import org.jacop.constraints.Alldifferent;
import org.jacop.constraints.Min;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XeqY;
import org.jacop.core.IntVar;
import org.jacop.core.Store;
@@ -132,7 +132,16 @@ public void model() {
for(int j = 0; j < n; j++) {
binary[i][j] = new IntVar(store, "binary_" + i + "_" + j, 0, base-1);
}
- store.impose(new SumWeight (binary[i], weights, x[i]));
+
+ int n = weights.length;
+ IntVar[] vs = new IntVar[n+1];
+ int[] ws = new int[n+1];
+ System.arraycopy(binary[i], 0, vs, 0, n);
+ System.arraycopy(weights, 0, ws, 0, n);
+ vs[n] = x[i];
+ ws[n] = -1;
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight (binary[i], weights, x[i]));
}
//
diff --git a/src/main/java/org/jacop/examples/fd/Diet.java b/src/main/java/org/jacop/examples/fd/Diet.java
index 0567554ba..a7b4c6f17 100644
--- a/src/main/java/org/jacop/examples/fd/Diet.java
+++ b/src/main/java/org/jacop/examples/fd/Diet.java
@@ -33,7 +33,7 @@
import java.util.ArrayList;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XgteqC;
import org.jacop.constraints.knapsack.Knapsack;
import org.jacop.core.IntDomain;
@@ -115,13 +115,31 @@ public void model() {
IntVar[] sums = new IntVar[n];
for(int i = 0; i < n; i++) {
sums[i] = new IntVar(store, "sums_" + i, 0, IntDomain.MaxInt);
- store.impose(new SumWeight(x, matrix[i], sums[i]));
+
+ int n = x.length;
+ IntVar[] xs = new IntVar[n+1];
+ int[] ms = new int[n+1];
+ System.arraycopy(x, 0, xs, 0, n);
+ System.arraycopy(matrix[i], 0, ms, 0, n);
+ xs[n] = sums[i];
+ ms[n] = -1;
+ store.impose(new LinearInt(store, xs, ms, "==", 0));
+ // store.impose(new SumWeight(x, matrix[i], sums[i]));
store.impose(new XgteqC(sums[i], limits[i]));
}
// Cost to minimize: x * price
cost = new IntVar(store, "cost", 0, 120);
- store.impose( new SumWeight(x, price, cost) );
+
+ int n = x.length;
+ IntVar[] xs = new IntVar[n+1];
+ int[] ms = new int[n+1];
+ System.arraycopy(x, 0, xs, 0, n);
+ System.arraycopy(price, 0, ms, 0, n);
+ xs[n] = cost;
+ ms[n] = -1;
+ store.impose(new LinearInt(store, xs, ms, "==", 0));
+ // store.impose( new SumWeight(x, price, cost) );
vars = new ArrayList();
for(IntVar v : x)
@@ -155,7 +173,15 @@ public void modelKnapsack() {
store.impose(new Knapsack(matrix[i], price, x, cost, minReq));
else {
// this category has some items with zero profit, violates knapsack conditions so it is not used.
- store.impose(new SumWeight(x, matrix[i], minReq));
+ int n = x.length;
+ IntVar[] xs = new IntVar[n+1];
+ int[] ms = new int[n+1];
+ System.arraycopy(x, 0, xs, 0, n);
+ System.arraycopy(matrix[i], 0, ms, 0, n);
+ xs[n] = minReq;
+ ms[n] = -1;
+ store.impose(new LinearInt(store, xs, ms, "==", 0));
+ // store.impose(new SumWeight(x, matrix[i], minReq));
}
}
diff --git a/src/main/java/org/jacop/examples/fd/DonaldGeraldRobert.java b/src/main/java/org/jacop/examples/fd/DonaldGeraldRobert.java
index d2cea68ce..9b6cb4cf8 100644
--- a/src/main/java/org/jacop/examples/fd/DonaldGeraldRobert.java
+++ b/src/main/java/org/jacop/examples/fd/DonaldGeraldRobert.java
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import org.jacop.constraints.Alldifferent;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XneqC;
import org.jacop.constraints.XplusYeqZ;
import org.jacop.core.IntVar;
@@ -48,7 +48,7 @@
* The solution is provided below.
*
* Donald 526485
- * Gerald =====> +197485
+ * Gerald{@literal =====>} +197485
* Robert 723970
*
* @author Radoslaw Szymanek
@@ -95,9 +95,23 @@ public void model() {
IntVar robertValue = new IntVar(store, "Robert", 0, 999999);
// Constraints for getting value for words
- store.impose(new SumWeight(donald, weights, donaldValue));
- store.impose(new SumWeight(gerald, weights, geraldValue));
- store.impose(new SumWeight(robert, weights, robertValue));
+ int[] ws = {100000, 10000, 1000, 100, 10, 1, -1};
+
+ IntVar[] donaldN = new IntVar[donald.length+1];
+ System.arraycopy(donald, 0, donaldN, 0, donald.length);
+ donaldN[donald.length] = donaldValue;
+ store.impose(new LinearInt(store, donaldN, ws, "==", 0));
+ // store.impose(new SumWeight(donald, weights, donaldValue));
+ IntVar[] geraldN = new IntVar[gerald.length+1];
+ System.arraycopy(gerald, 0, geraldN, 0, gerald.length);
+ geraldN[gerald.length] = geraldValue;
+ store.impose(new LinearInt(store, geraldN, ws, "==", 0));
+ // store.impose(new SumWeight(gerald, weights, geraldValue));
+ IntVar[] robertN = new IntVar[robert.length+1];
+ System.arraycopy(robert, 0, robertN, 0, robert.length);
+ robertN[robert.length] = robertValue;
+ store.impose(new LinearInt(store, robertN, ws, "==", 0));
+ // store.impose(new SumWeight(robert, weights, robertValue));
// Equation
store.impose(new XplusYeqZ(donaldValue, geraldValue, robertValue));
diff --git a/src/main/java/org/jacop/examples/fd/ExampleFD.java b/src/main/java/org/jacop/examples/fd/ExampleFD.java
index 2aeb1eb04..c46171b8f 100644
--- a/src/main/java/org/jacop/examples/fd/ExampleFD.java
+++ b/src/main/java/org/jacop/examples/fd/ExampleFD.java
@@ -59,7 +59,7 @@
* It is an abstract class to describe all necessary functions of any store.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public abstract class ExampleFD {
diff --git a/src/main/java/org/jacop/examples/fd/FittingNumbers.java b/src/main/java/org/jacop/examples/fd/FittingNumbers.java
index 0d2d70da4..990572910 100644
--- a/src/main/java/org/jacop/examples/fd/FittingNumbers.java
+++ b/src/main/java/org/jacop/examples/fd/FittingNumbers.java
@@ -33,7 +33,7 @@
import java.util.ArrayList;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.core.IntVar;
import org.jacop.core.IntervalDomain;
import org.jacop.core.Store;
@@ -76,7 +76,15 @@ public void model() {
vars.add(counters[i]);
}
- store.impose(new SumWeight(counters, elements, sum));
+ int n = counters.length;
+ IntVar[] vs = new IntVar[n+1];
+ int[] ws = new int[n+1];
+ System.arraycopy(counters, 0, vs, 0, n);
+ System.arraycopy(elements, 0, ws, 0, n);
+ vs[n] = sum;
+ ws[n] = -1;
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight(counters, elements, sum));
System.out.println(store);
}
@@ -84,7 +92,7 @@ public void model() {
/**
* It executes the program to solve simple Kakro puzzle.
- * @param args
+ * @param args commans arguments (none)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/FurnitureMoving.java b/src/main/java/org/jacop/examples/fd/FurnitureMoving.java
index dfacacee6..16e81f089 100644
--- a/src/main/java/org/jacop/examples/fd/FurnitureMoving.java
+++ b/src/main/java/org/jacop/examples/fd/FurnitureMoving.java
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import org.jacop.constraints.Cumulative;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XlteqY;
import org.jacop.constraints.XplusYeqZ;
@@ -52,7 +52,7 @@
*
* @author Hakan Kjellerstrand (hakank@bonetmail.com) and Radoslaw Szymanek
*
- * Problem from Marriott & Stuckey: 'Programming with constraints', page 112f
+ * Problem from Marriott {@literal &} Stuckey: 'Programming with constraints', page 112f
*
* Feature: testing cumulative.
*
@@ -85,7 +85,7 @@ public void model() {
starts = new IntVar[4];
starts[0] = Sp; starts[1] = Sc; starts[2] = Sb; starts[3] = St;
- store.impose(new Sum(starts, sumStartTimes));
+ store.impose(new SumInt(store, starts, "==", sumStartTimes));
IntVar[] durations = new IntVar[4];
IntVar[] resources = new IntVar[4];
@@ -131,7 +131,7 @@ public void model() {
/**
* It executes the program which solves this logic puzzle.
- * @param args
+ * @param args command arguments (none)
*/
public static void main(String args[]) {
@@ -151,6 +151,8 @@ public static void main(String args[]) {
/**
* It specifies search for that logic puzzle.
+ *
+ * @return true when solution is found false otherwise
*/
public boolean searchSpecific() {
diff --git a/src/main/java/org/jacop/examples/fd/Gates.java b/src/main/java/org/jacop/examples/fd/Gates.java
index d0f41fdb6..02abe55d2 100644
--- a/src/main/java/org/jacop/examples/fd/Gates.java
+++ b/src/main/java/org/jacop/examples/fd/Gates.java
@@ -151,7 +151,7 @@ public void not(BooleanVar in, BooleanVar out) {
/**
* It executes a program to solve gates problems.
- * @param args
+ * @param args parameters (none)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/GeostExample.java b/src/main/java/org/jacop/examples/fd/GeostExample.java
index a54f9fee6..cfa934013 100644
--- a/src/main/java/org/jacop/examples/fd/GeostExample.java
+++ b/src/main/java/org/jacop/examples/fd/GeostExample.java
@@ -50,7 +50,7 @@
* a square of a given size.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class GeostExample extends ExampleFD {
diff --git a/src/main/java/org/jacop/examples/fd/HistoricHomes.java b/src/main/java/org/jacop/examples/fd/HistoricHomes.java
index 5f6aa799f..3fc470c5e 100644
--- a/src/main/java/org/jacop/examples/fd/HistoricHomes.java
+++ b/src/main/java/org/jacop/examples/fd/HistoricHomes.java
@@ -183,7 +183,7 @@ public void model() {
/**
* It executes the program to solve this simple logic puzzle.
- * @param args
+ * @param args parameters (none)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/Kakro.java b/src/main/java/org/jacop/examples/fd/Kakro.java
index 935e4d1f2..e4e7d147d 100644
--- a/src/main/java/org/jacop/examples/fd/Kakro.java
+++ b/src/main/java/org/jacop/examples/fd/Kakro.java
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import org.jacop.constraints.Alldiff;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.core.IntVar;
import org.jacop.core.Store;
@@ -105,7 +105,7 @@ public void model() {
for (int m = j + 1; m < noColumns && rowDescription[i][m] == 1; m++)
row.add(elements[i][m]);
- store.impose(new Sum(row, sum));
+ store.impose(new SumInt(store, row, "==", sum));
store.impose(new Alldiff(row));
}
@@ -121,7 +121,7 @@ public void model() {
for (int m = i + 1; m < noRows && columnDescription[m][j] == 1; m++)
column.add(elements[m][j]);
- store.impose(new Sum(column, sum));
+ store.impose(new SumInt(store, column, "==", sum));
store.impose(new Alldiff(column));
}
@@ -130,7 +130,7 @@ public void model() {
/**
* It executes the program to solve simple Kakro puzzle.
- * @param args
+ * @param args no parameters
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/KnapsackExample.java b/src/main/java/org/jacop/examples/fd/KnapsackExample.java
index 253abc5a7..e5ac2fe58 100644
--- a/src/main/java/org/jacop/examples/fd/KnapsackExample.java
+++ b/src/main/java/org/jacop/examples/fd/KnapsackExample.java
@@ -33,7 +33,7 @@
import java.util.ArrayList;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XgteqY;
import org.jacop.constraints.XlteqC;
import org.jacop.constraints.XplusYeqC;
@@ -46,7 +46,7 @@
* It shows the capabilities and usage of Knapsack constraint.
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
* It models and solves a simple knapsack problem. There
* are two different models. The first one uses quantity
@@ -187,8 +187,27 @@ public void modelNoKnapsackConstraint() {
IntVar profit = new IntVar(store, "Profit", 0, 1000000);
IntVar weight = new IntVar(store, "Weight", 0, 1000000);
- store.impose(new SumWeight(quantity, weights, weight));
- store.impose(new SumWeight(quantity, profits, profit));
+ int n = quantity.length;
+ IntVar[] qs = new IntVar[n + 1];
+ int[] ws = new int[n + 1];
+ for (int i = 0; i < n; i++) {
+ qs[i] = quantity[i];
+ ws[i] = weights[i];
+ }
+ qs[n] = weight;
+ ws[n] = -1;
+ store.impose(new LinearInt(store, qs, ws, "==", 0));
+ // store.impose(new SumWeight(quantity, weights, weight));
+ IntVar[] qps = new IntVar[n + 1];
+ int[] ps = new int[n + 1];
+ for (int i = 0; i < n; i++) {
+ qps[i] = quantity[i];
+ ps[i] = profits[i];
+ }
+ qps[n] = profit;
+ ps[n] = -1;
+ store.impose(new LinearInt(store, qps, ps, "==", 0));
+ // store.impose(new SumWeight(quantity, profits, profit));
store.impose(new XlteqC(weight, volume));
@@ -252,12 +271,31 @@ public void modelBoth() {
IntVar profit = new IntVar(store, "Profit", 0, 1000000);
IntVar weight = new IntVar(store, "Weight", 0, 1000000);
- store.impose(new SumWeight(quantity, weights, weight));
+ int n = quantity.length;
+ IntVar[] qs = new IntVar[n + 1];
+ int[] ws = new int[n + 1];
+ for (int i = 0; i < n; i++) {
+ qs[i] = quantity[i];
+ ws[i] = weights[i];
+ }
+ qs[n] = weight;
+ ws[n] = -1;
+ store.impose(new LinearInt(store, qs, ws, "==", 0));
+ // store.impose(new SumWeight(quantity, weights, weight));
store.impose(new Knapsack(profits, weights, quantity,
weight, profit));
- store.impose(new SumWeight(quantity, profits, profit));
+ IntVar[] qps = new IntVar[n + 1];
+ int[] ps = new int[n + 1];
+ for (int i = 0; i < n; i++) {
+ qps[i] = quantity[i];
+ ps[i] = profits[i];
+ }
+ qps[n] = profit;
+ ps[n] = -1;
+ store.impose(new LinearInt(store, qps, ps, "==", 0));
+ // store.impose(new SumWeight(quantity, profits, profit));
store.impose(new XlteqC(weight, volume));
@@ -331,8 +369,27 @@ public void modelBasic() {
IntVar profit = new IntVar(store, "Profit", 0, 1000000);
IntVar weight = new IntVar(store, "Weight", 0, 1000000);
- store.impose(new SumWeight(quantity, weights, weight));
- store.impose(new SumWeight(quantity, profits, profit));
+ int n = quantity.length;
+ IntVar[] qs = new IntVar[n + 1];
+ int[] ws = new int[n + 1];
+ for (int i = 0; i < n; i++) {
+ qs[i] = quantity[i];
+ ws[i] = weights[i];
+ }
+ qs[n] = weight;
+ ws[n] = -1;
+ store.impose(new LinearInt(store, qs, ws, "==", 0));
+ // store.impose(new SumWeight(quantity, weights, weight));
+ IntVar[] qps = new IntVar[n + 1];
+ int[] ps = new int[n + 1];
+ for (int i = 0; i < n; i++) {
+ qps[i] = quantity[i];
+ ps[i] = profits[i];
+ }
+ qps[n] = profit;
+ ps[n] = -1;
+ store.impose(new LinearInt(store, qps, ps, "==", 0));
+ // store.impose(new SumWeight(quantity, profits, profit));
store.impose(new XlteqC(weight, volume));
@@ -363,7 +420,7 @@ public void modelBasic() {
* If no arguments is provided or improper number of them the program will use
* internal instance of the knapsack problem.
*
- * @param args
+ * @param args the capacity of the knapsack, 4 strings denoting the item (weight, profit, maximumQuantity, name), the number of strings total must be equal to 1+4*noOfItems.
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/Langford.java b/src/main/java/org/jacop/examples/fd/Langford.java
index a1edb39c2..1a82c4bce 100644
--- a/src/main/java/org/jacop/examples/fd/Langford.java
+++ b/src/main/java/org/jacop/examples/fd/Langford.java
@@ -47,7 +47,7 @@
* It solves Langford problem.
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Langford extends ExampleFD {
diff --git a/src/main/java/org/jacop/examples/fd/LatinSquare.java b/src/main/java/org/jacop/examples/fd/LatinSquare.java
index 378f6f475..ed9a0de83 100644
--- a/src/main/java/org/jacop/examples/fd/LatinSquare.java
+++ b/src/main/java/org/jacop/examples/fd/LatinSquare.java
@@ -92,7 +92,7 @@ public void model() {
/**
* It executes the program to solve the LatinSquare problem.
- * @param args
+ * @param args size of the problem
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/LeastDiff.java b/src/main/java/org/jacop/examples/fd/LeastDiff.java
index 9fc0fbc4f..c365b4f1e 100644
--- a/src/main/java/org/jacop/examples/fd/LeastDiff.java
+++ b/src/main/java/org/jacop/examples/fd/LeastDiff.java
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import org.jacop.constraints.Alldifferent;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XgtY;
import org.jacop.constraints.XplusYeqZ;
import org.jacop.core.IntVar;
@@ -95,8 +95,25 @@ public void model() {
IntVar value_fghij = new IntVar(store, "v_fghij", 0, 99999);
// Constraints for getting value for words
- store.impose(new SumWeight (abcde, weights5, value_abcde));
- store.impose(new SumWeight (fghij, weights5, value_fghij));
+ int n = abcde.length;
+ IntVar[] vs = new IntVar[n + 1];
+ int[] ws = new int[n + 1];
+ for (int ii = 0; ii < n; ii++) {
+ vs[ii] = abcde[ii];
+ ws[ii] = weights5[ii];
+ }
+ vs[n] = value_abcde;
+ ws[n] = -1;
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight (abcde, weights5, value_abcde));
+ n = fghij.length;
+ IntVar[] qs = new IntVar[n + 1];
+ for (int ii = 0; ii < n; ii++) {
+ qs[ii] = fghij[ii];
+ }
+ qs[n] = value_fghij;
+ store.impose(new LinearInt(store, qs, ws, "==", 0));
+ // store.impose(new SumWeight (fghij, weights5, value_fghij));
// abcde > fghij
store.impose(new XgtY (value_abcde, value_fghij));
@@ -117,7 +134,7 @@ public void model() {
/**
* It executes the program which solves this simple optimization problem.
- * @param args
+ * @param args parameters (none)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/MagicSquares.java b/src/main/java/org/jacop/examples/fd/MagicSquares.java
index 6714781f8..2dc51366a 100644
--- a/src/main/java/org/jacop/examples/fd/MagicSquares.java
+++ b/src/main/java/org/jacop/examples/fd/MagicSquares.java
@@ -37,7 +37,7 @@
import org.jacop.constraints.Alldistinct;
import org.jacop.constraints.Assignment;
import org.jacop.constraints.Constraint;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XltY;
import org.jacop.core.BoundDomain;
import org.jacop.core.IntVar;
@@ -101,7 +101,7 @@ public void model() {
for (int i = 0; i < number; i++) {
for (int j = 0; j < number; j++)
row[j] = squares[i * number + j];
- store.impose(new Sum(row, k));
+ store.impose(new SumInt(store, row, "==", k));
}
IntVar column[] = new IntVar[number];
@@ -109,7 +109,7 @@ public void model() {
for (int j = 0; j < number; j++) {
for (int i = 0; i < number; i++)
column[i] = squares[i * number + j];
- store.impose(new Sum(column, k));
+ store.impose(new SumInt(store, column, "==", k));
}
IntVar diagonal[] = new IntVar[number];
@@ -117,11 +117,11 @@ public void model() {
for (int i = 0; i < number; i++)
diagonal[i] = squares[(i) * number + i];
- store.impose(new Sum(diagonal, k));
+ store.impose(new SumInt(store, diagonal, "==", k));
for (int i = number; i > 0; i--)
diagonal[i - 1] = squares[(i - 1) * number + (number - i)];
- store.impose(new Sum(diagonal, k));
+ store.impose(new SumInt(store, diagonal, "==", k));
// symmetry breaking
store.impose(new XltY(squares[0], squares[number - 1]));
@@ -157,7 +157,7 @@ public void modelBound() {
for (int i = 0; i < number; i++) {
for (int j = 0; j < number; j++)
row[j] = squares[i * number + j];
- store.impose(new Sum(row, k));
+ store.impose(new SumInt(store, row, "==", k));
}
IntVar column[] = new IntVar[number];
@@ -165,7 +165,7 @@ public void modelBound() {
for (int j = 0; j < number; j++) {
for (int i = 0; i < number; i++)
column[i] = squares[i * number + j];
- store.impose(new Sum(column, k));
+ store.impose(new SumInt(store, column, "==", k));
}
IntVar diagonal[] = new IntVar[number];
@@ -173,11 +173,11 @@ public void modelBound() {
for (int i = 0; i < number; i++)
diagonal[i] = squares[(i) * number + i];
- store.impose(new Sum(diagonal, k));
+ store.impose(new SumInt(store, diagonal, "==", k));
for (int i = number; i > 0; i--)
diagonal[i - 1] = squares[(i - 1) * number + (number - i)];
- store.impose(new Sum(diagonal, k));
+ store.impose(new SumInt(store, diagonal, "==", k));
// symmetry breaking
//store.impose(new XltY(squares[0], squares[number - 1]));
@@ -231,7 +231,7 @@ public void model4Shaving() {
for (int i = 0; i < number; i++) {
for (int j = 0; j < number; j++)
row[j] = squares[i * number + j];
- Constraint cx = new Sum(row, k);
+ Constraint cx = new SumInt(store, row, "==", k);
store.impose(cx);
guidingShaving.add(cx);
}
@@ -242,7 +242,7 @@ public void model4Shaving() {
for (int i = 0; i < number; i++)
column[i] = squares[i * number + j];
- Constraint cx = new Sum(column, k);
+ Constraint cx = new SumInt(store, column, "==", k);
store.impose(cx);
guidingShaving.add(cx);
}
@@ -252,13 +252,13 @@ public void model4Shaving() {
for (int i = 0; i < number; i++)
diagonal[i] = squares[(i) * number + i];
- Constraint cx = new Sum(diagonal, k);
+ Constraint cx = new SumInt(store, diagonal, "==", k);
store.impose(cx);
guidingShaving.add(cx);
for (int i = number; i > 0; i--)
diagonal[i - 1] = squares[(i - 1) * number + (number - i)];
- store.impose(new Sum(diagonal, k));
+ store.impose(new SumInt(store, diagonal, "==", k));
// symmetry breaking
store.impose(new XltY(squares[0], squares[number - 1]));
@@ -310,7 +310,7 @@ public void modelDual() {
for (int i = 0; i < number; i++) {
for (int j = 0; j < number; j++)
row[j] = squares[i * number + j];
- store.impose(new Sum(row, k));
+ store.impose(new SumInt(store, row, "==", k));
}
IntVar column[] = new IntVar[number];
@@ -318,7 +318,7 @@ public void modelDual() {
for (int j = 0; j < number; j++) {
for (int i = 0; i < number; i++)
column[i] = squares[i * number + j];
- store.impose(new Sum(column, k));
+ store.impose(new SumInt(store, column, "==", k));
}
IntVar diagonal[] = new IntVar[number];
@@ -326,11 +326,11 @@ public void modelDual() {
for (int i = 0; i < number; i++)
diagonal[i] = squares[(i) * number + i];
- store.impose(new Sum(diagonal, k));
+ store.impose(new SumInt(store, diagonal, "==", k));
for (int i = number; i > 0; i--)
diagonal[i - 1] = squares[(i - 1) * number + (number - i)];
- store.impose(new Sum(diagonal, k));
+ store.impose(new SumInt(store, diagonal, "==", k));
// // symmetry breaking
// store.impose(new XltY(squares[0], squares[number-1]));
diff --git a/src/main/java/org/jacop/examples/fd/MineSweeper.java b/src/main/java/org/jacop/examples/fd/MineSweeper.java
index d39682c1a..c33d16a3c 100644
--- a/src/main/java/org/jacop/examples/fd/MineSweeper.java
+++ b/src/main/java/org/jacop/examples/fd/MineSweeper.java
@@ -36,7 +36,7 @@
import java.io.IOException;
import java.util.ArrayList;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XeqC;
import org.jacop.core.BooleanVar;
import org.jacop.core.IntVar;
@@ -150,7 +150,7 @@ public void model() {
}
}
}
- store.impose(new Sum(lst, game[i][j]));
+ store.impose(new SumInt(store, lst, "==", game[i][j]));
} // end if problem[i][j] > X
@@ -439,9 +439,9 @@ public static int[][] readFromArray(String[] description) {
* % a comment which also is ignored
* number of rows
* number of columns
- * <
+ * {@literal <}
* row number of neighbours lines...
- * >
+ * {@literal >}
*
* 0..8 means number of neighbours, "." mean unknown (may be a mine)
*
diff --git a/src/main/java/org/jacop/examples/fd/NonTransitiveDice.java b/src/main/java/org/jacop/examples/fd/NonTransitiveDice.java
index 0b0c6084a..acb2d4ba7 100644
--- a/src/main/java/org/jacop/examples/fd/NonTransitiveDice.java
+++ b/src/main/java/org/jacop/examples/fd/NonTransitiveDice.java
@@ -38,7 +38,7 @@
import org.jacop.constraints.Max;
import org.jacop.constraints.Min;
import org.jacop.constraints.Reified;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XgtY;
import org.jacop.constraints.XltY;
@@ -188,7 +188,7 @@ public void model() {
for (int m = 0; m < noSides; m++)
matrix[j * noSides + m] = wins[i][j][m];
- store.impose(new Sum(matrix, winningSum[i]));
+ store.impose(new SumInt(store, matrix, "==", winningSum[i]));
}
IntVar minimumWinning = new IntVar(store, "MinDominance", 0, noSides * noSides);
diff --git a/src/main/java/org/jacop/examples/fd/Parcel.java b/src/main/java/org/jacop/examples/fd/Parcel.java
index 0816af9ad..d8062be4b 100644
--- a/src/main/java/org/jacop/examples/fd/Parcel.java
+++ b/src/main/java/org/jacop/examples/fd/Parcel.java
@@ -35,7 +35,7 @@
import org.jacop.constraints.Circuit;
import org.jacop.constraints.Element;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.core.IntVar;
import org.jacop.core.Store;
@@ -123,13 +123,13 @@ public void model() {
for (int j = 0; j <= i; j++)
tripLoads[j] = loads[j];
IntVar partialLoad = new IntVar(store, "partialLoad[0-" + i + "]", 0, 15);
- store.impose(new Sum(tripLoads, partialLoad));
+ store.impose(new SumInt(store, tripLoads, "==", partialLoad));
}
cost = new IntVar(store, "Cost", 0, 100000);
// Computes the travel cost.
- store.impose(new Sum(costs, cost));
+ store.impose(new SumInt(store, costs, "==", cost));
vars.add(cost);
@@ -137,7 +137,7 @@ public void model() {
/**
* It executes the program to solve the parcel shipment problem.
- * @param args
+ * @param args no parameters
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/PerfectSquare.java b/src/main/java/org/jacop/examples/fd/PerfectSquare.java
index 106b42301..f2b939c4f 100644
--- a/src/main/java/org/jacop/examples/fd/PerfectSquare.java
+++ b/src/main/java/org/jacop/examples/fd/PerfectSquare.java
@@ -38,7 +38,7 @@
import org.jacop.constraints.Or;
import org.jacop.constraints.PrimitiveConstraint;
import org.jacop.constraints.Reified;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XgtC;
import org.jacop.constraints.XgteqY;
import org.jacop.constraints.XlteqC;
@@ -66,7 +66,7 @@
* a square of a given size.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PerfectSquare extends ExampleFD {
@@ -456,7 +456,7 @@ public void modelBasic() {
sumList.add(s);
}
- store.impose(new Sum(sumList, limit));
+ store.impose(new SumInt(store, sumList, "==", limit));
}
@@ -471,7 +471,7 @@ public void modelBasic() {
store.impose(new XmulCeqZ(b, squares[problemNo][1][j], s));
sumList.add(s);
}
- store.impose(new Sum(sumList, limit));
+ store.impose(new SumInt(store, sumList, "==", limit));
}
System.out.println("Number of variables: " + store.size());
diff --git a/src/main/java/org/jacop/examples/fd/ProAndCon.java b/src/main/java/org/jacop/examples/fd/ProAndCon.java
index 758ea5e66..f03388b16 100644
--- a/src/main/java/org/jacop/examples/fd/ProAndCon.java
+++ b/src/main/java/org/jacop/examples/fd/ProAndCon.java
@@ -36,8 +36,8 @@
import org.jacop.constraints.Alldifferent;
import org.jacop.constraints.Reified;
-import org.jacop.constraints.Sum;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.SumInt;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XeqY;
import org.jacop.constraints.XlteqC;
@@ -133,27 +133,27 @@ public void model() {
ArrayList votesMotion1 = new ArrayList();
for (int i = 0; i < 5; i++)
votesMotion1.add(vote[i][iMotion1]);
- store.impose(new Sum(votesMotion1, sum4Group[iMotion1]));
+ store.impose(new SumInt(store, votesMotion1, "==", sum4Group[iMotion1]));
ArrayList votesMotion2 = new ArrayList();
for (int i = 0; i < 5; i++)
votesMotion2.add(vote[i][iMotion2]);
- store.impose(new Sum(votesMotion2, sum4Group[iMotion2]));
+ store.impose(new SumInt(store, votesMotion2, "==", sum4Group[iMotion2]));
ArrayList votesMotion3 = new ArrayList();
for (int i = 0; i < 5; i++)
votesMotion3.add(vote[i][iMotion3]);
- store.impose(new Sum(votesMotion3, sum4Group[iMotion3]));
+ store.impose(new SumInt(store, votesMotion3, "==", sum4Group[iMotion3]));
ArrayList votesMotion4 = new ArrayList();
for (int i = 0; i < 5; i++)
votesMotion4.add(vote[i][iMotion4]);
- store.impose(new Sum(votesMotion4, sum4Group[iMotion4]));
+ store.impose(new SumInt(store, votesMotion4, "==", sum4Group[iMotion4]));
ArrayList votesMotion5 = new ArrayList();
for (int i = 0; i < 5; i++)
votesMotion5.add(vote[i][iMotion5]);
- store.impose(new Sum(votesMotion5, sum4Group[iMotion5]));
+ store.impose(new SumInt(store, votesMotion5, "==", sum4Group[iMotion5]));
// Clues enconding
@@ -172,7 +172,7 @@ public void model() {
vars.add(noYesVotes); vars.add(noNoVotes); vars.add(noVotes);
// We constraint number of yes votes.
- store.impose(new Sum(sum4Group, noYesVotes));
+ store.impose(new SumInt(store, sum4Group, "==", noYesVotes));
// To connect no of yes votes with no of no votes.
store.impose(new XplusYeqZ(noYesVotes, noNoVotes, noVotes));
@@ -192,16 +192,38 @@ public void model() {
weightedVotes[i] = new IntVar(store, "weightedVotes4" + surname[i], 1,
32);
- store.impose(new SumWeight(vote[iAkerman], weights,
- weightedVotes[iAkerman]));
- store.impose(new SumWeight(vote[iBaird], weights,
- weightedVotes[iBaird]));
- store.impose(new SumWeight(vote[iChatham], weights,
- weightedVotes[iChatham]));
- store.impose(new SumWeight(vote[iDuval], weights,
- weightedVotes[iDuval]));
- store.impose(new SumWeight(vote[iEtting], weights,
- weightedVotes[iEtting]));
+ int n = weights.length;
+ IntVar[] vs = new IntVar[n+1];
+ int[] ws = new int[n+1];
+ System.arraycopy(vote[iAkerman], 0, vs, 0, n);
+ System.arraycopy(weights, 0, ws, 0, n);
+ vs[n] = weightedVotes[iAkerman];
+ ws[n] = -1;
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight(vote[iAkerman], weights,
+ // weightedVotes[iAkerman]));
+ System.arraycopy(vote[iAkerman], 0, vs, 0, n);
+ System.arraycopy(weights, 0, ws, 0, n);
+ vs[n] = weightedVotes[iAkerman];
+ ws[n] = -1;
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight(vote[iBaird], weights,
+ // weightedVotes[iBaird]));
+ System.arraycopy(vote[iChatham], 0, vs, 0, n);
+ vs[n] = weightedVotes[iChatham];
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight(vote[iChatham], weights,
+ // weightedVotes[iChatham]));
+ System.arraycopy(vote[iDuval], 0, vs, 0, n);
+ vs[n] = weightedVotes[iDuval];
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight(vote[iDuval], weights,
+ // weightedVotes[iDuval]));
+ System.arraycopy(vote[iEtting], 0, vs, 0, n);
+ vs[n] = weightedVotes[iEtting];
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+ // store.impose(new SumWeight(vote[iEtting], weights,
+ // weightedVotes[iEtting]));
// All weightes votes must be different.
store.impose(new Alldifferent(weightedVotes));
@@ -222,14 +244,14 @@ public void model() {
// There are 5 votes for each person, this means that no of yes votes is
// at most 2.
IntVar sumOfReified = new IntVar(store, "noAgreeBairdAndDuval", 1, 5);
- store.impose(new Sum(reified, sumOfReified));
+ store.impose(new SumInt(store, reified, "==", sumOfReified));
store.impose(new XlteqC(sumOfReified, 2));
// 5. Mr. Chatham never made two yes votes on consecutive motions.
// implied constraint, the sum must be smaller than 4.
IntVar sumChatham = new IntVar(store, "sumChatham", 0, 3);
- store.impose(new Sum(vote[iChatham], sumChatham));
+ store.impose(new SumInt(store, vote[iChatham], "==", sumChatham));
// We take each pair and make sure they are not two yes votes
IntVar two = new IntVar(store, "2", 2, 2);
@@ -252,7 +274,7 @@ public void model() {
/**
* It executes the program which solves this logic puzzle.
- * @param args
+ * @param args command arguments (none here)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/Queens.java b/src/main/java/org/jacop/examples/fd/Queens.java
index cce3853b7..c821b714f 100644
--- a/src/main/java/org/jacop/examples/fd/Queens.java
+++ b/src/main/java/org/jacop/examples/fd/Queens.java
@@ -35,7 +35,7 @@
import org.jacop.constraints.Alldiff;
import org.jacop.constraints.Element;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XneqY;
import org.jacop.constraints.XplusCeqZ;
import org.jacop.core.IntVar;
@@ -213,7 +213,7 @@ public void modelFields() {
for (int j = 0; j < numberQ; j++)
row[j] = fields[i * numberQ + j];
IntVar rowSum = new IntVar(store, "row" + (i + 1), 1, 1);
- store.impose(new Sum(row, rowSum));
+ store.impose(new SumInt(store, row, "==", rowSum));
if (i == 0) {
store.impose(new Element(firstRowPosition, row, one));
}
@@ -227,7 +227,7 @@ public void modelFields() {
for (int i = 0; i < numberQ; i++)
column[i] = fields[i * numberQ + j];
IntVar columnSum = new IntVar(store, "column" + (j + 1), 1, 1);
- store.impose(new Sum(column, columnSum));
+ store.impose(new SumInt(store, column, "==", columnSum));
if (j == 0) {
store.impose(new Element(firstColumnPosition, column, one));
}
@@ -249,7 +249,7 @@ public void modelFields() {
IntVar diagonalSum = new IntVar(store, "diagonal-west-south-F" + (i + 1)
+ "," + 1, 0, 1);
diagonalSums[indexSum++] = diagonalSum;
- store.impose(new Sum(diagonal, diagonalSum));
+ store.impose(new SumInt(store, diagonal, "==", diagonalSum));
}
for (int i = numberQ - 1; i > 0; i--) {
@@ -260,7 +260,7 @@ public void modelFields() {
IntVar diagonalSum = new IntVar(store, "diagonal-west-north-F" + (i + 1)
+ "," + 1, 0, 1);
diagonalSums[indexSum++] = diagonalSum;
- store.impose(new Sum(diagonal, diagonalSum));
+ store.impose(new SumInt(store, diagonal, "==", diagonalSum));
}
for (int j = 1; j < numberQ - 1; j++) {
@@ -272,7 +272,7 @@ public void modelFields() {
IntVar diagonalSum = new IntVar(store, "diagonal-west-south-F" + (1)
+ "," + (j + 1), 0, 1);
diagonalSums[indexSum++] = diagonalSum;
- store.impose(new Sum(diagonal, diagonalSum));
+ store.impose(new SumInt(store, diagonal, "==", diagonalSum));
}
for (int j = 1; j < numberQ - 1; j++) {
@@ -284,17 +284,17 @@ public void modelFields() {
IntVar diagonalSum = new IntVar(store, "diagonal-west-north-F"
+ (numberQ) + "," + (j + 1), 0, 1);
diagonalSums[indexSum++] = diagonalSum;
- store.impose(new Sum(diagonal, diagonalSum));
+ store.impose(new SumInt(store, diagonal, "==", diagonalSum));
}
IntVar numberOfDiagonals = new IntVar(store, "takenDiagonals",
2 * numberQ - 1, 2 * numberQ);
- store.impose(new Sum(diagonalSums, numberOfDiagonals));
+ store.impose(new SumInt(store, diagonalSums, "==", numberOfDiagonals));
IntVar queenNo = new IntVar(store, "noQ", numberQ, numberQ);
- store.impose(new Sum(fields, queenNo));
+ store.impose(new SumInt(store, fields, "==", queenNo));
}
diff --git a/src/main/java/org/jacop/examples/fd/SendMoreMoney.java b/src/main/java/org/jacop/examples/fd/SendMoreMoney.java
index ed955e759..f18a7a537 100644
--- a/src/main/java/org/jacop/examples/fd/SendMoreMoney.java
+++ b/src/main/java/org/jacop/examples/fd/SendMoreMoney.java
@@ -34,7 +34,7 @@
import java.util.ArrayList;
import org.jacop.constraints.Alldiff;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XmulCeqZ;
import org.jacop.constraints.XneqC;
import org.jacop.constraints.XneqY;
@@ -56,11 +56,11 @@
* different letters represent different digits
* SEND 9567
- * +MORE =======> +1085
+ * +MORE ======={@literal >}+1085
* MONEY 10652
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
public class SendMoreMoney extends ExampleFD {
@@ -433,11 +433,19 @@ public void model() {
IntVar r = new IntVar(store, "R", 0, 9);
IntVar y = new IntVar(store, "Y", 0, 9);
+ /**
+ * We create auxilary variables in order to make it easier to express some of the
+ * constraints. Each auxilary variable holds a value for a given word.
+ */
+ IntVar valueSEND = new IntVar(store, "v(SEND)", 0, 9999);
+ IntVar valueMORE = new IntVar(store, "v(MORE)", 0, 9999);
+ IntVar valueMONEY = new IntVar(store, "v(MONEY)", 0, 99999);
+
// Creating arrays for FDVs
IntVar digits[] = { s, e, n, d, m, o, r, y };
- IntVar send[] = { s, e, n, d };
- IntVar more[] = { m, o, r, e };
- IntVar money[] = { m, o, n, e, y };
+ IntVar send[] = { s, e, n, d, valueSEND };
+ IntVar more[] = { m, o, r, e, valueMORE };
+ IntVar money[] = { m, o, n, e, y, valueMONEY };
for (IntVar v : digits)
vars.add(v);
@@ -488,16 +496,8 @@ public void model() {
* the constraint.
*/
- int[] weights5 = { 10000, 1000, 100, 10, 1 };
- int[] weights4 = { 1000, 100, 10, 1 };
-
- /**
- * We create auxilary variables in order to make it easier to express some of the
- * constraints. Each auxilary variable holds a value for a given word.
- */
- IntVar valueSEND = new IntVar(store, "v(SEND)", 0, 9999);
- IntVar valueMORE = new IntVar(store, "v(MORE)", 0, 9999);
- IntVar valueMONEY = new IntVar(store, "v(MONEY)", 0, 99999);
+ int[] weights5 = { 10000, 1000, 100, 10, 1, -1 };
+ int[] weights4 = { 1000, 100, 10, 1, -1 };
/**
* Constraints for getting value for words
@@ -505,9 +505,12 @@ public void model() {
* MORE = 1000 * M + 100 * O + R * 10 + E * 1
* MONEY = 10000 * M + 1000 * O + 100 * N + E * 10 + Y * 1
*/
- store.impose(new SumWeight(send, weights4, valueSEND));
- store.impose(new SumWeight(more, weights4, valueMORE));
- store.impose(new SumWeight(money, weights5, valueMONEY));
+ store.impose(new LinearInt(store, send, weights4, "==", 0));
+ // store.impose(new SumWeight(send, weights4, valueSEND));
+ store.impose(new LinearInt(store, more, weights4, "==", 0));
+ // store.impose(new SumWeight(more, weights4, valueMORE));
+ store.impose(new LinearInt(store, money, weights5, "==", 0));
+ // store.impose(new SumWeight(money, weights5, valueMONEY));
/**
* The auxilary variables allow us to express the main constraint
@@ -521,9 +524,10 @@ public void model() {
* It removes 2 wrong decisions.
*/
- int [] weightsImplied = {1000, 91, 10, 1, -9000, -900, -90};
- IntVar [] varsImplied = {s, e, r, d, m, o, n};
- store.impose(new SumWeight(varsImplied, weightsImplied, y));
+ int [] weightsImplied = {1000, 91, 10, 1, -9000, -900, -90, -1};
+ IntVar [] varsImplied = {s, e, r, d, m, o, n, y};
+ store.impose(new LinearInt(store, varsImplied, weightsImplied, "==", 0));
+ // store.impose(new SumWeight(varsImplied, weightsImplied, y));
/**
* The two constraints below were not explicit in the problem description. However,
diff --git a/src/main/java/org/jacop/examples/fd/StonesOfHeaven.java b/src/main/java/org/jacop/examples/fd/StonesOfHeaven.java
index 7ce80626f..70d845db3 100644
--- a/src/main/java/org/jacop/examples/fd/StonesOfHeaven.java
+++ b/src/main/java/org/jacop/examples/fd/StonesOfHeaven.java
@@ -164,7 +164,7 @@ public void model() {
/**
* It executes a simple program to solve this logic puzzle.
- * @param args
+ * @param args command arguments (none here)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/Sudoku.java b/src/main/java/org/jacop/examples/fd/Sudoku.java
index cad1d169c..bd3340065 100644
--- a/src/main/java/org/jacop/examples/fd/Sudoku.java
+++ b/src/main/java/org/jacop/examples/fd/Sudoku.java
@@ -46,7 +46,7 @@
/**
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Sudoku extends ExampleFD {
diff --git a/src/main/java/org/jacop/examples/fd/SurvoPuzzle.java b/src/main/java/org/jacop/examples/fd/SurvoPuzzle.java
index f05ebc643..5752f6757 100644
--- a/src/main/java/org/jacop/examples/fd/SurvoPuzzle.java
+++ b/src/main/java/org/jacop/examples/fd/SurvoPuzzle.java
@@ -37,7 +37,7 @@
import java.util.ArrayList;
import org.jacop.constraints.Alldiff;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XeqY;
import org.jacop.core.IntVar;
@@ -146,7 +146,7 @@ public void model() {
//
for(int i = 0; i < r; i++) {
IntVar r_sum = new IntVar(store, "r_" + i, 1, r*c*r*c);
- store.impose(new Sum(x[i], r_sum));
+ store.impose(new SumInt(store, x[i], "==", r_sum));
store.impose(new XeqC(r_sum, rowsums[i]));
}
@@ -160,7 +160,7 @@ public void model() {
cols.add(x[i][j]);
}
IntVar c_sum = new IntVar(store, "c_" + j, 1, r*c*r*c);
- store.impose(new Sum(cols, c_sum));
+ store.impose(new SumInt(store, cols, "==", c_sum));
store.impose(new XeqC(c_sum, colsums[j]));
}
diff --git a/src/main/java/org/jacop/examples/fd/TSP.java b/src/main/java/org/jacop/examples/fd/TSP.java
index c2ec4be77..80419bc7b 100644
--- a/src/main/java/org/jacop/examples/fd/TSP.java
+++ b/src/main/java/org/jacop/examples/fd/TSP.java
@@ -33,7 +33,7 @@
import org.jacop.constraints.Circuit;
import org.jacop.constraints.Element;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.core.IntVar;
import org.jacop.core.Store;
import org.jacop.search.DepthFirstSearch;
@@ -107,7 +107,7 @@ public void model() {
// Computes overall cost of traveling
// simply sum of all costs
- store.impose(new Sum(costs, cost));
+ store.impose(new SumInt(store, costs, "==", cost));
}
diff --git a/src/main/java/org/jacop/examples/fd/Tunapalooza.java b/src/main/java/org/jacop/examples/fd/Tunapalooza.java
index 0bbcb4c7c..9b28566c9 100644
--- a/src/main/java/org/jacop/examples/fd/Tunapalooza.java
+++ b/src/main/java/org/jacop/examples/fd/Tunapalooza.java
@@ -37,7 +37,7 @@
import org.jacop.constraints.And;
import org.jacop.constraints.Or;
import org.jacop.constraints.Reified;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XeqY;
import org.jacop.constraints.XneqC;
@@ -50,7 +50,7 @@
* It solves a simple logic puzzle about music concert.
*
* @author Lesniak Kamil, Harezlak Roman, Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
* Tim and Keri have a full day ahead for themselves as they plan to see
* and hear everything at Tunapalooza '98, the annual save-the-tuna
@@ -159,7 +159,7 @@ public void model() {
IntVar two = new IntVar(store, "2", 2, 2);
IntVar sum[] = { statement1, statement2, statement3 };
- store.impose(new Sum(sum, two));
+ store.impose(new SumInt(store, sum, "==", two));
for (IntVar v : sum)
vars.add(v);
diff --git a/src/main/java/org/jacop/examples/fd/WhoKilledAgatha.java b/src/main/java/org/jacop/examples/fd/WhoKilledAgatha.java
index 2c235f329..c541d3a27 100644
--- a/src/main/java/org/jacop/examples/fd/WhoKilledAgatha.java
+++ b/src/main/java/org/jacop/examples/fd/WhoKilledAgatha.java
@@ -35,7 +35,7 @@
import org.jacop.constraints.Eq;
import org.jacop.constraints.IfThen;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XlteqC;
import org.jacop.core.Domain;
@@ -218,7 +218,7 @@ public void model() {
a[j] = hates[i][j];
}
IntVar a_sum = new IntVar(store, "a_sum"+i, 0, n);
- store.impose(new Sum(a, a_sum));
+ store.impose(new SumInt(store, a, "==", a_sum));
store.impose(new XlteqC(a_sum, 2));
vars.add(a_sum);
@@ -276,7 +276,7 @@ public boolean search() {
/**
* It runs the program which solves the logic puzzle "Who killed Agatha".
- * @param args
+ * @param args parameters (none)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/WolfGoatCabbage.java b/src/main/java/org/jacop/examples/fd/WolfGoatCabbage.java
index 3a1bffc80..7764e4bac 100644
--- a/src/main/java/org/jacop/examples/fd/WolfGoatCabbage.java
+++ b/src/main/java/org/jacop/examples/fd/WolfGoatCabbage.java
@@ -36,7 +36,7 @@
import org.jacop.constraints.ExtensionalSupportVA;
import org.jacop.constraints.Reified;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XneqY;
import org.jacop.core.IntVar;
@@ -146,7 +146,7 @@ public void model() {
IntVar numberOnBoat = new IntVar(store, "numberOnBoatInMove" + i, 0,
1);
- store.impose(new Sum(b, numberOnBoat));
+ store.impose(new SumInt(store, b, "==", numberOnBoat));
store.impose(new XneqY(wolf[i], goat[i]));
store.impose(new XneqY(goat[i], cabbage[i]));
diff --git a/src/main/java/org/jacop/examples/fd/carsequencing/CarSequencing.java b/src/main/java/org/jacop/examples/fd/carsequencing/CarSequencing.java
index 1d4cdeebe..3f3a1508b 100644
--- a/src/main/java/org/jacop/examples/fd/carsequencing/CarSequencing.java
+++ b/src/main/java/org/jacop/examples/fd/carsequencing/CarSequencing.java
@@ -558,7 +558,7 @@ public static String[] readFile(String file) {
/**
* It executes the program to solve car sequencing problem.
- * @param args
+ * @param args parameters (none)
*/
public static void main(String args[]) {
@@ -580,7 +580,7 @@ public static void main(String args[]) {
/**
* It executes the program to solve car sequencing problem.
- * @param args
+ * @param args parameters (none)
*/
public static void test(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/crosswords/CrossWord.java b/src/main/java/org/jacop/examples/fd/crosswords/CrossWord.java
index edb872ba8..8d8d05d39 100644
--- a/src/main/java/org/jacop/examples/fd/crosswords/CrossWord.java
+++ b/src/main/java/org/jacop/examples/fd/crosswords/CrossWord.java
@@ -255,7 +255,7 @@ public void model() {
/**
* It prints a variable crosswordTemplate.
- * @param crossWordTemplate
+ * @param crossWordTemplate the template
*/
public void printSolution(char[][] crossWordTemplate) {
@@ -278,7 +278,7 @@ public void printSolution(char[][] crossWordTemplate) {
* of it for use by an extensional constraint.
*
* @param file filename containing dictionary
- * @param wordSizes
+ * @param wordSizes size of the words
*/
public void readDictionaryFromFile(String file, ArrayList wordSizes) {
diff --git a/src/main/java/org/jacop/examples/fd/filters/AR.java b/src/main/java/org/jacop/examples/fd/filters/AR.java
index 0b731392a..0438dcfeb 100644
--- a/src/main/java/org/jacop/examples/fd/filters/AR.java
+++ b/src/main/java/org/jacop/examples/fd/filters/AR.java
@@ -44,7 +44,7 @@
* Nonpipelined Designs" IEEE Trans. on CAD, vol. 11, no. 8, August 1992.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class AR extends Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/DCT.java b/src/main/java/org/jacop/examples/fd/filters/DCT.java
index fa0559488..e8cb80c7f 100644
--- a/src/main/java/org/jacop/examples/fd/filters/DCT.java
+++ b/src/main/java/org/jacop/examples/fd/filters/DCT.java
@@ -43,7 +43,7 @@
* Circuits and Systems, Volume 12, Issue 8, Aug. 1993 Page(s):1107 - 1122
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class DCT extends Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/DFQ.java b/src/main/java/org/jacop/examples/fd/filters/DFQ.java
index faeb7920e..5f0510370 100644
--- a/src/main/java/org/jacop/examples/fd/filters/DFQ.java
+++ b/src/main/java/org/jacop/examples/fd/filters/DFQ.java
@@ -37,7 +37,7 @@
* It specifies DFQ filter benchmark.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class DFQ extends Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/DOT.java b/src/main/java/org/jacop/examples/fd/filters/DOT.java
index 85862962b..8bb83d39e 100644
--- a/src/main/java/org/jacop/examples/fd/filters/DOT.java
+++ b/src/main/java/org/jacop/examples/fd/filters/DOT.java
@@ -42,7 +42,7 @@
* Power Data Path Synthesis" ICCAD 1995
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class DOT extends Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/EWF.java b/src/main/java/org/jacop/examples/fd/filters/EWF.java
index 9732725d9..f1e135321 100644
--- a/src/main/java/org/jacop/examples/fd/filters/EWF.java
+++ b/src/main/java/org/jacop/examples/fd/filters/EWF.java
@@ -41,7 +41,7 @@
* @see "Michel, P. and Lauther U. and Duzy, P., The Synthesis Approach to Digital System Design, Kluwer Academic Publisher, 1992"
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class EWF extends Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/FFT.java b/src/main/java/org/jacop/examples/fd/filters/FFT.java
index 0c9dd0dce..086fd8bef 100644
--- a/src/main/java/org/jacop/examples/fd/filters/FFT.java
+++ b/src/main/java/org/jacop/examples/fd/filters/FFT.java
@@ -42,7 +42,7 @@
* Symposium on VLSI p. 0095
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class FFT extends Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/FIR.java b/src/main/java/org/jacop/examples/fd/filters/FIR.java
index 93e2d1a25..67da052c5 100644
--- a/src/main/java/org/jacop/examples/fd/filters/FIR.java
+++ b/src/main/java/org/jacop/examples/fd/filters/FIR.java
@@ -37,11 +37,11 @@
* FIR benchmark (16-point FIR filter).
*
* Source: Ramesh Karri, Karin Hogstedt and Alex Orailoglu "Computer-Aided
- * Design of Fault-Tolerant VLSI Design Systems" IEEE Design & Test, Fall 1996
+ * Design of Fault-Tolerant VLSI Design Systems" IEEE Design {@literal &} Test, Fall 1996
* (Vol. 13, No. 3), pp. 88-96
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class FIR extends Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/FIR16.java b/src/main/java/org/jacop/examples/fd/filters/FIR16.java
index 81fbe9ede..75b1b3a48 100644
--- a/src/main/java/org/jacop/examples/fd/filters/FIR16.java
+++ b/src/main/java/org/jacop/examples/fd/filters/FIR16.java
@@ -41,7 +41,7 @@
* IEEE Trans. on CAD, vol. 25, no. 3, March 2006.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class FIR16 extends Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/Filter.java b/src/main/java/org/jacop/examples/fd/filters/Filter.java
index a73283e05..0374161d2 100644
--- a/src/main/java/org/jacop/examples/fd/filters/Filter.java
+++ b/src/main/java/org/jacop/examples/fd/filters/Filter.java
@@ -38,7 +38,7 @@
* filter problem.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*/
public abstract class Filter {
diff --git a/src/main/java/org/jacop/examples/fd/filters/FilterBenchmark.java b/src/main/java/org/jacop/examples/fd/filters/FilterBenchmark.java
index eab8e1c1f..1a5a65208 100644
--- a/src/main/java/org/jacop/examples/fd/filters/FilterBenchmark.java
+++ b/src/main/java/org/jacop/examples/fd/filters/FilterBenchmark.java
@@ -62,7 +62,7 @@
* This is a set of filter scheduling examples, commonly used in High-Level Synthesis.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class FilterBenchmark {
@@ -82,7 +82,7 @@ public class FilterBenchmark {
* algorithmic pipelining, multiplier pipelining,
* chaining, no special techniques).
*
- * @param args
+ * @param args parameters (none)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/fd/muca/MUCA.java b/src/main/java/org/jacop/examples/fd/muca/MUCA.java
index eeab69159..290be9316 100644
--- a/src/main/java/org/jacop/examples/fd/muca/MUCA.java
+++ b/src/main/java/org/jacop/examples/fd/muca/MUCA.java
@@ -41,7 +41,7 @@
import org.jacop.constraints.Among;
import org.jacop.constraints.ExtensionalSupportVA;
import org.jacop.constraints.IfThen;
-import org.jacop.constraints.Sum;
+import org.jacop.constraints.SumInt;
import org.jacop.constraints.XeqC;
import org.jacop.constraints.XgteqC;
import org.jacop.constraints.XplusYgtC;
@@ -62,7 +62,7 @@
* It solves the Mixed Multi-Unit Combinatorial Auctions.
*
* @author Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*
*
* The idea originated from reading the following paper
@@ -1012,7 +1012,7 @@ public void model() {
n.addDom(0, 0);
n.addDom(bid_xor.size(), bid_xor.size());
- store.impose(new Sum(xorUsedTransformation, n));
+ store.impose(new SumInt(store, xorUsedTransformation, "==", n));
usedXorBids.add(n);
@@ -1128,13 +1128,13 @@ public void model() {
}
- store.impose(new Sum(weights, sum[g]));
+ store.impose(new SumInt(store, weights, "==", sum[g]));
}
cost = new IntVar(store, "cost", minCost, maxCost);
- store.impose(new Sum(bidCosts, cost));
+ store.impose(new SumInt(store, bidCosts, "==", cost));
}
diff --git a/src/main/java/org/jacop/examples/fd/nonogram/Nonogram.java b/src/main/java/org/jacop/examples/fd/nonogram/Nonogram.java
index 6545a3948..bb5893cfa 100644
--- a/src/main/java/org/jacop/examples/fd/nonogram/Nonogram.java
+++ b/src/main/java/org/jacop/examples/fd/nonogram/Nonogram.java
@@ -167,7 +167,7 @@ public void readFromFile(String filename) {
* It produces and FSM given a sequence representing a rule. e.g. [2, 3]
* specifies that there are two black dots followed by three black dots.
*
- * @param sequence
+ * @param sequence a sequence representing a rule. e.g. [2, 3]
* @return Finite State Machine used by Regular automaton to enforce proper sequence.
*/
public FSM createAutomaton(int [] sequence) {
diff --git a/src/main/java/org/jacop/examples/flatzinc/FlatzincSGMPCS.java b/src/main/java/org/jacop/examples/flatzinc/FlatzincSGMPCS.java
index 2845718bf..e0ae91b10 100644
--- a/src/main/java/org/jacop/examples/flatzinc/FlatzincSGMPCS.java
+++ b/src/main/java/org/jacop/examples/flatzinc/FlatzincSGMPCS.java
@@ -47,7 +47,7 @@
* It is used for test purpose only.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class FlatzincSGMPCS {
Store store;
diff --git a/src/main/java/org/jacop/examples/flatzinc/FlatzincSolver.java b/src/main/java/org/jacop/examples/flatzinc/FlatzincSolver.java
index bb1b41350..6358656e8 100644
--- a/src/main/java/org/jacop/examples/flatzinc/FlatzincSolver.java
+++ b/src/main/java/org/jacop/examples/flatzinc/FlatzincSolver.java
@@ -46,7 +46,7 @@
* It is used for test purpose only.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class FlatzincSolver {
Store store;
@@ -95,6 +95,9 @@ void ex(String[] args) {
else
result = label.labeling(fl.getStore(), select);
+ if (! fl.getOptions().getAll() && fl.getSolve().lastSolution != null)
+ System.out.print(fl.getSolve().lastSolution);
+
fl.getSolve().statistics(result);
// System.out.println(fl.getTables());
diff --git a/src/main/java/org/jacop/examples/flatzinc/FloatMinimize.java b/src/main/java/org/jacop/examples/flatzinc/FloatMinimize.java
index 01deb27c9..7517a29e4 100644
--- a/src/main/java/org/jacop/examples/flatzinc/FloatMinimize.java
+++ b/src/main/java/org/jacop/examples/flatzinc/FloatMinimize.java
@@ -46,7 +46,7 @@
* It is used for test purpose only.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class FloatMinimize {
Store store;
@@ -103,7 +103,7 @@ void ex(String[] args) {
DepthFirstSearch label = new DepthFirstSearch();
SplitSelectFloat s = new SplitSelectFloat(store, vars, fl.getSearch().getFloatVarSelect());
- Optimize min = new Optimize(store, label, s, (FloatVar)fl.getCost());
+ Optimize min = new Optimize(store, label, s, (FloatVar)fl.getCost());
boolean result = min.minimize();
if ( result ) {
diff --git a/src/main/java/org/jacop/examples/floats/Rosenbrock.java b/src/main/java/org/jacop/examples/floats/Rosenbrock.java
index 9f7306868..9a24f495d 100644
--- a/src/main/java/org/jacop/examples/floats/Rosenbrock.java
+++ b/src/main/java/org/jacop/examples/floats/Rosenbrock.java
@@ -124,7 +124,7 @@ void rosenbrock() {
DepthFirstSearch label = new DepthFirstSearch();
SplitSelectFloat s = new SplitSelectFloat(store, new FloatVar[] {x1, x2}, null);
- Optimize min = new Optimize(store, label, s, z);
+ Optimize min = new Optimize(store, label, s, z);
boolean result = min.minimize();
System.out.println ("\nPrecision = " + FloatDomain.precision());
diff --git a/src/main/java/org/jacop/examples/floats/SixHumpCamelFunction.java b/src/main/java/org/jacop/examples/floats/SixHumpCamelFunction.java
index 0584ac644..6c3f5271b 100644
--- a/src/main/java/org/jacop/examples/floats/SixHumpCamelFunction.java
+++ b/src/main/java/org/jacop/examples/floats/SixHumpCamelFunction.java
@@ -154,7 +154,7 @@ void six_hump_camel_function() {
DepthFirstSearch label = new DepthFirstSearch();
SplitSelectFloat s = new SplitSelectFloat(store, new FloatVar[] {x1, x2}, null); //new LargestDomainFloat());
- Optimize min = new Optimize(store, label, s, f);
+ Optimize min = new Optimize(store, label, s, f);
boolean result = min.minimize();
if (!result)
diff --git a/src/main/java/org/jacop/examples/set/ExampleSet.java b/src/main/java/org/jacop/examples/set/ExampleSet.java
index ad53ec172..bc8e3447f 100644
--- a/src/main/java/org/jacop/examples/set/ExampleSet.java
+++ b/src/main/java/org/jacop/examples/set/ExampleSet.java
@@ -50,7 +50,7 @@
* It is an abstract class to describe all necessary functions of any store.
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public abstract class ExampleSet {
diff --git a/src/main/java/org/jacop/examples/set/Gardner.java b/src/main/java/org/jacop/examples/set/Gardner.java
index d45d68e61..0bd2c830f 100644
--- a/src/main/java/org/jacop/examples/set/Gardner.java
+++ b/src/main/java/org/jacop/examples/set/Gardner.java
@@ -52,14 +52,14 @@
* It specifies a simple Gardner problem which use set functionality from JaCoP.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Gardner extends ExampleSet {
/**
* It executes the program which solves this gardner problem.
- * @param args
+ * @param args parameters (none)
*/
public static void main(String args[]) {
diff --git a/src/main/java/org/jacop/examples/set/SocialGolfer.java b/src/main/java/org/jacop/examples/set/SocialGolfer.java
index 7ecc8529c..f59461115 100644
--- a/src/main/java/org/jacop/examples/set/SocialGolfer.java
+++ b/src/main/java/org/jacop/examples/set/SocialGolfer.java
@@ -33,7 +33,7 @@
import java.util.ArrayList;
-import org.jacop.constraints.SumWeight;
+import org.jacop.constraints.LinearInt;
import org.jacop.constraints.XlteqY;
import org.jacop.core.IntVar;
import org.jacop.core.IntervalDomain;
@@ -58,7 +58,7 @@
* It is a Social Golfer example based on set variables.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class SocialGolfer extends ExampleSet {
@@ -77,7 +77,7 @@ public class SocialGolfer extends ExampleSet {
*
* It runs a number of social golfer problems.
*
- * @param args
+ * @param args parameters (none)
*/
public static void main (String args[]) {
@@ -157,9 +157,9 @@ public static void main (String args[]) {
/**
* It sets the parameters for the model creation function.
*
- * @param weeks
- * @param groups
- * @param players
+ * @param weeks how many weeks to play
+ * @param groups how many groups will play
+ * @param players how many players will play
*/
public void setup(int weeks, int groups, int players) {
@@ -235,7 +235,16 @@ public void model() {
for (int j=0; j=1) if indexOffset is equal to 0.
+ * The list is addressed by positive integers ({@literal >=1}) if indexOffset is equal to 0.
*/
public double list[];
diff --git a/src/main/java/org/jacop/floats/constraints/EquationSystem.java b/src/main/java/org/jacop/floats/constraints/EquationSystem.java
index 591cd32d4..4870a5a39 100644
--- a/src/main/java/org/jacop/floats/constraints/EquationSystem.java
+++ b/src/main/java/org/jacop/floats/constraints/EquationSystem.java
@@ -47,7 +47,7 @@
* non-linear equations.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class EquationSystem extends Constraint {
@@ -72,7 +72,8 @@ public class EquationSystem extends Constraint {
/**
* It constructs the constraint EquationSystem.
- * @param f a variable that defines an eqation
+ * @param store current store
+ * @param f a variable that defines an eqation
* @param x variables of eqation system
*/
public EquationSystem(Store store, FloatVar[] f, FloatVar[] x) {
diff --git a/src/main/java/org/jacop/floats/constraints/ExpPeqR.java b/src/main/java/org/jacop/floats/constraints/ExpPeqR.java
index fae9943c5..711198b0f 100644
--- a/src/main/java/org/jacop/floats/constraints/ExpPeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/ExpPeqR.java
@@ -50,7 +50,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class ExpPeqR extends Constraint {
diff --git a/src/main/java/org/jacop/floats/constraints/IntervalGaussSeidel.java b/src/main/java/org/jacop/floats/constraints/IntervalGaussSeidel.java
index 26d450cfb..d3696443c 100644
--- a/src/main/java/org/jacop/floats/constraints/IntervalGaussSeidel.java
+++ b/src/main/java/org/jacop/floats/constraints/IntervalGaussSeidel.java
@@ -46,7 +46,7 @@
* coefficients.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class IntervalGaussSeidel {
diff --git a/src/main/java/org/jacop/floats/constraints/LinearFloat.java b/src/main/java/org/jacop/floats/constraints/LinearFloat.java
index 409153725..6b7a0bdda 100644
--- a/src/main/java/org/jacop/floats/constraints/LinearFloat.java
+++ b/src/main/java/org/jacop/floats/constraints/LinearFloat.java
@@ -43,16 +43,22 @@
* LinearFloat constraint implements the weighted summation over several
* Variable's . It provides the weighted sum from all Variable's on the list.
*
+ * This version works as argument to Reified and Xor constraints. For
+ * other constraints And, Or, Not, Eq, IfThen, IfThenElse it does not
+ * work currently.
+ *
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class LinearFloat extends Linear {
/**
- * @param list
- * @param weights
- * @param sum
+ * @param store current store
+ * @param list variables which are being multiplied by weights.
+ * @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
+ * @param sum variable containing the sum of weighted variables.
*/
public LinearFloat(Store store, FloatVar[] list, double[] weights, String rel, double sum) {
@@ -61,8 +67,10 @@ public LinearFloat(Store store, FloatVar[] list, double[] weights, String rel, d
/**
* It constructs the constraint LinearFloat.
+ * @param store current store
* @param variables variables which are being multiplied by weights.
* @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}"
* @param sum variable containing the sum of weighted variables.
*/
public LinearFloat(Store store, ArrayList extends FloatVar> variables,
diff --git a/src/main/java/org/jacop/floats/constraints/LnPeqR.java b/src/main/java/org/jacop/floats/constraints/LnPeqR.java
index 6dc955b8c..af0533361 100644
--- a/src/main/java/org/jacop/floats/constraints/LnPeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/LnPeqR.java
@@ -41,7 +41,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class LnPeqR extends ExpPeqR {
diff --git a/src/main/java/org/jacop/floats/constraints/Max.java b/src/main/java/org/jacop/floats/constraints/Max.java
index c1d0e2792..dd6e9aa35 100644
--- a/src/main/java/org/jacop/floats/constraints/Max.java
+++ b/src/main/java/org/jacop/floats/constraints/Max.java
@@ -48,7 +48,7 @@
* max(list) = max.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Max extends Constraint {
diff --git a/src/main/java/org/jacop/floats/constraints/Min.java b/src/main/java/org/jacop/floats/constraints/Min.java
index a6bdd99db..d6db2c44a 100644
--- a/src/main/java/org/jacop/floats/constraints/Min.java
+++ b/src/main/java/org/jacop/floats/constraints/Min.java
@@ -46,7 +46,7 @@
* varable from all FD varaibles on the list.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class Min extends Constraint {
diff --git a/src/main/java/org/jacop/floats/constraints/MultivariateIntervalNewton.java b/src/main/java/org/jacop/floats/constraints/MultivariateIntervalNewton.java
index d56ace13f..3a4b7f820 100644
--- a/src/main/java/org/jacop/floats/constraints/MultivariateIntervalNewton.java
+++ b/src/main/java/org/jacop/floats/constraints/MultivariateIntervalNewton.java
@@ -54,7 +54,7 @@
* method for solving a system of non linear equations.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class MultivariateIntervalNewton {
diff --git a/src/main/java/org/jacop/floats/constraints/PdivCeqR.java b/src/main/java/org/jacop/floats/constraints/PdivCeqR.java
index e8dca95c0..9bb5ce5ea 100644
--- a/src/main/java/org/jacop/floats/constraints/PdivCeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/PdivCeqR.java
@@ -40,7 +40,7 @@
* Boundary consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PdivCeqR extends PmulCeqR {
diff --git a/src/main/java/org/jacop/floats/constraints/PdivQeqR.java b/src/main/java/org/jacop/floats/constraints/PdivQeqR.java
index 494ffdd2b..3ba372271 100644
--- a/src/main/java/org/jacop/floats/constraints/PdivQeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/PdivQeqR.java
@@ -40,7 +40,7 @@
* Boundary consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PdivQeqR extends PmulQeqR {
diff --git a/src/main/java/org/jacop/floats/constraints/PeqC.java b/src/main/java/org/jacop/floats/constraints/PeqC.java
index d31aec3be..40985df02 100644
--- a/src/main/java/org/jacop/floats/constraints/PeqC.java
+++ b/src/main/java/org/jacop/floats/constraints/PeqC.java
@@ -50,7 +50,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PeqC extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/floats/constraints/PeqQ.java b/src/main/java/org/jacop/floats/constraints/PeqQ.java
index fc589ffb8..432213fb4 100644
--- a/src/main/java/org/jacop/floats/constraints/PeqQ.java
+++ b/src/main/java/org/jacop/floats/constraints/PeqQ.java
@@ -49,7 +49,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PeqQ extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/floats/constraints/PgtC.java b/src/main/java/org/jacop/floats/constraints/PgtC.java
index 00bb7f4a1..49d163f05 100644
--- a/src/main/java/org/jacop/floats/constraints/PgtC.java
+++ b/src/main/java/org/jacop/floats/constraints/PgtC.java
@@ -45,10 +45,10 @@
import org.jacop.floats.core.FloatDomain;
/**
- * Constraint P #> C
+ * Constraint P {@literal >} C
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PgtC extends PrimitiveConstraint {
@@ -72,7 +72,7 @@ public class PgtC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"p", "c"};
/**
- * It constructs constraint P > C.
+ * It constructs constraint P {@literal >} C.
* @param p variable p.
* @param c constant c.
*/
diff --git a/src/main/java/org/jacop/floats/constraints/PgtQ.java b/src/main/java/org/jacop/floats/constraints/PgtQ.java
index b6379dcac..f2d47b01c 100644
--- a/src/main/java/org/jacop/floats/constraints/PgtQ.java
+++ b/src/main/java/org/jacop/floats/constraints/PgtQ.java
@@ -45,11 +45,11 @@
import org.jacop.floats.core.FloatDomain;
/**
- * Constraint P > Q for floats
+ * Constraint P {@literal >} Q for floats
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PgtQ extends PrimitiveConstraint {
@@ -74,7 +74,7 @@ public class PgtQ extends PrimitiveConstraint {
public static String[] xmlAttributes = {"p", "q"};
/**
- * It constructs constraint P <= Q.
+ * It constructs constraint P {@literal <=} Q.
* @param p variable p.
* @param q constant q.
*/
diff --git a/src/main/java/org/jacop/floats/constraints/PgteqC.java b/src/main/java/org/jacop/floats/constraints/PgteqC.java
index c99d7933d..b250e61a6 100644
--- a/src/main/java/org/jacop/floats/constraints/PgteqC.java
+++ b/src/main/java/org/jacop/floats/constraints/PgteqC.java
@@ -45,10 +45,10 @@
import org.jacop.floats.core.FloatDomain;
/**
- * Constraints P #>= C for floats
+ * Constraints P {@literal >=} C for floats
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PgteqC extends PrimitiveConstraint {
@@ -72,7 +72,7 @@ public class PgteqC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"p", "c"};
/**
- * It constructs constraint P >= C.
+ * It constructs constraint P {@literal >=} C.
* @param p variable p.
* @param c constant c.
*/
diff --git a/src/main/java/org/jacop/floats/constraints/PgteqQ.java b/src/main/java/org/jacop/floats/constraints/PgteqQ.java
index 00bca9c63..64192d2a5 100644
--- a/src/main/java/org/jacop/floats/constraints/PgteqQ.java
+++ b/src/main/java/org/jacop/floats/constraints/PgteqQ.java
@@ -45,10 +45,10 @@
import org.jacop.floats.core.FloatDomain;
/**
- * Constraints P >= Q for floats
+ * Constraints P {@literal >=} Q for floats
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PgteqQ extends PrimitiveConstraint {
@@ -72,7 +72,7 @@ public class PgteqQ extends PrimitiveConstraint {
public static String[] xmlAttributes = {"p", "q"};
/**
- * It constructs constraint P >= Q.
+ * It constructs constraint P {@literal >=} Q.
* @param p variable p.
* @param q variable q.
*/
diff --git a/src/main/java/org/jacop/floats/constraints/PltC.java b/src/main/java/org/jacop/floats/constraints/PltC.java
index c11598a2c..021309e5c 100644
--- a/src/main/java/org/jacop/floats/constraints/PltC.java
+++ b/src/main/java/org/jacop/floats/constraints/PltC.java
@@ -45,10 +45,10 @@
import org.jacop.floats.core.FloatDomain;
/**
- * Constraint P #< C for floats
+ * Constraint P {@literal <} C for floats
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PltC extends PrimitiveConstraint {
@@ -72,7 +72,7 @@ public class PltC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"p", "c"};
/**
- * It constructs constraint P < C.
+ * It constructs constraint P {@literal <} C.
* @param p variable p.
* @param c constant c.
*/
diff --git a/src/main/java/org/jacop/floats/constraints/PltQ.java b/src/main/java/org/jacop/floats/constraints/PltQ.java
index 412cfd4aa..31a706327 100644
--- a/src/main/java/org/jacop/floats/constraints/PltQ.java
+++ b/src/main/java/org/jacop/floats/constraints/PltQ.java
@@ -45,10 +45,10 @@
import org.jacop.floats.core.FloatDomain;
/**
- * Constraint P < Q for floats
+ * Constraint P {@literal <} Q for floats
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PltQ extends PrimitiveConstraint {
@@ -72,7 +72,7 @@ public class PltQ extends PrimitiveConstraint {
public static String[] xmlAttributes = {"p", "q"};
/**
- * It constructs constraint P < C.
+ * It constructs constraint P {@literal <} C.
* @param p variable p.
* @param q constant q.
*/
diff --git a/src/main/java/org/jacop/floats/constraints/PlteqC.java b/src/main/java/org/jacop/floats/constraints/PlteqC.java
index b4eb59097..5667de71e 100644
--- a/src/main/java/org/jacop/floats/constraints/PlteqC.java
+++ b/src/main/java/org/jacop/floats/constraints/PlteqC.java
@@ -45,11 +45,11 @@
import org.jacop.floats.core.FloatDomain;
/**
- * Constraint X #<= C for floats
+ * Constraint X {@literal <=} C for floats
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PlteqC extends PrimitiveConstraint {
@@ -73,7 +73,7 @@ public class PlteqC extends PrimitiveConstraint {
public static String[] xmlAttributes = {"p", "c"};
/**
- * It constructs constraint P <= C.
+ * It constructs constraint P {@literal <=} C.
* @param p variable p.
* @param c constant c.
*/
diff --git a/src/main/java/org/jacop/floats/constraints/PlteqQ.java b/src/main/java/org/jacop/floats/constraints/PlteqQ.java
index f333b3a78..927f415f9 100644
--- a/src/main/java/org/jacop/floats/constraints/PlteqQ.java
+++ b/src/main/java/org/jacop/floats/constraints/PlteqQ.java
@@ -45,11 +45,11 @@
import org.jacop.floats.core.FloatDomain;
/**
- * Constraint P <= Q for floats
+ * Constraint P {@literal <=} Q for floats
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PlteqQ extends PrimitiveConstraint {
@@ -74,7 +74,7 @@ public class PlteqQ extends PrimitiveConstraint {
public static String[] xmlAttributes = {"p", "q"};
/**
- * It constructs constraint P <= Q.
+ * It constructs constraint P {@literal <=} Q.
* @param p variable p.
* @param q constant q.
*/
diff --git a/src/main/java/org/jacop/floats/constraints/PminusCeqR.java b/src/main/java/org/jacop/floats/constraints/PminusCeqR.java
index 071358c8e..65c930954 100644
--- a/src/main/java/org/jacop/floats/constraints/PminusCeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/PminusCeqR.java
@@ -39,7 +39,7 @@
* Bound consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PminusCeqR extends PplusCeqR {
diff --git a/src/main/java/org/jacop/floats/constraints/PminusQeqR.java b/src/main/java/org/jacop/floats/constraints/PminusQeqR.java
index 965a87e4e..ccc92473d 100644
--- a/src/main/java/org/jacop/floats/constraints/PminusQeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/PminusQeqR.java
@@ -39,7 +39,7 @@
* Bound consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PminusQeqR extends PplusQeqR {
diff --git a/src/main/java/org/jacop/floats/constraints/PmulCeqR.java b/src/main/java/org/jacop/floats/constraints/PmulCeqR.java
index 207726fb9..3a2140479 100644
--- a/src/main/java/org/jacop/floats/constraints/PmulCeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/PmulCeqR.java
@@ -50,7 +50,7 @@
* Boundary consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PmulCeqR extends Constraint {
diff --git a/src/main/java/org/jacop/floats/constraints/PmulQeqR.java b/src/main/java/org/jacop/floats/constraints/PmulQeqR.java
index 284c97bc7..acf2e53e0 100644
--- a/src/main/java/org/jacop/floats/constraints/PmulQeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/PmulQeqR.java
@@ -50,7 +50,7 @@
* Boundary consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PmulQeqR extends Constraint {
diff --git a/src/main/java/org/jacop/floats/constraints/PneqC.java b/src/main/java/org/jacop/floats/constraints/PneqC.java
index 15ebba05e..34e71eea2 100644
--- a/src/main/java/org/jacop/floats/constraints/PneqC.java
+++ b/src/main/java/org/jacop/floats/constraints/PneqC.java
@@ -50,7 +50,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PneqC extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/floats/constraints/PneqQ.java b/src/main/java/org/jacop/floats/constraints/PneqQ.java
index 7dd58a0d3..b054bad20 100644
--- a/src/main/java/org/jacop/floats/constraints/PneqQ.java
+++ b/src/main/java/org/jacop/floats/constraints/PneqQ.java
@@ -49,7 +49,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PneqQ extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/floats/constraints/PplusCeqR.java b/src/main/java/org/jacop/floats/constraints/PplusCeqR.java
index e136190d3..d4eeaed69 100644
--- a/src/main/java/org/jacop/floats/constraints/PplusCeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/PplusCeqR.java
@@ -49,7 +49,7 @@
* Bound consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PplusCeqR extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/floats/constraints/PplusQeqR.java b/src/main/java/org/jacop/floats/constraints/PplusQeqR.java
index 74ada896a..2c456e4f0 100644
--- a/src/main/java/org/jacop/floats/constraints/PplusQeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/PplusQeqR.java
@@ -51,7 +51,7 @@
* Bound consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class PplusQeqR extends PrimitiveConstraint {
diff --git a/src/main/java/org/jacop/floats/constraints/SinPeqR.java b/src/main/java/org/jacop/floats/constraints/SinPeqR.java
index cfc72f8c0..17ce8618c 100644
--- a/src/main/java/org/jacop/floats/constraints/SinPeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/SinPeqR.java
@@ -56,7 +56,7 @@
* Bounds consistency can be used; third parameter of constructor controls this.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class SinPeqR extends Constraint {
diff --git a/src/main/java/org/jacop/floats/constraints/SqrtPeqR.java b/src/main/java/org/jacop/floats/constraints/SqrtPeqR.java
index 63fb8bb0b..8fbb8bd79 100644
--- a/src/main/java/org/jacop/floats/constraints/SqrtPeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/SqrtPeqR.java
@@ -41,7 +41,7 @@
* Boundary consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class SqrtPeqR extends PmulQeqR {
diff --git a/src/main/java/org/jacop/floats/constraints/TanPeqR.java b/src/main/java/org/jacop/floats/constraints/TanPeqR.java
index 84e259400..dcf2a0971 100644
--- a/src/main/java/org/jacop/floats/constraints/TanPeqR.java
+++ b/src/main/java/org/jacop/floats/constraints/TanPeqR.java
@@ -56,7 +56,7 @@
* Bounds consistency can be used; third parameter of constructor controls this.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class TanPeqR extends Constraint {
diff --git a/src/main/java/org/jacop/floats/constraints/XeqP.java b/src/main/java/org/jacop/floats/constraints/XeqP.java
index aa7bfa378..2e9a56756 100644
--- a/src/main/java/org/jacop/floats/constraints/XeqP.java
+++ b/src/main/java/org/jacop/floats/constraints/XeqP.java
@@ -49,7 +49,7 @@
* Domain consistency is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class XeqP extends Constraint {
diff --git a/src/main/java/org/jacop/floats/constraints/linear/BNode.java b/src/main/java/org/jacop/floats/constraints/linear/BNode.java
index 600f1aa7d..05f32c8b5 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/BNode.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/BNode.java
@@ -35,7 +35,7 @@
* Binary Node of the tree representing linear constraint.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
import org.jacop.floats.core.FloatDomain;
diff --git a/src/main/java/org/jacop/floats/constraints/linear/BTree.java b/src/main/java/org/jacop/floats/constraints/linear/BTree.java
index 1a4a09270..6f84c595e 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/BTree.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/BTree.java
@@ -35,7 +35,7 @@
* Binary Node of the tree representing linear constraint.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class BTree{
diff --git a/src/main/java/org/jacop/floats/constraints/linear/BinaryNode.java b/src/main/java/org/jacop/floats/constraints/linear/BinaryNode.java
index 85bd54607..5cafecdf7 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/BinaryNode.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/BinaryNode.java
@@ -35,7 +35,7 @@
* Binary Node of the tree representing linear constraint.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
import org.jacop.floats.core.FloatDomain;
diff --git a/src/main/java/org/jacop/floats/constraints/linear/BoundsVar.java b/src/main/java/org/jacop/floats/constraints/linear/BoundsVar.java
index 2a0287d3a..667660bfc 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/BoundsVar.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/BoundsVar.java
@@ -40,7 +40,7 @@
* values
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
class BoundsVar implements MutableVar {
diff --git a/src/main/java/org/jacop/floats/constraints/linear/BoundsVarValue.java b/src/main/java/org/jacop/floats/constraints/linear/BoundsVarValue.java
index cd5c124d5..27c7d2692 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/BoundsVarValue.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/BoundsVarValue.java
@@ -41,7 +41,7 @@
* Defines a current bounds for the Linear constraint.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
class BoundsVarValue implements MutableVarValue {
diff --git a/src/main/java/org/jacop/floats/constraints/linear/Linear.java b/src/main/java/org/jacop/floats/constraints/linear/Linear.java
index 3f164108b..463632349 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/Linear.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/Linear.java
@@ -55,7 +55,7 @@
* The weights must be positive integers.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class Linear extends PrimitiveConstraint {
@@ -119,9 +119,11 @@ public class Linear extends PrimitiveConstraint {
public static String[] xmlAttributes = {"list", "weights", "sum"};
/**
- * @param list
- * @param weights
- * @param sum
+ * @param store current store
+ * @param list variables which are being multiplied by weights.
+ * @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}", "{@literal !=}"
+ * @param sum variable containing the sum of weighted variables.
*/
public Linear(Store store, FloatVar[] list, double[] weights, String rel, double sum) {
@@ -275,8 +277,10 @@ RootBNode buildBinaryTree(BinaryNode[] nodes) {
/**
* It constructs the constraint Linear.
+ * @param store current store
* @param variables variables which are being multiplied by weights.
* @param weights weight for each variable.
+ * @param rel the relation, one of "==", "{@literal <}", "{@literal >}", "{@literal <=}", "{@literal >=}"
* @param sum variable containing the sum of weighted variables.
*/
public Linear(Store store, ArrayList extends FloatVar> variables,
diff --git a/src/main/java/org/jacop/floats/constraints/linear/RootBNode.java b/src/main/java/org/jacop/floats/constraints/linear/RootBNode.java
index 3acb6cfc9..fbb517335 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/RootBNode.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/RootBNode.java
@@ -35,7 +35,7 @@
* Binary Node of the tree representing linear constraint.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
import org.jacop.core.IntDomain;
diff --git a/src/main/java/org/jacop/floats/constraints/linear/VarNode.java b/src/main/java/org/jacop/floats/constraints/linear/VarNode.java
index 241567d99..fedcdbdc4 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/VarNode.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/VarNode.java
@@ -35,7 +35,7 @@
* Binary Node of the tree representing linear constraint.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
import org.jacop.floats.core.FloatVar;
diff --git a/src/main/java/org/jacop/floats/constraints/linear/VarWeightNode.java b/src/main/java/org/jacop/floats/constraints/linear/VarWeightNode.java
index 53192cd64..2a9e5b476 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/VarWeightNode.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/VarWeightNode.java
@@ -35,7 +35,7 @@
* Binary Node of the tree representing linear constraint.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
import org.jacop.floats.core.FloatVar;
diff --git a/src/main/java/org/jacop/floats/constraints/linear/VariableNode.java b/src/main/java/org/jacop/floats/constraints/linear/VariableNode.java
index ecdd9dbc7..e7bf020c0 100644
--- a/src/main/java/org/jacop/floats/constraints/linear/VariableNode.java
+++ b/src/main/java/org/jacop/floats/constraints/linear/VariableNode.java
@@ -35,7 +35,7 @@
* Binary Node of the tree representing linear constraint.
*
* @author Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
import org.jacop.floats.core.FloatVar;
diff --git a/src/main/java/org/jacop/floats/core/FloatDomain.java b/src/main/java/org/jacop/floats/core/FloatDomain.java
index a32e4ac11..9787c4649 100644
--- a/src/main/java/org/jacop/floats/core/FloatDomain.java
+++ b/src/main/java/org/jacop/floats/core/FloatDomain.java
@@ -47,7 +47,7 @@
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public abstract class FloatDomain extends Domain {
@@ -81,6 +81,8 @@ public abstract class FloatDomain extends Domain {
/**
* It defines rounding method
+ *
+ * @param out defines rounding method true = outward, false = no rounding outward
*/
public static void setOutward(boolean out) {
outward = out;
diff --git a/src/main/java/org/jacop/floats/core/FloatInterval.java b/src/main/java/org/jacop/floats/core/FloatInterval.java
index 8f2c25b71..23a6daad6 100644
--- a/src/main/java/org/jacop/floats/core/FloatInterval.java
+++ b/src/main/java/org/jacop/floats/core/FloatInterval.java
@@ -39,7 +39,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public final class FloatInterval {
@@ -117,10 +117,10 @@ public double min() {
*/
public boolean singleton() {
- // double large = (Math.abs(max) >= Math.abs(min)) ? max : min;
- double small = (Math.abs(max) >= Math.abs(min)) ? min : max;
+ double large = (Math.abs(max) >= Math.abs(min)) ? max : min;
+ // double small = (Math.abs(max) >= Math.abs(min)) ? min : max;
- return (max-min) <= FloatDomain.epsilon(small);
+ return (max-min) <= FloatDomain.epsilon(large);
}
diff --git a/src/main/java/org/jacop/floats/core/FloatIntervalDomain.java b/src/main/java/org/jacop/floats/core/FloatIntervalDomain.java
index e3e86af26..77dd65587 100644
--- a/src/main/java/org/jacop/floats/core/FloatIntervalDomain.java
+++ b/src/main/java/org/jacop/floats/core/FloatIntervalDomain.java
@@ -56,7 +56,7 @@
*
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
- * @version 4.3
+ * @version 4.4
*/
public class FloatIntervalDomain extends FloatDomain {
@@ -100,7 +100,7 @@ public FloatIntervalDomain() {
* specified in xmlAttributes.
*
* @param tf a place to write the content of the object.
- * @throws SAXException
+ * @throws SAXException exception from org.xml.sax
*/
public void toXML(TransformerHandler tf) throws SAXException {
@@ -259,8 +259,9 @@ public void unionAdapt(FloatInterval i) {
/**
* It adds a value to the domain. It adds at the end without
* checks for the correctness of domain representation.
+ *
+ * @param i value to be added
*/
-
public void addLastElement(double i) {
assert checkInvariants() == null : checkInvariants() ;
diff --git a/src/main/java/org/jacop/floats/core/FloatIntervalDomainIntervalEnumeration.java b/src/main/java/org/jacop/floats/core/FloatIntervalDomainIntervalEnumeration.java
index 300a06781..f1a7e7dfc 100644
--- a/src/main/java/org/jacop/floats/core/FloatIntervalDomainIntervalEnumeration.java
+++ b/src/main/java/org/jacop/floats/core/FloatIntervalDomainIntervalEnumeration.java
@@ -38,7 +38,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class FloatIntervalDomainIntervalEnumeration extends FloatIntervalEnumeration {
diff --git a/src/main/java/org/jacop/floats/core/FloatIntervalEnumeration.java b/src/main/java/org/jacop/floats/core/FloatIntervalEnumeration.java
index 1a5d8d943..fd6a24d5c 100644
--- a/src/main/java/org/jacop/floats/core/FloatIntervalEnumeration.java
+++ b/src/main/java/org/jacop/floats/core/FloatIntervalEnumeration.java
@@ -40,7 +40,7 @@
*
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public abstract class FloatIntervalEnumeration implements Enumeration{
diff --git a/src/main/java/org/jacop/floats/core/FloatVar.java b/src/main/java/org/jacop/floats/core/FloatVar.java
index a62d48346..e31697416 100644
--- a/src/main/java/org/jacop/floats/core/FloatVar.java
+++ b/src/main/java/org/jacop/floats/core/FloatVar.java
@@ -43,7 +43,7 @@
* Defines a Float Domain Variable and related operations on it.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
public class FloatVar extends Var {
diff --git a/src/main/java/org/jacop/floats/search/LargestDomainFloat.java b/src/main/java/org/jacop/floats/search/LargestDomainFloat.java
index 813830417..f6bd6e596 100644
--- a/src/main/java/org/jacop/floats/search/LargestDomainFloat.java
+++ b/src/main/java/org/jacop/floats/search/LargestDomainFloat.java
@@ -41,7 +41,7 @@
* domain has the priority.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
* @param it specifies the class of the variable being used in this variable selection method.
*/
diff --git a/src/main/java/org/jacop/floats/search/LargestMaxFloat.java b/src/main/java/org/jacop/floats/search/LargestMaxFloat.java
index f15c433de..87898c7bd 100644
--- a/src/main/java/org/jacop/floats/search/LargestMaxFloat.java
+++ b/src/main/java/org/jacop/floats/search/LargestMaxFloat.java
@@ -39,7 +39,7 @@
* Defines a LargestMaxFloat comparator for Variables.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
* @param type of IntVar being compared.
*/
diff --git a/src/main/java/org/jacop/floats/search/LargestMinFloat.java b/src/main/java/org/jacop/floats/search/LargestMinFloat.java
index 459a2c67a..5f90543c1 100644
--- a/src/main/java/org/jacop/floats/search/LargestMinFloat.java
+++ b/src/main/java/org/jacop/floats/search/LargestMinFloat.java
@@ -39,7 +39,7 @@
* Defines a LargestMinFloat comparator for Variables.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
* @param type of IntVar being compared.
*/
diff --git a/src/main/java/org/jacop/floats/search/Optimize.java b/src/main/java/org/jacop/floats/search/Optimize.java
index 206d64aa1..5dc2a532b 100644
--- a/src/main/java/org/jacop/floats/search/Optimize.java
+++ b/src/main/java/org/jacop/floats/search/Optimize.java
@@ -52,16 +52,16 @@
* Implements optimization for floating point varibales
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
*/
-public class Optimize {
+public class Optimize {
Store store;
- DepthFirstSearch search;
+ DepthFirstSearch search;
FloatVar cost;
SplitSelectFloat split;
- SelectChoicePoint select;
+ SelectChoicePoint select;
Var[] variables;
double costValue = Double.NaN;
@@ -70,7 +70,7 @@ public class Optimize {
FloatInterval lastCost;
FloatInterval[] lastVarValues;
- public Optimize(Store store, DepthFirstSearch search, SelectChoicePoint select, FloatVar cost) {
+ public Optimize(Store store, DepthFirstSearch search, SelectChoicePoint select, FloatVar cost) {
this.store = store;
this.search = search;
@@ -85,7 +85,7 @@ public Optimize(Store store, DepthFirstSearch search, SelectChoicePoint select,
for (int i = 0; i < sVar.length; i++)
variables[i] = sVar[i];
- search.setSolutionListener(new ResultListener(variables));
+ search.setSolutionListener(new ResultListener(variables));
split = new SplitSelectFloat(store, new FloatVar[] {cost}, null);
diff --git a/src/main/java/org/jacop/floats/search/SmallestDomainFloat.java b/src/main/java/org/jacop/floats/search/SmallestDomainFloat.java
index 068da96de..4225f0a58 100644
--- a/src/main/java/org/jacop/floats/search/SmallestDomainFloat.java
+++ b/src/main/java/org/jacop/floats/search/SmallestDomainFloat.java
@@ -41,7 +41,7 @@
* domain has the priority.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
* @param type of variable being used in the search.
*/
diff --git a/src/main/java/org/jacop/floats/search/SmallestMaxFloat.java b/src/main/java/org/jacop/floats/search/SmallestMaxFloat.java
index 755dd0a8e..83a6149da 100644
--- a/src/main/java/org/jacop/floats/search/SmallestMaxFloat.java
+++ b/src/main/java/org/jacop/floats/search/SmallestMaxFloat.java
@@ -40,7 +40,7 @@
* have a priority over variable with maximum value equal 10.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
* @param type of variable being used in the search.
*/
diff --git a/src/main/java/org/jacop/floats/search/SmallestMinFloat.java b/src/main/java/org/jacop/floats/search/SmallestMinFloat.java
index 8b19ee39d..f61e2b799 100644
--- a/src/main/java/org/jacop/floats/search/SmallestMinFloat.java
+++ b/src/main/java/org/jacop/floats/search/SmallestMinFloat.java
@@ -40,7 +40,7 @@
* which have smaller minimal value in their domain.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
* @param type of variable being used in the search.
*/
diff --git a/src/main/java/org/jacop/floats/search/SplitSelectFloat.java b/src/main/java/org/jacop/floats/search/SplitSelectFloat.java
index 88f64ef72..bdebd6814 100644
--- a/src/main/java/org/jacop/floats/search/SplitSelectFloat.java
+++ b/src/main/java/org/jacop/floats/search/SplitSelectFloat.java
@@ -52,11 +52,11 @@
/**
* It is simple and customizable selector of decisions (constraints) which will
* be enforced by search. However, it does not use P=c as a search decision
- * but rather P <= c (potentially splitting the domain), unless c is equal to
- * the maximal value in the domain of P then the constraint P < c is used.
+ * but rather P {@literal <=} c (potentially splitting the domain), unless c is equal to
+ * the maximal value in the domain of P then the constraint P {@literal <} c is used.
*
* @author Krzysztof Kuchcinski and Radoslaw Szymanek
- * @version 4.3
+ * @version 4.4
* @param type of variable being used in the search.
*/
@@ -79,6 +79,7 @@ public class SplitSelectFloat extends SimpleSelect {
/**
* The constructor to create a simple choice select mechanism.
+ * @param store current store
* @param variables variables upon which the choice points are created.
* @param varSelect the variable comparator to choose the variable.
*/
@@ -93,6 +94,7 @@ public SplitSelectFloat(Store store, T[] variables,
/**
* It constructs a simple selection mechanism for choice points.
+ * @param store current store
* @param variables variables used as basis of the choice point.
* @param varSelect the main variable comparator.
* @param tieBreakerVarSelect secondary variable comparator employed if the first one gives the same metric.
diff --git a/src/main/java/org/jacop/floats/search/WeightedDegreeFloat.java b/src/main/java/org/jacop/floats/search/WeightedDegreeFloat.java
index 08e5e781c..8aedda9b2 100644
--- a/src/main/java/org/jacop/floats/search/WeightedDegreeFloat.java
+++ b/src/main/java/org/jacop/floats/search/WeightedDegreeFloat.java
@@ -47,7 +47,7 @@
*
* @author Radoslaw Szymanek and Krzysztof Kuchcinski
*
- * @version 4.3
+ * @version 4.4
* @param type of variable being compared.
*
*/
diff --git a/src/main/java/org/jacop/fz/Constraints.java b/src/main/java/org/jacop/fz/Constraints.java
index 5db661fff..fdfad3ed5 100644
--- a/src/main/java/org/jacop/fz/Constraints.java
+++ b/src/main/java/org/jacop/fz/Constraints.java
@@ -31,6 +31,8 @@
package org.jacop.fz;
import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
import org.jacop.constraints.*;
import org.jacop.constraints.knapsack.Knapsack;
@@ -83,7 +85,7 @@ public class Constraints implements ParserTreeConstants {
Tables dictionary;
Store store;
String p;
- IntVar zero, one;
+ // IntVar zero, one;
final static int eq=0, ne=1, lt=2, gt=3, le=4, ge=5;
boolean intPresent = true;
boolean floatPresent = true;
@@ -105,14 +107,15 @@ public class Constraints implements ParserTreeConstants {
// boolean storeLevelIncreased=false;
- final static boolean debug = false;
+ static boolean debug = false;
/**
* It creates an object to parse the constraint part of the flatzinc file.
* @param store the constraint store in which the constraints are being created.
*/
- public Constraints(Store store) {
+ public Constraints(Store store, Tables dict) {
this.store = store;
+ this.dictionary = dict;
sat = new SatTranslation(store);
sat.debug = debug;
@@ -164,11 +167,32 @@ public Constraints(Store store) {
// }
// }
// }
-// }
+//
+//}
+ void generateAllConstraints(SimpleNode astTree, Options opt) {
+
+ this.debug = opt.debug();
+ this.opt = opt;
+
+ int n = astTree.jjtGetNumChildren();
+
+ for (int i=0; i< n; i++) {
+ SimpleNode node = (SimpleNode)astTree.jjtGetChild(i);
+ // go for ConstraintItems
+ if (node.getId() == JJTCONSTRAINTITEMS) {
+
+ int k = node.jjtGetNumChildren();
+ for (int j = 0; j < k; j++) {
+ generateConstraint((SimpleNode)node.jjtGetChild(j));
+ }
+ }
+ }
- void generateConstraints(SimpleNode constraintWithAnnotations, Tables table, Options opt) throws FailException {
+ poseDelayedConstraints();
+
+ }
- this.opt = opt;
+ void generateConstraint(SimpleNode constraintWithAnnotations) throws FailException {
// if (!storeLevelIncreased) {
// System.out.println("1. Level="+store.level);
@@ -185,10 +209,6 @@ void generateConstraints(SimpleNode constraintWithAnnotations, Tables table, Opt
domainConsistency = false;
definedVar = null;
- dictionary = table;
- this.zero = table.zero;
- this.one = table.one;
-
int numberChildren = constraintWithAnnotations.jjtGetNumChildren();
// System.out.println ("numberChildren = "+numberChildren);
if (numberChildren > 1 )
@@ -196,8 +216,6 @@ void generateConstraints(SimpleNode constraintWithAnnotations, Tables table, Opt
SimpleNode node = (SimpleNode)constraintWithAnnotations.jjtGetChild(0);
-// node.dump("=> ");
-
// Predicates
if (node.getId() == JJTCONSTELEM) {
@@ -438,11 +456,18 @@ else if (p2.getType() == 0) {// p2 int
else if (p3.getType() == 0) {// p3 int
pose(new XmulYeqC(getVariable(p1), getVariable(p2), getInt(p3)));
}
- else
- pose(new XmulYeqZ(getVariable(p1), getVariable(p2), getVariable(p3)));
+ else {
+ IntVar v1 = getVariable(p1), v2 = getVariable(p2), v3 = getVariable(p3);
+ if (v1.min() >= 0 && v1.max() <= 1 && v2.min() >= 0 && v2.max() <= 1 && v3.min() >= 0 && v3.max() <= 1)
+ pose(new AndBoolSimple(v1, v2, v3));
+ else if ( (v1.singleton() && v1.value() == 0) || (v2.singleton() && v2.value() == 0))
+ v3.domain.in(store.level, v3, 0,0);
+ else
+ pose(new XmulYeqZ(v1, v2, v3));
+ }
}
else if (p.startsWith("div", 4)) {
- // p1/p2 = p3 <=> p2 * p3 = p1
+ // p1/p2 = p3
ASTScalarFlatExpr p1 = (ASTScalarFlatExpr)node.jjtGetChild(0);
ASTScalarFlatExpr p2 = (ASTScalarFlatExpr)node.jjtGetChild(1);
ASTScalarFlatExpr p3 = (ASTScalarFlatExpr)node.jjtGetChild(2);
@@ -453,23 +478,6 @@ else if (p.startsWith("div", 4)) {
pose(new XdivYeqZ(v1, v2, v3));
-// Variable r = new Variable(store, IntDomain.MinInt, IntDomain.MaxInt);
-// Variable t = new Variable(store, IntDomain.MinInt, IntDomain.MaxInt);
-
-// pose(new XplusYeqZ(r, t, v1));
-
-// // follows new flatzinc standard; reminder has the same sign as the first argument
-// Variable absV2 = new Variable(store, 0, IntDomain.MaxInt);
-// Variable minusAbsV2 = new Variable(store, IntDomain.MinInt, 0);
-// pose(new AbsXeqY(v2, absV2));
-// pose(new XplusYeqC(minusAbsV2, absV2, 0));
-// pose(new IfThen(new XgtC(v1, 0), new And(new XltY(r, absV2), new XgteqC(r, 0))));
-// pose(new IfThen(new XltC(v1, 0), new And(new XgtY(r, minusAbsV2), new XlteqC(r, 0))));
-
-// // pose(new Eq(new XgtC(v2, 0), new And(new XltY(r, v2), new XgteqC(r, 0))));
-// // pose(new Eq(new XltC(v2, 0), new And(new XgtY(r, v2), new XlteqC(r, 0))));
-
-// pose(new XmulYeqZ(v2, v3, t));
}
else if (p.startsWith("mod", 4)) {
ASTScalarFlatExpr p1 = (ASTScalarFlatExpr)node.jjtGetChild(0);
@@ -482,22 +490,6 @@ else if (p.startsWith("mod", 4)) {
pose(new XmodYeqZ(v1, v2, v3));
-// Variable t1 = new Variable(store, IntDomain.MinInt, IntDomain.MaxInt);
-// Variable t2 = new Variable(store, IntDomain.MinInt, IntDomain.MaxInt);
-
-// pose(new XplusYeqZ(t2, v3, v1));
-// // follows new flatzinc standard; reminder has the same sign as the first argument
-// Variable absV2 = new Variable(store, 0, IntDomain.MaxInt);
-// Variable minusAbsV2 = new Variable(store, IntDomain.MinInt, 0);
-// pose(new AbsXeqY(v2, absV2));
-// pose(new XplusYeqC(minusAbsV2, absV2, 0));
-// pose(new IfThen(new XgtC(v1, 0), new And(new XltY(v3, absV2), new XgteqC(v3, 0))));
-// pose(new IfThen(new XltC(v1, 0), new And(new XgtY(v3, minusAbsV2), new XlteqC(v3, 0))));
-
-// // pose(new Eq(new XgtC(v2, 0), new And(new XltY(v3, v2), new XgteqC(v3, 0))));
-// // pose(new Eq(new XltC(v2, 0), new And(new XgtY(v3, v2), new XlteqC(v3, 0))));
-
-// pose(new XmulYeqZ(t1, v2, t2));
}
else if (p.startsWith("min", 4)) {
ASTScalarFlatExpr p1 = (ASTScalarFlatExpr)node.jjtGetChild(0);
@@ -611,9 +603,9 @@ else if (p.startsWith("xor", 11)) {
IntVar[] a1 = getVarArray(p1);
if (opt.useSat())
- sat.generate_xor(a1, one);
+ sat.generate_xor(a1, dictionary.getConstant(1)); // one);
else
- pose(new XorBool(a1, one));
+ pose(new XorBool(a1, dictionary.getConstant(1))); // one));
}
else if (p.startsWith("element", 11)) {
@@ -753,7 +745,7 @@ else if (p.startsWith("or", 5)) {
if (opt.useSat())
sat.generate_or(new IntVar[] {v1, v2}, v3);
else
- pose(new OrBool(new IntVar[] {v1, v2}, v3));
+ pose(new OrBoolSimple(v1, v2, v3));
}
// bool_and
else if (p.startsWith("and", 5)) {
@@ -769,7 +761,7 @@ else if (p.startsWith("and", 5)) {
if (opt.useSat())
sat.generate_and(new IntVar[] {v1, v2}, v3);
else
- pose(new AndBool(new IntVar[] {v1, v2}, v3));
+ pose(new AndBoolSimple(v1, v2, v3));
}
// bool_xor
else if (p.startsWith("xor", 5)) {
@@ -827,8 +819,20 @@ else if (p.startsWith("right_imp", 5)) {
// x1 \/ ... \/ xm \/ not y1 \/ ... \/ not yn
else if (p.startsWith("clause", 5)) {
- IntVar[] a1 = getVarArray((SimpleNode)node.jjtGetChild(0));
- IntVar[] a2 = getVarArray((SimpleNode)node.jjtGetChild(1));
+ boolean reified = p.startsWith("_reif", 11);
+
+ IntVar[] a1 = unique(getVarArray((SimpleNode)node.jjtGetChild(0)));
+ IntVar[] a2 = unique(getVarArray((SimpleNode)node.jjtGetChild(1)));
+ for (IntVar v1 : a1)
+ for (IntVar v2 : a2)
+ if (v1.equals(v2))
+ if (reified) {
+ IntVar r = getVariable((ASTScalarFlatExpr)node.jjtGetChild(2));
+ r.domain.in(store.level, r, 1, 1);
+ return;
+ }
+ else
+ return; // already satisfied since a variable is both negated and not negated
if (a1.length == 0 && a2.length == 0 )
return;
@@ -844,29 +848,49 @@ else if (p.startsWith("clause", 5)) {
else { // not SAT generation, use CP constraints
ArrayList a1reduced = new ArrayList();
for (int i = 0; i < a1.length; i++)
- if (a1[i].max() != 0)
+ if (a1[i].min() == 1)
+ if (reified) {
+ IntVar r = getVariable((ASTScalarFlatExpr)node.jjtGetChild(2));
+ r.domain.in(store.level, r, 1, 1);
+ return;
+ }
+ else
+ return; // already satisfied since a variable is both negated and not negated
+ else if (a1[i].max() != 0)
a1reduced.add(a1[i]);
- ArrayList a2reduced = new ArrayList();
+
+ ArrayList a2reduced = new ArrayList();
for (int i = 0; i < a2.length; i++)
- if (a2[i].min() != 1)
+ if (a2[i].max() == 0)
+ if (reified) {
+ IntVar r = getVariable((ASTScalarFlatExpr)node.jjtGetChild(2));
+ r.domain.in(store.level, r, 1, 1);
+ return;
+ }
+ else
+ return; // already satisfied since a variable is both negated and not negated
+ else if (a2[i].min() != 1)
a2reduced.add(a2[i]);
+
if (a1reduced.size() == 0 && a2reduced.size() == 0 )
throw store.failException;
PrimitiveConstraint c;
if (a1reduced.size() == 0)
- c = new AndBool(a2reduced, zero);
- else if (a2reduced.size() == 0)
- c = new OrBool(a1reduced, one);
+ c = new AndBool(a2reduced, dictionary.getConstant(0));
+ else if (a2reduced.size() == 0) {
+ c = new OrBool(a1reduced, dictionary.getConstant(1));
+ }
else if (a1reduced.size() == 1 && a2reduced.size() == 1)
c = new XlteqY(a2reduced.get(0), a1reduced.get(0));
- else
+ else
c = new BoolClause(a1reduced, a2reduced);
// bool_clause_reif/3 defined in redefinitions-2.0.
- if (p.startsWith("_reif", 11)) {
+ if (reified) {
IntVar r = getVariable((ASTScalarFlatExpr)node.jjtGetChild(2));
- pose(new Reified(c, r)); }
+ pose(new Reified(c, r));
+ }
else
pose(c);
}
@@ -1000,7 +1024,13 @@ else if (p.startsWith("in", 4)) {
IntDomain d = getSetLiteral(node, 1);
IntVar v1 = getVariable(p1);
if (p.startsWith("_reif", 6))
- c = new org.jacop.constraints.In(v1, d);
+ // if (opt.useSat()) { // it can be moved to SAT solver but it is slow in the current implementation
+ // IntVar v3 = getVariable((ASTScalarFlatExpr)node.jjtGetChild(2));
+ // sat.generate_inSet_reif(v1, d, v3);
+ // return;
+ // }
+ // else
+ c = new org.jacop.constraints.In(v1, d);
else {
v1.domain.in(store.level, v1, d);
return;
@@ -1095,6 +1125,10 @@ else if (p.startsWith("symdiff", 4)) {
else if (p.equals("bool2int") || p.equals("int2bool") ) {
// node.dump("");
+ //nothing to generate here; already alias variables take care of this
+ // need only add equality if p2 is output var
+
+ /*
ASTScalarFlatExpr p1 = (ASTScalarFlatExpr)node.jjtGetChild(0);
ASTScalarFlatExpr p2 = (ASTScalarFlatExpr)node.jjtGetChild(1);
@@ -1103,8 +1137,14 @@ else if (p.equals("bool2int") || p.equals("int2bool") ) {
// else
pose(new XeqY(getVariable(p1), getVariable(p2)));
+ */
}
// ========== JaCoP constraints ==================>>
+ // check for reified (pattern "jacop_\S+_reif"; in Java "jacop_\\S+_reif")
+ else if (p.matches("jacop_\\S+_reif")) {
+ System.out.println("Refications for " + p + " not supported");
+ System.exit(0);
+ }
else if (p.startsWith("jacop_"))
if (p.startsWith("cumulative", 6)) {
@@ -1113,18 +1153,17 @@ else if (p.startsWith("jacop_"))
IntVar[] r = getVarArray((SimpleNode)node.jjtGetChild(2));
IntVar b = getVariable((ASTScalarFlatExpr)node.jjtGetChild(3));
- // if (b.min() == b.max())
- // b = new IntVar(store, 0, b.max());
-
- // if (boundsConsistency)
- // pose(new Cumulative(s, d, r, b, true, false, false));
- // else
- pose(new Cumulative(s, d, r, b, true, true, false));
+ if (s.length > 200)
+ // for large number of taks (>200)
+ // edge-finding is not used
+ pose(new Cumulative(s, d, r, b, false, true, false));
+ else
+ pose(new Cumulative(s, d, r, b, true, true, false));
}
else if (p.startsWith("circuit", 6)) {
IntVar[] v = getVarArray((SimpleNode)node.jjtGetChild(0));
-
+
pose(new Circuit(v));
if ( domainConsistency && ! opt.getBoundConsistency()) // we add additional implied constraint if domain consistency is required
@@ -1147,7 +1186,7 @@ else if (p.startsWith("alldiff", 6)) {
// intiallization; we collect all vectors and pose it at the end when all constraints are posed
// pose(new Alldistinct(v));
- if (boundsConsistency) {
+ if (boundsConsistency || opt.getBoundConsistency()) {
pose(new Alldiff(v));
// System.out.println("Alldiff imposed");
}
@@ -1179,7 +1218,39 @@ else if (p.startsWith("among_var", 6)) {
// we do not not pose AmongVar directly because of possible inconsistency with its
// intiallization; we collect all constraints and pose them at the end when all other constraints are posed
- delayedConstraints.add(new AmongVar(x, s, v));
+ // ---- KK, 2015-10-17
+ // among must not have duplicated variables there
+ // could be constants that have the same value and
+ // are duplicated.
+ IntVar[] xx = new IntVar[x.length];
+ HashSet varSet = new HashSet();
+ for (int i = 0; i < x.length; i++) {
+ if (varSet.contains(x[i]) && x[i].singleton())
+ xx[i] = new IntVar(store, x[i].min(), x[i].max());
+ else {
+ xx[i] = x[i];
+ varSet.add(x[i]);
+ }
+ }
+ IntVar[] ss = new IntVar[s.length];
+ varSet = new HashSet();
+ for (int i = 0; i < s.length; i++) {
+ if (varSet.contains(s[i]) && s[i].singleton())
+ ss[i] = new IntVar(store, s[i].min(), s[i].max());
+ else {
+ ss[i] = s[i];
+ varSet.add(s[i]);
+ }
+ }
+ IntVar vv;
+ if (varSet.contains(v) && v.singleton())
+ vv = new IntVar(store, v.min(), v.max());
+ else
+ vv = v;
+ //----
+
+
+ delayedConstraints.add(new AmongVar(xx, ss, vv));
// pose(new AmongVar(x, s, v));
}
else if (p.startsWith("among", 6)) {
@@ -1187,9 +1258,26 @@ else if (p.startsWith("among", 6)) {
IntDomain s = getSetLiteral(node, 1);
IntVar v = getVariable((ASTScalarFlatExpr)node.jjtGetChild(2));
- // if (s.singleton())
- // pose(new Count(x, v, s.value()));
- // else {
+ // ---- KK, 2015-10-17
+ // among must not have duplicated variables. In x vecor
+ // could be constants that have the same value and
+ // are duplicated.
+ IntVar[] xx = new IntVar[x.length];
+ HashSet varSet = new HashSet();
+ for (int i = 0; i < x.length; i++) {
+ if (varSet.contains(x[i]) && x[i].singleton())
+ xx[i] = new IntVar(store, x[i].min(), x[i].max());
+ else {
+ xx[i] = x[i];
+ varSet.add(x[i]);
+ }
+ }
+ IntVar vv;
+ if (varSet.contains(v) && v.singleton())
+ vv = new IntVar(store, v.min(), v.max());
+ else
+ vv = v;
+ //----
IntervalDomain setImpl = new IntervalDomain();
for (ValueEnumeration e = s.valueEnumeration(); e.hasMoreElements();) {
@@ -1198,7 +1286,7 @@ else if (p.startsWith("among", 6)) {
setImpl.unionAdapt(new IntervalDomain(val, val));
}
- pose(new Among(x, setImpl, v));
+ pose(new Among(xx, setImpl, vv));
// }
}
@@ -1268,6 +1356,7 @@ else if (p.startsWith("global_cardinality_low_up_closed", 6)) {
pose( new GCC(x, counter));
}
else if (p.startsWith("diff2_strict", 6)) {
+
IntVar[] x = getVarArray((SimpleNode)node.jjtGetChild(0));
IntVar[] y = getVarArray((SimpleNode)node.jjtGetChild(1));
IntVar[] lx = getVarArray((SimpleNode)node.jjtGetChild(2));
@@ -1306,7 +1395,15 @@ else if (p.startsWith("nvalue", 6)) {
IntVar n = getVariable((ASTScalarFlatExpr)node.jjtGetChild(0));
IntVar[] x = getVarArray((SimpleNode)node.jjtGetChild(1));
- pose(new Values(x, n));
+ // reification is defined in nvalue.mzn as decomposition
+ // if (p.startsWith("_reif", 12)) {
+ // IntVar b = getVariable((ASTScalarFlatExpr)node.jjtGetChild(2));
+ // IntVar tmp = new IntVar(store, 1, x.length);
+ // pose(new Values(x, tmp));
+ // pose(new Reified(new XeqY(tmp, n), b));
+ // }
+ // else
+ pose(new Values(x, n));
}
else if (p.startsWith("minimum_arg_int", 6)) {
IntVar[] x = getVarArray((SimpleNode)node.jjtGetChild(0));
@@ -1345,10 +1442,54 @@ else if (p.startsWith("table_int", 6) ||
for (int j=0; j varSet = new HashSet();
+ for (int i = 0; i < x.length; i++) {
+ if (varSet.contains(x[i]) && x[i].singleton())
+ xx[i] = new IntVar(store, x[i].min(), x[i].max());
+ else {
+ xx[i] = x[i];
+ varSet.add(xx[i]);
+ }
+ }
+ //----
+ */
+
// Build DFA
FSM dfa = new FSM();
FSMState[] s = new FSMState[Q];
@@ -1513,10 +1674,6 @@ else if (p.startsWith("lex_less_int", 6) || p.startsWith("lex_less_bool", 6)) {
// System.out.println ("lex_less_int: x.length = " + x.length + " y.length = " + y.length);
pose(new LexOrder(x, y, true));
-
- // DecomposedConstraint c = new org.jacop.constraints.Lex(new IntVar[][] {x, y}, true);
- // store.imposeDecomposition(c);
-
}
else if (p.startsWith("lex_lesseq_int", 6) || p.startsWith("lex_lesseq_bool", 6)) {
IntVar[] x = getVarArray((SimpleNode)node.jjtGetChild(0));
@@ -1525,19 +1682,32 @@ else if (p.startsWith("lex_lesseq_int", 6) || p.startsWith("lex_lesseq_bool", 6)
// System.out.println ("lex_lesseq_int: x.length = " + x.length + " y.length = " + y.length);
pose(new LexOrder(x, y, false));
-
- // DecomposedConstraint c = new org.jacop.constraints.Lex(new IntVar[][] {x, y});
- // store.imposeDecomposition(c);
}
else if (p.startsWith("bin_packing", 6)) {
IntVar[] bin = getVarArray((SimpleNode)node.jjtGetChild(0));
IntVar[] capacity = getVarArray((SimpleNode)node.jjtGetChild(1));
int[] w = getIntArray((SimpleNode)node.jjtGetChild(2));
-
- pose( new org.jacop.constraints.binpacking.Binpacking(bin, capacity, w) );
-// Constraint binPack = new org.jacop.constraints.binpacking.Binpacking(bin, capacity, w);
-// delayedConstraints.add(binPack);
+ int min_bin = getInt((ASTScalarFlatExpr)node.jjtGetChild(3));
+
+ // ---- KK, 2015-10-18
+ // bin_packing must not have duplicated variables. on x vecor
+ // could be constants that have the same value and
+ // are duplicated.
+ IntVar[] binx = new IntVar[bin.length];
+ HashSet varSet = new HashSet();
+ for (int i = 0; i < bin.length; i++) {
+ if (varSet.contains(bin[i]) && bin[i].singleton())
+ binx[i] = new IntVar(store, bin[i].min(), bin[i].max());
+ else {
+ binx[i] = bin[i];
+ varSet.add(bin[i]);
+ }
+ }
+
+ //pose( new org.jacop.constraints.binpacking.Binpacking(binx, capacity, w) );
+ Constraint binPack = new org.jacop.constraints.binpacking.Binpacking(binx, capacity, w, min_bin);
+ delayedConstraints.add(binPack);
}
else if (p.startsWith("float_maximum", 6)) {
FloatVar p2 = getFloatVariable((ASTScalarFlatExpr)node.jjtGetChild(1));
@@ -1694,16 +1864,16 @@ void int_negate(SimpleNode node) throws FailException {
PrimitiveConstraint c = null;
if (p2.getType() == 0) { // p2 int
IntVar v1 = getVariable(p1);
- c = new XplusCeqZ(v1, p2.getInt(), zero);
+ c = new XplusCeqZ(v1, p2.getInt(), dictionary.getConstant(0)); // zero);
}
else if (p1.getType() == 0) { // p1 int
IntVar v2 = getVariable(p2);
- c = new XplusCeqZ(v2, p1.getInt(), zero);
+ c = new XplusCeqZ(v2, p1.getInt(), dictionary.getConstant(0)); // zero);
}
else {
IntVar v1 = getVariable(p1);
IntVar v2 = getVariable(p2);
- c = new XplusYeqZ(v1, v2, zero);
+ c = new XplusYeqZ(v1, v2, dictionary.getConstant(0)); // zero);
}
pose(c);
}
@@ -1749,7 +1919,12 @@ else if (v3.min() == 1) {
return;
}
else
- c = new XeqC(v1, i2);
+ // if (opt.useSat()) { // it can be moved to SAT solver but it is slow in the current implementation
+ // sat.generate_eqC_reif(v1, i2, v3);
+ // return;
+ // }
+ // else
+ c = new XeqC(v1, i2);
break;
case ne :
@@ -1769,7 +1944,12 @@ else if (v3.min() == 1) {
return;
}
else
- c = new XneqC(v1, i2);
+ // if (opt.useSat()) { // it can be moved to SAT solver but it is slow in the current implementation
+ // sat.generate_neC_reif(v1, i2, v3);
+ // return;
+ // }
+ // else
+ c = new XneqC(v1, i2);
break;
case lt :
if (v1.max() < i2) {
@@ -1893,7 +2073,12 @@ else if (i1 > v2.max() ) {
return;
}
else
- c = new XgteqC(v2, i1);
+ // if (opt.useSat()) { // it can be moved to SAT solver but it is slow in the current implementation
+ // sat.generate_geC_reif(v2, i1, v3);
+ // return;
+ // }
+ // else
+ c = new XgteqC(v2, i1);
break;
case ge :
if (i1 > v2.max()) {
@@ -2447,10 +2632,20 @@ void int_lin_relation(int operation, SimpleNode node) throws FailException {
throw store.failException;
}
- Constraint c = new SumWeight(p2, p1, par3);
- // System.out.println (c);
-
- pose(c);
+ if (allWeightsOne(p1))
+ pose(new SumBool(store, p2, "==", par3));
+ else {
+ int n = p1.length;
+ IntVar[] vs = new IntVar[n+1];
+ int[] ws = new int[n+1];
+ System.arraycopy(p2, 0, vs, 0, n);
+ System.arraycopy(p1, 0, ws, 0, n);
+ vs[n] = par3;
+ ws[n] = -1;
+ store.impose(new LinearInt(store, vs, ws, "==", 0));
+
+ // pose(new SumWeight(p2, p1, par3));
+ }
return;
}
@@ -2470,6 +2665,19 @@ void int_lin_relation(int operation, SimpleNode node) throws FailException {
}
}
+ // If a linear term contains only constants and can be evaluated
+ // check if satisfied and do not generate constraint
+
+ boolean p2Fixed = allConstants(p2);
+ int s=0;
+ if (p2Fixed) {
+ int el=0;
+ while (el < p2.length) {
+ s += p2[el].min()*p1[el];
+ el++;
+ }
+ }
+
if (p.startsWith("_reif", 10)) { // reified
IntVar p4 = getVariable((ASTScalarFlatExpr)node.jjtGetChild(3));
@@ -2477,11 +2685,21 @@ void int_lin_relation(int operation, SimpleNode node) throws FailException {
IntVar t;
switch (operation) {
case eq :
+
+ if (p2Fixed) {
+ if (s == p3)
+ p4.domain.in(store.level, p4, 1, 1);
+ else
+ p4.domain.in(store.level, p4, 0, 0);
+ return;
+ }
+
if (p1.length == 1) {
if (p1[0] == 1)
pose(new Reified(new XeqC(p2[0], p3), p4));
else
- pose(new Reified(new XmulCeqZ(p2[0], p1[0], new IntVar(store, p3,p3)), p4));
+ // pose(new Reified(new XmulCeqZ(p2[0], p1[0], new IntVar(store, p3,p3)), p4));
+ pose(new Reified(new XmulCeqZ(p2[0], p1[0], dictionary.getConstant(p3)), p4));
}
else if (p1.length == 2 && p1[0] == 1 && p1[1] == -1) {
pose(new Reified(new XplusCeqZ(p2[1], p3, p2[0]), p4));
@@ -2503,7 +2721,10 @@ else if (p1.length == 2 && p1[0] == -1 && p1[1] == -1) {
for (int i=0; i p4
+ if (opt.useSat())
+ sat.generate_allZero_reif(unique(p2), p4);
+ else
+ pose(new Not(new OrBoolVector(p2, p4)));
+ else
+ pose(new Reified(new SumBool(store, p2, "<=", t), p4));
+ else
+ pose(new Reified(new SumInt(store, p2, "<=", t), p4));
}
else if (allWeightsMinusOne(p1)) {
- t = new IntVar(store, -p3, -p3);
- pose(new Reified(new SumInt(store, p2, ">=", t), p4));
+ t = dictionary.getConstant(-p3); //new IntVar(store, -p3, -p3);
+ if (boolSum(p2))
+ pose(new Reified(new SumBool(store, p2, ">=", t), p4));
+ else
+ pose(new Reified(new SumInt(store, p2, ">=", t), p4));
}
else {
pose(new Reified(new LinearInt(store,p2, p1, "<=", p3), p4));
@@ -2580,19 +2837,6 @@ else if (allWeightsMinusOne(p1)) {
}
else { // non reified
- // If a linear term contains only constants and can be evaluated
- // check if satisfied and do not generate constraint
-
- boolean p2Fixed = allConstants(p2);
- int s=0;
- if (p2Fixed) {
- int el=0;
- while (el < p2.length) {
- s += p2[el].min()*p1[el];
- el++;
- }
- }
-
IntVar t;
switch (operation) {
case eq :
@@ -2604,7 +2848,7 @@ else if (allWeightsMinusOne(p1)) {
throw store.failException;
if (p1.length == 1) {
- pose(new XmulCeqZ(p2[0], p1[0], new IntVar(store, p3, p3)));
+ pose(new XmulCeqZ(p2[0], p1[0], dictionary.getConstant(p3))); // new IntVar(store, p3, p3)));
}
else if (p1.length == 2 && p1[0] == 1 && p1[1] == -1) {
if (p3 != 0)
@@ -2648,13 +2892,6 @@ else if (paramZero(p2[2]))
pose(new XplusYeqZ(p2[1], p2[2], p2[0]));
}
else {
- // IntVar v;
- // if (p3==0)
- // v = zero;
- // else if (p3 == 1)
- // v = one;
- // else
- // v = new IntVar(store, p3, p3);
int pos = sumPossible(p1, p3);
if (pos > -1) {
IntVar[] vect = new IntVar[p1.length-1];
@@ -2662,28 +2899,28 @@ else if (paramZero(p2[2]))
for (int i=0; i -1) {
IntVar[] vect = new IntVar[p1.length-1];
@@ -2744,7 +2991,10 @@ else if (posGe > -1) {
for (int i=0; i", p2[posGe]));
+ if (boolSum(vect))
+ pose(new SumBool(store, vect, ">", p2[posGe]));
+ else
+ pose(new SumInt(store, vect, ">", p2[posGe]));
}
else {
// pose(new Linear(store, p2, p1, "<", p3));
@@ -2802,12 +3052,18 @@ else if (p1.length == 2 && p1[0] == -1 && p1[1] == 1)
pose(new XplusClteqZ(p2[1], -p3, p2[0]) );
else if (allWeightsOne(p1)) {
- t = new IntVar(store, p3, p3);
- pose(new SumInt(store, p2, "<=", t));
+ t = dictionary.getConstant(p3); //new IntVar(store, p3, p3);
+ if (boolSum(p2))
+ pose(new SumBool(store, p2, "<=", t));
+ else
+ pose(new SumInt(store, p2, "<=", t));
}
else if (allWeightsMinusOne(p1)) {
- t = new IntVar(store, -p3, -p3);
- pose(new SumInt(store, p2, ">=", t));
+ t = dictionary.getConstant(-p3); //new IntVar(store, -p3, -p3);
+ if (boolSum(p2))
+ pose(new SumBool(store, p2, ">=", t));
+ else
+ pose(new SumInt(store, p2, ">=", t));
}
// else if (sumPossible(p1, p3) > -1) {
// int pos = sumPossible(p1, p3);
@@ -2830,7 +3086,10 @@ else if (allWeightsMinusOne(p1)) {
for (int i=0; i -1) {
IntVar[] vect = new IntVar[p1.length-1];
@@ -2838,7 +3097,10 @@ else if (posGe > -1) {
for (int i=0; i=", p2[posGe]));
+ if (boolSum(vect))
+ pose(new SumBool(store, vect, ">=", p2[posGe]));
+ else
+ pose(new SumInt(store, vect, ">=", p2[posGe]));
}
else {
pose(new LinearInt(store, p2, p1, "<=", p3));
@@ -2863,6 +3125,13 @@ else if (posGe > -1) {
}
}
+ boolean boolSum(IntVar[] vs) {
+ for (IntVar v : vs)
+ if (v.min() < 0 || v.max() > 1)
+ return false;
+ return true;
+ }
+
boolean paramZero(IntVar v) {
return v.singleton() && v.value() == 0;
}
@@ -3438,25 +3707,27 @@ else if (node.getId() == JJTSCALARFLATEXPR) {
}
IntVar getVariable(ASTScalarFlatExpr node) {
-
if (node.getType() == 0) {// int
int val = node.getInt();
- if (val == 0) return zero;
- else if (val == 1) return one;
- else return new IntVar(store, val, val);
+ return dictionary.getConstant(val);
+ // if (val == 0) return zero;
+ // else if (val == 1) return one;
+ // else return new IntVar(store, val, val);
}
if (node.getType() == 1) {// bool
int val = node.getInt();
- if (val == 0) return zero;
- else if (val == 1) return one;
- return new IntVar(store, val, val);
+ return dictionary.getConstant(val);
+ // if (val == 0) return zero;
+ // else if (val == 1) return one;
+ // return new IntVar(store, val, val);
}
else if (node.getType() == 2) { // ident
IntVar int_boolVar = dictionary.getVariable(node.getIdent());
if (int_boolVar == null) {
int bInt = dictionary.getInt(node.getIdent());
- return new IntVar(store, bInt, bInt);
- } return int_boolVar;
+ return dictionary.getConstant(bInt); // new IntVar(store, bInt, bInt);
+ }
+ return int_boolVar;
}
else if (node.getType() == 3) {// array access
if (node.getInt() >= dictionary.getVariableArray(node.getIdent()).length ||
@@ -3465,8 +3736,9 @@ else if (node.getType() == 3) {// array access
System.exit(0);
return new IntVar(store);
}
- else
+ else {
return dictionary.getVariableArray(node.getIdent())[node.getInt()];
+ }
}
else {
System.err.println("Wrong parameter " + node);
@@ -3567,8 +3839,7 @@ else if (node.getId() == JJTSCALARFLATEXPR) {
if (ia != null) {
IntVar[] aa = new IntVar[ia.length];
for (int i=0; i vs = dictionary.aliasTable.keySet();
+
+ for (IntVar v : vs) {
+ IntVar b = dictionary.aliasTable.get(v);
+
+ // give values to output vars
+ if (dictionary.isOutput(v))
+ pose(new XeqY(v, b));
+ }
+ }
+
void pose(Constraint c) throws FailException {
store.imposeWithConsistency(c);
@@ -3711,4 +3999,73 @@ void pose(Constraint c) throws FailException {
if (debug)
System.out.println(c);
}
+
+ void generateAlias(SimpleNode constraintWithAnnotations) {
+
+ // int numberChildren = constraintWithAnnotations.jjtGetNumChildren();
+
+ // if (numberChildren > 1 )
+ // parseAnnotations(constraintWithAnnotations);
+
+ SimpleNode node = (SimpleNode)constraintWithAnnotations.jjtGetChild(0);
+
+// node.dump("=> ");
+
+ if (node.getId() == JJTCONSTELEM) {
+
+ p = ((ASTConstElem)node).getName();
+
+ if (p.startsWith("bool2int") || p.startsWith("int2bool")) {
+
+ ASTScalarFlatExpr p1 = (ASTScalarFlatExpr)node.jjtGetChild(0);
+ ASTScalarFlatExpr p2 = (ASTScalarFlatExpr)node.jjtGetChild(1);
+ IntVar v1 = getVariable(p1),
+ v2 = getVariable(p2);
+ dictionary.addAlias(v1, v2);
+
+ if (v1.singleton() || v2.singleton()) {
+ v1.domain.in(store.level, v1, v2.domain);
+ v2.domain.in(store.level, v2, v1.domain);
+ }
+
+ if (debug)
+ System.out.println("Alias: " + v1 + " == " + v2);
+ }
+ }
+ }
+
+ IntVar[] unique(IntVar[] vs) {
+
+ HashSet varSet = new HashSet();
+ for (IntVar v : vs)
+ varSet.add(v);
+
+ int l = varSet.size();
+ IntVar[] rs = new IntVar[l];
+
+ int i = 0;
+ for (IntVar v : varSet) {
+ rs[i++] = v;
+ }
+
+ return rs;
+ }
+
+ int[] uniqueIndex(IntVar[] vs) {
+
+ ArrayList il = new ArrayList();
+ HashSet varSet = new HashSet();
+ for (int i=0; i.
+ *
+ */
+package org.jacop.fz;
+
+import java.util.Comparator;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+
+import org.jacop.core.BooleanVar;
+import org.jacop.core.IntVar;
+import org.jacop.core.Var;
+import org.jacop.set.core.SetVar;
+import org.jacop.floats.core.FloatVar;
+
+import org.jacop.fz.Tables;
+import org.jacop.fz.Options;
+
+/**
+ *
+ * The class gathers variables and array variables for default or
+ * complementary search. Two methods are supported. One gathers all
+ * output variables and the second one all non-introduced variables
+ * and arrays.
+ *
+ * @author Krzysztof Kuchcinski
+ * @version 4.4
+ *
+ */
+public class DefaultSearchVars {
+
+ Var[] int_search_variables = new IntVar[0],
+ set_search_variables = new SetVar[0],
+ bool_search_variables = new BooleanVar[0];
+ FloatVar[] float_search_variables = new FloatVar[0];
+
+ Tables dictionary;
+
+ /**
+ * It constructs the class for collecting default and complementary search variables.
+ * @param dict tables with model variables.
+ */
+ public DefaultSearchVars(Tables dict) {
+ this.dictionary = dict;
+ }
+
+ /**
+ * It collects all output variables for search.
+ */
+ void outputVars() {
+
+ // ==== Collect ALL OUTPUT variables ====
+
+ LinkedHashSet int_vars = new LinkedHashSet();
+ LinkedHashSet bool_vars = new LinkedHashSet();
+ LinkedHashSet set_vars = new LinkedHashSet();
+ LinkedHashSet float_vars = new LinkedHashSet();
+
+ // collect output arrays
+ for (int i=0; i());
+ }
+
+ /**
+ * It collects all variables that were identified as search
+ * variables by VariablesParameters class during parsing variable
+ * definitions.
+ */
+ void defaultVars() {
+
+ LinkedHashSet int_vars = new LinkedHashSet();
+ LinkedHashSet bool_vars = new LinkedHashSet();
+
+ for (int i=0; i());
+
+ LinkedHashSet set_vars = new LinkedHashSet();
+ for (int i=0; i float_vars = new LinkedHashSet();
+
+ for (int i=0; i implements Comparator {
+
+ DomainSizeComparator() { }
+
+ public int compare(T o1, T o2) {
+ int v1 = o1.getSize();
+ int v2 = o2.getSize();
+ return v1 - v2;
+ }
+ }
+}
diff --git a/src/main/java/org/jacop/fz/FlatzincLoader.java b/src/main/java/org/jacop/fz/FlatzincLoader.java
index 198da9546..ae66ab778 100644
--- a/src/main/java/org/jacop/fz/FlatzincLoader.java
+++ b/src/main/java/org/jacop/fz/FlatzincLoader.java
@@ -59,8 +59,6 @@ public class FlatzincLoader {
*
* TODO what are the conditions for different exceptions being thrown? Write little info below.
*
- * @throws ParseException
- * @throws TokenMgrError
*/
diff --git a/src/main/java/org/jacop/fz/Fz2jacop.java b/src/main/java/org/jacop/fz/Fz2jacop.java
index 2be16b344..16e64238d 100644
--- a/src/main/java/org/jacop/fz/Fz2jacop.java
+++ b/src/main/java/org/jacop/fz/Fz2jacop.java
@@ -51,8 +51,6 @@ public class Fz2jacop {
*
* TODO what are the conditions for different exceptions being thrown? Write little info below.
*
- * @throws ParseException
- * @throws TokenMgrError
*/
public static void main(String[] args) {
@@ -109,6 +107,10 @@ public static void main(String[] args) {
System.out.println("%% Out of memory error; consider option -Xmx... for JVM");
} catch (StackOverflowError e) {
System.out.println("%% Stack overflow exception error; consider option -Xss... for JVM");
+ } catch (TrivialSolution e) {
+ // do nothing
+ Runtime.getRuntime().removeShutdownHook(t);
+ return;
}
if (opt.getStatistics()) {
diff --git a/src/main/java/org/jacop/fz/Options.java b/src/main/java/org/jacop/fz/Options.java
index df6f416c1..cb27704e6 100644
--- a/src/main/java/org/jacop/fz/Options.java
+++ b/src/main/java/org/jacop/fz/Options.java
@@ -68,7 +68,11 @@ public class Options {
boolean runSearch = true;
boolean use_sat = false;
-
+
+ boolean complementary_search = false;
+
+ boolean debug = false;
+
/**
* It constructs an Options object and parses all the parameters/options provided
* to flatzinc to jacop parser.
@@ -103,6 +107,9 @@ else if (args.length == 1) {
" override annotation \":: domain\" and select constraints\n"+
" implementing bounds consistency (default false).\n"+
" -sat use SAT solver for boolean constraints.\n" +
+ " -cs, --complementary-search - try to gather all model, non-introduced\n" +
+ " variables to define the final or default search, instead of using\n" +
+ " output variables only.\n" +
" -i, --interval print intervals instead of values for floating variables\n"+
" -p , --precision defines precision for floating operations\n"+
" overrides precision definition in search annotation."
@@ -162,6 +169,14 @@ else if (args[i].equals("-b") || args[i].equals("--bound")) {
boundConsistency = true;
i++;
}
+ else if (args[i].equals("-cs") || args[i].equals("--complementary-search")) {
+ complementary_search = true;
+ i++;
+ }
+ else if (args[i].equals("-debug") ) {
+ debug = true;
+ i++;
+ }
else {
System.out.println("fz2jacop: not recognized option "+ args[i]);
i++;
@@ -271,7 +286,7 @@ public boolean getBoundConsistency() {
}
/**
- * It returns precision defined in the command line
+ * It returns precision defined in the command line
* @return precision.
*/
public double getPrecision() {
@@ -279,19 +294,38 @@ public double getPrecision() {
}
/**
- * It defines precision.
+ * It informs whether precision is defined.
+ * @return true if precision for floating point solver is defined
*/
public boolean precision() {
return precisionDefined;
}
/**
- * It defines precision.
+ * It defines whether sat is used.
+ * @return true sat is used, false otherwise
*/
public boolean useSat() {
return use_sat;
}
+ /**
+ * It defines whether to use debug information print-out.
+ * @return true if debugging information is printed, false otherwise
+ */
+ public boolean debug() {
+ return debug;
+ }
+
+ /**
+ * It defines wheter additional search should use output variables only (false, default).
+ * or should try to collect all non introduced variables (true).
+ * @return additional search should use output variables only (false, default).
+ * or should try to collect all non introduced variables (true)
+ */
+ public boolean complementarySearch() {
+ return complementary_search;
+ }
}
diff --git a/src/main/java/org/jacop/fz/OutputArrayAnnotation.java b/src/main/java/org/jacop/fz/OutputArrayAnnotation.java
index 29aad261a..0e38106ea 100644
--- a/src/main/java/org/jacop/fz/OutputArrayAnnotation.java
+++ b/src/main/java/org/jacop/fz/OutputArrayAnnotation.java
@@ -86,6 +86,14 @@ IntDomain getIndexes(int i) {
return indexes.get(i);
}
+ boolean contains(Var x) {
+
+ for (Var v : array)
+ if (x.equals(v))
+ return true;
+ return false;
+ }
+
public String toString() {
StringBuilder s = new StringBuilder(id + " = array"+indexes.size() + "d(");
diff --git a/src/main/java/org/jacop/fz/RunWhenShuttingDown.java b/src/main/java/org/jacop/fz/RunWhenShuttingDown.java
index 27b33ff1c..a7b4845ff 100644
--- a/src/main/java/org/jacop/fz/RunWhenShuttingDown.java
+++ b/src/main/java/org/jacop/fz/RunWhenShuttingDown.java
@@ -42,6 +42,9 @@ public RunWhenShuttingDown(Parser parser) {
public void run() {
+ if (! parser.options.getAll() && parser.solver.lastSolution != null)
+ System.out.println(parser.solver.lastSolution);
+
parser.solver.printStatisticsIterrupt();
}
diff --git a/src/main/java/org/jacop/fz/SearchItem.java b/src/main/java/org/jacop/fz/SearchItem.java
index dcdaa2aa9..f061d138a 100644
--- a/src/main/java/org/jacop/fz/SearchItem.java
+++ b/src/main/java/org/jacop/fz/SearchItem.java
@@ -54,6 +54,7 @@
import org.jacop.search.SmallestMin;
import org.jacop.search.SplitSelect;
import org.jacop.search.WeightedDegree;
+import org.jacop.search.InputOrderSelect;
import org.jacop.floats.search.SmallestDomainFloat;
import org.jacop.floats.search.LargestDomainFloat;
import org.jacop.floats.search.SmallestMinFloat;
@@ -333,6 +334,10 @@ else if (indomain != null && indomain.equals("indomain_reverse_split")) {
return sel;
}
}
+ else if (var_selection_heuristic.equals("input_order")) {
+ Indomain indom = getIndomain(indomain);
+ return new InputOrderSelect(store, search_variables, indom);
+ }
else {
Indomain indom = getIndomain(indomain);
if (tieBreaking == null)
@@ -409,27 +414,27 @@ else if (indomain.equals("indomain_max"))
- Indomain getIndomain(String indomain) {
+ Indomain getIndomain(String indomain) {
if (indomain == null)
- return new IndomainMin();
+ return new IndomainMin();
else if (indomain.equals("indomain_min"))
- return new IndomainMin();
+ return new IndomainMin();
else if (indomain.equals("indomain_max"))
- return new IndomainMax();
+ return new IndomainMax();
else if (indomain.equals("indomain_middle"))
- return new IndomainMiddle();
+ return new IndomainMiddle();
else if (indomain.equals("indomain_median"))
- return new IndomainMedian();
+ return new IndomainMedian();
else if (indomain.equals("indomain_random"))
- return new IndomainRandom();
+ return new IndomainRandom();
else
System.err.println("Warning: Not implemented indomain method \""+
indomain +"\"; used indomain_min");
- return new IndomainMin();
+ return new IndomainMin();
}
- public ComparatorVariable getVarSelect() {
+ public ComparatorVariable getVarSelect() {
tieBreaking = null;
if (var_selection_heuristic == null)
@@ -437,31 +442,31 @@ public ComparatorVariable getVarSelect() {
else if (var_selection_heuristic.equals("input_order"))
return null;
else if (var_selection_heuristic.equals("first_fail"))
- return new SmallestDomain();
+ return new SmallestDomain();
else if (var_selection_heuristic.equals("anti_first_fail")) {
// does not follow flatzinc definition but may give better results ;)
//tieBreaking = new MostConstrainedStatic();
- return new LargestDomain();
+ return new LargestDomain();
}
else if (var_selection_heuristic.equals("most_constrained")) {
- //tieBreaking = new MostConstrainedStatic();
- return new SmallestDomain();
+ tieBreaking = new MostConstrainedStatic();
+ return new SmallestDomain();
}
else if (var_selection_heuristic.equals("occurrence"))
- return new MostConstrainedStatic();
+ return new MostConstrainedStatic();
else if (var_selection_heuristic.equals("smallest")) {
// does not follow flatzinc definition but may give better results ;)
// tieBreaking = new MostConstrainedStatic();
//tieBreaking = new SmallestDomain();
- return new SmallestMin();
+ return new SmallestMin();
}
else if (var_selection_heuristic.equals("largest"))
- return new LargestMax();
+ return new LargestMax();
else if (var_selection_heuristic.equals("max_regret"))
- return new MaxRegret();
+ return new MaxRegret();
else if (var_selection_heuristic.equals("weighted_degree")) {
store.variableWeightManagement = true;
- return new WeightedDegree();
+ return new WeightedDegree();
}
else
System.err.println("Warning: Not implemented variable selection heuristic \""+
@@ -470,7 +475,7 @@ else if (var_selection_heuristic.equals("weighted_degree")) {
return null; // input_order
}
- public ComparatorVariable getFloatVarSelect() {
+ public ComparatorVariable getFloatVarSelect() {
tieBreaking = null;
if (var_selection_heuristic == null)
@@ -478,26 +483,26 @@ public ComparatorVariable getFloatVarSelect() {
else if (var_selection_heuristic.equals("input_order"))
return null;
else if (var_selection_heuristic.equals("first_fail"))
- return new SmallestDomainFloat();
+ return new SmallestDomainFloat();
else if (var_selection_heuristic.equals("anti_first_fail")) {
// does not follow flatzinc definition but may give better results ;)
//tieBreaking = new MostConstrainedStatic();
- return new LargestDomainFloat();
+ return new LargestDomainFloat();
}
// else if (var_selection_heuristic.equals("most_constrained")) {
// //tieBreaking = new MostConstrainedStatic();
// return new SmallestDomainFloat();
// }
else if (var_selection_heuristic.equals("occurrence"))
- return new MostConstrainedStatic();
+ return new MostConstrainedStatic();
else if (var_selection_heuristic.equals("smallest")) {
// does not follow flatzinc definition but may give better results ;)
// tieBreaking = new MostConstrainedStatic();
//tieBreaking = new SmallestDomain();
- return new SmallestMinFloat();
+ return new SmallestMinFloat();
}
else if (var_selection_heuristic.equals("largest"))
- return new LargestMaxFloat();
+ return new LargestMaxFloat();
// else if (var_selection_heuristic.equals("max_regret"))
// return new MaxRegret();
// else if (var_selection_heuristic.equals("weighted_degree")) {
@@ -511,7 +516,7 @@ else if (var_selection_heuristic.equals("largest"))
return null; // input_order
}
- ComparatorVariable getsetVarSelect() {
+ ComparatorVariable getsetVarSelect() {
tieBreaking = null;
if (var_selection_heuristic == null)
@@ -519,23 +524,23 @@ ComparatorVariable getsetVarSelect() {
else if (var_selection_heuristic.equals("input_order"))
return null;
else if (var_selection_heuristic.equals("first_fail"))
- return new MinCardDiff();
+ return new MinCardDiff();
else if (var_selection_heuristic.equals("smallest"))
- return new MinGlbCard();
+ return new MinGlbCard();
else if (var_selection_heuristic.equals("occurrence"))
- return new MostConstrainedStatic();
+ return new MostConstrainedStatic();
else if (var_selection_heuristic.equals("anti_first_fail"))
- return new MaxCardDiff();
+ return new MaxCardDiff();
else if (var_selection_heuristic.equals("weighted_degree")) {
store.variableWeightManagement = true;
- return new WeightedDegree();
+ return new WeightedDegree