本文整理汇总了C++中IP::add_boolean_cube方法的典型用法代码示例。如果您正苦于以下问题:C++ IP::add_boolean_cube方法的具体用法?C++ IP::add_boolean_cube怎么用?C++ IP::add_boolean_cube使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::add_boolean_cube方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main_program
void main_program()
{
using namespace std;
IP ip;
int n = 3;
auto P = ip.add_boolean_cube(n*n, n*n, n*n);
// Exactly one indicator equal to 1.
cerr << "Indicator variables\n";
for (int i = 0; i < n*n; ++i) {
for (int j = 0; j < n*n; ++j) {
Sum k_sum;
for (int k = 0; k < n*n; ++k) {
k_sum += P[i][j][k];
}
ip.add_constraint(k_sum == 1);
// Advanced tip: One can use std::move to avoid a copy
// here:
// ip.add_constraint(move(k_sum) == 1);
}
}
// All rows have every number.
cerr << "Row constraints\n";
for (int i = 0; i < n*n; ++i) {
for (int k = 0; k < n*n; ++k) {
Sum row_k_sum;
for (int j = 0; j < n*n; ++j) {
row_k_sum += P[i][j][k];
}
ip.add_constraint(row_k_sum == 1);
}
}
// All columns have every number.
cerr << "Columns constraints\n";
for (int j = 0; j < n*n; ++j) {
for (int k = 0; k < n*n; ++k) {
Sum col_k_sum;
for (int i = 0; i < n*n; ++i) {
col_k_sum += P[i][j][k];
}
ip.add_constraint(col_k_sum == 1);
}
}
// The n*n subsquares have every number.
cerr << "Square constraints\n";
for (int i1 = 0; i1 < n; ++i1) {
for (int j1 = 0; j1 < n; ++j1) {
for (int k = 0; k < n*n; ++k) {
Sum square_k_sum;
for (int i2 = 0; i2 < n; ++i2) {
for (int j2 = 0; j2 < n; ++j2) {
square_k_sum += P[n*i1 + i2][n*j1 + j2][k];
}
}
ip.add_constraint(square_k_sum == 1);
}
}
}
// A very difficult sudoku…
const char* given[] = {"1**" "***" "7**",
"**7" "1*9" "***",
"68*" "*7*" "***",
"**1" "*9*" "6**",
"***" "3**" "*2*",
"*4*" "***" "**3",
"**8" "*6*" "1**",
"5**" "***" "*4*",
"***" "**2" "**5"};
// http://www.mirror.co.uk/news/weird-news/worlds-hardest-sudoku-puzzle-ever-942299
//const char* given[] = {"8**" "***" "***",
// "**3" "6**" "***",
// "*7*" "*9*" "2**",
// "*5*" "**7" "***",
// "***" "*45" "7**",
// "***" "1**" "*3*",
// "**1" "***" "*68",
// "**8" "5**" "*1*",
// "*9*" "***" "4**"};
//const char* given[] = {"**" "**",
// "**" "**",
// "**" "12",
// "**" "34"};
cerr << "Preassignments\n";
for (int i = 0; i < n*n; ++i) {
for (int j = 0; j < n*n; ++j) {
if (given[i][j] != '*') {
//.........这里部分代码省略.........