use of org.opt4j.satdecoding.Constraint in project opt4j by felixreimann.
the class QueensSATDecoder method createConstraints.
/*
* (non-Javadoc)
*
* @see org.opt4j.sat.AbstractSATDecoder#createConstraints()
*/
@Override
public Set<Constraint> createConstraints() {
Set<Constraint> constraints = new HashSet<Constraint>();
int size = problem.size();
for (int i = 0; i < size; i++) {
Constraint constraint = new Constraint("=", 1);
for (int j = 0; j < size; j++) {
constraint.add(new Literal(i * size + j, true));
}
constraints.add(constraint);
}
for (int j = 0; j < size; j++) {
Constraint constraint = new Constraint("=", 1);
for (int i = 0; i < size; i++) {
constraint.add(new Literal(i * size + j, true));
}
constraints.add(constraint);
}
for (int k = -size + 1; k < size; k++) {
// diagonal 1
Constraint constraint = new Constraint("<=", 1);
for (int j = 0; j < size; j++) {
int i = k + j;
if (0 <= i && i < size) {
constraint.add(new Literal(i * size + j, true));
}
}
constraints.add(constraint);
}
for (int k = 0; k < 2 * size - 1; k++) {
// diagonal 2
Constraint constraint = new Constraint("<=", 1);
for (int j = 0; j < size; j++) {
int i = k - j;
if (0 <= i && i < size) {
constraint.add(new Literal(i * size + j, true));
}
}
constraints.add(constraint);
}
return constraints;
}
use of org.opt4j.satdecoding.Constraint in project opt4j by felixreimann.
the class ConstraintTest method equalityTestOfOperator.
@Test
public void equalityTestOfOperator() {
Object object1 = "literal1";
Object object2 = "literal2";
Constraint c1 = new Constraint(Operator.LE, 2);
c1.add(2, new Literal(object1, true));
c1.add(2, new Literal(object2, true));
Constraint c2 = new Constraint(Operator.GE, 2);
c2.add(2, new Literal(object1, true));
c2.add(2, new Literal(object2, true));
Constraint c3 = new Constraint(Operator.EQ, 2);
c3.add(2, new Literal(object1, true));
c3.add(2, new Literal(object2, true));
Assert.assertFalse(c1.equals(c2));
Assert.assertFalse(c1.equals(c3));
Assert.assertFalse(c2.equals(c3));
}
use of org.opt4j.satdecoding.Constraint in project opt4j by felixreimann.
the class ConstraintTest method equalityTestOfRhs2.
@Test
public void equalityTestOfRhs2() {
Constraint c1 = new Constraint(">=", 1);
c1.add(2, new Literal("papa", true));
Constraint c2 = new Constraint("<=", 1);
c2.add(2, new Literal("lala", true));
// returns true, should be false
Assert.assertFalse(c1.equals(c2));
}
Aggregations