flatzinc.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "test/flatzinc.hh"
00035
00036 namespace Test { namespace FlatZinc {
00037
00038 FlatZincTest::FlatZincTest(const std::string& name, const std::string& source,
00039 const std::string& expected, bool allSolutions)
00040 : Base("FlatZinc::"+name), _name(name), _source(source), _expected(expected),
00041 _allSolutions(allSolutions) {}
00042
00043 bool
00044 FlatZincTest::run(void) {
00045 using namespace Gecode;
00046 Support::Timer t_total;
00047 t_total.start();
00048 Gecode::FlatZinc::FlatZincOptions fznopt("Gecode/FlatZinc");
00049 fznopt.allSolutions(_allSolutions);
00050 Gecode::FlatZinc::Printer p;
00051 Gecode::FlatZinc::FlatZincSpace* fg = NULL;
00052 try {
00053 std::stringstream ss(_source);
00054 fg = Gecode::FlatZinc::parse(ss, p, olog);
00055
00056 if (fg) {
00057 fg->createBranchers(p, fg->solveAnnotations(), fznopt,
00058 false, olog);
00059 fg->shrinkArrays(p);
00060 std::ostringstream os;
00061 fg->run(os, p, fznopt, t_total);
00062
00063 if (_expected == os.str()) {
00064 return true;
00065 } else {
00066 if (opt.log)
00067 olog << "FlatZinc produced the following output:\n" << os.str() << "\n";
00068 return false;
00069 }
00070 } else {
00071 if (opt.log)
00072 olog << "Could not parse input\n";
00073 return false;
00074 }
00075 delete fg;
00076 } catch (Gecode::FlatZinc::Error& e) {
00077 if (opt.log)
00078 olog << ind(2) << "FlatZinc error : " << e.toString() << std::endl;
00079 return false;
00080 }
00081 return true;
00082 }
00083
00084 }}
00085
00086