}
+void oneQueenInEachRow(CSolver* solver, vector<Element*> &elems){
+ Predicate *eq = solver->createPredicateOperator(SATC_EQUALS);
+ int N = elems.size();
+ for(int i=0; i<N; i++){
+ vector<BooleanEdge> rowConstr;
+ for(int j=0; j<N; j++){
+ Element* e1 = elems[j];
+ Element* e2 = solver->getElementConst(3, (uint64_t) i);
+ Element* in[] = {e1, e2};
+ BooleanEdge equals = solver->applyPredicate(eq, in, 2);
+ rowConstr.push_back(equals);
+ }
+ if(rowConstr.size()>0){
+ solver->addConstraint(solver->applyLogicalOperation(SATC_OR, &rowConstr[0], rowConstr.size()) );
+ }
+ }
+}
+
+void generateRowConstraints(CSolver* solver, int N, vector<Element*> &elems){
+ oneQueenInEachRow(solver, elems);
+ differentInEachRow(solver, N, elems);
+}
+
void diagonallyDifferentConstraint(CSolver *solver, int N, vector<Element*> &elems){
Predicate *eq = solver->createPredicateOperator(SATC_EQUALS);
for(int i=N-1; i>0; i--){
elems.push_back(solver->getElementVar(domainSet));
}
mustHaveValueConstraint(solver, elems);
- differentInEachRow(solver, N, elems);
+ generateRowConstraints(solver, N, elems);
diagonallyDifferentConstraintBothDir(solver, N, elems);
// solver->printConstraints();
// solver->serialize();