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.jacop jacop - 4.3.0 + 4.4.0 jar JaCoP @@ -143,10 +143,32 @@ setup to run configuration. --> maven-surefire-report-plugin 2.18.1 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.7 + 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 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 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 xs, ArrayList 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 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 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 variables, @@ -103,48 +108,15 @@ public LinearIntDom(Store store, ArrayList 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 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 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 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 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 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 bin, + ArrayList 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 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 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=", 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=", 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(); } // else if (var_selection_heuristic.equals("most_constrained")) { // tieBreaking = new MostConstrainedStatic(); // return new SmallestDomain(); // } else if (var_selection_heuristic.equals("largest")) - return new MaxLubCard(); + return new MaxLubCard(); // else if (var_selection_heuristic.equals("max_regret")) // return new MaxRegret(); else @@ -547,7 +552,7 @@ else if (var_selection_heuristic.equals("largest")) IntVar getVariable(ASTScalarFlatExpr node) { if (node.getType() == 0) //int - return new IntVar(store, node.getInt(), node.getInt()); + return dictionary.getConstant(node.getInt()); //new IntVar(store, node.getInt(), node.getInt()); else if (node.getType() == 2) // ident return dictionary.getVariable(node.getIdent()); else if (node.getType() == 3) {// array access @@ -721,18 +726,21 @@ public String toString() { if (search_type == null) s += "defult_search\n"; else if (search_seq.size() == 0) { - s = search_type + ", "; + s += search_type + "("; if (search_variables == null) s += "[]"; else - s += Arrays.asList(search_variables); + s += "array1d(1.."+ search_variables.length + ", " + Arrays.asList(search_variables); s += ", "+explore + ", " + var_selection_heuristic+", "+indomain; if (floatSearch) s += ", " + precision; } else { - for (SearchItem se : search_seq) - s += se +"\n"; + for (int i=0; i < search_seq.size(); i++) //SearchItem se : search_seq) + if (i == search_seq.size()-1) + s += search_seq.get(i) + ")"; + else + s += search_seq.get(i) + "), "; } return s; } diff --git a/src/main/java/org/jacop/fz/Solve.java b/src/main/java/org/jacop/fz/Solve.java index 8ade8dbe5..35a986baa 100644 --- a/src/main/java/org/jacop/fz/Solve.java +++ b/src/main/java/org/jacop/fz/Solve.java @@ -124,17 +124,34 @@ public class Solve implements ParserTreeConstants { int solveKind=-1; SatTranslation sat; + + public StringBuffer lastSolution = null; /** * It creates a parser for the solve part of the flatzinc file. * * @param store the constraint store within which context the search will take place. + * @param sat sat translation used */ public Solve(Store store, SatTranslation sat) { this.store = store; this.sat = sat; } + + public void solveModel(SimpleNode astTree, Tables table, Options opt) { + int n = astTree.jjtGetNumChildren(); + + for (int i=0; i< n; i++) { + SimpleNode node = (SimpleNode)astTree.jjtGetChild(i); + + if (node.getId() == JJTMODELEND) { + // int k = node.jjtGetNumChildren(); + search((ASTSolveItem)node.jjtGetChild(0), table, opt); + } + } + } + /** * It parses the solve part. * @@ -149,8 +166,9 @@ public void search(ASTSolveItem node, Tables table, Options opt) { initNumberConstraints = store.numberConstraints(); if (opt.getVerbose()) - System.out.println("%% Model constraints defined.\n%% Variables = "+store.size() + ", Bool variables = "+NumberBoolVariables + - ", Constraints = "+initNumberConstraints + ", SAT clauses = " + sat.numberClauses()); + System.out.println("%% Model constraints defined.\n%% Variables = "+store.size() + " and Bool variables = "+ + NumberBoolVariables + " of that constant variables = " + table.constantTable.size() + + "\n%% Constraints = "+initNumberConstraints + ", SAT clauses = " + sat.numberClauses()); dictionary = table; options = opt; @@ -376,7 +394,6 @@ else if (final_search[3] != null) { } last_search = list_seq_searches.get(list_seq_searches.size()-1); - // LDS & Credit heuristic search if (si.exploration().equals("lds")) lds_search(label, si.ldsValue); @@ -503,6 +520,9 @@ else if (si.exploration().equals("credit")) System.exit(0); } + if (! options.getAll() && lastSolution != null) + System.out.print(lastSolution.toString()); + printStatisticsForSingleSearch(false, Result); } @@ -601,7 +621,7 @@ else if (optimization) { } } - System.out.println("\n%% Model variables : "+ (store.size()+NumberBoolVariables)+ + System.out.println("%% Model variables : "+ (store.size()+NumberBoolVariables)+ "\n%% Model constraints : "+initNumberConstraints+ "\n\n%% Search CPU time : " + (searchTimeMeter.getThreadCpuTime(tread.getId()) - startCPU)/(long)1e+6 + "ms"+ "\n%% Search nodes : "+nodes+ @@ -612,6 +632,8 @@ else if (optimization) { "\n%% Max search depth : "+depth+ "\n%% Number solutions : "+ solutions ); + // System.out.println("\n%% " + store.failConstraintsStatistics); + // System.out.println("\n%% " + store.failConstraintsIdStatistics); } } @@ -621,83 +643,36 @@ DepthFirstSearch[] setSubSearchForAll(DepthFirstSearch label, Options DepthFirstSearch[] intAndSetSearch = new DepthFirstSearch[4]; - Var[] int_search_variables = null, - set_search_variables = null, - bool_search_variables = null; - FloatVar[] float_search_variables = null; - - // collect integer & bool variables for search - int int_varSize = 0, bool_varSize=0; - for (int i=0; i()); - - // collect set variables for search - int n=0; - int varSize = dictionary.defaultSearchSetVariables.size(); - for (int i=0; i[] setSubSearchForAll(DepthFirstSearch label, Options "\n%% Max search depth : 0"+ "\n%% Number solutions : 1" ); - System.exit(0); + + throw new TrivialSolution(); } return intAndSetSearch; @@ -1044,6 +1013,9 @@ void run_sequence_search(int solveKind, SimpleNode kind, SearchItem si) { System.exit(0); } + if (! options.getAll() && lastSolution != null) + System.out.print(lastSolution.toString()); + printStatisticsForSeqSearch(false, Result); } @@ -1104,7 +1076,7 @@ else if (optimization) { solutions = label.getSolutionListener().solutionsNo(); } - System.out.println("\n%% Model variables : "+ (store.size()+ NumberBoolVariables) + + System.out.println("%% Model variables : "+ (store.size()+ NumberBoolVariables) + "\n%% Model constraints : "+initNumberConstraints+ "\n\n%% Search CPU time : " + (searchTimeMeter.getThreadCpuTime(tread.getId()) - startCPU)/(long)1e+6 + "ms"+ "\n%% Search nodes : "+nodes+ @@ -1116,7 +1088,8 @@ else if (optimization) { "\n%% Number solutions : "+ solutions ); } - + // System.out.println("\n%% " + store.failConstraintsStatistics); + // System.out.println("\n%% " + store.failConstraintsIdStatistics); } boolean anyTimeOutOccured(ArrayList> list_seq_searches) { @@ -1240,7 +1213,8 @@ void printSolution() { // T = System.currentTimeMillis(); // System.out.println("% Search time since last solution : " + (T - TOld)/1000 + " s"); // TOld = T; - + StringBuffer printBuffer = new StringBuffer(); + if (dictionary.outputVariables.size() > 0) for (int i=0; i search, SelectChoicePoint selec FinalNumberSolutions++; printSolution(); - System.out.println("----------"); + // System.out.println("----------"); return returnCode; } diff --git a/src/main/java/org/jacop/fz/Tables.java b/src/main/java/org/jacop/fz/Tables.java index a6a22d311..65e809057 100644 --- a/src/main/java/org/jacop/fz/Tables.java +++ b/src/main/java/org/jacop/fz/Tables.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import org.jacop.core.IntDomain; import org.jacop.core.IntVar; @@ -54,7 +55,9 @@ public class Tables { Store store; - IntVar zero, one; + // IntVar zero, one; + + HashMap constantTable = new HashMap(); // intTable keeps both int & bool (0=false, 1=true) parameters HashMap intTable = new HashMap(); @@ -97,6 +100,10 @@ public class Tables { ArrayList defaultSearchSetArrays = new ArrayList(); + // HashMap> boolAliasTable = new HashMap>(); + // HashMap> intAliasTable = new HashMap>(); + HashMap aliasTable = new HashMap(); + /** * It constructs the storage object to store different objects, like int, array of ints, sets, ... . */ @@ -104,10 +111,71 @@ public Tables() {} public Tables(Store s) { this.store = s; - this.zero = new IntVar(store, "zero", 0,0); - this.one = new IntVar(store, "one", 1,1); } + public IntVar getConstant(int c) { + IntVar v = constantTable.get(c); + + if (v == null) { + v = new IntVar(store, c, c); + constantTable.put(c, v); + } + + return v; + } + + public void addAlias(IntVar b, IntVar v) { + IntVar x = aliasTable.get(v); + if (x == null) + aliasTable.put(v, b); + else + System.err.println("%% Double int var alias for bool var"); + + // System.out.println(v + " is alias of " + b); + } + + IntVar getAlias(IntVar b) { + IntVar v = aliasTable.get(b); + if ( v == null) + return b; + else + return v; + } + + // public void addBoolAlias(IntVar b, IntVar v) { + // HashSet x = boolAliasTable.get(b); + // if (x == null) + // x = new HashSet(); + // x.add(v); + // boolAliasTable.put(b, x); + // // System.out.println(b + " == " + x); + // } + + // HashSet getBoolAlias(IntVar b) { + // HashSet x = boolAliasTable.get(b); + // if (x == null) + // return new HashSet(); + // else + // return x; + // } + + // public void addIntAlias(IntVar v, IntVar b) { + // HashSet x = intAliasTable.get(v); + // if (x == null) + // x = new HashSet(); + // x.add(b); + // intAliasTable.put(v, x); + // // System.out.println(v + " == " + b); + // } + + // HashSet getIntAlias(IntVar v) { + // HashSet x = intAliasTable.get(v); + // if (x == null) + // return new HashSet(); + // else + // return x; + // } + /** * It adds an int parameter. * @@ -278,7 +346,7 @@ public void addVariable(String ident, IntVar var) { * @return the variable of the given identity. */ public IntVar getVariable(String ident) { - return variableTable.get(ident); + return getAlias(variableTable.get(ident)); } @@ -328,15 +396,16 @@ public IntVar[] getVariableArray(String ident) { if (intA != null) { a = new IntVar[intA.length]; for (int i =0; i keys = dictionary[i].keySet(); - // for (String k : keys) { - // Var[] a = (Var[])dictionary[i].get(k); - // s += k+"="; - // s += Arrays.asList(a); - // s += ", "; - // } - // s+="}\n"; - // } - // // Set Variables Array - // else if (i == indexSetVariableArray) { - // s+= tableNames[i]+"\n"; //"Set var arrays\n"; - // s +="{"; - // java.util.Set keys = dictionary[i].keySet(); - // for (String k : keys) { - // Var[] a = (Var[])dictionary[i].get(k); - // s += k+"="; - // s += Arrays.asList(a); - // s += ", "; - // } - // s+="}\n"; - // } - // others + else if (i == indexConstantTable) { + s+= tableNames[i]+"\n"; + s +="{"; + java.util.Set keys = dictionary[i].keySet(); + for (Integer k : keys) { + Var a = (Var)dictionary[i].get(k); + s += a; + s += ", "; + } + s+="}\n"; + } else { - s+= tableNames[i]+"\n"; + s += tableNames[i]+" (" + dictionary[i].size()+ ")\n"; s += dictionary[i] + "\n"; } } diff --git a/src/main/java/org/jacop/fz/TrivialSolution.java b/src/main/java/org/jacop/fz/TrivialSolution.java new file mode 100644 index 000000000..63aba0ac2 --- /dev/null +++ b/src/main/java/org/jacop/fz/TrivialSolution.java @@ -0,0 +1,49 @@ +/** + * TrivialSolution.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.fz; + +/** + * It is thrown in flazinc when search is not needed since the solution is known. + * + * @author Krzysztof Kuchcinski + */ + +public class TrivialSolution extends RuntimeException { + + public TrivialSolution() { + } + + @Override + public Throwable fillInStackTrace() { + return this; + } +} diff --git a/src/main/java/org/jacop/fz/VariablesParameters.java b/src/main/java/org/jacop/fz/VariablesParameters.java index c9344d933..b8adac690 100644 --- a/src/main/java/org/jacop/fz/VariablesParameters.java +++ b/src/main/java/org/jacop/fz/VariablesParameters.java @@ -58,7 +58,7 @@ * generateParameters(...) below. * * @author Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * */ public class VariablesParameters implements ParserTreeConstants { @@ -200,7 +200,7 @@ void generateVariables(SimpleNode node, Tables table, Store store) { if (lowInterval < MIN_INT || highInterval > MAX_INT) throw new ArithmeticException("Bounds for " + ident + ": "+ lowInterval +".."+ highInterval + " are too low/high"); - + if (interval) varInt = new IntVar(store, ident, new IntervalDomain(lowInterval, highInterval)); else @@ -535,7 +535,7 @@ void generateArrayVariables(SimpleNode node, Tables table, Store store) { dictionary = table; annotations = new HashSet(); indexBounds = new ArrayList(); - boolean output_array = false; + boolean var_introduced = false, output_array = false; OutputArrayAnnotation outArrayAnn=null; int type = getType(node); @@ -548,6 +548,8 @@ void generateArrayVariables(SimpleNode node, Tables table, Store store) { String ident = ((ASTVarDeclItem)node).getIdent(); + if (annotations.contains("var_is_introduced")) + var_introduced = true; if (annotations.contains("output_array")) { output_array = true; outArrayAnn = new OutputArrayAnnotation(ident, indexBounds); @@ -564,16 +566,19 @@ void generateArrayVariables(SimpleNode node, Tables table, Store store) { varArrayInt = null; if (initChild < ((ASTVarDeclItem)node).jjtGetNumChildren()) { varArrayInt = getScalarFlatExpr_ArrayVar(store, node, initChild); - for (int i=0; i this.currentLevel; @@ -628,6 +628,7 @@ public final void markTime(String s) { /** * get the time associated with given mark, or 0 if none * @param s the mark + * @return the time associated with given mark, or 0 if none */ public final long getTime(String s) { if (timeMap.containsKey(s)) @@ -649,6 +650,9 @@ public final long getTimeDiff(String s) { /** * logs important messages in comments + * + * @param s the message + * @param args the arguments for the message */ public final void logc(String s, Object... args) { if (verbosity > 0) { @@ -660,6 +664,10 @@ public final void logc(String s, Object... args) { /** * logs less important messages, in comments + * + * @param level verbosity level + * @param s the message + * @param args the arguments for the message */ public final void logc(int level, String s, Object... args) { if (verbosity >= level) { @@ -738,6 +746,8 @@ public String toString() { /** * creates the solver, which in turn creates all inner components and * connect them together. + * + * @param config configuration for the solver */ public Core(Config config) { // set the config @@ -775,4 +785,4 @@ public void initialize(Core core) { assert core == this; } -} \ No newline at end of file +} diff --git a/src/main/java/org/jacop/jasat/core/RunSolver.java b/src/main/java/org/jacop/jasat/core/RunSolver.java index 0c1e77b4a..530028ac2 100644 --- a/src/main/java/org/jacop/jasat/core/RunSolver.java +++ b/src/main/java/org/jacop/jasat/core/RunSolver.java @@ -217,7 +217,7 @@ public Config handle(OptParse parser, Config e, String arg) { try { int i = Integer.parseInt(arg); e.verbosity = i; - } catch (Exception _) { + } catch (Exception ex) { e.verbosity = 1; return e; } diff --git a/src/main/java/org/jacop/jasat/core/SolverComponent.java b/src/main/java/org/jacop/jasat/core/SolverComponent.java index 6d5595f10..e233fc227 100644 --- a/src/main/java/org/jacop/jasat/core/SolverComponent.java +++ b/src/main/java/org/jacop/jasat/core/SolverComponent.java @@ -43,6 +43,8 @@ public interface SolverComponent { /** * initializes the component with the given solver. May be called only once. * This method must register the component to the solver for the run. + * + * @param core core component to initialize */ public void initialize(Core core); diff --git a/src/main/java/org/jacop/jasat/core/Trail.java b/src/main/java/org/jacop/jasat/core/Trail.java index 62321a9cb..d8f387ca3 100644 --- a/src/main/java/org/jacop/jasat/core/Trail.java +++ b/src/main/java/org/jacop/jasat/core/Trail.java @@ -108,8 +108,8 @@ public void ensureCapacity(int numVar) { /** - * Sets a literal, that is, a variable signed with its value (> 0 for true, - * < 0 for false). This must be used only for asserted values, + * Sets a literal, that is, a variable signed with its value ({@literal >} 0 for true, + * {@literal <} 0 for false). This must be used only for asserted values, * not the ones propagated from unit clauses. * @param literal the literal * @param level the current level @@ -226,7 +226,7 @@ public int getLevel(int var) { /** * It returns the index of the clause that caused this variable to be set - * @param literal the literal. Must be set. + * @param var the literal. Must be set. * @return an index if there was an explanation, 0 otherwise */ public int getExplanation(int var) { @@ -271,6 +271,8 @@ public boolean isSet(int var) { /** * returns the number of currently set variables + * + * @return the number of currently set variables */ public int size() { return assertionStack.size(); @@ -297,7 +299,6 @@ public String toString() { /** * to be called before any use of the trail * @param core the Solver instance - * @param size the initial size of trail */ public void initialize(Core core) { diff --git a/src/main/java/org/jacop/jasat/core/clauses/AbstractClausesDatabase.java b/src/main/java/org/jacop/jasat/core/clauses/AbstractClausesDatabase.java index ae55c96b1..35ebe0669 100644 --- a/src/main/java/org/jacop/jasat/core/clauses/AbstractClausesDatabase.java +++ b/src/main/java/org/jacop/jasat/core/clauses/AbstractClausesDatabase.java @@ -153,6 +153,8 @@ public final int uniqueIdToIndex(int clauseId) { } /** + * @param literal the literal to check + * @param clauseIndex the clause id for checking * @return true if the literal watches the clause, false otherwise */ protected final boolean doesWatch(int literal, int clauseIndex) { @@ -199,7 +201,7 @@ protected final void ensureWatch(int var) { } /** - * adds a watch (var => clause), ie make var watch clause + * adds a watch (var {@literal =>} clause), ie make var watch clause * @param literal the watching literal * @param clauseIndex the index of clause to watch. Not a unique ID. */ @@ -281,7 +283,8 @@ protected final void removeWatch(int literal, int clauseIndex) { /** * prints the content of the database in a nice way, each line being - * prefixed with @param prefix + * prefixed with + * @param prefix prefix for printed line * @return a String representation of the database */ public String toString(String prefix) { diff --git a/src/main/java/org/jacop/jasat/core/clauses/BinaryClausesDatabase.java b/src/main/java/org/jacop/jasat/core/clauses/BinaryClausesDatabase.java index dbe66f305..403f34141 100644 --- a/src/main/java/org/jacop/jasat/core/clauses/BinaryClausesDatabase.java +++ b/src/main/java/org/jacop/jasat/core/clauses/BinaryClausesDatabase.java @@ -58,7 +58,7 @@ public final class BinaryClausesDatabase extends AbstractClausesDatabase { /** * - * @TODO Efficiency, + * TODO Efficiency, * * Watches require a very large array, but there maybe not so many * binary clauses. Maybe a hashmap, connecting variable and list of diff --git a/src/main/java/org/jacop/jasat/core/clauses/ClauseDatabaseInterface.java b/src/main/java/org/jacop/jasat/core/clauses/ClauseDatabaseInterface.java index 4002e1ca6..3eb303ef6 100644 --- a/src/main/java/org/jacop/jasat/core/clauses/ClauseDatabaseInterface.java +++ b/src/main/java/org/jacop/jasat/core/clauses/ClauseDatabaseInterface.java @@ -51,6 +51,7 @@ public interface ClauseDatabaseInterface { * the solver will get in the conflict state. * * @param clause the clause to add + * @param isModelClause defined if the clause is model clause * @return the unique ID referring to the clause */ public int addClause(int[] clause, boolean isModelClause); @@ -66,6 +67,7 @@ public interface ClauseDatabaseInterface { /** * It removes the clause which unique ID is @param clauseId. + * @param clauseId clause id */ public void removeClause(int clauseId); @@ -83,16 +85,15 @@ public interface ClauseDatabaseInterface { * It returns the clause obtained by resolution between clauseIndex and clause. * It will also modify in place the given SetClause (avoid allocating). * - * @param clauseId the unique id of the clause + * @param clauseIndex the unique id of the clause * @param clause an explanation clause that is modified by resolution * @return the clause obtained by resolution - * @throws TrivialClause if the clause becomes trivial because of resolution */ public MapClause resolutionWith(int clauseIndex, MapClause clause); /** * Do everything needed to return to the given level. - * @param level the level to return to. Must be < solver.getCurrentLevel(). + * @param level the level to return to. Must be {@literal <} solver.getCurrentLevel(). */ public void backjump(int level); @@ -107,6 +108,7 @@ public interface ClauseDatabaseInterface { * writer. * * @param output the output writer to which all the clauses will be written to. + * @throws java.io.IOException execption from java.io package */ public void toCNF(BufferedWriter output) throws java.io.IOException; diff --git a/src/main/java/org/jacop/jasat/core/clauses/DatabasesStore.java b/src/main/java/org/jacop/jasat/core/clauses/DatabasesStore.java index 79ab4f79b..03379e226 100644 --- a/src/main/java/org/jacop/jasat/core/clauses/DatabasesStore.java +++ b/src/main/java/org/jacop/jasat/core/clauses/DatabasesStore.java @@ -242,6 +242,9 @@ public final int uniqueIdToIndex(int clauseId) { /** * It gets a unique id from a clause index, relative to a database, * and a database index. + * @param clauseIndex clause index + * @param databaseIndex database index + * @return unique id from a clause index */ public final int indexesToUniqueId(int clauseIndex, int databaseIndex) { assert databaseIndex < currentIndex; diff --git a/src/main/java/org/jacop/jasat/core/clauses/LongClausesDatabase.java b/src/main/java/org/jacop/jasat/core/clauses/LongClausesDatabase.java index 98d10aa5d..d13e82c53 100644 --- a/src/main/java/org/jacop/jasat/core/clauses/LongClausesDatabase.java +++ b/src/main/java/org/jacop/jasat/core/clauses/LongClausesDatabase.java @@ -250,7 +250,8 @@ public int size() { /** - * be sure that the database can contain @param numberOfClauses clauses + * be sure that the database can contain numberOfClauses clauses + * @param size the size of the database to be ensured */ public void ensureSize(int size) { diff --git a/src/main/java/org/jacop/jasat/core/clauses/MapClause.java b/src/main/java/org/jacop/jasat/core/clauses/MapClause.java index 2d9ff27f9..af4fe50ff 100644 --- a/src/main/java/org/jacop/jasat/core/clauses/MapClause.java +++ b/src/main/java/org/jacop/jasat/core/clauses/MapClause.java @@ -109,7 +109,7 @@ public boolean removeLiteral(int literal) { * literal is added. If variable exists as the opposite literal then the opposite * literal is removed and nothing is added. * - * @param literal + * @param literal the literal to be added */ public void partialResolveWith(int literal) { @@ -143,7 +143,7 @@ public boolean containsLiteral(int literal) { /** * Predicate which is true iff the variable or its opposite is present - * @param var a variable (> 0) + * @param var a variable ({@literal >} 0) * @return true if the literal or its opposite is in the clause */ public boolean containsVariable(int var) { @@ -154,6 +154,7 @@ public boolean containsVariable(int var) { } /** + * @param trail the trail to check * @return true if all literals of the clause are false in the trail */ public boolean isUnsatisfiableIn(Trail trail) { @@ -173,6 +174,7 @@ public boolean isUnsatisfiableIn(Trail trail) { /** * @param literal the only satisfiable literal in the clause + * @param trail the trail for the literal * @return true if the clause is unit with only @param literal not set */ public boolean isUnitIn(int literal, Trail trail) { @@ -216,7 +218,7 @@ public boolean isEmpty() { /** * returns the number of literals in the clause - * @return + * @return the number of literals in the clause */ public int size() { return literals.size(); @@ -225,6 +227,7 @@ public int size() { /** * converts the clause to an int[] suitable for the efficient clauses pool * implementations. The clause must not be empty. + * @param pool the pool for clause implementation * @return an equivalent clause */ public int[] toIntArray(MemoryPool pool) { @@ -252,6 +255,7 @@ public int[] toIntArray() { /** * true iff the clause is trivial (contains a literal and its opposite). * Now, by construction, a MapClause cannot be trivial + * @return true iff the clause is trivial */ @Deprecated public boolean isTrivial() { @@ -304,6 +308,9 @@ public final boolean addAll(Iterable clause) { /** * same as previous + * @param clause clause the literals to add + * @return true if the resulting SetClause is trivial (tautology), false + * otherwise */ public final boolean addAll(int[] clause) { boolean answer = false; diff --git a/src/main/java/org/jacop/jasat/core/clauses/TernaryClausesDatabase.java b/src/main/java/org/jacop/jasat/core/clauses/TernaryClausesDatabase.java index 5c88fd014..467dec98e 100644 --- a/src/main/java/org/jacop/jasat/core/clauses/TernaryClausesDatabase.java +++ b/src/main/java/org/jacop/jasat/core/clauses/TernaryClausesDatabase.java @@ -46,7 +46,7 @@ * Pros : no need to change watches. * Cons : need to check the clause every time any literal changes. * - * @TODO, check if this the efficient way of dealing with ternary clauses. + * TODO, check if this the efficient way of dealing with ternary clauses. * * @author Simon Cruanes and Radoslaw Szymanek * diff --git a/src/main/java/org/jacop/jasat/modules/StatModule.java b/src/main/java/org/jacop/jasat/modules/StatModule.java index ec99eb6b2..624b859de 100644 --- a/src/main/java/org/jacop/jasat/modules/StatModule.java +++ b/src/main/java/org/jacop/jasat/modules/StatModule.java @@ -214,7 +214,7 @@ private void printBlank() { /** * Create a StatModule. It can schedule - * @param threaded + * @param threaded true if threaded */ public StatModule(boolean threaded) { this.threaded = threaded; diff --git a/src/main/java/org/jacop/jasat/modules/interfaces/AssertionListener.java b/src/main/java/org/jacop/jasat/modules/interfaces/AssertionListener.java index f6924bfd6..ea5bf13ad 100644 --- a/src/main/java/org/jacop/jasat/modules/interfaces/AssertionListener.java +++ b/src/main/java/org/jacop/jasat/modules/interfaces/AssertionListener.java @@ -47,6 +47,7 @@ public interface AssertionListener extends SolverComponent { * Called when a variable is set * @param literal the literal that is set * propagation, false otherwise + * @param level the search level */ public void onAssertion(int literal, int level); diff --git a/src/main/java/org/jacop/jasat/utils/BasicPreprocessor.java b/src/main/java/org/jacop/jasat/utils/BasicPreprocessor.java index d15a1f55c..e447cc598 100644 --- a/src/main/java/org/jacop/jasat/utils/BasicPreprocessor.java +++ b/src/main/java/org/jacop/jasat/utils/BasicPreprocessor.java @@ -26,6 +26,7 @@ public class BasicPreprocessor { /** * add a clause (just parsed from a file, e.g.) to the solver, after * processing + * @param clause clause to be added */ public void addModelClause(IntVec clause) { diff --git a/src/main/java/org/jacop/jasat/utils/CnfParser.java b/src/main/java/org/jacop/jasat/utils/CnfParser.java index cd4ea151e..2a230dd9d 100644 --- a/src/main/java/org/jacop/jasat/utils/CnfParser.java +++ b/src/main/java/org/jacop/jasat/utils/CnfParser.java @@ -194,6 +194,7 @@ public Iterator iterator() { * creates an instance of the parser for some input stream * @param pool the memory pool to use * @param stream the stream from which to read clauses + * @throws ParseException excpetion when parsing fails */ public CnfParser(MemoryPool pool, InputStream stream) throws ParseException { this.pool = pool; diff --git a/src/main/java/org/jacop/jasat/utils/Factory.java b/src/main/java/org/jacop/jasat/utils/Factory.java index a2fda6600..5c9fc898a 100644 --- a/src/main/java/org/jacop/jasat/utils/Factory.java +++ b/src/main/java/org/jacop/jasat/utils/Factory.java @@ -4,12 +4,12 @@ * a factory for type E * @author simon * - * @param the type to produce + * @param E the type to produce */ public interface Factory { /** - * method to call to get a new instance of the type + * method to call to get a new instance of the type E * @return a new instance of E */ public E newInstance(); diff --git a/src/main/java/org/jacop/jasat/utils/Utils.java b/src/main/java/org/jacop/jasat/utils/Utils.java index 905eb8c77..4b10e5838 100644 --- a/src/main/java/org/jacop/jasat/utils/Utils.java +++ b/src/main/java/org/jacop/jasat/utils/Utils.java @@ -50,7 +50,7 @@ public final class Utils { * resize for int[][] * @param array the array to resize * @param newSize the size of the array we want - * @return a new array which first elements are the same + * @return a new array which first elements are the same * as the ones in array */ public final static int[][] resize(int[][] array, int newSize) { @@ -61,7 +61,11 @@ public final static int[][] resize(int[][] array, int newSize) { /** * the same, but with the number of elements to copy from old list + * @param array array to be extended + * @param newSize new size for the array * @param size the number of elements to copy from the old + * @return a new array which first elements are the same + * as the ones in array */ public final static int[][] resize(int[][] array, int newSize, int size) { assert size < newSize; @@ -117,7 +121,7 @@ public static String showClause(int[] clause) { /** * get the "absolute value" of the int (the variable that corresponds to * the literal) - * literal -> variable + * literal {@literal ->} variable * @param i the literal * @return the variable */ @@ -128,7 +132,7 @@ public static int var(int i) { /** * given a positive var, returns the literal that represents the negation * of the variable - * variable -> literal + * variable {@literal ->} literal * @param i the variable * @return the negated variable */ diff --git a/src/main/java/org/jacop/jasat/utils/structures/IntHashMap.java b/src/main/java/org/jacop/jasat/utils/structures/IntHashMap.java index 1ff96a0df..219eb887d 100644 --- a/src/main/java/org/jacop/jasat/utils/structures/IntHashMap.java +++ b/src/main/java/org/jacop/jasat/utils/structures/IntHashMap.java @@ -57,6 +57,7 @@ public boolean containsKey(int key) { /** * get the value associated with key, or null otherwise * @param key the key + * @return the value associated with key, or null otherwise */ public E get(int key) { @@ -334,6 +335,8 @@ public T[] toArray(T[] arg0) { /** * iterates over all entries in the map + * + * @return iterator for enumeration of elements in this map */ public Iterable> entrySet() { return new Iterable>() { diff --git a/src/main/java/org/jacop/jasat/utils/structures/IntMap.java b/src/main/java/org/jacop/jasat/utils/structures/IntMap.java index 1f3d3e517..a7089ece4 100644 --- a/src/main/java/org/jacop/jasat/utils/structures/IntMap.java +++ b/src/main/java/org/jacop/jasat/utils/structures/IntMap.java @@ -73,6 +73,8 @@ public int size() { /** * predicate to check if the map is empty + * + * @return true if the map is empty, false otherwise */ public boolean isEmpty() { return map.isEmpty(); diff --git a/src/main/java/org/jacop/jasat/utils/structures/IntPriorityQueue.java b/src/main/java/org/jacop/jasat/utils/structures/IntPriorityQueue.java index 777d039c3..1779df96f 100644 --- a/src/main/java/org/jacop/jasat/utils/structures/IntPriorityQueue.java +++ b/src/main/java/org/jacop/jasat/utils/structures/IntPriorityQueue.java @@ -18,7 +18,7 @@ public final class IntPriorityQueue { /** * the priority of i is now the old priority (or 0) + the amount. The - * priority stays >= 0. + * priority stays {@literal >=} 0. * @param i the int of which we want to modify the priority * @param amount the amount by which we modify the priority * @return the new priority of i @@ -30,6 +30,8 @@ public int addPriority(int i, int amount) { /** * equivalent to addPriority(i, 1) + * @param i the int of which we want to modify the priority + * @return the new priority of i */ public int percolateUp(int i) { // TODO @@ -38,6 +40,8 @@ public int percolateUp(int i) { /** * equivalent to addPriority(i, -1); + * @param i the int of which we want to modify the priority + * @return the new priority of i */ public int percolateDown(int i) { // TODO @@ -77,6 +81,8 @@ public void remove(int i) { /** * access the element with highest priority, or 0 if it is empty + * + * @return the element with highest priority, or 0 if it is empty */ public int getTop() { // TODO @@ -85,6 +91,8 @@ public int getTop() { /** * checks if the priority queue is empty + * + * @return true if the priority queue is empty and false otherwise */ public boolean isEmpty() { return root == null; diff --git a/src/main/java/org/jacop/jasat/utils/structures/IntQueue.java b/src/main/java/org/jacop/jasat/utils/structures/IntQueue.java index 77d102b72..e787c1d25 100644 --- a/src/main/java/org/jacop/jasat/utils/structures/IntQueue.java +++ b/src/main/java/org/jacop/jasat/utils/structures/IntQueue.java @@ -61,6 +61,8 @@ public int peek() { /** * takes the first element, removes it from the FIFO and returns it + * + * @return the first element from the FIFO queue */ public int pop() { assert start != stop; diff --git a/src/main/java/org/jacop/jasat/utils/structures/IntTrie.java b/src/main/java/org/jacop/jasat/utils/structures/IntTrie.java index 084199e67..576575c85 100644 --- a/src/main/java/org/jacop/jasat/utils/structures/IntTrie.java +++ b/src/main/java/org/jacop/jasat/utils/structures/IntTrie.java @@ -281,7 +281,7 @@ public static abstract class Node { /** * allocate a new value of type E - * @return + * @return the value of type E */ public abstract E getNew(); } diff --git a/src/main/java/org/jacop/jasat/utils/structures/IntVec.java b/src/main/java/org/jacop/jasat/utils/structures/IntVec.java index 03a6a4f37..de23be44a 100644 --- a/src/main/java/org/jacop/jasat/utils/structures/IntVec.java +++ b/src/main/java/org/jacop/jasat/utils/structures/IntVec.java @@ -72,6 +72,8 @@ public void set(int index, int i) { /** * number of elements + * + * @return number of elements in the vector */ public int size() { return numElem; diff --git a/src/main/java/org/jacop/satwrapper/SatTranslation.java b/src/main/java/org/jacop/satwrapper/SatTranslation.java index 6dabe0ee1..9e4ee0476 100644 --- a/src/main/java/org/jacop/satwrapper/SatTranslation.java +++ b/src/main/java/org/jacop/satwrapper/SatTranslation.java @@ -42,7 +42,7 @@ * SatTranslation defines SAT clauses for typical logical constraints * * @author Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class SatTranslation { @@ -127,17 +127,27 @@ public void generate_or(IntVar[] a, IntVar c) { // (a1 \/ a2 \/ ... \/ an \/ -c) // /\ // for all i: (-ai \/ c) + for (int i = 0; i < a.length; i++) + if (a[i].min() == 1) { + c.domain.in(store.level, c, 1,1); + return; + } + generate_clause(a, new IntVar[] {c}); for (int i = 0; i < a.length; i++) generate_clause(new IntVar[] {c}, new IntVar[] {a[i]}); } - public void generate_and(IntVar[] a, IntVar c) { // -a1 \/ -a2 \/ ... \/ c // /\ // for all i: ai \/ -c + for (int i = 0; i < a.length; i++) + if (a[i].max() == 0) { + c.domain.in(store.level, c, 0,0); + return; + } generate_clause(new IntVar[] {c}, a); for (int i = 0; i < a.length; i++) @@ -151,6 +161,8 @@ public void generate_and(IntVar[] a, IntVar c) { * Our method cuts list to 3 or 2 element parts, generates XOR for them * and composesd them back to the original XOR. * Further improvements possible, if using 4-7 decompositions. + * @param a parameters to be xor'ed + * @param c result */ public void generate_xor(IntVar[] a, IntVar c) { @@ -301,6 +313,150 @@ public void generate_implication_reif(IntVar a, IntVar b, IntVar c) { generate_clause(new IntVar[] {c}, new IntVar[] {b}); } + public void generate_allZero_reif(IntVar[] as, IntVar c) { + // allZero(a) <=> c + // - (a[0] \/ .. \/ a[n]) <=> c + // =========== + // /\_i (-a[i] \/ -c) /\ (a[0] \/ .. a[n] \/ c) + + // if any as[i] == 1 => c == 0 + for (int i=0; i b + // =========== + // ( -(x = c)) \/ b=1) /\ ( (x = c) \/ - b=1) + System.out.println("generate_eqC_reif("+x+", "+c+", "+b+")"); + + // clauses.register(x,false); + // clauses.register(b,false); + clauses.register(x); + clauses.register(b); + + int xLiteral = clauses.cpVarToBoolVar(x, c, true); + int bLiteral = clauses.cpVarToBoolVar(b, 1, true); + + int[] clause = new int[2]; + clause[0] = - xLiteral; + clause[1] = bLiteral; + clauses.addModelClause(clause); + + clause = new int[2]; + clause[0] = xLiteral; + clause[1] = - bLiteral; + clauses.addModelClause(clause); + + numberClauses += 2; + } + + public void generate_neC_reif(IntVar x, int c, IntVar b) { + // Assumes that both x and b are not ground and + // c is still in the domain of x + // (x != c) <=> b + // =========== + // ( -(x = c)) \/ b=0) /\ ( (x = c) \/ - b=0) + + clauses.register(x); + clauses.register(b); + + int xLiteral = clauses.cpVarToBoolVar(x, c, true); + int bLiteral = clauses.cpVarToBoolVar(b, 0, true); + + int[] clause = new int[2]; + clause[0] = - xLiteral; + clause[1] = bLiteral; + clauses.addModelClause(clause); + + clause = new int[2]; + clause[0] = xLiteral; + clause[1] = - bLiteral; + clauses.addModelClause(clause); + + numberClauses += 2; + } + + // inefficient propagation for large domains by SimpleCpVarDomain + // and LazyCpVarDomain is not yet implemented + public void generate_geC_reif(IntVar x, int c, IntVar b) { + // Assumes that both x and b are not ground and + // c is still in the domain of x + // (x >= c) <=> b + // =========== + // (x >= c) => b \/ (x >= c) <= b + // ( -(x >= c)) \/ b=1) /\ ( (x >= c) \/ - b=1) + // ( (x <= c-1) \/ b=1) /\ ( - (x <= c-1) \/ - b=1) + + clauses.register(x); + clauses.register(b); + + int xLiteral = clauses.cpVarToBoolVar(x, c-1, false); + int bLiteral = clauses.cpVarToBoolVar(b, 1, true); + + int[] clause = new int[2]; + clause[0] = xLiteral; + clause[1] = bLiteral; + clauses.addModelClause(clause); + + clause = new int[2]; + clause[0] = - xLiteral; + clause[1] = - bLiteral; + clauses.addModelClause(clause); + + numberClauses += 2; + } + + public void generate_inSet_reif(IntVar x, org.jacop.core.IntDomain d, IntVar b) { + // x = d1 \/ d = d2 \/ ... \/ x = dn <=> b + // =========== + // (x = d1 \/ d = d2 \/ ... \/ x = dn \/ -b) /\ + // (-(x =d1) \/ b) /\ ( -(x = d2) \/ b) /\ ... /\ ( -(x = dn) \/ b) + + clauses.register(x); + clauses.register(b); + + int n = d.getSize(); + int[] xLiterals = new int[n]; + org.jacop.core.ValueEnumeration values = d.valueEnumeration(); + int j=0; + while (values.hasMoreElements()) + xLiterals[j] = clauses.cpVarToBoolVar(x, values.nextElement(), true); + int bLiteral = clauses.cpVarToBoolVar(b, 1, true); + + int[] clause = new int[n+1]; + for (int i = 0; i < n; i++) + clause[i] = xLiterals[i]; + clause[n-1] = - bLiteral; + clauses.addModelClause(clause); + + numberClauses++; + + for (int i = 0; i < n; i++) { + clause = new int[2]; + clause[0] = - xLiterals[i]; + clause[1] = bLiteral; + clauses.addModelClause(clause); + + numberClauses++; + } + } + */ public void impose() { diff --git a/src/main/java/org/jacop/satwrapper/SatWrapper.java b/src/main/java/org/jacop/satwrapper/SatWrapper.java index 6f224070c..4448a14ed 100644 --- a/src/main/java/org/jacop/satwrapper/SatWrapper.java +++ b/src/main/java/org/jacop/satwrapper/SatWrapper.java @@ -137,6 +137,7 @@ public void register(IntVar result) { /** * registers the variable so that we can use it in SAT solver * @param variable the CP IntVar variable + * @param translate indicate whether to use == or {@literal <=} */ public void register(IntVar variable, boolean translate) { @@ -500,6 +501,8 @@ public int getMostActiveLiteral() { /** * (for debug) show what a literal means + * @param literal literal for showing its meaning + * @return literal meaning */ public String showLiteralMeaning(int literal) { if (! isVarLiteral(literal)) @@ -619,11 +622,11 @@ public final void impose(Store store) { /** * given a CP variable and a value, retrieve the associated boolean literal - * for either 'variable = value' or either 'variable <= value' + * for either 'variable = value' or either 'variable {@literal <=} value' * @param variable the CP variable * @param value a value in the range of this variable * @param isEquality a boolean, true if we want the literal that stands for - * 'x=d', false for 'x<=d' + * 'x=d', false for 'x{@literal <=}d' * @return the corresponding literal, or 0 if it is out of bounds */ public final int @@ -655,7 +658,7 @@ public final SatCPBridge boolVarToDomain(int literal) { /** * get the IntVar back from a literal * @param literal the literal - * @return + * @return IntVar represented by the literal */ public final IntVar boolVarToCpVar(int literal) { assert isVarLiteral(literal); @@ -667,6 +670,8 @@ public final IntVar boolVarToCpVar(int literal) { /** * transform a literal 'x=v' into a value 'v' for some CP variable + * @param literal literal to be transformed to value it represents + * @return the value represented by this literal */ public final int boolVarToCpValue(int literal) { assert isVarLiteral(literal); @@ -678,10 +683,10 @@ public final int boolVarToCpValue(int literal) { } /** - * checks if the boolean variable represents an assertion 'x=v' or 'x<=v' + * checks if the boolean variable represents an assertion 'x=v' or 'x{@literal <=}v' * @param literal the boolean literal * @return true if the literal represents a proposition 'x=v', false if - * it represents 'x<=v' + * it represents 'x{@literal <=}v' */ public final boolean isEqualityBoolVar(int literal) { assert isVarLiteral(literal); @@ -694,7 +699,7 @@ public final boolean isEqualityBoolVar(int literal) { /** * checks if this literal corresponds to some CP variable * @param literal the literal - * @return true if this literal stands for some 'x=v' or 'x<=v' proposition + * @return true if this literal stands for some 'x=v' or 'x{@literal <=}v' proposition */ public final boolean isVarLiteral(int literal) { /* @@ -712,6 +717,7 @@ public final boolean isVarLiteral(int literal) { * @param o the object that logs something (use this) * @param format the format string (the message, if no formatting) * @param args the arguments to fill in the format + * @return always true */ public boolean log(Object o, String format, Object... args) { if (verbosity >= 1) { diff --git a/src/main/java/org/jacop/satwrapper/translation/DomainTranslator.java b/src/main/java/org/jacop/satwrapper/translation/DomainTranslator.java index 35bc39cba..8b1e76448 100644 --- a/src/main/java/org/jacop/satwrapper/translation/DomainTranslator.java +++ b/src/main/java/org/jacop/satwrapper/translation/DomainTranslator.java @@ -26,7 +26,7 @@ public final class DomainTranslator implements WrapperComponent { * those clauses to the wrapper queue. * @param variable the variable to translate * - * @see Propagation via Lazy Clause Generation, + * see Propagation via Lazy Clause Generation, * Olga Ohrimenko1 , Peter J. Stuckey , and Michael Codish * */ diff --git a/src/main/java/org/jacop/satwrapper/translation/LazyCpVarDomain.java b/src/main/java/org/jacop/satwrapper/translation/LazyCpVarDomain.java index 635220460..ffba4f01a 100644 --- a/src/main/java/org/jacop/satwrapper/translation/LazyCpVarDomain.java +++ b/src/main/java/org/jacop/satwrapper/translation/LazyCpVarDomain.java @@ -85,8 +85,7 @@ public boolean isTranslated() { /** * creates the var list - * @param var the variable this list represents - * @param firstVar + * @param variable the variable this list represents */ public LazyCpVarDomain(IntVar variable) { super(variable); diff --git a/src/main/java/org/jacop/satwrapper/translation/SatCPBridge.java b/src/main/java/org/jacop/satwrapper/translation/SatCPBridge.java index 7388fbc05..4c2cfa2ca 100644 --- a/src/main/java/org/jacop/satwrapper/translation/SatCPBridge.java +++ b/src/main/java/org/jacop/satwrapper/translation/SatCPBridge.java @@ -11,11 +11,10 @@ /** * interface representing the domain of a CP variable as a range. It is used - * to provide literals to represent assertions like 'X = v' or 'X <= v' where X + * to provide literals to represent assertions like 'X = v' or 'X{@literal <=} v' where X * is the CP variable and v a value from its domain * @author simon * - * @param E the type of the JaCoP variable represented */ public abstract class SatCPBridge implements WrapperComponent { @@ -66,10 +65,10 @@ public void setDomain(int minValue, int maxValue) { /** * return the literal that represents the assertion 'var = value'. - * For the proposition 'var <= value', set the isEquality flag to false + * For the proposition 'var{@literal <=} value', set the isEquality flag to false * @param value the value for the variable this range represents - * @param isEquality true if we want the literal for 'x=d' kind of - * propositions, false for 'x<=d' + * @param isEquality true if we want the literal for '{@code x=d}' kind of + * propositions, false for '{@code x<=d}' * @return the literal corresponding to 'var = this value'. If the value * is out of the domain of the variable, returns 0. */ @@ -78,14 +77,14 @@ public void setDomain(int minValue, int maxValue) { /** * return the value corresponding to given literal (variable) * @param literal the literal standing for 'var = value' - * @return the value such that 'var = value' (or 'var <= value') + * @return the value such that 'var = value' (or 'var{@literal <=} value') */ public abstract int boolVarToCpValue(int literal); /** * checks if the literal stands for a 'x=d' proposition, or a - * 'x<=d' proposition + * 'x{@literal <=}d' proposition * @param literal the literal (among literals from this range) * @return true if the literal stands for 'x=d', false otherwise */ @@ -96,7 +95,7 @@ public void setDomain(int minValue, int maxValue) { * this object manages * @param literal a literal * @return true if there is a 'd' such that literal stands for 'x=d' - * or 'x<=d' + * or 'x{@literal <=}d' */ public final boolean isInThisRange(int literal) { return wrapper.boolVarToCpVar(literal) == variable; @@ -106,7 +105,6 @@ public final boolean isInThisRange(int literal) { * does all propagation required, in a way specific to this range. This part * may not be used, if the variable is not bound to a DomainClausesDatabase. * This will be called only if this.isTranslated() is false. - * @param db the database to add propagated literals to * @param literal the literal that has been asserted */ public abstract void propagate(int literal); diff --git a/src/main/java/org/jacop/satwrapper/translation/SimpleCpVarDomain.java b/src/main/java/org/jacop/satwrapper/translation/SimpleCpVarDomain.java index 758e125d1..f403b2051 100644 --- a/src/main/java/org/jacop/satwrapper/translation/SimpleCpVarDomain.java +++ b/src/main/java/org/jacop/satwrapper/translation/SimpleCpVarDomain.java @@ -8,8 +8,8 @@ /** * A simple representation for small domains, not lazy. It allocates boolean - * variables to stand for propositions '[x=v]' and '[x<=v]' for each value v of - * the domain of x (even '[x<=max]', which is a tautology, for simplicity) + * variables to stand for propositions '[x=v]' and '[x{@literal <=}v]' for each value v of + * the domain of x (even '[x{@literal <=}max]', which is a tautology, for simplicity) * @author simon * */ diff --git a/src/main/java/org/jacop/search/ComparatorVariable.java b/src/main/java/org/jacop/search/ComparatorVariable.java index 9f5b0f839..512d4f09c 100644 --- a/src/main/java/org/jacop/search/ComparatorVariable.java +++ b/src/main/java/org/jacop/search/ComparatorVariable.java @@ -37,7 +37,7 @@ * Defines an interface for comparing variables. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param Variable type being compared. */ diff --git a/src/main/java/org/jacop/search/ConsistencyListener.java b/src/main/java/org/jacop/search/ConsistencyListener.java index b47c7cb7f..52acf7316 100644 --- a/src/main/java/org/jacop/search/ConsistencyListener.java +++ b/src/main/java/org/jacop/search/ConsistencyListener.java @@ -39,7 +39,7 @@ * listeners working together in any fashion. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public interface ConsistencyListener { diff --git a/src/main/java/org/jacop/search/CreditCalculator.java b/src/main/java/org/jacop/search/CreditCalculator.java index d311b4df8..a5e69c88a 100644 --- a/src/main/java/org/jacop/search/CreditCalculator.java +++ b/src/main/java/org/jacop/search/CreditCalculator.java @@ -40,7 +40,7 @@ * ExitChildListener, TimeOutListener, and Consistency Listener. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ @@ -464,6 +464,7 @@ public void setChildrenListeners(ConsistencyListener child) { consistencyListeners[0] = child; } + @SuppressWarnings("unchecked") public void setChildrenListeners(ExitChildListener child) { exitChildListeners = new ExitChildListener[1]; exitChildListeners[0] = child; diff --git a/src/main/java/org/jacop/search/DepthFirstSearch.java b/src/main/java/org/jacop/search/DepthFirstSearch.java index 1317cf448..e3726da3e 100644 --- a/src/main/java/org/jacop/search/DepthFirstSearch.java +++ b/src/main/java/org/jacop/search/DepthFirstSearch.java @@ -56,7 +56,7 @@ * be attached to modify the search. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variables used in this search. */ @@ -869,7 +869,7 @@ public void setStore(Store store) { public void setCostVar(Var cost) { costVariable = cost; - + optimize = true; } /** @@ -1072,6 +1072,26 @@ public boolean labeling(Store store, SelectChoicePoint select) { } + // KKU, 2015-12-17: might be used to set cost variable and + // optimization = true for all sub-searches does not do it + // automatically since it might not be the intention (we might + // want to find only a single solution in the sub-search). This is + // why it is not added to labeling with costVar. + void setOptimizationForChildSearches(DepthFirstSearch s, Var costVar) { + + // set cost and optimization for child searches + if (s != null) { + DepthFirstSearch[] childs = (DepthFirstSearch[])s.childSearches; + while (childs != null) { + for (DepthFirstSearch child : childs) { + child.setCostVar(costVar); + child.setOptimize( true); + setOptimizationForChildSearches(s, costVar); + } + } + } + } + public boolean labeling(Store store, SelectChoicePoint select, Var costVar) { this.store = store; @@ -1086,6 +1106,7 @@ public boolean labeling(Store store, SelectChoicePoint select, Var costVar) { costVariable = costVar; optimize = true; cost = null; + // timeOutOccured = false; // timeOut = System.currentTimeMillis() + tOut * 1000; diff --git a/src/main/java/org/jacop/search/ExitChildListener.java b/src/main/java/org/jacop/search/ExitChildListener.java index 4f1f8fb8b..c9ed39bc3 100644 --- a/src/main/java/org/jacop/search/ExitChildListener.java +++ b/src/main/java/org/jacop/search/ExitChildListener.java @@ -39,7 +39,7 @@ * It works for both the right and left child. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable used in the search. */ diff --git a/src/main/java/org/jacop/search/ExitListener.java b/src/main/java/org/jacop/search/ExitListener.java index c10e96518..0aa6a7919 100644 --- a/src/main/java/org/jacop/search/ExitListener.java +++ b/src/main/java/org/jacop/search/ExitListener.java @@ -38,7 +38,7 @@ * the labeling procedure. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public interface ExitListener { diff --git a/src/main/java/org/jacop/search/Indomain.java b/src/main/java/org/jacop/search/Indomain.java index b52ab7e55..644fc2e15 100644 --- a/src/main/java/org/jacop/search/Indomain.java +++ b/src/main/java/org/jacop/search/Indomain.java @@ -37,7 +37,7 @@ * Defines a interface for different indomain enumeration methods. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of variable for which the assignment value is being generated. */ diff --git a/src/main/java/org/jacop/search/IndomainDefaultValue.java b/src/main/java/org/jacop/search/IndomainDefaultValue.java index 2078930ab..94749863d 100644 --- a/src/main/java/org/jacop/search/IndomainDefaultValue.java +++ b/src/main/java/org/jacop/search/IndomainDefaultValue.java @@ -48,7 +48,7 @@ * * @author Krzysztof Kuchcinski * - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ diff --git a/src/main/java/org/jacop/search/IndomainHierarchical.java b/src/main/java/org/jacop/search/IndomainHierarchical.java index 334e31494..fa5218588 100644 --- a/src/main/java/org/jacop/search/IndomainHierarchical.java +++ b/src/main/java/org/jacop/search/IndomainHierarchical.java @@ -42,7 +42,7 @@ * * @author 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/search/IndomainList.java b/src/main/java/org/jacop/search/IndomainList.java index 9f375611d..5f6f8577e 100644 --- a/src/main/java/org/jacop/search/IndomainList.java +++ b/src/main/java/org/jacop/search/IndomainList.java @@ -39,7 +39,7 @@ * functionality was proposed by Ben Weiner. * * @author Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ public class IndomainList implements Indomain { diff --git a/src/main/java/org/jacop/search/IndomainMax.java b/src/main/java/org/jacop/search/IndomainMax.java index 41da5225c..d96f3d462 100644 --- a/src/main/java/org/jacop/search/IndomainMax.java +++ b/src/main/java/org/jacop/search/IndomainMax.java @@ -38,7 +38,7 @@ * maximal value in the domain of the variable. * * @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/search/IndomainMedian.java b/src/main/java/org/jacop/search/IndomainMedian.java index 120816767..d8f433a04 100644 --- a/src/main/java/org/jacop/search/IndomainMedian.java +++ b/src/main/java/org/jacop/search/IndomainMedian.java @@ -43,7 +43,7 @@ * median value in the domain of FD variable and then right and left values. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of variable being used in search. */ diff --git a/src/main/java/org/jacop/search/IndomainMiddle.java b/src/main/java/org/jacop/search/IndomainMiddle.java index bdb4d03bd..e952a467c 100644 --- a/src/main/java/org/jacop/search/IndomainMiddle.java +++ b/src/main/java/org/jacop/search/IndomainMiddle.java @@ -41,7 +41,7 @@ * middle value in the domain of FD variable and then right and left values. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of variable being used in search. */ diff --git a/src/main/java/org/jacop/search/IndomainMin.java b/src/main/java/org/jacop/search/IndomainMin.java index c8be1fa2a..d9d27d438 100644 --- a/src/main/java/org/jacop/search/IndomainMin.java +++ b/src/main/java/org/jacop/search/IndomainMin.java @@ -38,7 +38,7 @@ * minimal value in the domain of variable * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of variable being used in search. */ diff --git a/src/main/java/org/jacop/search/IndomainRandom.java b/src/main/java/org/jacop/search/IndomainRandom.java index 08da0abbd..82054a5aa 100644 --- a/src/main/java/org/jacop/search/IndomainRandom.java +++ b/src/main/java/org/jacop/search/IndomainRandom.java @@ -42,7 +42,7 @@ * intervals * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ diff --git a/src/main/java/org/jacop/search/IndomainSimpleRandom.java b/src/main/java/org/jacop/search/IndomainSimpleRandom.java index 22b9526d8..f7d04f195 100644 --- a/src/main/java/org/jacop/search/IndomainSimpleRandom.java +++ b/src/main/java/org/jacop/search/IndomainSimpleRandom.java @@ -40,7 +40,7 @@ * intervals * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ diff --git a/src/main/java/org/jacop/search/InitializeListener.java b/src/main/java/org/jacop/search/InitializeListener.java index dbd3035aa..aa2cfa5c5 100644 --- a/src/main/java/org/jacop/search/InitializeListener.java +++ b/src/main/java/org/jacop/search/InitializeListener.java @@ -38,7 +38,7 @@ * the labeling procedure. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public interface InitializeListener { @@ -52,7 +52,7 @@ public interface InitializeListener { /** * It sets the children listeners of this initialize listener. - * @param children + * @param children children listeners being set */ public void setChildrenListeners(InitializeListener[] children); diff --git a/src/main/java/org/jacop/search/InputOrderSelect.java b/src/main/java/org/jacop/search/InputOrderSelect.java index c158f4998..3f40f6a32 100644 --- a/src/main/java/org/jacop/search/InputOrderSelect.java +++ b/src/main/java/org/jacop/search/InputOrderSelect.java @@ -44,7 +44,7 @@ * It is simple input order selector of variables. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ @@ -71,6 +71,7 @@ public class InputOrderSelect implements SelectChoicePoint { * @param variables a list of variables which must be assigned a value by search. * @param indomain the indomain heuristic for assigning values to variables. */ + @SuppressWarnings("unchecked") public InputOrderSelect(Store store, T[] variables, Indomain indomain) { diff --git a/src/main/java/org/jacop/search/LDS.java b/src/main/java/org/jacop/search/LDS.java index 36e32b880..800ba448c 100644 --- a/src/main/java/org/jacop/search/LDS.java +++ b/src/main/java/org/jacop/search/LDS.java @@ -39,7 +39,7 @@ * search to change your depth first search into limited discrepancy search. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ @@ -197,7 +197,8 @@ public void setChildrenListeners(ExitChildListener[] children) { exitChildListeners = children; } - public void setChildrenListeners(ExitChildListener child) { + @SuppressWarnings("unchecked") + public void setChildrenListeners(ExitChildListener child) { exitChildListeners = new ExitChildListener[1]; exitChildListeners[0] = child; } diff --git a/src/main/java/org/jacop/search/LargestDomain.java b/src/main/java/org/jacop/search/LargestDomain.java index 3cc0bfec6..370f51543 100644 --- a/src/main/java/org/jacop/search/LargestDomain.java +++ b/src/main/java/org/jacop/search/LargestDomain.java @@ -38,7 +38,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/search/LargestMax.java b/src/main/java/org/jacop/search/LargestMax.java index 82a330031..51f7304ee 100644 --- a/src/main/java/org/jacop/search/LargestMax.java +++ b/src/main/java/org/jacop/search/LargestMax.java @@ -37,7 +37,7 @@ * Defines a LargestMax 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/search/LargestMin.java b/src/main/java/org/jacop/search/LargestMin.java index 8901b006f..d1c1d6944 100644 --- a/src/main/java/org/jacop/search/LargestMin.java +++ b/src/main/java/org/jacop/search/LargestMin.java @@ -37,7 +37,7 @@ * Defines a LargestMin 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/search/MaxRegret.java b/src/main/java/org/jacop/search/MaxRegret.java index e523f1d5e..e4f53ed3a 100644 --- a/src/main/java/org/jacop/search/MaxRegret.java +++ b/src/main/java/org/jacop/search/MaxRegret.java @@ -39,7 +39,7 @@ * Defines a MaxRegret comparator for Variables. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param variable of type IntVar. */ diff --git a/src/main/java/org/jacop/search/MinDomainOverDegree.java b/src/main/java/org/jacop/search/MinDomainOverDegree.java index 4e8eb974a..187ce1d38 100644 --- a/src/main/java/org/jacop/search/MinDomainOverDegree.java +++ b/src/main/java/org/jacop/search/MinDomainOverDegree.java @@ -39,7 +39,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/search/MostConstrainedDynamic.java b/src/main/java/org/jacop/search/MostConstrainedDynamic.java index ca77f7fd9..930b0f99c 100644 --- a/src/main/java/org/jacop/search/MostConstrainedDynamic.java +++ b/src/main/java/org/jacop/search/MostConstrainedDynamic.java @@ -37,7 +37,7 @@ * Defines a MostConstrainedDynamic comparator for Variables. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of variable being compared. */ diff --git a/src/main/java/org/jacop/search/MostConstrainedStatic.java b/src/main/java/org/jacop/search/MostConstrainedStatic.java index aded2377c..fb754bb1b 100644 --- a/src/main/java/org/jacop/search/MostConstrainedStatic.java +++ b/src/main/java/org/jacop/search/MostConstrainedStatic.java @@ -37,7 +37,7 @@ * Defines a MostConstraintStatic comparator for Variables. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of variable being compared. */ diff --git a/src/main/java/org/jacop/search/NoGoodsCollector.java b/src/main/java/org/jacop/search/NoGoodsCollector.java index dbbc5b777..1cc07257f 100644 --- a/src/main/java/org/jacop/search/NoGoodsCollector.java +++ b/src/main/java/org/jacop/search/NoGoodsCollector.java @@ -46,7 +46,7 @@ * when collector is informed about exiting the search. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class NoGoodsCollector implements ExitChildListener, TimeOutListener, ExitListener { @@ -190,6 +190,7 @@ public void setChildrenListeners(ExitListener child) { exitListeners[0] = child; } + @SuppressWarnings("unchecked") public void setChildrenListeners(ExitChildListener child) { exitChildListeners = new ExitChildListener[1]; exitChildListeners[0] = child; diff --git a/src/main/java/org/jacop/search/OneSolution.java b/src/main/java/org/jacop/search/OneSolution.java index 5d2c9e85b..091008a4c 100644 --- a/src/main/java/org/jacop/search/OneSolution.java +++ b/src/main/java/org/jacop/search/OneSolution.java @@ -41,7 +41,7 @@ * again search for a single solution. * * @author Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class OneSolution extends SimpleSolutionListener implements ConsistencyListener, InitializeListener { @@ -64,7 +64,7 @@ public void executedAtInitialize(Store store) { /** * It sets the children listeners of this initialize listener. - * @param children + * @param children children listeners */ public void setChildrenListeners(InitializeListener[] children) { diff --git a/src/main/java/org/jacop/search/PrintOutListener.java b/src/main/java/org/jacop/search/PrintOutListener.java index 64d85805e..12f7e65bd 100644 --- a/src/main/java/org/jacop/search/PrintOutListener.java +++ b/src/main/java/org/jacop/search/PrintOutListener.java @@ -36,7 +36,7 @@ * add your own functionality. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ import org.jacop.core.Var; diff --git a/src/main/java/org/jacop/search/RandomSelect.java b/src/main/java/org/jacop/search/RandomSelect.java index 17b494a11..88a05899b 100644 --- a/src/main/java/org/jacop/search/RandomSelect.java +++ b/src/main/java/org/jacop/search/RandomSelect.java @@ -44,7 +44,7 @@ * be enforced by search. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ public class RandomSelect implements SelectChoicePoint { @@ -71,6 +71,7 @@ public class RandomSelect implements SelectChoicePoint { * @param variables variables upon which the choice points are created. * @param indomain the value heuristic to choose a value for a given variable. */ + @SuppressWarnings("unchecked") public RandomSelect(T[] variables, Indomain indomain) { position = new IdentityHashMap(); diff --git a/src/main/java/org/jacop/search/Search.java b/src/main/java/org/jacop/search/Search.java index 73b8450f6..77f246adf 100644 --- a/src/main/java/org/jacop/search/Search.java +++ b/src/main/java/org/jacop/search/Search.java @@ -43,7 +43,7 @@ * in the right place and act accordingly to the output of listeners. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variables used in this search. */ diff --git a/src/main/java/org/jacop/search/SelectChoicePoint.java b/src/main/java/org/jacop/search/SelectChoicePoint.java index 0fd56cbda..70bf18ade 100644 --- a/src/main/java/org/jacop/search/SelectChoicePoint.java +++ b/src/main/java/org/jacop/search/SelectChoicePoint.java @@ -43,7 +43,7 @@ * enforced. * * @author Radoslaw Szymanek and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of the variable for which choice point is being created. */ diff --git a/src/main/java/org/jacop/search/Shaving.java b/src/main/java/org/jacop/search/Shaving.java index 0f5e5b64a..4381c7b9f 100644 --- a/src/main/java/org/jacop/search/Shaving.java +++ b/src/main/java/org/jacop/search/Shaving.java @@ -73,9 +73,10 @@ * * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ +@SuppressWarnings("unchecked") public class Shaving implements ExitChildListener, ConsistencyListener { /** diff --git a/src/main/java/org/jacop/search/SimpleMatrixSelect.java b/src/main/java/org/jacop/search/SimpleMatrixSelect.java index 6133c6e05..adbee1534 100644 --- a/src/main/java/org/jacop/search/SimpleMatrixSelect.java +++ b/src/main/java/org/jacop/search/SimpleMatrixSelect.java @@ -49,7 +49,7 @@ * mainComparator = InputOrder, tieBreakingComparator = InputOrder. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable being used in the Search. */ diff --git a/src/main/java/org/jacop/search/SimpleSelect.java b/src/main/java/org/jacop/search/SimpleSelect.java index a3eab350a..bc62eff6e 100644 --- a/src/main/java/org/jacop/search/SimpleSelect.java +++ b/src/main/java/org/jacop/search/SimpleSelect.java @@ -43,9 +43,10 @@ * be enforced by search. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ +@SuppressWarnings("unchecked") public class SimpleSelect implements SelectChoicePoint { static final boolean debugAll = false; diff --git a/src/main/java/org/jacop/search/SimpleSolutionListener.java b/src/main/java/org/jacop/search/SimpleSolutionListener.java index bfb9541af..f70bd071d 100644 --- a/src/main/java/org/jacop/search/SimpleSolutionListener.java +++ b/src/main/java/org/jacop/search/SimpleSolutionListener.java @@ -49,7 +49,7 @@ * functionality of search when a solution is encountered are required. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable being used in search. */ @@ -390,10 +390,10 @@ public int findSolutionMatchingParent(int parentNo) { if (!isRecordingSolutions()) { - if (parentSolutionNo[0] == parentNo) - return 0; - else - return -1; + // if (parentSolutionNo[0] == parentNo) + return 0; + // else + // return -1; } diff --git a/src/main/java/org/jacop/search/SimpleTimeOut.java b/src/main/java/org/jacop/search/SimpleTimeOut.java index d2bb0ddd9..47bd77d0d 100644 --- a/src/main/java/org/jacop/search/SimpleTimeOut.java +++ b/src/main/java/org/jacop/search/SimpleTimeOut.java @@ -38,7 +38,7 @@ * before the timeout. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class SimpleTimeOut implements TimeOutListener { diff --git a/src/main/java/org/jacop/search/SmallestDomain.java b/src/main/java/org/jacop/search/SmallestDomain.java index ab5f7d188..c36591243 100644 --- a/src/main/java/org/jacop/search/SmallestDomain.java +++ b/src/main/java/org/jacop/search/SmallestDomain.java @@ -38,7 +38,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/search/SmallestMax.java b/src/main/java/org/jacop/search/SmallestMax.java index 658ce5cbb..a3f08d0c0 100644 --- a/src/main/java/org/jacop/search/SmallestMax.java +++ b/src/main/java/org/jacop/search/SmallestMax.java @@ -38,7 +38,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/search/SmallestMin.java b/src/main/java/org/jacop/search/SmallestMin.java index 176529f6b..1c6a50423 100644 --- a/src/main/java/org/jacop/search/SmallestMin.java +++ b/src/main/java/org/jacop/search/SmallestMin.java @@ -38,7 +38,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/search/SolutionListener.java b/src/main/java/org/jacop/search/SolutionListener.java index 2080b3483..0bb95b89c 100644 --- a/src/main/java/org/jacop/search/SolutionListener.java +++ b/src/main/java/org/jacop/search/SolutionListener.java @@ -41,7 +41,7 @@ * to be informed about the solution. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable for which the solution is being stored. */ diff --git a/src/main/java/org/jacop/search/SplitSelect.java b/src/main/java/org/jacop/search/SplitSelect.java index 45346e56d..003cb1c86 100644 --- a/src/main/java/org/jacop/search/SplitSelect.java +++ b/src/main/java/org/jacop/search/SplitSelect.java @@ -42,11 +42,11 @@ /** * It is simple and customizable selector of decisions (constraints) which will * be enforced by search. However, it does not use X=c as a search decision - * but rather X <= c (potentially splitting the domain), unless c is equal to - * the maximal value in the domain of X then the constraint X < c is used. + * but rather X {@literal <=} c (potentially splitting the domain), unless c is equal to + * the maximal value in the domain of X then the constraint X {@literal <} c is used. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ diff --git a/src/main/java/org/jacop/search/TimeOutListener.java b/src/main/java/org/jacop/search/TimeOutListener.java index 6b0cfdee0..fb2e10fe4 100644 --- a/src/main/java/org/jacop/search/TimeOutListener.java +++ b/src/main/java/org/jacop/search/TimeOutListener.java @@ -38,7 +38,7 @@ * timeout has occurred. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public interface TimeOutListener { diff --git a/src/main/java/org/jacop/search/TraceGenerator.java b/src/main/java/org/jacop/search/TraceGenerator.java index 237a1119f..de4f9a79e 100644 --- a/src/main/java/org/jacop/search/TraceGenerator.java +++ b/src/main/java/org/jacop/search/TraceGenerator.java @@ -97,7 +97,7 @@ * check that getChoiceConstraint returns false. * * Can CPviz handle search for Set variables handle correctly 100%? - * If not maybe we should just make TraceGenerator? + * If not maybe we should just make {@code TraceGenerator}? * * * FilterDom should not use string representation of the domain just @@ -530,6 +530,7 @@ public void rightChild(PrimitiveConstraint choice, boolean status) { // ================================================================= // Metods for tracing using ExitListener + @SuppressWarnings("unchecked") public void setChildrenListeners(ExitChildListener child) { exitChildListeners = new ExitChildListener[1]; exitChildListeners[0] = child; diff --git a/src/main/java/org/jacop/search/TransformExtensional.java b/src/main/java/org/jacop/search/TransformExtensional.java index 2b734bc98..3ec4acb0b 100644 --- a/src/main/java/org/jacop/search/TransformExtensional.java +++ b/src/main/java/org/jacop/search/TransformExtensional.java @@ -48,7 +48,7 @@ * given the scope of the variables of interest. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class TransformExtensional implements InitializeListener { diff --git a/src/main/java/org/jacop/search/WeightedDegree.java b/src/main/java/org/jacop/search/WeightedDegree.java index 6acc8ea78..617052198 100644 --- a/src/main/java/org/jacop/search/WeightedDegree.java +++ b/src/main/java/org/jacop/search/WeightedDegree.java @@ -44,7 +44,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/search/sgmpcs/ImproveSolution.java b/src/main/java/org/jacop/search/sgmpcs/ImproveSolution.java index 8bcbd01c6..e30880dfa 100644 --- a/src/main/java/org/jacop/search/sgmpcs/ImproveSolution.java +++ b/src/main/java/org/jacop/search/sgmpcs/ImproveSolution.java @@ -40,7 +40,7 @@ * enforced. * * @author krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of the variable for which choice point is being created. */ diff --git a/src/main/java/org/jacop/search/sgmpcs/SGMPCSCalculator.java b/src/main/java/org/jacop/search/sgmpcs/SGMPCSCalculator.java index 0589af64c..5a5a241e0 100644 --- a/src/main/java/org/jacop/search/sgmpcs/SGMPCSCalculator.java +++ b/src/main/java/org/jacop/search/sgmpcs/SGMPCSCalculator.java @@ -38,7 +38,7 @@ * Defines functionality for SGMPCS search * * @author Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class SGMPCSCalculator implements ConsistencyListener { diff --git a/src/main/java/org/jacop/search/sgmpcs/SGMPCSearch.java b/src/main/java/org/jacop/search/sgmpcs/SGMPCSearch.java index 3a0400fd5..865780ecb 100644 --- a/src/main/java/org/jacop/search/sgmpcs/SGMPCSearch.java +++ b/src/main/java/org/jacop/search/sgmpcs/SGMPCSearch.java @@ -69,7 +69,7 @@ * * @author Krzysztof Kuchcinski * - * @version 4.3 + * @version 4.4 */ public class SGMPCSearch { @@ -149,7 +149,7 @@ public SGMPCSearch(Store store, IntVar[] vars, IntVar cost) { search = new SimpleImprovementSearch(store, vars, cost); } - public SGMPCSearch(Store store, IntVar[] vars, IntVar cost, ImproveSolution search) { + public SGMPCSearch(Store store, IntVar[] vars, IntVar cost, ImproveSolution search) { this.store = store; this.vars = vars; diff --git a/src/main/java/org/jacop/search/sgmpcs/SimpleImprovementSearch.java b/src/main/java/org/jacop/search/sgmpcs/SimpleImprovementSearch.java index 9ce6dfc25..8a7d997a5 100644 --- a/src/main/java/org/jacop/search/sgmpcs/SimpleImprovementSearch.java +++ b/src/main/java/org/jacop/search/sgmpcs/SimpleImprovementSearch.java @@ -59,7 +59,7 @@ * enforced. * * @author krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param type of the variable for which choice point is being created. */ diff --git a/src/main/java/org/jacop/set/constraints/AdiffBeqC.java b/src/main/java/org/jacop/set/constraints/AdiffBeqC.java index ecb8d229d..7c9a90006 100644 --- a/src/main/java/org/jacop/set/constraints/AdiffBeqC.java +++ b/src/main/java/org/jacop/set/constraints/AdiffBeqC.java @@ -47,7 +47,7 @@ * A \ B = C. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class AdiffBeqC extends Constraint { @@ -345,15 +345,6 @@ public int getConsistencyPruningEvent(Var var) { return SetDomain.ANY; } - - @Override - public String id() { - if (id != null) - return id; - else - return this.getClass().getSimpleName() + numberId; - } - @Override public void impose(Store store) { a.putModelConstraint(this, getConsistencyPruningEvent(a)); diff --git a/src/main/java/org/jacop/set/constraints/AdisjointB.java b/src/main/java/org/jacop/set/constraints/AdisjointB.java index 9ccc8678d..b3d937b35 100644 --- a/src/main/java/org/jacop/set/constraints/AdisjointB.java +++ b/src/main/java/org/jacop/set/constraints/AdisjointB.java @@ -44,7 +44,7 @@ * do not contain any common element. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class AdisjointB extends Constraint { @@ -227,14 +227,6 @@ public int getConsistencyPruningEvent(Var var) { return SetDomain.ANY; } - @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/set/constraints/AeqB.java b/src/main/java/org/jacop/set/constraints/AeqB.java index 524d3366a..dbe8e9d53 100644 --- a/src/main/java/org/jacop/set/constraints/AeqB.java +++ b/src/main/java/org/jacop/set/constraints/AeqB.java @@ -44,7 +44,7 @@ * have the same value. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class AeqB extends PrimitiveConstraint { @@ -152,14 +152,6 @@ public int getNotConsistencyPruningEvent(Var var) { return SetDomain.GROUND; } - @Override - public String id() { - if (id != null) - return id; - else - return this.getClass().getSimpleName() + numberId; - } - @Override public void impose(Store store) { a.putModelConstraint(this, getConsistencyPruningEvent(a)); diff --git a/src/main/java/org/jacop/set/constraints/AeqS.java b/src/main/java/org/jacop/set/constraints/AeqS.java index 219d1a05e..10614b9a0 100644 --- a/src/main/java/org/jacop/set/constraints/AeqS.java +++ b/src/main/java/org/jacop/set/constraints/AeqS.java @@ -46,7 +46,7 @@ * * @author Radoslaw Szymanek and Krzysztof Kuchcinski * - * @version 4.3 + * @version 4.4 */ public class AeqS extends PrimitiveConstraint { @@ -142,14 +142,6 @@ public int getNotConsistencyPruningEvent(Var var) { return SetDomain.GROUND; } - @Override - public String id() { - if (id != null) - return id; - else - return this.getClass().getSimpleName() + numberId; - } - @Override public void impose(Store store) { a.putModelConstraint(this, getConsistencyPruningEvent(a)); diff --git a/src/main/java/org/jacop/set/constraints/AinB.java b/src/main/java/org/jacop/set/constraints/AinB.java index cfdb56841..97fe9fcee 100644 --- a/src/main/java/org/jacop/set/constraints/AinB.java +++ b/src/main/java/org/jacop/set/constraints/AinB.java @@ -44,7 +44,7 @@ * in the set value of set variable B. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class AinB extends PrimitiveConstraint { @@ -192,13 +192,6 @@ public int getNotConsistencyPruningEvent(Var var) { return SetDomain.ANY; } - @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/set/constraints/AinS.java b/src/main/java/org/jacop/set/constraints/AinS.java index eece06f9f..6b33efce4 100644 --- a/src/main/java/org/jacop/set/constraints/AinS.java +++ b/src/main/java/org/jacop/set/constraints/AinS.java @@ -45,7 +45,7 @@ * a provided set. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class AinS extends PrimitiveConstraint { @@ -89,6 +89,7 @@ public AinS(SetVar a, IntDomain set) { * * @param a variable that is restricted to be included within a provided set. * @param set set that is restricted to contain the value of set variable a. + * @param strict strict inclusion (true) */ public AinS(SetVar a, IntDomain set, boolean strict) { @@ -149,14 +150,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/set/constraints/AintersectBeqC.java b/src/main/java/org/jacop/set/constraints/AintersectBeqC.java index 337909394..c2c756e25 100644 --- a/src/main/java/org/jacop/set/constraints/AintersectBeqC.java +++ b/src/main/java/org/jacop/set/constraints/AintersectBeqC.java @@ -45,7 +45,7 @@ * is equal to C. A /\ B = C. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class AintersectBeqC extends Constraint { @@ -303,14 +303,6 @@ public int getConsistencyPruningEvent(Var var) { return SetDomain.ANY; } - @Override - public String id() { - if (id != null) - return id; - else - return this.getClass().getSimpleName() + numberId; - } - @Override public void impose(Store store) { a.putModelConstraint(this,getConsistencyPruningEvent(a)); diff --git a/src/main/java/org/jacop/set/constraints/AunionBeqC.java b/src/main/java/org/jacop/set/constraints/AunionBeqC.java index 5f8ce16ec..f45f73c63 100644 --- a/src/main/java/org/jacop/set/constraints/AunionBeqC.java +++ b/src/main/java/org/jacop/set/constraints/AunionBeqC.java @@ -46,7 +46,7 @@ * * @author Radoslaw Szymanek and Krzysztof Kuchcinski * - * @version 4.3 + * @version 4.4 */ public class AunionBeqC extends Constraint { @@ -89,8 +89,8 @@ public class AunionBeqC extends Constraint { /** * It constructs an AunionBeqC constraint to restrict the domain of the variables A, B and C. * - * @param a - * @param b + * @param a variable representing the first parameter + * @param b variable representing the second parameter * @param c variable that is restricted to be the union of a and b. */ @@ -286,14 +286,6 @@ public int getConsistencyPruningEvent(Var var) { return SetDomain.ANY; } - @Override - public String id() { - if (id != null) - return id; - else - return this.getClass().getSimpleName() + numberId; - } - @Override public void impose(Store store) { a.putModelConstraint(this,getConsistencyPruningEvent(a)); diff --git a/src/main/java/org/jacop/set/constraints/CardA.java b/src/main/java/org/jacop/set/constraints/CardA.java index 8205f29f9..8b2a1da73 100644 --- a/src/main/java/org/jacop/set/constraints/CardA.java +++ b/src/main/java/org/jacop/set/constraints/CardA.java @@ -45,7 +45,7 @@ * The set cardinality constraint. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class CardA extends Constraint { @@ -176,14 +176,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/set/constraints/CardAeqX.java b/src/main/java/org/jacop/set/constraints/CardAeqX.java index 7323f4d5b..9aea2cc08 100644 --- a/src/main/java/org/jacop/set/constraints/CardAeqX.java +++ b/src/main/java/org/jacop/set/constraints/CardAeqX.java @@ -155,16 +155,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/set/constraints/EinA.java b/src/main/java/org/jacop/set/constraints/EinA.java index 70f420d86..96d9b51d4 100644 --- a/src/main/java/org/jacop/set/constraints/EinA.java +++ b/src/main/java/org/jacop/set/constraints/EinA.java @@ -45,7 +45,7 @@ * in the domain of the set variable. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class EinA extends PrimitiveConstraint { @@ -148,14 +148,6 @@ public int getNotConsistencyPruningEvent(Var var) { return SetDomain.ANY; } - @Override - public String id() { - if (id != null) - return id; - else - return this.getClass().getSimpleName() + numberId; - } - @Override public void impose(Store store) { a.putModelConstraint(this, getConsistencyPruningEvent(a)); diff --git a/src/main/java/org/jacop/set/constraints/ElementSet.java b/src/main/java/org/jacop/set/constraints/ElementSet.java index 8ad87cd18..503b594ce 100644 --- a/src/main/java/org/jacop/set/constraints/ElementSet.java +++ b/src/main/java/org/jacop/set/constraints/ElementSet.java @@ -51,7 +51,7 @@ * then indexOffset must be specified to be equal to -1. * * @author Radoslaw Szymanek, Krzysztof Kuchcinski and Robert Åkemalm - * @version 4.3 + * @version 4.4 */ public class ElementSet extends Constraint { @@ -203,14 +203,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 impose(Store store) { index.putModelConstraint(this,getConsistencyPruningEvent(index)); diff --git a/src/main/java/org/jacop/set/constraints/Lex.java b/src/main/java/org/jacop/set/constraints/Lex.java index fa01ac8fb..ded68a2e7 100644 --- a/src/main/java/org/jacop/set/constraints/Lex.java +++ b/src/main/java/org/jacop/set/constraints/Lex.java @@ -48,13 +48,13 @@ * set variables is being constrained to be lexicographically ordered. * * For example, - * {} type of variable being used in search. */ diff --git a/src/main/java/org/jacop/set/search/IndomainSetMin.java b/src/main/java/org/jacop/set/search/IndomainSetMin.java index e52bf09a3..c9c698d69 100644 --- a/src/main/java/org/jacop/set/search/IndomainSetMin.java +++ b/src/main/java/org/jacop/set/search/IndomainSetMin.java @@ -39,7 +39,7 @@ * minimal value in the domain of variable * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of variable being used in search. */ diff --git a/src/main/java/org/jacop/set/search/IndomainSetRandom.java b/src/main/java/org/jacop/set/search/IndomainSetRandom.java index faf997307..69432ce7a 100644 --- a/src/main/java/org/jacop/set/search/IndomainSetRandom.java +++ b/src/main/java/org/jacop/set/search/IndomainSetRandom.java @@ -42,7 +42,7 @@ * maximal value in the domain of variable * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 * @param type of variable being used in search. */ @@ -59,7 +59,7 @@ public IndomainSetRandom() { /** * It creates random indomain heuristic according to the provided random * generator. - * @param seed + * @param seed seed for random number genrator */ public IndomainSetRandom(Random seed) { this.seed = seed; diff --git a/src/main/java/org/jacop/set/search/MaxCardDiff.java b/src/main/java/org/jacop/set/search/MaxCardDiff.java index 7611d9618..daad69073 100644 --- a/src/main/java/org/jacop/set/search/MaxCardDiff.java +++ b/src/main/java/org/jacop/set/search/MaxCardDiff.java @@ -40,7 +40,7 @@ * difference in cardinality between the greatest lower bound and the least upper bound has the priority. * * @author Krzysztof Kuchcinski and Robert Åkemalm - * @version 4.3 + * @version 4.4 * @param type of variable being used in search. */ diff --git a/src/main/java/org/jacop/set/search/MaxGlbCard.java b/src/main/java/org/jacop/set/search/MaxGlbCard.java index a0f192d92..8a5b3b4a5 100644 --- a/src/main/java/org/jacop/set/search/MaxGlbCard.java +++ b/src/main/java/org/jacop/set/search/MaxGlbCard.java @@ -39,7 +39,7 @@ * cardinality for the greatest lower bound has the priority. * * @author Krzysztof Kuchcinski, Robert Åkemalm, 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/set/search/MaxLubCard.java b/src/main/java/org/jacop/set/search/MaxLubCard.java index 079232c3a..b749c3fe9 100644 --- a/src/main/java/org/jacop/set/search/MaxLubCard.java +++ b/src/main/java/org/jacop/set/search/MaxLubCard.java @@ -39,9 +39,9 @@ * Defines a maximum cardinality, of the least upper bound, variable comparator. The variable with the maximum * cardinality for the least upper bound has the priority. * - * @author Krzysztof Kuchcinski and Robert Åkemalm - * @version 4.3 - * @param + * @author Krzysztof Kuchcinski and Robert Åkemalm + * @version 4.4 + * @param type of variable */ public class MaxLubCard implements ComparatorVariable { diff --git a/src/main/java/org/jacop/set/search/MinCardDiff.java b/src/main/java/org/jacop/set/search/MinCardDiff.java index f7f5e6c3d..9c30285fe 100644 --- a/src/main/java/org/jacop/set/search/MinCardDiff.java +++ b/src/main/java/org/jacop/set/search/MinCardDiff.java @@ -40,7 +40,7 @@ * difference in cardinality between the greatest lower bound and the least upper bound has the priority. * * @author Krzysztof Kuchcinski and Robert Åkemalm - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ diff --git a/src/main/java/org/jacop/set/search/MinGlbCard.java b/src/main/java/org/jacop/set/search/MinGlbCard.java index eb578e6a5..d17374c67 100644 --- a/src/main/java/org/jacop/set/search/MinGlbCard.java +++ b/src/main/java/org/jacop/set/search/MinGlbCard.java @@ -40,8 +40,8 @@ * cardinality for the greatest lower bound has the priority. * * @author Krzysztof Kuchcinski and Robert Åkemalm - * @version 4.3 - * @param + * @version 4.4 + * @param type of variable */ public class MinGlbCard implements ComparatorVariable { diff --git a/src/main/java/org/jacop/set/search/MinLubCard.java b/src/main/java/org/jacop/set/search/MinLubCard.java index 3bd2991ff..eecbfffb0 100644 --- a/src/main/java/org/jacop/set/search/MinLubCard.java +++ b/src/main/java/org/jacop/set/search/MinLubCard.java @@ -40,7 +40,7 @@ * cardinality for the least upper bound has the priority. * * @author Krzysztof Kuchcinski and Robert Åkemalm - * @version 4.3 + * @version 4.4 * @param type of variable being used in the search. */ diff --git a/src/main/java/org/jacop/ui/PrintSchedule.java b/src/main/java/org/jacop/ui/PrintSchedule.java index c2a780dd2..f4eafc6f9 100644 --- a/src/main/java/org/jacop/ui/PrintSchedule.java +++ b/src/main/java/org/jacop/ui/PrintSchedule.java @@ -42,7 +42,7 @@ * Prints the computed schedule * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ public class PrintSchedule { diff --git a/src/main/java/org/jacop/util/IndexDomainView.java b/src/main/java/org/jacop/util/IndexDomainView.java index c7c305241..9fb33b975 100644 --- a/src/main/java/org/jacop/util/IndexDomainView.java +++ b/src/main/java/org/jacop/util/IndexDomainView.java @@ -41,7 +41,7 @@ * Defines index domain view for a variable and related operations on it. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class IndexDomainView { @@ -156,7 +156,7 @@ public void intializeSupportSweep() { /** * It removes all values for which no support was found since the initialization of * the support sweep. - * @param store + * @param store current store */ public void removeUnSupportedValues(Store store) { diff --git a/src/main/java/org/jacop/util/MDD.java b/src/main/java/org/jacop/util/MDD.java index 9b1a78bcc..0f509871a 100644 --- a/src/main/java/org/jacop/util/MDD.java +++ b/src/main/java/org/jacop/util/MDD.java @@ -45,7 +45,7 @@ * on ad-hoc n-ary constraints.", CP 2008. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class MDD { diff --git a/src/main/java/org/jacop/util/Matrix.java b/src/main/java/org/jacop/util/Matrix.java index eb6f15be3..51cca8e05 100644 --- a/src/main/java/org/jacop/util/Matrix.java +++ b/src/main/java/org/jacop/util/Matrix.java @@ -41,7 +41,7 @@ * Matrix and operations on matrices. * * @author Krzysztof Kuchcinski and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ public class Matrix { diff --git a/src/main/java/org/jacop/util/SimpleArrayList.java b/src/main/java/org/jacop/util/SimpleArrayList.java index d1e6e50d4..5c2ca3d08 100644 --- a/src/main/java/org/jacop/util/SimpleArrayList.java +++ b/src/main/java/org/jacop/util/SimpleArrayList.java @@ -40,7 +40,7 @@ * tailored for JaCoP. Use with care, check when it uses == instead of equals(). * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param the type which is being stored by this class. */ diff --git a/src/main/java/org/jacop/util/SimpleHashSet.java b/src/main/java/org/jacop/util/SimpleHashSet.java index 9a85084d3..cac947249 100644 --- a/src/main/java/org/jacop/util/SimpleHashSet.java +++ b/src/main/java/org/jacop/util/SimpleHashSet.java @@ -40,7 +40,7 @@ * util class. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 * @param Class being stored in SimpleHashSet. */ diff --git a/src/main/java/org/jacop/util/SparseSet.java b/src/main/java/org/jacop/util/SparseSet.java index 660223870..51980976c 100644 --- a/src/main/java/org/jacop/util/SparseSet.java +++ b/src/main/java/org/jacop/util/SparseSet.java @@ -35,7 +35,7 @@ * Sparse set representation of the set. * * @author Radoslaw Szymanek and Krzysztof Kuchcinski - * @version 4.3 + * @version 4.4 */ public class SparseSet { @@ -61,7 +61,7 @@ public class SparseSet { /** * It creates a SparseSet with given upper limit on the value * of the biggest element in the set. - * @param size + * @param size the upper limit for the SparseSet */ public SparseSet(int size) { diff --git a/src/main/java/org/jacop/util/fsm/FSM.java b/src/main/java/org/jacop/util/fsm/FSM.java index 5add03df3..52006b594 100644 --- a/src/main/java/org/jacop/util/fsm/FSM.java +++ b/src/main/java/org/jacop/util/fsm/FSM.java @@ -45,7 +45,7 @@ * Deterministic Finite Acyclic graph. * * @author Polina Makeeva and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ public class FSM { diff --git a/src/main/java/org/jacop/util/fsm/FSMState.java b/src/main/java/org/jacop/util/fsm/FSMState.java index 14a0c54e3..5c8030707 100644 --- a/src/main/java/org/jacop/util/fsm/FSMState.java +++ b/src/main/java/org/jacop/util/fsm/FSMState.java @@ -35,7 +35,7 @@ /** * @author Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ public class FSMState { @@ -60,7 +60,7 @@ public class FSMState { * It constructs a FSM state. * * @param transitions it specifies transition - * @param id + * @param id state id */ public FSMState(HashSet transitions, int id) { this.transitions = transitions; diff --git a/src/main/java/org/jacop/util/fsm/FSMTransition.java b/src/main/java/org/jacop/util/fsm/FSMTransition.java index e37ec3b94..398b5d39c 100644 --- a/src/main/java/org/jacop/util/fsm/FSMTransition.java +++ b/src/main/java/org/jacop/util/fsm/FSMTransition.java @@ -37,7 +37,7 @@ /** * @author Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ public class FSMTransition { diff --git a/src/main/java/org/jacop/util/fsm/LexicalAnalyzer.java b/src/main/java/org/jacop/util/fsm/LexicalAnalyzer.java index 8fad68f5d..d4eaf6da9 100644 --- a/src/main/java/org/jacop/util/fsm/LexicalAnalyzer.java +++ b/src/main/java/org/jacop/util/fsm/LexicalAnalyzer.java @@ -37,7 +37,7 @@ /** * @author Polina Maakeva and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ class LexicalAnalyzer { diff --git a/src/main/java/org/jacop/util/fsm/RegularExpressionParser.java b/src/main/java/org/jacop/util/fsm/RegularExpressionParser.java index 5eaab9e91..248834b1b 100644 --- a/src/main/java/org/jacop/util/fsm/RegularExpressionParser.java +++ b/src/main/java/org/jacop/util/fsm/RegularExpressionParser.java @@ -42,7 +42,7 @@ * Instances of this class parse the word combination little language. * * @author Polina Makeeva and Radoslaw Szymanek - * @version 4.3 + * @version 4.4 */ public class RegularExpressionParser { @@ -74,7 +74,7 @@ public RegularExpressionParser(StringReader input) throws SyntaxException { * @param parseOneNext if parsing should parse only one item. * * @return An expression that is the root of the parse tree produced by the parser. - * @throws SyntaxException + * @throws SyntaxException execption rised when syntax is not followed */ public Expression parse(boolean parseOneNext) throws SyntaxException { @@ -260,7 +260,7 @@ public SyntaxException() { /** * The constructor to create an syntax exception with a given message. - * @param msg + * @param msg message for the syntax exception */ public SyntaxException(final String msg) { super(msg); @@ -283,12 +283,12 @@ public abstract class Expression { * string does not contain the words that this Expression object * requires, then this method returns null. * - * @param set - * The string that this method will search for the words it - * requires. */ - abstract int getType(); + /** + * @return type + */ + abstract int getType(); /** * It specifies if the expression is simple. diff --git a/src/main/jjtree/org/jacop/fz/Parser.jjt b/src/main/jjtree/org/jacop/fz/Parser.jjt index 1080c9a8c..638984668 100644 --- a/src/main/jjtree/org/jacop/fz/Parser.jjt +++ b/src/main/jjtree/org/jacop/fz/Parser.jjt @@ -56,7 +56,7 @@ public class Parser { Store store = new Store(); Tables dict = new Tables(store); VariablesParameters cg = new VariablesParameters(); - Constraints cc = new Constraints(store); + Constraints cc = new Constraints(store, dict); Solve solver = new Solve(store, cc.sat); Options options; @@ -199,7 +199,16 @@ void model() #model: constraint_items() model_end() -// {jjtThis.dump("");} + {//jjtThis.dump(""); + // print debug information + // if (options.debug()) + // System.out.println(dict); + + // generate constraints + cc.generateAllConstraints(jjtThis, options); + // search + solver.solveModel(jjtThis, dict, options); + } } // pred_decl_items : pred_decl_items pred_decl_item ';' @@ -220,7 +229,7 @@ void var_decl_items() #VarDeclItems: { ( var_decl_item() )* { //jjtThis.dump(""); - jjtThis.removeChildren(); + // jjtThis.removeChildren(); solver.setNumberBoolVariables(cg.numberBooleanVariables); } // { System.out.println(dict); } @@ -235,9 +244,9 @@ void constraint_items() #ConstraintItems: ( constraint_item() )* { //jjtThis.dump(""); - cc.poseDelayedConstraints(); + // cc.poseDelayedConstraints(); - jjtThis.removeChildren(); + // jjtThis.removeChildren(); } } @@ -281,20 +290,20 @@ void var_decl_item() #VarDeclItem: { jjtThis.setKind(0); jjtThis.setId(t.image); cg.generateVariables(jjtThis, dict, store); - jjtThis.removeChildren(); + // jjtThis.removeChildren(); } | non_array_ti_expr_tail() t=ident_anns() non_array_flat_expr() { jjtThis.setKind(1); jjtThis.setId(t.image); cg.generateParameters(jjtThis, dict); - jjtThis.removeChildren(); + // jjtThis.removeChildren(); } | t1= t2= array_decl_tail(jjtThis) { jjtThis.setIndexes(Integer.parseInt(t1.image), Integer.parseInt(t2.image)); cg.generateArray(jjtThis, dict, store); - jjtThis.removeChildren(); + // jjtThis.removeChildren(); } } @@ -355,8 +364,8 @@ void constraint_item() #Constraint: { constraint_elem() annotations() { // jjtThis.dump(""); - cc.generateConstraints(jjtThis, dict, options); - jjtThis.removeChildren(); + cc.generateAlias(jjtThis); + // jjtThis.removeChildren(); } } @@ -391,7 +400,7 @@ void solve_item() #SolveItem: { annotations() solve_kind() { - solver.search(jjtThis, dict, options); + // solver.search(jjtThis, dict, options); } } diff --git a/src/main/minizinc/org/jacop/minizinc/all_different_int.mzn b/src/main/minizinc/org/jacop/minizinc/all_different_int.mzn index 631c79dc9..6e4912373 100644 --- a/src/main/minizinc/org/jacop/minizinc/all_different_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/all_different_int.mzn @@ -8,3 +8,6 @@ predicate all_different_int(array[int] of var int: x) = predicate jacop_alldiff(array[int] of var int: x); + +% predicate jacop_alldiff_reif(array[int] of var int: x, var bool: n) = +% abort("Reified all_different/1 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/all_distinct.mzn b/src/main/minizinc/org/jacop/minizinc/all_distinct.mzn index 5e3e68ab6..71ccb173e 100644 --- a/src/main/minizinc/org/jacop/minizinc/all_distinct.mzn +++ b/src/main/minizinc/org/jacop/minizinc/all_distinct.mzn @@ -8,3 +8,6 @@ predicate all_distinct(array[int] of var int: x) = predicate jacop_alldistinct(array[int] of var int: x); + +% predicate jacop_alldistinct_reif(array[int] of var int: x, var bool: n) = +% abort("Reified all_distinct/1 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/among.mzn b/src/main/minizinc/org/jacop/minizinc/among.mzn index e1d39b2fc..b5f71dee2 100644 --- a/src/main/minizinc/org/jacop/minizinc/among.mzn +++ b/src/main/minizinc/org/jacop/minizinc/among.mzn @@ -4,4 +4,20 @@ predicate among(var int: n, array[int] of var int: x, set of int: v) = jacop_among(x, v, n); -predicate jacop_among(array[int] of var int: x, set of int: v, var int: n); \ No newline at end of file +predicate jacop_among(array[int] of var int: x, set of int: v, var int: n); + +%-----------------------------------------------------------------------------% +% Reified version of among_var. +%-----------------------------------------------------------------------------% +predicate among_reif(var int: n, array[int] of var int: x, set of int: v, var bool: b) = + let { + int: l = min(index_set(x)), + int: u = max(index_set(x)), + int: mm = u - l + 1, + var 0..mm: ni + } + in + jacop_among(x, v, ni) + /\ + (b <-> ni = n) +; diff --git a/src/main/minizinc/org/jacop/minizinc/arg_max_int.mzn b/src/main/minizinc/org/jacop/minizinc/arg_max_int.mzn index b88a7e4f4..5e38d04c6 100644 --- a/src/main/minizinc/org/jacop/minizinc/arg_max_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/arg_max_int.mzn @@ -2,3 +2,7 @@ predicate maximum_arg_int(array[int] of var int: x, var int: i) = jacop_maximum_arg_int(x,i); predicate jacop_maximum_arg_int(array[int] of var int: x, var int: i); + +% predicate jacop_maximum_arg_int_reif(array[int] of var int: x, var int: i, var bool: b) = +% abort("Reified maximum_arg/2 is not supported."); + diff --git a/src/main/minizinc/org/jacop/minizinc/arg_min_int.mzn b/src/main/minizinc/org/jacop/minizinc/arg_min_int.mzn index 585b444da..89b4404fc 100644 --- a/src/main/minizinc/org/jacop/minizinc/arg_min_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/arg_min_int.mzn @@ -2,3 +2,6 @@ predicate minimum_arg_int(array[int] of var int: x, var int: i) = jacop_minimum_arg_int(x,i); predicate jacop_minimum_arg_int(array[int] of var int: x, var int: i); + +% predicate jacop_minimum_arg_int_reif(array[int] of var int: x, var int: i, var bool: b) = +% abort("Reified minimum_arg/2 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/at_least_int.mzn b/src/main/minizinc/org/jacop/minizinc/at_least_int.mzn index 176fbb5c2..2aef97687 100644 --- a/src/main/minizinc/org/jacop/minizinc/at_least_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/at_least_int.mzn @@ -1,16 +1,32 @@ %-----------------------------------------------------------------------------% % Requires at least 'n' variables in 'x' to take the value 'v'. %-----------------------------------------------------------------------------% -include "among.mzn"; +% include "among.mzn"; +include "count.mzn"; predicate at_least_int(int: n, array[int] of var int: x, int: v) = + % let { + % int: max_n = max(index_set(x)), + % var n..max_n: var_n, + % set of int: set_v={v} + % } + % in + % among(var_n, x, set_v); let { int: max_n = max(index_set(x)), - var n..max_n: var_n, - set of int: set_v={v} + var n..max_n: var_n } in - among(var_n, x, set_v); + count(x, v, var_n); % sum(i in index_set(x)) ( bool2int(x[i] == v) ) >= n; +predicate at_least_int_reif(int: n, array[int] of var int: x, int: v, var bool: b) = + let { + int: max_n = max(index_set(x)), + var 0..max_n: var_n + } + in + count(x, v, var_n) + /\ + (n <= var_n) <-> b; diff --git a/src/main/minizinc/org/jacop/minizinc/at_most_int.mzn b/src/main/minizinc/org/jacop/minizinc/at_most_int.mzn index aa795dc36..d0c669676 100644 --- a/src/main/minizinc/org/jacop/minizinc/at_most_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/at_most_int.mzn @@ -1,15 +1,30 @@ %-----------------------------------------------------------------------------% % Requires at most 'n' variables in 'x' to take the value 'v'. %-----------------------------------------------------------------------------% -include "among.mzn"; +% include "among.mzn"; +include "count.mzn"; predicate at_most_int(int: n, array[int] of var int: x, int: v) = + % let { + % var 0..n: var_n, + % set of int: set_v={v} + % } + % in + % among(var_n, x, set_v); let { var 0..n: var_n, - set of int: set_v={v} } in - among(var_n, x, set_v); + count(x, v, var_n); % sum(i in index_set(x)) ( bool2int(x[i] == v) ) <= n; +predicate at_most_int_reif(int: n, array[int] of var int: x, int: v, var bool: b) = + let { + int: max_n = max(index_set(x)), + var 0..max_n: var_n + } + in + count(x, v, var_n) + /\ + (n >= var_n) <-> b; diff --git a/src/main/minizinc/org/jacop/minizinc/bin_packing.mzn b/src/main/minizinc/org/jacop/minizinc/bin_packing.mzn index 1ab7ba559..4ded577d8 100644 --- a/src/main/minizinc/org/jacop/minizinc/bin_packing.mzn +++ b/src/main/minizinc/org/jacop/minizinc/bin_packing.mzn @@ -19,7 +19,10 @@ predicate bin_packing(int: c, array[cap_index] of var 0..c: cap } in - jacop_bin_packing(bin, cap, w) + jacop_bin_packing(bin, cap, w, lb_array(bin)) )); -predicate jacop_bin_packing(array[int] of var int: bin, array[int] of var int: cap, array[int] of int: w); \ No newline at end of file +predicate jacop_bin_packing(array[int] of var int: bin, array[int] of var int: cap, array[int] of int: w, int: min_bin); + +% predicate jacop_bin_packing_reif(array[int] of var int: bin, array[int] of var int: cap, array[int] of int: w, int: min_bin, var bool: b) = +% abort("Reified bin_packing/3 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/bin_packing_capa.mzn b/src/main/minizinc/org/jacop/minizinc/bin_packing_capa.mzn index 2ac977986..080a4a96c 100644 --- a/src/main/minizinc/org/jacop/minizinc/bin_packing_capa.mzn +++ b/src/main/minizinc/org/jacop/minizinc/bin_packing_capa.mzn @@ -25,7 +25,7 @@ predicate bin_packing_capa(array[int] of int: c, } in forall (i in index_set(c) ) ( cap[i] <= c[i]) /\ - jacop_bin_packing(bin, cap, w) + jacop_bin_packing(bin, cap, w, lb_array(bin)) ))); %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/bin_packing_load.mzn b/src/main/minizinc/org/jacop/minizinc/bin_packing_load.mzn index 485284e9a..902e66ee1 100644 --- a/src/main/minizinc/org/jacop/minizinc/bin_packing_load.mzn +++ b/src/main/minizinc/org/jacop/minizinc/bin_packing_load.mzn @@ -15,7 +15,7 @@ predicate bin_packing_load(array[int] of var int: load, "bin_packing_load: the bin and weight arrays must have identical index sets", assert(lb_array(w) >= 0, "bin_packing_load: the weights must be non-negative", - jacop_bin_packing(bin, load, w) + jacop_bin_packing(bin, load, w, lb_array(bin)) )); %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/circuit.mzn b/src/main/minizinc/org/jacop/minizinc/circuit.mzn index 6844a2457..69e60faf1 100644 --- a/src/main/minizinc/org/jacop/minizinc/circuit.mzn +++ b/src/main/minizinc/org/jacop/minizinc/circuit.mzn @@ -3,6 +3,13 @@ that \p j is the successor of \p i. */ predicate circuit(array[int] of var int: x) = - jacop_circuit(x); + if min(index_set(x)) = 1 then + jacop_circuit(x) + else + jacop_circuit([x[i] - min(index_set(x)) + 1 | i in index_set(x)]) + endif; + +predicate jacop_circuit(array[int] of var int: x); -predicate jacop_circuit(array[int] of var int: x) +% predicate jacop_circuit_reif(array[int] of var int: x, var bool: b) = +% abort("Reified circuit/1 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/count.mzn b/src/main/minizinc/org/jacop/minizinc/count.mzn index 8799a2b7a..c9b69a89a 100644 --- a/src/main/minizinc/org/jacop/minizinc/count.mzn +++ b/src/main/minizinc/org/jacop/minizinc/count.mzn @@ -12,7 +12,7 @@ predicate count(array[int] of var int: x, int: y, var int: c) = %-----------------------------------------------------------------------------% % Reified version of count. %-----------------------------------------------------------------------------% -predicate count_reif(array[int] of var int: x, int: y, var int: c, var bool: b) = +predicate jacop_count_reif(array[int] of var int: x, int: y, var int: c, var bool: b) = let { int: l = min(index_set(x)), int: u = max(index_set(x)), @@ -28,4 +28,3 @@ predicate count_reif(array[int] of var int: x, int: y, var int: c, var bool: b) %-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------% - diff --git a/src/main/minizinc/org/jacop/minizinc/cumulative.mzn b/src/main/minizinc/org/jacop/minizinc/cumulative.mzn index 982f85d1a..a80b1508d 100644 --- a/src/main/minizinc/org/jacop/minizinc/cumulative.mzn +++ b/src/main/minizinc/org/jacop/minizinc/cumulative.mzn @@ -19,4 +19,9 @@ predicate cumulative(array[int] of var int: s, predicate jacop_cumulative(array[int] of var int: s, array[int] of var int: d, - array[int] of var int: r, var int: b); \ No newline at end of file + array[int] of var int: r, var int: b); + +% predicate jacop_cumulative_reif(array[int] of var int: s, +% array[int] of var int: d, +% array[int] of var int: r, var int: b, var bool: b_reif) = +% abort("Reified cumulative/4 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/diff2.mzn b/src/main/minizinc/org/jacop/minizinc/diff2.mzn index fc63efcda..98fea1174 100644 --- a/src/main/minizinc/org/jacop/minizinc/diff2.mzn +++ b/src/main/minizinc/org/jacop/minizinc/diff2.mzn @@ -23,4 +23,12 @@ predicate diff2(array[int] of var int: x, array[int] of var int: y, predicate jacop_diff2(array[int,int] of var int: r); predicate jacop_list_diff2(array[int] of var int: x, array[int] of var int: y, - array[int] of var int: lx, array[int] of var int: ly); \ No newline at end of file + array[int] of var int: lx, array[int] of var int: ly); + +% predicate jacop_list_diff2_reif(array[int] of var int: x, array[int] of var int: y, +% array[int] of var int: lx, array[int] of var int: ly, var bool: b) = +% abort("Reified diff2/4 is not supported."); + +% predicate jacop_diff2_reif(array[int,int] of var int: r, var bool: b) = +% abort("Reified diff2/1 is not supported."); + diff --git a/src/main/minizinc/org/jacop/minizinc/diffn.mzn b/src/main/minizinc/org/jacop/minizinc/diffn.mzn index c1ac0cc86..7645cca25 100644 --- a/src/main/minizinc/org/jacop/minizinc/diffn.mzn +++ b/src/main/minizinc/org/jacop/minizinc/diffn.mzn @@ -23,3 +23,7 @@ predicate diffn(array[int] of var int: x, predicate jacop_diff2_strict(array[int] of var int: x, array[int] of var int: y, array[int] of var int: lx, array[int] of var int: ly); + +% predicate jacop_diff2_strict_reif(array[int] of var int: x, array[int] of var int: y, +% array[int] of var int: lx, array[int] of var int: ly, var bool: b) = +% abort("Reified diffn/1 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/exactly_int.mzn b/src/main/minizinc/org/jacop/minizinc/exactly_int.mzn index 1137d0483..9733ae4b2 100644 --- a/src/main/minizinc/org/jacop/minizinc/exactly_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/exactly_int.mzn @@ -3,11 +3,12 @@ %-----------------------------------------------------------------------------% predicate exactly_int(int: n, array[int] of var int: x, int: v) = - let { - set of int: set_v={v} - } - in - among(n, x, set_v); + % let { + % set of int: set_v={v} + % } + % in + % among(n, x, set_v); + count(x, v, n); % n == sum(i in index_set(x)) ( bool2int(x[i] == v) ); diff --git a/src/main/minizinc/org/jacop/minizinc/geost.mzn b/src/main/minizinc/org/jacop/minizinc/geost.mzn index b610b7aec..5684c5a61 100644 --- a/src/main/minizinc/org/jacop/minizinc/geost.mzn +++ b/src/main/minizinc/org/jacop/minizinc/geost.mzn @@ -120,6 +120,18 @@ predicate jacop_geost( array[int ] of var int : kind ); +% predicate jacop_geost_reif( +% int : k , +% array[int,int] of int : rect_size , +% array[int,int] of int : rect_offset , +% array[int ] of set of int : shape , +% array[int,int] of var int : x , +% array[int ] of var int : kind , +% var bool : b +% ) = +% abort("Reified geost/6 is not supported."); + + predicate geost_bb( int : k , @@ -157,6 +169,19 @@ predicate jacop_geost_bb( ); +% predicate jacop_geost_bb_reif( +% int : k , +% array[int,int] of int : rect_size , +% array[int,int] of int : rect_offset , +% array[int ] of set of int : shape , +% array[int,int] of var int : x , +% array[int ] of var int : kind , +% array[int ] of int : l , +% array[int ] of int : u , +% var bool : b +% ) = +% abort("Reified geost_bb/8 is not supported."); + predicate geost_nonoverlap_k( array[int] of var int : x1, diff --git a/src/main/minizinc/org/jacop/minizinc/global_cardinality_closed.mzn b/src/main/minizinc/org/jacop/minizinc/global_cardinality_closed.mzn index 38b1bf11c..b6bb0e3ac 100644 --- a/src/main/minizinc/org/jacop/minizinc/global_cardinality_closed.mzn +++ b/src/main/minizinc/org/jacop/minizinc/global_cardinality_closed.mzn @@ -18,7 +18,13 @@ predicate global_cardinality_closed(array[int] of var int: x, predicate jacop_global_cardinality_closed(array[int] of var int: x, array[int] of int: cover, - array[int] of var int: counts) + array[int] of var int: counts); + + +% predicate jacop_global_cardinality_closed_reif(array[int] of var int: x, +% array[int] of int: cover, +% array[int] of var int: counts, var bool: b) = +% abort("Reified global_cardinality_closed/3 is not supported."); %-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/global_cardinality_low_up_closed.mzn b/src/main/minizinc/org/jacop/minizinc/global_cardinality_low_up_closed.mzn index 90199d8eb..73e07e44e 100644 --- a/src/main/minizinc/org/jacop/minizinc/global_cardinality_low_up_closed.mzn +++ b/src/main/minizinc/org/jacop/minizinc/global_cardinality_low_up_closed.mzn @@ -22,5 +22,11 @@ predicate jacop_global_cardinality_low_up_closed(array[int] of var int: x, array[int] of int: lbound, array[int] of int: ubound); +% predicate jacop_global_cardinality_low_up_closed_reif(array[int] of var int: x, +% array[int] of int: cover, +% array[int] of int: lbound, +% array[int] of int: ubound, var bool: b) = +% abort("Reified global_cardinality_low_up_closed/4 is not supported."); + %-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/inverse.mzn b/src/main/minizinc/org/jacop/minizinc/inverse.mzn index 0d70ade53..445cd748e 100644 --- a/src/main/minizinc/org/jacop/minizinc/inverse.mzn +++ b/src/main/minizinc/org/jacop/minizinc/inverse.mzn @@ -17,11 +17,9 @@ predicate jacop_assignment(array[int] of var int: f, array[int] of var int: invf, int: index_f, int: index_invf); -/** @group globals.channeling - Given a function \a f represented as an array, return the inverse function. -*/ -function array[int] of var int: inverse(array[int] of var int: f) = - let { - array[lb_array(f)..ub_array(f)] of var index_set(f): invf; - constraint inverse(f,invf); - } in f; +% predicate jacop_assignment_reif(array[int] of var int: f, +% array[int] of var int: invf, +% int: index_f, int: index_invf, var bool: b) = +% abort("Reified inverse/2 is not supported."); + + diff --git a/src/main/minizinc/org/jacop/minizinc/jacop.mzn b/src/main/minizinc/org/jacop/minizinc/jacop.mzn index 635ea8609..99ce48d08 100644 --- a/src/main/minizinc/org/jacop/minizinc/jacop.mzn +++ b/src/main/minizinc/org/jacop/minizinc/jacop.mzn @@ -1,6 +1,10 @@ %% ===== JaCoP specific search annotations ===== annotation weighted_degree; +annotation lds(int: d); +annotation credit(int: c, ann: b); +annotation bbs(int: b); + %% ===== JaCoP specific global constraints ===== include "all_distinct.mzn"; include "among_var.mzn"; diff --git a/src/main/minizinc/org/jacop/minizinc/knapsack.mzn b/src/main/minizinc/org/jacop/minizinc/knapsack.mzn index 1045e1bb9..b625f12a3 100644 --- a/src/main/minizinc/org/jacop/minizinc/knapsack.mzn +++ b/src/main/minizinc/org/jacop/minizinc/knapsack.mzn @@ -24,8 +24,13 @@ predicate knapsack(array[int] of int: w, array[int] of int:p, } in jacop_knapsack([w[i] | i in index_set(w) where w[i] > 0], [p[i] | i in index_set(p) where w[i] > 0], W, profit, [x[i] | i in index_set(x) where w[i] > 0]) /\ - P = profit + sum( i in index_set(p)) (p[i]*x[i]*bool2int(w[i]=0)) + P = profit + sum( i in index_set(p) where w[i]=0) (p[i]*x[i]) ))); predicate jacop_knapsack(array[int] of int:w, array[int] of int:p, var int: W, var int: P, array[int] of var int:x); + +% predicate jacop_knapsack_reif(array[int] of int:w, array[int] of int:p, +% var int: W, var int: P, array[int] of var int:x, var bool: b) = +% abort("Reified knapsack/5 is not supported."); + diff --git a/src/main/minizinc/org/jacop/minizinc/lex_less_bool.mzn b/src/main/minizinc/org/jacop/minizinc/lex_less_bool.mzn index a181f5bea..17d9426ba 100644 --- a/src/main/minizinc/org/jacop/minizinc/lex_less_bool.mzn +++ b/src/main/minizinc/org/jacop/minizinc/lex_less_bool.mzn @@ -32,4 +32,8 @@ predicate lex_lt_bool(array[int] of var bool: x, array[int] of var bool: y) = lex_less(x, y); +% predicate jacop_lex_less_bool_reif(array[int] of var bool: x, +% array[int] of var bool: y, var bool: b) = +% abort("Reified lex_less/2 is not supported."); + %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/lex_less_int.mzn b/src/main/minizinc/org/jacop/minizinc/lex_less_int.mzn index 8abe69fa0..7ec4c3250 100644 --- a/src/main/minizinc/org/jacop/minizinc/lex_less_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/lex_less_int.mzn @@ -31,4 +31,9 @@ predicate lex_lt_int(array[int] of var int: x, array[int] of var int: y) = lex_less(x, y); +% predicate jacop_lex_less_int_reif(array[int] of var int: x, +% array[int] of var int: y, var bool: b) = +% abort("Reified lex_less/2 is not supported."); + + %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/lex_lesseq_bool.mzn b/src/main/minizinc/org/jacop/minizinc/lex_lesseq_bool.mzn index 7217d3fee..04b56f9d6 100644 --- a/src/main/minizinc/org/jacop/minizinc/lex_lesseq_bool.mzn +++ b/src/main/minizinc/org/jacop/minizinc/lex_lesseq_bool.mzn @@ -32,4 +32,8 @@ predicate lex_leq_bool(array[int] of var bool: x, array[int] of var bool: y) = lex_lesseq(x, y); +% predicate jacop_lex_lesseq_bool_reif(array[int] of var bool: x, +% array[int] of var bool: y, var bool: b) = +% abort("Reified lex_lesseq/2 is not supported."); + %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/lex_lesseq_int.mzn b/src/main/minizinc/org/jacop/minizinc/lex_lesseq_int.mzn index d78ed48c4..ec9bd0ecf 100644 --- a/src/main/minizinc/org/jacop/minizinc/lex_lesseq_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/lex_lesseq_int.mzn @@ -32,4 +32,8 @@ predicate lex_leq_int(array[int] of var int: x, array[int] of var int: y) = lex_lesseq(x, y); +% predicate jacop_lex_lesseq_int_reif(array[int] of var int: x, +% array[int] of var int: y, var bool: b) = +% abort("Reified lex_lesseq/2 is not supported."); + %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/network_flow.mzn b/src/main/minizinc/org/jacop/minizinc/network_flow.mzn index 669c682db..d1c04b079 100644 --- a/src/main/minizinc/org/jacop/minizinc/network_flow.mzn +++ b/src/main/minizinc/org/jacop/minizinc/network_flow.mzn @@ -61,3 +61,9 @@ predicate network_flow_cost(array[int,1..2] of int: arc, predicate jacop_networkflow(array[int, int] of int: arc, array[int] of var int: flow, array[int] of var int: weight, array[int] of int: balance, var int: cost); + +% predicate jacop_networkflow_reif(array[int, int] of int: arc, +% array[int] of var int: flow, array[int] of var int: weight, +% array[int] of int: balance, var int: cost, var bool: b) = +% abort("Reified networkflow/3 and networkflow_cost/5 are not supported."); + diff --git a/src/main/minizinc/org/jacop/minizinc/nvalue.mzn b/src/main/minizinc/org/jacop/minizinc/nvalue.mzn index 790c57d79..ac6e6408b 100644 --- a/src/main/minizinc/org/jacop/minizinc/nvalue.mzn +++ b/src/main/minizinc/org/jacop/minizinc/nvalue.mzn @@ -5,3 +5,12 @@ predicate nvalue(var int: n, array[int] of var int: x) = jacop_nvalue(n, x); predicate jacop_nvalue(var int: n, array[int] of var int: x); + +predicate jacop_nvalue_reif(var int: n, array[int] of var int: x, var bool: b) = + let { + var 1..card(index_set(x)): t, + } in + jacop_nvalue(t, x) + /\ + (b <-> n = t) + ; diff --git a/src/main/minizinc/org/jacop/minizinc/regular.mzn b/src/main/minizinc/org/jacop/minizinc/regular.mzn index 939e6c971..f0bb8e810 100644 --- a/src/main/minizinc/org/jacop/minizinc/regular.mzn +++ b/src/main/minizinc/org/jacop/minizinc/regular.mzn @@ -33,3 +33,7 @@ predicate regular(array[int] of var int: x, int: Q, int: S, predicate jacop_regular(array[int] of var int: x, int: Q, int: S, array[int, int] of int: d, int: q0, set of int: F, int: min_index); + +% predicate jacop_regular_reif(array[int] of var int: x, int: Q, int: S, +% array[int, int] of int: d, int: q0, set of int: F, int: min_index, var bool: b) = +% abort("Reified regular/6 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/stretch.mzn b/src/main/minizinc/org/jacop/minizinc/stretch.mzn index 57ae4e5f5..52cb57218 100644 --- a/src/main/minizinc/org/jacop/minizinc/stretch.mzn +++ b/src/main/minizinc/org/jacop/minizinc/stretch.mzn @@ -11,4 +11,8 @@ predicate stretch(array[int] of int: values, array[int] of int: min_v, array[int jacop_stretch(values, min_v, max_v, x); predicate jacop_stretch(array[int] of int: values, array[int] of int: min_v, array[int] of int: max_v, - array[int] of var int: x); \ No newline at end of file + array[int] of var int: x); + +% predicate jacop_stretch_reif(array[int] of int: values, array[int] of int: min_v, array[int] of int: max_v, +% array[int] of var int: x, var bool: b) = +% abort("Reified stretch/4 is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/subcircuit.mzn b/src/main/minizinc/org/jacop/minizinc/subcircuit.mzn index a853c4db7..c0e8f7fb2 100644 --- a/src/main/minizinc/org/jacop/minizinc/subcircuit.mzn +++ b/src/main/minizinc/org/jacop/minizinc/subcircuit.mzn @@ -6,13 +6,17 @@ include "alldifferent.mzn"; is not in the circuit. */ predicate subcircuit(array[int] of var int: x) = - jacop_subcircuit(x); + if min(index_set(x)) = 1 then + jacop_subcircuit(x) + else + jacop_subcircuit([x[i] - min(index_set(x)) + 1 | i in index_set(x)]) + endif; predicate jacop_subcircuit(array[int] of var int: x); -predicate subcircuit_reif(array[int] of var int: x, var bool: b) = - abort("Reified subcircuit/1 is not supported."); +% predicate subcircuit_reif(array[int] of var int: x, var bool: b) = +% abort("Reified subcircuit/1 is not supported."); %-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------% diff --git a/src/main/minizinc/org/jacop/minizinc/table_bool.mzn b/src/main/minizinc/org/jacop/minizinc/table_bool.mzn index 6dc2e1c35..775275590 100644 --- a/src/main/minizinc/org/jacop/minizinc/table_bool.mzn +++ b/src/main/minizinc/org/jacop/minizinc/table_bool.mzn @@ -11,6 +11,6 @@ predicate table_bool(array[int] of var bool: x, array[int, int] of bool: t) = predicate jacop_table_bool(array[int] of var bool: x, array[int, int] of bool: t); -predicate table_bool_reif(array[int] of var bool: x, array[int, int] of bool: t, - var bool: b) = - abort("Reified table/2 for Booleans is not supported."); +% predicate table_bool_reif(array[int] of var bool: x, array[int, int] of bool: t, +% var bool: b) = +% abort("Reified table/2 for Booleans is not supported."); diff --git a/src/main/minizinc/org/jacop/minizinc/table_int.mzn b/src/main/minizinc/org/jacop/minizinc/table_int.mzn index 28cd62ad7..6c46a7e9a 100644 --- a/src/main/minizinc/org/jacop/minizinc/table_int.mzn +++ b/src/main/minizinc/org/jacop/minizinc/table_int.mzn @@ -11,107 +11,5 @@ predicate table_int(array[int] of var int: x, array[int, int] of int: t) = predicate jacop_table_int(array[int] of var int: x, array[int, int] of int: t); -%-----------------------------------------------------------------------------% -% Reified version -% -% We only support special cases of a few variables. -% -% The approach is to add the Boolean variable to the list of variables and -% create an extended table. The extended table covers all combinations of -% assignments to the original variables, and every entry in it is padded with a -% value that depends on whether that entry occurs in the original table. -% -% For example, the original table constraint -% -% x y -% --- -% 2 3 -% 5 8 -% 4 1 -% -% reified with a Boolean b is turned into a table constraint of the form -% -% x y b -% --------- -% 2 3 true -% 5 8 true -% 4 1 true -% ... false -% ... false % for all other pairs (x,y) -% ... false -% - -predicate table_int_reif(array[int] of var int: x, array[int, int] of int: t, - var bool: b) = - - let { int: n_vars = length(x) } - in - - assert(n_vars in 1..5, - "'table' constraints in a reified context " ++ - "are only supported for 1..5 variables.", - - if n_vars = 1 then - - x[1] in { t[it,1] | it in index_set_1of2(t) } <-> b - - else - - let { set of int: ix = index_set(x), - set of int: full_size = 1..product(i in ix)( dom_size(x[i]) ), - array[full_size, 1..n_vars + 1] of int: t_b = - array2d(full_size, 1..n_vars + 1, - - if n_vars = 2 then - - [ let { array[ix] of int: tpl = [i1,i2] } in - (tpl ++ [bool2int(aux_is_in_table(tpl,t))])[p] - | i1 in dom(x[1]), - i2 in dom(x[2]), - p in 1..n_vars + 1 ] - - else if n_vars = 3 then - - [ let { array[ix] of int: tpl = [i1,i2,i3] } in - (tpl ++ [bool2int(aux_is_in_table(tpl,t))])[p] - | i1 in dom(x[1]), - i2 in dom(x[2]), - i3 in dom(x[3]), - p in 1..n_vars + 1 ] - - else if n_vars = 4 then - - [ let { array[ix] of int: tpl = [i1,i2,i3,i4] } - in - (tpl ++ [bool2int(aux_is_in_table(tpl,t))])[p] - | i1 in dom(x[1]), - i2 in dom(x[2]), - i3 in dom(x[3]), - i4 in dom(x[4]), - p in 1..n_vars + 1 ] - - else % if n_vars = 5 then - - [ let { array[ix] of int: tpl = [i1,i2,i3,i4,i5] } in - (tpl ++ [bool2int(aux_is_in_table(tpl,t))])[p] - | i1 in dom(x[1]), - i2 in dom(x[2]), - i3 in dom(x[3]), - i4 in dom(x[4]), - i5 in dom(x[5]), - p in 1..n_vars + 1 ] - - endif endif endif ) } - in - table_int(x ++ [bool2int(b)], t_b) - - endif - ); - -test aux_is_in_table(array[int] of int: e, array[int, int] of int: t) = - exists(i in index_set_1of2(t))( - forall(j in index_set(e))( t[i,j] = e[j] ) - ); - %-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------% diff --git a/src/main/scala/org/jacop/examples/scala/Powell.scala b/src/main/scala/org/jacop/examples/scala/Powell.scala index d58b319c0..0a4f13cb6 100644 --- a/src/main/scala/org/jacop/examples/scala/Powell.scala +++ b/src/main/scala/org/jacop/examples/scala/Powell.scala @@ -12,6 +12,7 @@ object Powell extends App with jacop { // constraint x(0) + 10.0*x(1) #= 0.0 + //sum(x, Array[Double](1, 10, 0, 0)) #= 0 scala.math.sqrt(5.0)*(x(2) - x(3)) #= 0.0 diff --git a/src/main/scala/org/jacop/scala/jacop.scala b/src/main/scala/org/jacop/scala/jacop.scala index f7294794f..55dc77384 100644 --- a/src/main/scala/org/jacop/scala/jacop.scala +++ b/src/main/scala/org/jacop/scala/jacop.scala @@ -3,6 +3,7 @@ */ package org.jacop.scala +import org.jacop.core._ import org.jacop.constraints._ import org.jacop.set.constraints._ import org.jacop.floats.constraints._ @@ -277,7 +278,7 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * @return IntVar variable being the result of the addition constraint. */ def +(that: org.jacop.core.IntVar) = { - val result = new IntVar() + val result = new IntVar(this.min() + that.min(), this.max() + that.max()) val c = new XplusYeqZ(this, that, result) getModel.constr += c result @@ -290,7 +291,7 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * @return IntVar variable being the result of the addition constraint. */ def +(that: Int) = { - val result = new IntVar() + val result = new IntVar(this.min() + that, this.max() + that) val c = new XplusCeqZ(this, that, result) getModel.constr += c result @@ -303,7 +304,7 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * @return IntVar variable being the result of the subtraction constraint. */ def -(that: org.jacop.core.IntVar) = { - val result = new IntVar() + val result = new IntVar(this.min() - that.max(), this.max() - that.min()) val c = new XplusYeqZ(result, that, this) getModel.constr += c result @@ -316,7 +317,7 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * @return IntVar variable being the result of the subtraction constraint. */ def -(that: Int) = { - val result = new IntVar() + val result = new IntVar(this.min() - that, this.max() - that) val c = new XplusCeqZ(result, that, this) getModel.constr += c result @@ -329,6 +330,7 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * @return IntVar variable being the result of the multiplication constraint. */ def *(that: org.jacop.core.IntVar) = { + val bounds = IntDomain.mulBounds(this.min(), this.max(), that.min(), that.max()) val result = new IntVar() val c = new XmulYeqZ(this, that, result) getModel.constr += c @@ -340,9 +342,10 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * * @param that a second integer parameter for the multiplication constraint. * @return IntVar variable being the result of the multiplication constraint. -  */ + */ def *(that: Int) = { - val result = new IntVar() + val bounds = IntDomain.mulBounds(this.min(), this.max(), that, that) + val result = new IntVar(bounds.min(), bounds.max()) val c = new XmulCeqZ(this, that, result) getModel.constr += c result @@ -355,7 +358,8 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * @return IntVar variable being the result of the integer division constraint. */ def div(that: org.jacop.core.IntVar) = { - val result = new IntVar() + val bounds = IntDomain.divBounds(this.min(), this.max(), that.min(), that.max()) + val result = new IntVar(bounds.min(), bounds.max()) val c = new XdivYeqZ(this, that, result) getModel.constr += c result @@ -368,10 +372,26 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * @return IntVar variable being the result of the integer reminder from division constraint. */ def mod(that: org.jacop.core.IntVar) = { - val result = new IntVar() - val c = new XmodYeqZ(this, that, result) - getModel.constr += c - result + var reminderMin : Int = 0; + var reminderMax : Int = 0; + + if (this.min() >= 0) { + reminderMin = 0 + reminderMax = Math.max(Math.abs(that.min()), Math.abs(that.max())) - 1 + } + else if (this.max() < 0) { + reminderMax = 0 + reminderMin = - Math.max(Math.abs(that.min()), Math.abs(that.max())) + 1 + } + else { + reminderMin = Math.min(Math.min(that.min(),-that.min()), Math.min(that.max(),-that.max())) + 1 + reminderMax = Math.max(Math.max(that.min(),-that.min()), Math.max(that.max(),-that.max())) - 1 + } + + val result = new IntVar(reminderMin, reminderMax) + val c = new XmodYeqZ(this, that, result) + getModel.constr += c + result } /** @@ -393,7 +413,7 @@ class IntVar(name: String, min: Int, max: Int) extends org.jacop.core.IntVar(get * @return the defined constraint. */ def unary_- = { - val result = new IntVar() + val result = new IntVar(-this.max(), -this.min()) val c = new XplusYeqC(this, result, 0) getModel.constr += c result diff --git a/src/main/scala/org/jacop/scala/package.scala b/src/main/scala/org/jacop/scala/package.scala index 73d654fbc..830033149 100644 --- a/src/main/scala/org/jacop/scala/package.scala +++ b/src/main/scala/org/jacop/scala/package.scala @@ -104,45 +104,65 @@ package object scala { } /** -* Wrapper for [[org.jacop.constraints.Sum]]. +* Wrapper for [[org.jacop.constraints.SumInt]] and [[org.jacop.constraints.SumBool]]. * * @param res array of variables to be summed up. * @param result summation result. */ def sum[T <: org.jacop.core.IntVar](res: List[T], result: IntVar)(implicit m: ClassTag[T]) { - val c = new Sum(res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], result) + val c = if (boolSum(res) ) new SumBool(impModel, res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], "==", result) + else new SumInt(impModel, res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], "==", result) if (trace) println(c) impModel.impose( c ) } /** -* Wrapper for [[org.jacop.constraints.Sum]]. +* Wrapper for [[org.jacop.constraints.Sum]] and [[org.jacop.constraints.SumBool]]. * * @param res array of variables to be summed up. * @return summation result. */ def sum[T <: org.jacop.core.IntVar](res: List[T])(implicit m: ClassTag[T]) : IntVar = { val result = new IntVar() - val c = new Sum(res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], result) + val c = if (boolSum(res) ) new SumBool(impModel, res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], "==", result) + else new SumInt(impModel, res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], "==", result) impModel.constr += c result } + def boolSum[T <: org.jacop.core.IntVar](vs: List[T]) : Boolean = { + for (v <- vs) + if (v.min() < 0 || v.max() > 1) + return false + return true + } + + /** -* Wrapper for [[org.jacop.constraints.SumWeight]]. +* Wrapper for [[org.jacop.constraints.LinearInt]]. * * @param res array of variables to be summed up. * @param w array of weights. * @param result summation result. */ def weightedSum[T <: org.jacop.core.IntVar](res: List[T], w: Array[Int], result: IntVar)(implicit m: ClassTag[T]) { - val c = new SumWeight(res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], w, result) + val vect = new Array[org.jacop.core.IntVar](res.length + 1) + val weight = new Array[Int](res.length + 1) + + for ( i <- 0 to (res.length - 1)) { + vect(i) = res(i).asInstanceOf[org.jacop.core.IntVar] + weight(i) = 1 + } + vect(res.length) = result.asInstanceOf[org.jacop.core.IntVar] + weight(res.length) = -1 + + val c = new LinearInt(impModel, vect.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], weight, "==", 0) if (trace) println(c) impModel.impose( c ) } /** -* Wrapper for [[org.jacop.constraints.SumWeight]]. +* Wrapper for [[org.jacop.constraints.LinearInt]]. * * @param res array of variables to be summed up. * @param w array of weights. @@ -150,27 +170,47 @@ package object scala { */ def sum[T <: org.jacop.core.IntVar](res: List[T], w: Array[Int])(implicit m: ClassTag[T]) : IntVar = { val result = new IntVar() - val c = new SumWeight(res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], w, result) + val vect = new Array[org.jacop.core.IntVar](res.length + 1) + val weight = new Array[Int](res.length + 1) + + for ( i <- 0 to (res.length - 1)) { + vect(i) = res(i).asInstanceOf[org.jacop.core.IntVar] + weight(i) = 1 + } + vect(res.length) = result.asInstanceOf[org.jacop.core.IntVar] + weight(res.length) = -1 + + val c = new LinearInt(impModel, vect.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], weight, "==", 0) if (trace) println(c) impModel.impose( c ) result } /** -* Wrapper for [[org.jacop.constraints.SumWeightDom]]. +* Wrapper for [[org.jacop.constraints.LinearIntDom]]. * * @param res array of variables to be summed up (domain consistency used). * @param w array of weights. * @param result summation result. */ - def weightedSumDom[T <: org.jacop.core.IntVar](res: List[T], w: Array[Int], result: IntVar)(implicit m: ClassTag[T]) { - val c = new SumWeightDom(res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], w, result) + def sumDom[T <: org.jacop.core.IntVar](res: List[T], w: Array[Int], result: IntVar)(implicit m: ClassTag[T]) { + val vect = new Array[org.jacop.core.IntVar](res.length + 1) + val weight = new Array[Int](res.length + 1) + + for ( i <- 0 to (res.length - 1)) { + vect(i) = res(i).asInstanceOf[org.jacop.core.IntVar] + weight(i) = 1 + } + vect(res.length) = result.asInstanceOf[org.jacop.core.IntVar] + weight(res.length) = -1 + + val c = new LinearIntDom(impModel, vect.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], weight, "==", 0) if (trace) println(c) impModel.impose( c ) } /** -* Wrapper for [[org.jacop.constraints.SumWeightDom]]. +* Wrapper for [[org.jacop.constraints.LinearIntDom]]. * * @param res array of variables to be summed up. * @param w array of weights. @@ -178,7 +218,17 @@ package object scala { */ def sumDom[T <: org.jacop.core.IntVar](res: List[T], w: Array[Int])(implicit m: ClassTag[T]) : IntVar = { val result = new IntVar() - val c = new SumWeightDom(res.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], w, result) + val vect = new Array[org.jacop.core.IntVar](res.length + 1) + val weight = new Array[Int](res.length + 1) + + for ( i <- 0 to (res.length - 1)) { + vect(i) = res(i).asInstanceOf[org.jacop.core.IntVar] + weight(i) = 1 + } + vect(res.length) = result.asInstanceOf[org.jacop.core.IntVar] + weight(res.length) = -1 + + val c = new LinearIntDom(impModel, vect.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], weight, "==", 0) if (trace) println(c) impModel.impose( c ) result @@ -445,6 +495,17 @@ package object scala { impModel.impose( c ) } +/** +* Wrapper for [[org.jacop.constraints.Subcircuit]]. +* +* @param n array of varibales, which domains define next nodes in the graph. +*/ + def subcircuit(n: Array[IntVar]) { + val c = new Subcircuit(n.asInstanceOf[Array[org.jacop.core.IntVar]]) + if (trace) println(c) + impModel.impose( c ) + } + /** * Wrapper for [[org.jacop.constraints.Assignment]]. * @@ -490,7 +551,7 @@ package object scala { * @param tuples array of tuples allowed to be assigned to variables. */ def table[T <: org.jacop.core.IntVar](list: List[T], tuples: Array[Array[Int]])(implicit m: ClassTag[T]) { - val c = new ExtensionalSupportVA(list.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], tuples) + val c = new ExtensionalSupportMDD(list.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], tuples) if (trace) println(c) impModel.impose( c ) } @@ -536,6 +597,47 @@ package object scala { impModel.impose( c ) } +/** +* Wrapper for [[org.jacop.constraints.BoolClause]]. +* +* @param x list of positive variables. +* @param y list of negative variables. +*/ + def clause(x: Array[IntVar], y: Array[IntVar]) { + val c = new BoolClause(x.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], y.toArray.asInstanceOf[Array[org.jacop.core.IntVar]]) + if (trace) println(c) + impModel.impose( c ) + } + +/** +* Wrapper for [[org.jacop.constraints.ArgMin]]. +* +* @param x list of variables. +* @return index of minimal value on list x. +*/ + def arg_min(x: Array[IntVar]) : IntVar = { + val minIndex = new IntVar(1, x.length) + val c = new ArgMin(x.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], minIndex) + if (trace) println(c) + impModel.impose( c ) + minIndex + } + +/** +* Wrapper for [[org.jacop.constraints.ArgMax]]. +* +* @param x list of variables. +* @return index of maximal value on list x. +*/ + def arg_max(x: Array[IntVar]) : IntVar = { + val maxIndex = new IntVar(1, x.length) + val c = new ArgMax(x.toArray.asInstanceOf[Array[org.jacop.core.IntVar]], maxIndex) + if (trace) println(c) + impModel.impose( c ) + maxIndex + } + + // ================== Decompose constraints /** @@ -567,6 +669,17 @@ package object scala { impModel.imposeDecomposition( c ) } +/** +* Wrapper for [[org.jacop.constraints.LexOrder]]. +* +* @param x array of vectors of varibales to be lexicographically ordered. +*/ + def lex(x: Array[IntVar], y: Array[IntVar]) { + val c = new LexOrder(x.asInstanceOf[Array[org.jacop.core.IntVar]], y.asInstanceOf[Array[org.jacop.core.IntVar]]) + if (trace) println(c) + impModel.impose(c) + } + /** * Wrapper for [[org.jacop.constraints.Lex]]. * @@ -621,7 +734,6 @@ package object scala { // ================== Logical operations on constraints - /** * Wrapper for [[org.jacop.constraints.Or]]. * @@ -910,7 +1022,7 @@ package object scala { * @param res array of variables to be summed up. * @return summation result. */ - def linear[T <: org.jacop.floats.core.FloatVar](res: List[T], weight: Array[Double])(implicit m: Manifest[T]) : FloatVar = { + def sum[T <: org.jacop.floats.core.FloatVar](res: List[T], weight: Array[Double])(implicit m: Manifest[T]) : FloatVar = { val result = new FloatVar() val vect = new Array[org.jacop.floats.core.FloatVar](res.length + 1) val w = new Array[Double](res.length + 1)