| 41 | _allSolutions(allSolutions), _cmdlineOpt(cmdlineOpt) {} |
| 42 | |
| 43 | bool |
| 44 | FlatZincTest::run(void) { |
| 45 | using namespace Gecode; |
| 46 | Support::Timer t_total; |
| 47 | t_total.start(); |
| 48 | Gecode::FlatZinc::FlatZincOptions fznopt("Gecode/FlatZinc"); |
| 49 | if (!_cmdlineOpt.empty()) { |
| 50 | std::string cmd("fzn-gecode"); |
| 51 | int argc = static_cast<int>(_cmdlineOpt.size()) + 1; |
| 52 | std::vector<char*> argv(argc); |
| 53 | argv[0] = const_cast<char*>(cmd.data()); |
| 54 | for (int i = 1; i < argc; ++i) { |
| 55 | argv[i] = const_cast<char*>(_cmdlineOpt[i-1].data()); |
| 56 | } |
| 57 | fznopt.parse(argc, argv.data()); |
| 58 | } |
| 59 | fznopt.allSolutions(_allSolutions); |
| 60 | Gecode::FlatZinc::Printer p; |
| 61 | Gecode::FlatZinc::FlatZincSpace* fg = nullptr; |
| 62 | try { |
| 63 | std::stringstream ss(_source); |
| 64 | fg = Gecode::FlatZinc::parse(ss, p, olog); |
| 65 | |
| 66 | if (fg) { |
| 67 | fg->createBranchers(p, fg->solveAnnotations(), fznopt, |
| 68 | false, olog); |
| 69 | fg->shrinkArrays(p); |
| 70 | std::ostringstream os; |
| 71 | fg->run(os, p, fznopt, t_total); |
| 72 | |
| 73 | if (_expected == os.str()) { |
| 74 | return true; |
| 75 | } else { |
| 76 | if (opt.log) |
| 77 | olog << "FlatZinc produced the following output:\n" << os.str() << "\n"; |
| 78 | return false; |
| 79 | } |
| 80 | } else { |
| 81 | if (opt.log) |
| 82 | olog << "Could not parse input\n"; |
| 83 | return false; |
| 84 | } |
| 85 | delete fg; |
| 86 | } catch (Gecode::FlatZinc::Error& e) { |
| 87 | if (opt.log) |
| 88 | olog << ind(2) << "FlatZinc error : " << e.toString() << std::endl; |
| 89 | return false; |
| 90 | } |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | }} |
| 95 |
nothing calls this directly
no test coverage detected