dlvhex  2.5.0
testsuite/TestASPSolver.cpp
Go to the documentation of this file.
00001 /* dlvhex -- Answer-Set Programming with external interfaces.
00002  * Copyright (C) 2005, 2006, 2007 Roman Schindlauer
00003  * Copyright (C) 2006, 2007, 2008, 2009, 2010 Thomas Krennwallner
00004  * Copyright (C) 2009, 2010 Peter Schüller
00005  * 
00006  * This file is part of dlvhex.
00007  *
00008  * dlvhex is free software; you can redistribute it and/or modify it
00009  * under the terms of the GNU Lesser General Public License as
00010  * published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * dlvhex is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with dlvhex; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA.
00022  */
00023 
00031 #ifdef HAVE_CONFIG_H
00032 #  include "config.h"
00033 #endif
00034 
00035 #include "dlvhex2/ASPSolver.h"
00036 #include "dlvhex2/ASPSolverManager.h"
00037 #include "dlvhex2/ProgramCtx.h"
00038 #include "dlvhex2/Registry.h"
00039 #include "dlvhex2/Printer.h"
00040 #include "dlvhex2/HexParser.h"
00041 #include "dlvhex2/InputProvider.h"
00042 #include "dlvhex2/AnswerSet.h"
00043 
00044 #define BOOST_TEST_MODULE "TestASPSolver"
00045 #include <boost/test/unit_test.hpp>
00046 
00047 #include <iostream>
00048 
00049 #define LOG_REGISTRY_PROGRAM(ctx) \
00050   LOG(INFO,*ctx.registry()); \
00051     RawPrinter printer(std::cerr, ctx.registry()); \
00052     std::cerr << "edb = " << *ctx.edb << std::endl; \
00053     LOG(INFO,"idb"); \
00054     printer.printmany(ctx.idb,"\n"); \
00055     std::cerr << std::endl; \
00056     LOG(INFO,"idb end");
00057 
00058 LOG_INIT(Logger::ERROR | Logger::WARNING)
00059 
00060 DLVHEX_NAMESPACE_USE
00061 
00062 template<typename SolverSoftwareConfiguration>
00063 void testSimple()
00064 {
00065   ProgramCtx ctx;
00066   ctx.setupRegistry(RegistryPtr(new Registry));
00067 
00068   std::stringstream ss;
00069   ss <<
00070     //"#module(mp,[])." << std::endl <<
00071     "c(d,e). g(a)." << std::endl <<
00072     "f(X) v b :- g(X), not h(X,X)." << std::endl;
00073   InputProviderPtr ip(new InputProvider);
00074   ip->addStreamInput(ss, "testinput");
00075   ModuleHexParser parser;
00076   BOOST_REQUIRE_NO_THROW(parser.parse(ip, ctx));
00077 
00078     LOG_REGISTRY_PROGRAM(ctx);
00079 
00080   //
00081   // now starts the real test
00082   //
00083 
00084   SolverSoftwareConfiguration config;
00085   OrdinaryASPProgram program(ctx.registry(), ctx.idb, ctx.edb, 0);
00086 
00087   ASPSolverManager mgr;
00088   LOG(INFO,"calling solve");
00089   ASPSolverManager::ResultsPtr res = mgr.solve(config, program);
00090   BOOST_REQUIRE(res != 0);
00091   LOG(INFO,"solve returned results!");
00092 
00093   AnswerSet::Ptr int0 = res->getNextAnswerSet();
00094   BOOST_REQUIRE(int0 != 0);
00095   LOG(INFO,"got answer set " << *int0);
00096 
00097   AnswerSet::Ptr int1 = res->getNextAnswerSet();
00098   BOOST_REQUIRE(int1 != 0);
00099   LOG(INFO,"got answer set " << *int1);
00100 
00101   AnswerSet::Ptr int2 = res->getNextAnswerSet();
00102   BOOST_REQUIRE(int2 == 0);
00103 }
00104 
00105 #ifdef HAVE_DLV
00106 BOOST_AUTO_TEST_CASE(testASPSolverSimpleDLV) 
00107 {
00108   testSimple<ASPSolver::DLVSoftware::Configuration>();
00109 }
00110 #endif
00111  
00112 #ifdef HAVE_DLVDB
00113 BOOST_AUTO_TEST_CASE(testASPSolverSimpleDLVDB) 
00114 {
00115   testSimple<ASPSolver::DLVDBSoftware::Configuration>();
00116 }
00117 #endif
00118  
00119 #ifdef HAVE_LIBDLV
00120 BOOST_AUTO_TEST_CASE(testASPSolverSimpleDLVLib) 
00121 {
00122   testSimple<ASPSolver::DLVLibSoftware::Configuration>();
00123 }
00124 #endif
00125  
00126 #ifdef HAVE_LIBCLINGO
00127 BOOST_AUTO_TEST_CASE(testASPSolverSimpleClingo) 
00128 {
00129   testSimple<ASPSolver::ClingoSoftware::Configuration>();
00130 }
00131 #endif
00132