本文整理汇总了C++中Solver::addBinary方法的典型用法代码示例。如果您正苦于以下问题:C++ Solver::addBinary方法的具体用法?C++ Solver::addBinary怎么用?C++ Solver::addBinary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver::addBinary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: formulate
void formulate(int p, int n, Solver& s) {
_p = p; _n = n;
for (int i = 0; i < N*(p+n); ++i)
s.newVar();
for (int i = 0; i < N; ++i)
for (int j = 0; j < i; ++j) {
if (intersect(i, j)) {
for (int r = 1; r <= p; ++r) {
Lit a = vn(i, r);
Lit b = vn(j, r);
s.addBinary(~a, ~b);
}
for (int r = -1; r >= -n; --r) {
Lit a = vn(i, r);
Lit b = vn(j, r);
s.addBinary(~a, ~b);
}
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (i == j) continue;
if (!contain(i, j)) continue;
for (int pj = 1; pj <= p-1; ++pj) {
for (int pi = pj+1; pi <= p; ++pi) {
Lit a = vn(i, pi);
Lit b = vn(j, pj);
s.addBinary(~a, ~b);
}
}
for (int pj = -1; pj >= -n+1; --pj) {
for (int pi = pj-1; pi >= -n; --pi) {
Lit a = vn(i, pi);
Lit b = vn(j, pj);
s.addBinary(~a, ~b);
}
}
}
}
// Exact one for each color
/*vec<Lit>* c;
for (int i = 0; i < N; ++i) {
c = new vec<Lit>;
c->growTo(n+p);
for (int pi = 1; pi <= p; ++pi)
(*c)[i-1] = vn(i, pi);
for (int pi = -1; pi >= -n; --pi)
(*c)[p-pi-1] = vn(i, pi);
s.addClause(*c);
for (int j = 0; j < n+p; ++j)
for (int k = 0; k < j; ++k) {
s.addBinary(~vnalt(i, j), ~vnalt(i, k));
}
}*/
for (int i = 0; i < N; ++i) {
vec<Lit> c;
c.growTo(n+p);
for (int j = 0; j < n+p; ++j)
c[j] = vnalt(i, j);
s.addClause(c);
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < n+p; ++j)
for (int k = 0; k < j; ++k) {
s.addBinary(~vnalt(i, j), ~vnalt(i, k));
}
}
}