dlvhex
2.5.0
|
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 00033 #ifdef HAVE_CONFIG_H 00034 #include "config.h" 00035 #endif // HAVE_CONFIG_H 00036 00037 #include "dlvhex2/EvalGraphBuilder.h" 00038 #include "dlvhex2/EvalHeuristicOldDlvhex.h" 00039 #include "dlvhex2/ProgramCtx.h" 00040 #include "dlvhex2/Printer.h" 00041 #include "dlvhex2/Registry.h" 00042 #include "dlvhex2/PluginInterface.h" 00043 #include "dlvhex2/DependencyGraph.h" 00044 #include "dlvhex2/ComponentGraph.h" 00045 #include "dlvhex2/ModelGenerator.h" 00046 #include "dlvhex2/OnlineModelBuilder.h" 00047 #include "dlvhex2/ASPSolver.h" 00048 #include "dlvhex2/ASPSolverManager.h" 00049 00050 // this must be included before dummytypes! 00051 #define BOOST_TEST_MODULE __FILE__ 00052 #include <boost/test/unit_test.hpp> 00053 00054 #include "fixturesExt1.h" 00055 #include "graphviz.h" 00056 00057 #include <iostream> 00058 #include <fstream> 00059 #include <cstdlib> 00060 00061 #define LOG_REGISTRY_PROGRAM(ctx) \ 00062 LOG(INFO,*ctx.registry()); \ 00063 RawPrinter printer(std::cerr, ctx.registry()); \ 00064 std::cerr << "edb = " << *ctx.edb << std::endl; \ 00065 LOG(INFO,"idb"); \ 00066 printer.printmany(ctx.idb,"\n"); \ 00067 std::cerr << std::endl; \ 00068 LOG(INFO,"idb end"); 00069 00070 LOG_INIT(Logger::ERROR | Logger::WARNING) 00071 00072 DLVHEX_NAMESPACE_USE 00073 00074 typedef FinalEvalGraph::EvalUnit EvalUnit; 00075 typedef OnlineModelBuilder<FinalEvalGraph> FinalOnlineModelBuilder; 00076 typedef FinalOnlineModelBuilder::Model Model; 00077 typedef FinalOnlineModelBuilder::OptionalModel OptionalModel; 00078 00079 BOOST_FIXTURE_TEST_CASE(testEvalHeuristicExt1,ProgramExt1ProgramCtxDependencyGraphComponentGraphFixture) 00080 { 00081 LOG_REGISTRY_PROGRAM(ctx); 00082 00083 // eval graph 00084 FinalEvalGraph eg; 00085 00086 { 00087 // create builder that supervises the construction of eg 00088 ASPSolverManager::SoftwareConfigurationPtr extEvalConfig( 00089 new ASPSolver::DLVSoftware::Configuration); 00090 EvalGraphBuilder egbuilder(ctx, compgraph, eg, extEvalConfig); 00091 00092 { 00093 // create heuristic, which sends commands to egbuilder 00094 EvalHeuristicOldDlvhex heuristicOldDlvhex; 00095 heuristicOldDlvhex.build(egbuilder); 00096 LOG(INFO,"building eval graph finished"); 00097 00098 // log the (changed) component graph 00099 { 00100 const char* fnamev = "testEvalEndToEndExt1Verbose.dot"; 00101 LOG(INFO,"dumping verbose graph to " << fnamev); 00102 std::ofstream filev(fnamev); 00103 compgraph.writeGraphViz(filev, true); 00104 makeGraphVizPdf(fnamev); 00105 00106 const char* fnamet = "testEvalEndToEndExt1Terse.dot"; 00107 LOG(INFO,"dumping terse graph to " << fnamet); 00108 std::ofstream filet(fnamet); 00109 compgraph.writeGraphViz(filet, false); 00110 makeGraphVizPdf(fnamet); 00111 } 00112 } 00113 } 00114 00115 // 00116 // evaluate 00117 // 00118 dlvhex::ModelBuilderConfig<FinalEvalGraph> cfg(eg); 00119 FinalOnlineModelBuilder omb(cfg); 00120 00121 EvalUnit ufinal; 00122 00123 // setup final unit 00124 { 00125 BOOST_TEST_MESSAGE("adding ufinal"); 00126 LOG(INFO,"ufinal = " << ufinal); 00127 ufinal = eg.addUnit(FinalEvalGraph::EvalUnitPropertyBundle()); 00128 00129 FinalEvalGraph::EvalUnitIterator it, itend; 00130 boost::tie(it, itend) = eg.getEvalUnits(); 00131 for(; it != itend && *it != ufinal; ++it) 00132 { 00133 LOG(INFO,"adding dependency from ufinal to unit " << *it << " join order " << *it); 00134 // we can do this because we know that eval units (= vertices of a vecS adjacency list) are unsigned integers 00135 eg.addDependency(ufinal, *it, FinalEvalGraph::EvalUnitDepPropertyBundle(*it)); 00136 } 00137 } 00138 00139 LOG(INFO,"initial eval/model graph:"); 00140 omb.printEvalGraphModelGraph(std::cerr); 00141 00142 // evaluate 00143 BOOST_TEST_MESSAGE("requesting model #1"); 00144 OptionalModel m1 = omb.getNextIModel(ufinal); 00145 BOOST_REQUIRE(!!m1); 00146 InterpretationConstPtr int1 = omb.getModelGraph().propsOf(m1.get()).interpretation; 00147 BOOST_REQUIRE(int1 != 0); 00148 LOG(INFO,"model #1 is " << *int1); 00149 omb.printEvalGraphModelGraph(std::cerr); 00150 00151 BOOST_TEST_MESSAGE("requesting model #2"); 00152 OptionalModel m2 = omb.getNextIModel(ufinal); 00153 BOOST_REQUIRE(!m2); 00154 omb.printEvalGraphModelGraph(std::cerr); 00155 } 00156