本文整理汇总了C++中IP::set_external_solver方法的典型用法代码示例。如果您正苦于以下问题:C++ IP::set_external_solver方法的具体用法?C++ IP::set_external_solver怎么用?C++ IP::set_external_solver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::set_external_solver方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main_program
//.........这里部分代码省略.........
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] != '*') {
int k = given[i][j] - '1';
attest(0 <= k && k < n*n);
ip.add_constraint( P[i][j][k] );
}
}
}
auto print_solution = [&P, n]()
{
cout << endl;
for (int i = 0; i < n*n; ++i) {
for (int j = 0; j < n*n; ++j) {
for (int k = 0; k < n*n; ++k) {
if (P[i][j][k].bool_value()) {
cout << k+1;
}
}
if (j%n == n-1) {
cout << ' ';
}
}
cout << endl;
if (i%n == n-1) {
cout << endl;
}
}
};
cerr << "Solving with Minisat..." << endl;
auto start_time = wall_time();
ip.set_external_solver(IP::Minisat);
attest(ip.solve());
do {
print_solution();
} while (ip.next_solution());
cerr << "Found all solutions in " << wall_time() - start_time << " seconds." << endl;
cerr << "Solving with Gecode..." << endl;
start_time = wall_time();
ip.set_external_solver(IP::Gecode);
attest(ip.solve());
print_solution();
cerr << "Found a solution in " << wall_time() - start_time << " seconds." << endl;
cerr << "Solving with IP solver..." << endl;
start_time = wall_time();
ip.set_external_solver(IP::Default);
//ip.set_external_solver(IP::MOSEK);
ip.solve();
do {
print_solution();
} while (false /*ip.next_solution()*/);
cerr << "Found all solutions in " << wall_time() - start_time << " seconds." << endl;
}