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 00036 #ifndef FIXTURES_MCS_HPP_INCLUDED__08112010 00037 #define FIXTURES_MCS_HPP_INCLUDED__08112010 00038 00039 #include "dlvhex2/PlatformDefinitions.h" 00040 #include "dlvhex2/ComponentGraph.h" 00041 #include "dlvhex2/DependencyGraph.h" 00042 #include "dlvhex2/HexParser.h" 00043 #include "dlvhex2/InputProvider.h" 00044 #include "dlvhex2/ProgramCtx.h" 00045 #include "dlvhex2/Registry.h" 00046 #include "dlvhex2/PluginInterface.h" 00047 #include "fixturesDepgraphCompgraphGeneric.h" 00048 00049 class TestPluginAspCtxAcc: 00050 public dlvhex::PluginAtom 00051 { 00052 public: 00053 TestPluginAspCtxAcc(): 00054 dlvhex::PluginAtom("dlv_asp_context_acc", false) 00055 { 00056 addInputConstant(); 00057 addInputPredicate(); 00058 addInputPredicate(); 00059 addInputPredicate(); 00060 addInputConstant(); 00061 outputSize = 0; 00062 } 00063 00064 // won't be used 00065 virtual void retrieve(const Query&, Answer&) throw (dlvhex::PluginError) 00066 { assert(false); } 00067 }; 00068 00069 // provide program for equilibrium calculation 00070 // parse into ProgramCtx 00071 // register dummy atoms 00072 struct ProgramMCSMedEQProgramCtxFixture 00073 { 00074 std::string program; 00075 dlvhex::ProgramCtx ctx; 00076 dlvhex::PluginAtomPtr papAspCtxAcc; 00077 00078 ProgramMCSMedEQProgramCtxFixture(); 00079 ~ProgramMCSMedEQProgramCtxFixture() {} 00080 }; 00081 00082 typedef GenericDepGraphFixture<ProgramMCSMedEQProgramCtxFixture> 00083 ProgramMCSMedEQProgramCtxDependencyGraphFixture; 00084 typedef GenericDepGraphCompGraphFixture<ProgramMCSMedEQProgramCtxFixture> 00085 ProgramMCSMedEQProgramCtxDependencyGraphComponentGraphFixture; 00086 00087 // provide program for diagnosis calculation 00088 // parse into ProgramCtx 00089 // register dummy atoms 00090 struct ProgramMCSMedDProgramCtxFixture 00091 { 00092 std::string program; 00093 dlvhex::ProgramCtx ctx; 00094 dlvhex::PluginAtomPtr papAspCtxAcc; 00095 00096 ProgramMCSMedDProgramCtxFixture(); 00097 ~ProgramMCSMedDProgramCtxFixture() {} 00098 }; 00099 00100 typedef GenericDepGraphFixture<ProgramMCSMedDProgramCtxFixture> 00101 ProgramMCSMedDProgramCtxDependencyGraphFixture; 00102 typedef GenericDepGraphCompGraphFixture<ProgramMCSMedDProgramCtxFixture> 00103 ProgramMCSMedDProgramCtxDependencyGraphComponentGraphFixture; 00104 00105 // 00106 // implementation 00107 // 00108 00109 ProgramMCSMedEQProgramCtxFixture::ProgramMCSMedEQProgramCtxFixture(): 00110 papAspCtxAcc(new TestPluginAspCtxAcc) 00111 { 00112 using namespace dlvhex; 00113 ctx.setupRegistry(RegistryPtr(new Registry)); 00114 00115 ctx.addPluginAtom(papAspCtxAcc); 00116 00117 // program was obtained from trunk of mcs-ie via 'dlvhex --verbose=15 --plugindir=`pwd`/../build/src medExample/master.hex --ieenable --ieuseKR2010rewriting' 00118 std::stringstream ss; 00119 ss << 00120 "foo(X,c) :- bar. foo(c,Y) :- baz." << std::endl << // this is not from MCS, but required to test scc dependencies! 00121 "o2(xray_pneumonia)." << std::endl << 00122 "b3(pneumonia) :- a2(xray_pneumonia)." << std::endl << 00123 "o2(blood_marker)." << std::endl << 00124 "b3(marker) :- a2(blood_marker)." << std::endl << 00125 "o3(pneumonia)." << std::endl << 00126 "b4(need_ab) :- a3(pneumonia)." << std::endl << 00127 "o3(atyppneumonia)." << std::endl << 00128 "b4(need_strong) :- a3(atyppneumonia)." << std::endl << 00129 "o1(allergy_strong_ab)." << std::endl << 00130 "b4(allow_strong_ab) :- na1(allergy_strong_ab)." << std::endl << 00131 "a1(X) v na1(X) :- o1(X)." << std::endl << 00132 ":- not &dlv_asp_context_acc[1,a1,b1,o1,\"./medExample/kb1.dlv\"]()." << std::endl << 00133 "ctx(1)." << std::endl << 00134 "a2(X) v na2(X) :- o2(X)." << std::endl << 00135 ":- not &dlv_asp_context_acc[2,a2,b2,o2,\"./medExample/kb2.dlv\"]()." << std::endl << 00136 "ctx(2)." << std::endl << 00137 "a3(X) v na3(X) :- o3(X)." << std::endl << 00138 ":- not &dlv_asp_context_acc[3,a3,b3,o3,\"./medExample/kb3.dlv\"]()." << std::endl << 00139 "ctx(3)." << std::endl << 00140 "a4(X) v na4(X) :- o4(X)." << std::endl << 00141 ":- not &dlv_asp_context_acc[4,a4,b4,o4,\"./medExample/kb4.dlv\"]()." << std::endl << 00142 "ctx(4)." << std::endl; 00143 InputProviderPtr ip(new InputProvider); 00144 ip->addStreamInput(ss, "testcase"); 00145 ModuleHexParser parser; 00146 parser.parse(ip, ctx); 00147 00148 ctx.associateExtAtomsWithPluginAtoms(ctx.idb, true); 00149 } 00150 00151 ProgramMCSMedDProgramCtxFixture::ProgramMCSMedDProgramCtxFixture(): 00152 papAspCtxAcc(new TestPluginAspCtxAcc) 00153 { 00154 using namespace dlvhex; 00155 ctx.setupRegistry(RegistryPtr(new Registry)); 00156 00157 ctx.addPluginAtom(papAspCtxAcc); 00158 00159 // program was obtained from trunk of mcs-ie via 'dlvhex --verbose=15 --plugindir=`pwd`/../build/src medExample/master.hex --ieenable --ieuseKR2010rewriting --ieexplain=D' 00160 std::stringstream ss; 00161 ss << 00162 "o2(xray_pneumonia)." << std::endl << 00163 "normal(r1) v d1(r1) v d2(r1)." << std::endl << 00164 "b3(pneumonia) :- d2(r1)." << std::endl << 00165 "b3(pneumonia) :- not d1(r1), a2(xray_pneumonia)." << std::endl << 00166 "o2(blood_marker)." << std::endl << 00167 "normal(r2) v d1(r2) v d2(r2)." << std::endl << 00168 "b3(marker) :- d2(r2)." << std::endl << 00169 "b3(marker) :- not d1(r2), a2(blood_marker)." << std::endl << 00170 "o3(pneumonia)." << std::endl << 00171 "normal(r3) v d1(r3) v d2(r3)." << std::endl << 00172 "b4(need_ab) :- d2(r3)." << std::endl << 00173 "b4(need_ab) :- not d1(r3), a3(pneumonia)." << std::endl << 00174 "o3(atyppneumonia)." << std::endl << 00175 "normal(r4) v d1(r4) v d2(r4)." << std::endl << 00176 "b4(need_strong) :- d2(r4)." << std::endl << 00177 "b4(need_strong) :- not d1(r4), a3(atyppneumonia)." << std::endl << 00178 "o1(allergy_strong_ab)." << std::endl << 00179 "normal(r5) v d1(r5) v d2(r5)." << std::endl << 00180 "b4(allow_strong_ab) :- d2(r5)." << std::endl << 00181 "b4(allow_strong_ab) :- not d1(r5), na1(allergy_strong_ab)." << std::endl << 00182 "a1(X) v na1(X) :- o1(X)." << std::endl << 00183 ":- not &dlv_asp_context_acc[1,a1,b1,o1,\"./medExample/kb1.dlv\"]()." << std::endl << 00184 "ctx(1)." << std::endl << 00185 "a2(X) v na2(X) :- o2(X)." << std::endl << 00186 ":- not &dlv_asp_context_acc[2,a2,b2,o2,\"./medExample/kb2.dlv\"]()." << std::endl << 00187 "ctx(2)." << std::endl << 00188 "a3(X) v na3(X) :- o3(X)." << std::endl << 00189 ":- not &dlv_asp_context_acc[3,a3,b3,o3,\"./medExample/kb3.dlv\"]()." << std::endl << 00190 "ctx(3)." << std::endl << 00191 "a4(X) v na4(X) :- o4(X)." << std::endl << 00192 ":- not &dlv_asp_context_acc[4,a4,b4,o4,\"./medExample/kb4.dlv\"]()." << std::endl << 00193 "ctx(4)." << std::endl; 00194 InputProviderPtr ip(new InputProvider); 00195 ip->addStreamInput(ss, "testcase"); 00196 ModuleHexParser parser; 00197 parser.parse(ip, ctx); 00198 00199 ctx.associateExtAtomsWithPluginAtoms(ctx.idb, true); 00200 } 00201 00202 #endif // FIXTURES_MCS_HPP_INCLUDED__08112010