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 00031 #ifdef HAVE_CONFIG_H 00032 #include "config.h" 00033 #endif // HAVE_CONFIG_H 00034 00035 #include "dlvhex2/EvalGraph.h" 00036 #include "dlvhex2/CAUAlgorithms.h" 00037 #include "dlvhex2/Logger.h" 00038 00039 // must be included before fixtures! 00040 #define BOOST_TEST_MODULE __FILE__ 00041 #include <boost/test/unit_test.hpp> 00042 00043 #include "fixtureE2.h" 00044 #include "fixtureEx1.h" 00045 00046 #include <boost/foreach.hpp> 00047 #include <boost/graph/graph_traits.hpp> 00048 #include <boost/graph/adjacency_list.hpp> 00049 #include <boost/property_map/vector_property_map.hpp> 00050 #include <boost/concept/assert.hpp> 00051 #include <boost/concept_check.hpp> 00052 00053 #include <iostream> 00054 #include <set> 00055 #include <list> 00056 #include <string> 00057 #include <vector> 00058 #include <cassert> 00059 00060 LOG_INIT(Logger::ERROR | Logger::WARNING) 00061 00062 BOOST_AUTO_TEST_SUITE(root_TestEvalGraph) 00063 00064 BOOST_FIXTURE_TEST_CASE(setup_eval_graph_e2, EvalGraphE2Fixture) 00065 { 00066 BOOST_CHECK_EQUAL(eg.countEvalUnits(), 4); 00067 BOOST_CHECK_EQUAL(eg.countEvalUnitDeps(), 4); 00068 } 00069 00070 BOOST_FIXTURE_TEST_CASE(setup_eval_graph_e2mirrored, EvalGraphE2MirroredFixture) 00071 { 00072 BOOST_CHECK_EQUAL(eg.countEvalUnits(), 4); 00073 BOOST_CHECK_EQUAL(eg.countEvalUnitDeps(), 4); 00074 } 00075 00076 BOOST_FIXTURE_TEST_CASE(eval_graph_e2_findCAUs_markJoinRelevance_u1, EvalGraphE2Fixture) 00077 { 00078 CAUAlgorithms::AncestryPropertyMap apm; 00079 std::set<EvalUnit> caus; 00080 CAUAlgorithms::findCAUs(caus, eg, u1, apm); 00081 CAUAlgorithms::logAPM(apm); 00082 BOOST_REQUIRE_EQUAL(caus.size(), 0); 00083 00084 CAUAlgorithms::JoinRelevancePropertyMap jr; 00085 CAUAlgorithms::markJoinRelevance(jr, eg, u1, caus, apm); 00086 BOOST_CHECK_EQUAL(jr[u1], false); 00087 BOOST_CHECK_EQUAL(jr[u2], false); 00088 BOOST_CHECK_EQUAL(jr[u3], false); 00089 BOOST_CHECK_EQUAL(jr[u4], false); 00090 } 00091 00092 BOOST_FIXTURE_TEST_CASE(eval_graph_e2_findCAUs_markJoinRelevance_u2, EvalGraphE2Fixture) 00093 { 00094 CAUAlgorithms::AncestryPropertyMap apm; 00095 std::set<EvalUnit> caus; 00096 CAUAlgorithms::findCAUs(caus, eg, u2, apm); 00097 CAUAlgorithms::logAPM(apm); 00098 BOOST_CHECK_EQUAL(caus.size(), 0); 00099 00100 CAUAlgorithms::JoinRelevancePropertyMap jr; 00101 CAUAlgorithms::markJoinRelevance(jr, eg, u2, caus, apm); 00102 BOOST_CHECK_EQUAL(jr[u1], false); 00103 BOOST_CHECK_EQUAL(jr[u2], false); 00104 BOOST_CHECK_EQUAL(jr[u3], false); 00105 BOOST_CHECK_EQUAL(jr[u4], false); 00106 } 00107 00108 BOOST_FIXTURE_TEST_CASE(eval_graph_e2_findCAUs_markJoinRelevance_u3, EvalGraphE2Fixture) 00109 { 00110 CAUAlgorithms::AncestryPropertyMap apm; 00111 std::set<EvalUnit> caus; 00112 CAUAlgorithms::findCAUs(caus, eg, u3, apm); 00113 CAUAlgorithms::logAPM(apm); 00114 BOOST_CHECK_EQUAL(caus.size(), 0); 00115 00116 CAUAlgorithms::JoinRelevancePropertyMap jr; 00117 CAUAlgorithms::markJoinRelevance(jr, eg, u3, caus, apm); 00118 BOOST_CHECK_EQUAL(jr[u1], false); 00119 BOOST_CHECK_EQUAL(jr[u2], false); 00120 BOOST_CHECK_EQUAL(jr[u3], false); 00121 BOOST_CHECK_EQUAL(jr[u4], false); 00122 } 00123 00124 BOOST_FIXTURE_TEST_CASE(eval_graph_e2_findCAUs_markJoinRelevance_u4, EvalGraphE2Fixture) 00125 { 00126 CAUAlgorithms::AncestryPropertyMap apm; 00127 std::set<EvalUnit> caus; 00128 CAUAlgorithms::findCAUs(caus, eg, u4, apm); 00129 CAUAlgorithms::logAPM(apm); 00130 BOOST_CHECK_EQUAL(caus.size(), 1); 00131 BOOST_CHECK_EQUAL(caus.count(u1), 1); 00132 00133 CAUAlgorithms::JoinRelevancePropertyMap jr; 00134 CAUAlgorithms::markJoinRelevance(jr, eg, u4, caus, apm); 00135 BOOST_CHECK_EQUAL(jr[u1], false); 00136 BOOST_CHECK_EQUAL(jr[u2], true); 00137 BOOST_CHECK_EQUAL(jr[u3], true); 00138 BOOST_CHECK_EQUAL(jr[u4], false); 00139 } 00140 00141 BOOST_FIXTURE_TEST_CASE(eval_graph_ex1_findCAUs_markJoinRelevance_u4, EvalGraphEx1Fixture) 00142 { 00143 CAUAlgorithms::AncestryPropertyMap apm; 00144 std::set<EvalUnit> caus; 00145 CAUAlgorithms::findCAUs(caus, eg, u4, apm); 00146 CAUAlgorithms::logAPM(apm); 00147 BOOST_REQUIRE_EQUAL(caus.size(), 0); 00148 00149 CAUAlgorithms::JoinRelevancePropertyMap jr; 00150 CAUAlgorithms::markJoinRelevance(jr, eg, u4, caus, apm); 00151 BOOST_CHECK_EQUAL(jr[u1], false); 00152 BOOST_CHECK_EQUAL(jr[u2], false); 00153 BOOST_CHECK_EQUAL(jr[u3], false); 00154 BOOST_CHECK_EQUAL(jr[u4], false); 00155 BOOST_CHECK_EQUAL(jr[u5], false); 00156 BOOST_CHECK_EQUAL(jr[u6], false); 00157 BOOST_CHECK_EQUAL(jr[u7], false); 00158 BOOST_CHECK_EQUAL(jr[u8], false); 00159 BOOST_CHECK_EQUAL(jr[u9], false); 00160 BOOST_CHECK_EQUAL(jr[u10], false); 00161 BOOST_CHECK_EQUAL(jr[u11], false); 00162 } 00163 00164 BOOST_FIXTURE_TEST_CASE(eval_graph_ex1_findCAUs_markJoinRelevance_u7, EvalGraphEx1Fixture) 00165 { 00166 CAUAlgorithms::AncestryPropertyMap apm; 00167 std::set<EvalUnit> caus; 00168 CAUAlgorithms::findCAUs(caus, eg, u7, apm); 00169 CAUAlgorithms::logAPM(apm); 00170 BOOST_REQUIRE_EQUAL(caus.size(), 1); 00171 BOOST_REQUIRE_EQUAL(caus.count(u2), 1); 00172 00173 CAUAlgorithms::JoinRelevancePropertyMap jr; 00174 CAUAlgorithms::markJoinRelevance(jr, eg, u7, caus, apm); 00175 BOOST_CHECK_EQUAL(jr[u1], false); 00176 BOOST_CHECK_EQUAL(jr[u2], false); 00177 BOOST_CHECK_EQUAL(jr[u3], false); 00178 BOOST_CHECK_EQUAL(jr[u4], true); 00179 BOOST_CHECK_EQUAL(jr[u5], true); 00180 BOOST_CHECK_EQUAL(jr[u6], true); 00181 BOOST_CHECK_EQUAL(jr[u7], false); 00182 BOOST_CHECK_EQUAL(jr[u8], false); 00183 BOOST_CHECK_EQUAL(jr[u9], false); 00184 BOOST_CHECK_EQUAL(jr[u10], false); 00185 BOOST_CHECK_EQUAL(jr[u11], false); 00186 } 00187 00188 BOOST_FIXTURE_TEST_CASE(eval_graph_ex1_findCAUs_markJoinRelevance_u9, EvalGraphEx1Fixture) 00189 { 00190 CAUAlgorithms::AncestryPropertyMap apm; 00191 std::set<EvalUnit> caus; 00192 CAUAlgorithms::findCAUs(caus, eg, u9, apm); 00193 CAUAlgorithms::logAPM(apm); 00194 BOOST_REQUIRE_EQUAL(caus.size(), 0); 00195 00196 CAUAlgorithms::JoinRelevancePropertyMap jr; 00197 CAUAlgorithms::markJoinRelevance(jr, eg, u9, caus, apm); 00198 BOOST_CHECK_EQUAL(jr[u1], false); 00199 BOOST_CHECK_EQUAL(jr[u2], false); 00200 BOOST_CHECK_EQUAL(jr[u3], false); 00201 BOOST_CHECK_EQUAL(jr[u4], false); 00202 BOOST_CHECK_EQUAL(jr[u5], false); 00203 BOOST_CHECK_EQUAL(jr[u6], false); 00204 BOOST_CHECK_EQUAL(jr[u7], false); 00205 BOOST_CHECK_EQUAL(jr[u8], false); 00206 BOOST_CHECK_EQUAL(jr[u9], false); 00207 BOOST_CHECK_EQUAL(jr[u10], false); 00208 BOOST_CHECK_EQUAL(jr[u11], false); 00209 } 00210 00211 BOOST_FIXTURE_TEST_CASE(eval_graph_ex1_findCAUs_markJoinRelevance_u11, EvalGraphEx1Fixture) 00212 { 00213 CAUAlgorithms::AncestryPropertyMap apm; 00214 std::set<EvalUnit> caus; 00215 CAUAlgorithms::findCAUs(caus, eg, u11, apm); 00216 CAUAlgorithms::logAPM(apm); 00217 BOOST_REQUIRE_EQUAL(caus.size(), 1); 00218 BOOST_REQUIRE_EQUAL(caus.count(u7), 1); 00219 00220 CAUAlgorithms::JoinRelevancePropertyMap jr; 00221 CAUAlgorithms::markJoinRelevance(jr, eg, u11, caus, apm); 00222 BOOST_CHECK_EQUAL(jr[u1], false); 00223 BOOST_CHECK_EQUAL(jr[u2], false); 00224 BOOST_CHECK_EQUAL(jr[u3], false); 00225 BOOST_CHECK_EQUAL(jr[u4], false); 00226 BOOST_CHECK_EQUAL(jr[u5], false); 00227 BOOST_CHECK_EQUAL(jr[u6], false); 00228 BOOST_CHECK_EQUAL(jr[u7], false); 00229 BOOST_CHECK_EQUAL(jr[u8], false); 00230 BOOST_CHECK_EQUAL(jr[u9], true); 00231 BOOST_CHECK_EQUAL(jr[u10], true); 00232 BOOST_CHECK_EQUAL(jr[u11], false); 00233 } 00234 00235 BOOST_AUTO_TEST_SUITE_END()