BOOST_FIXTURE_TEST_CASE(testExtCountReach,ProgramExt1ProgramCtxFixture) { LOG_REGISTRY_PROGRAM(ctx); /* // full dependency graph { // clone registry, because full depgraph will modify it for auxiliary rules RegistryPtr cloneRegistry(new Registry(*ctx.registry())); DependencyGraphFull depgraph(cloneRegistry); depgraph.createNodesAndBasicDependencies(ctx.idb); depgraph.createUnifyingDependencies(); std::vector<ID> auxRules; depgraph.createExternalDependencies(auxRules); BOOST_CHECK_EQUAL(auxRules.size(), 1); BOOST_CHECK_EQUAL(depgraph.countNodes(), 13+2); // 1 aux rule + 1 aux predicate BOOST_CHECK_EQUAL(depgraph.countDependencies(), 12+3); // 3 aux dependencies const char* fnamev = "testDependencyGraphExtCountReachFullVerbose.dot"; LOG(INFO,"dumping verbose graph to " << fnamev); std::ofstream filev(fnamev); depgraph.writeGraphViz(filev, true); makeGraphVizPdf(fnamev); const char* fnamet = "testDependencyGraphExtCountReachFullTerse.dot"; LOG(INFO,"dumping terse graph to " << fnamet); std::ofstream filet(fnamet); depgraph.writeGraphViz(filet, false); makeGraphVizPdf(fnamet); } */ // smaller more efficient dependency graph { DependencyGraph depgraph(ctx, ctx.registry()); std::vector<ID> auxRules; depgraph.createDependencies(ctx.idb, auxRules); // TODO //BOOST_CHECK_EQUAL(depgraph.countNodes(), 10); //BOOST_CHECK_EQUAL(depgraph.countDependencies(), 13); // TODO test dependencies (will do manually with graphviz at the moment) const char* fnamev = "testDependencyGraphExtCountReachVerbose.dot"; LOG(INFO,"dumping verbose graph to " << fnamev); std::ofstream filev(fnamev); depgraph.writeGraphViz(filev, true); makeGraphVizPdf(fnamev); const char* fnamet = "testDependencyGraphExtCountReachTerse.dot"; LOG(INFO,"dumping terse graph to " << fnamet); std::ofstream filet(fnamet); depgraph.writeGraphViz(filet, false); makeGraphVizPdf(fnamet); } }
DLVHEX_NAMESPACE_USE BOOST_AUTO_TEST_CASE(testDisj) { ProgramCtx ctx; ctx.setupRegistry(RegistryPtr(new Registry)); std::stringstream ss; ss << // a <-(+)-> a (head/head = disjunctive) "a v b." << std::endl << "a v c." << std::endl; InputProviderPtr ip(new InputProvider); ip->addStreamInput(ss, "testinput"); ModuleHexParser parser; BOOST_REQUIRE_NO_THROW(parser.parse(ip, ctx)); LOG_REGISTRY_PROGRAM(ctx); ID ida = ctx.registry()->ogatoms.getIDByString("a"); ID idb = ctx.registry()->ogatoms.getIDByString("b"); ID idc = ctx.registry()->ogatoms.getIDByString("c"); BOOST_REQUIRE((ida | idb | idc) != ID_FAIL); // smaller more efficient dependency graph { DependencyGraph depgraph(ctx, ctx.registry()); std::vector<ID> auxRules; depgraph.createDependencies(ctx.idb, auxRules); BOOST_CHECK_EQUAL(depgraph.countNodes(), 2); BOOST_CHECK_EQUAL(depgraph.countDependencies(), 2); // TODO test dependencies (will do manually with graphviz at the moment) const char* fnamev = "testDependencyGraphDisjVerbose.dot"; LOG(INFO,"dumping verbose graph to " << fnamev); std::ofstream filev(fnamev); depgraph.writeGraphViz(filev, true); makeGraphVizPdf(fnamev); const char* fnamet = "testDependencyGraphDisjTerse.dot"; LOG(INFO,"dumping terse graph to " << fnamet); std::ofstream filet(fnamet); depgraph.writeGraphViz(filet, false); makeGraphVizPdf(fnamet); } }
void manager::on_message(connection_ptr conn, message_ptr msg) { const string content(msg->get_payload()); Value ret; cleanup(); // do some maintenance if(read(content, ret) && is_obj(ret)) { Object obj(ret.get_obj()); Value type(get_field_from_obj(obj, "msg")); if(is_string(type)) { const string& str(type.get_str()); if(str == "next") { client *cl(get_client(conn)); cl->counter++; } else if(str == "load_temp") { Value filev(get_field_from_obj(obj, "file")); string file(filev.get_str()); if(valid_temp_file(file)) { client *cl(get_client(conn)); cl->done = false; cl->counter = 0; if(cl->th != NULL) { delete cl->th; cl->th = NULL; } boost::thread *th = new boost::thread(boost::bind(&ui::manager::start_file, this, file, cl, true)); cl->th = th; } } else if(str == "load" || str == "load_temp") { Value filev(get_field_from_obj(obj, "file")); string file(filev.get_str()); client *cl(get_client(conn)); cl->done = false; cl->counter = 0; if(cl->th != NULL) { delete cl->th; cl->th = NULL; } boost::thread *th = new boost::thread(boost::bind(&ui::manager::start_file, this, file, cl, false)); cl->th = th; } else if(str == "jump") { Value node(get_field_from_obj(obj, "steps")); if(is_int(node)) { const int steps(node.get_int()); client *cl(get_client(conn)); cl->counter += steps; } } else if(str == "get_node") { Value node(get_field_from_obj(obj, "node")); if(is_int(node)) { db::node::node_id id((db::node::node_id)node.get_int()); DECLARE_JSON("node"); ADD_FIELD("node", (int)id); ADD_FIELD("info", sched::serial_ui_local::dump_node(id)); SEND_JSON(conn); } } else if(str == "change_node") { Value node(get_field_from_obj(obj, "node")); if(is_int(node)) { db::node::node_id id((db::node::node_id)node.get_int()); sched::serial_ui_local::change_node(id); DECLARE_JSON("changed_node"); ADD_FIELD("node", (int)id); SEND_JSON(conn); } } else if(str == "terminate") { client* cl(get_client(conn)); cl->done = true; } else { cerr << "Message not recognized: " << str << endl; } } } }