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
00035
00036
00037
00038 #include "test/flatzinc.hh"
00039
00040 namespace Test { namespace FlatZinc {
00041
00042 FlatZincTest::FlatZincTest(const std::string& name, const std::string& source,
00043 const std::string& expected, bool allSolutions)
00044 : Base("FlatZinc::"+name), _name(name), _source(source), _expected(expected),
00045 _allSolutions(allSolutions) {}
00046
00047 bool
00048 FlatZincTest::run(void) {
00049 using namespace Gecode;
00050 Support::Timer t_total;
00051 t_total.start();
00052 Gecode::FlatZinc::FlatZincOptions fznopt("Gecode/FlatZinc");
00053 fznopt.allSolutions(_allSolutions);
00054 Gecode::FlatZinc::Printer p;
00055 Gecode::FlatZinc::FlatZincSpace* fg = NULL;
00056 try {
00057 std::stringstream ss(_source);
00058 fg = Gecode::FlatZinc::parse(ss, p, olog);
00059
00060 if (fg) {
00061 fg->createBranchers(fg->solveAnnotations(), fznopt.seed(), fznopt.decay(),
00062 false, olog);
00063 fg->shrinkArrays(p);
00064 std::ostringstream os;
00065 fg->run(os, p, fznopt, t_total);
00066
00067 if (_expected == os.str()) {
00068 return true;
00069 } else {
00070 if (opt.log)
00071 olog << "FlatZinc produced the following output:\n" << os.str() << "\n";
00072 return false;
00073 }
00074 } else {
00075 if (opt.log)
00076 olog << "Could not parse input\n";
00077 return false;
00078 }
00079 delete fg;
00080 } catch (Gecode::FlatZinc::Error& e) {
00081 if (opt.log)
00082 olog << ind(2) << "FlatZinc error : " << e.toString() << std::endl;
00083 return false;
00084 }
00085
00086 }
00087
00088 }}
00089
00090