Generated on Thu Apr 11 13:58:55 2019 for Gecode by doxygen 1.6.3

flatzinc.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2014
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: test-flatzinc