dlvhex  2.5.0
DependencyGraph Class Reference

Implements the rule dependency graph. More...

#include <include/dlvhex2/DependencyGraph.h>

Collaboration diagram for DependencyGraph:

Data Structures

struct  DependencyInfo
 Stores meta information about a single dependency in the graph. More...
struct  HeadBodyHelper
 See boost::graph. More...
struct  HeadBodyInfo
 Stores for a given ordinary atom where it occurs. More...
struct  HeadPredicateTag
 See boost::graph. More...
struct  IDTag
 See boost:graph. More...
struct  InBodyTag
 See boost::graph. More...
struct  InHeadTag
 See boost::graph. More...
struct  NodeInfo
 Meta information about a single node in the graph. More...
struct  NodeMappingInfo
 See boost:graph. More...

Public Types

typedef boost::adjacency_list
< boost::vecS, boost::vecS,
boost::bidirectionalS,
NodeInfo, DependencyInfo
Graph
typedef boost::graph_traits
< Graph
Traits
typedef Graph::vertex_descriptor Node
typedef Graph::edge_descriptor Dependency
typedef Traits::vertex_iterator NodeIterator
typedef Traits::edge_iterator DependencyIterator
typedef Traits::out_edge_iterator PredecessorIterator
typedef Traits::in_edge_iterator SuccessorIterator

Public Member Functions

 DependencyGraph (ProgramCtx &ctx, RegistryPtr registry)
 Constructor.
virtual ~DependencyGraph ()
 Destructor.
void createDependencies (const std::vector< ID > &idb, std::vector< ID > &createdAuxRules)
 Creates all dependencies and auxiliary input rules.
virtual void writeGraphViz (std::ostream &o, bool verbose) const
 Output graph as graphviz source (dot file).
const GraphgetInternalGraph () const
 Retrieves the internal graph.
Node getNode (ID id) const
std::pair< NodeIterator,
NodeIterator
getNodes () const
 Get range over all nodes.
const NodeInfogetNodeInfo (Node node) const
 Get node info given node.
const DependencyInfogetDependencyInfo (Dependency dep) const
 Get dependency info given dependency.
std::pair< PredecessorIterator,
PredecessorIterator
getDependencies (Node node) const
 Get dependencies (to predecessors) = arcs from this node to others.
std::pair< SuccessorIterator,
SuccessorIterator
getProvides (Node node) const
 Get provides (dependencies to successors) = arcs from other nodes to this one.
Node sourceOf (Dependency d) const
 Get source of dependency = node that depends.
Node targetOf (Dependency d) const
 Get target of dependency = node upon which the source depends.
const NodeInfopropsOf (Node n) const
 Get node properties.
NodeInfopropsOf (Node n)
 Get node properties.
const DependencyInfopropsOf (Dependency d) const
 Get dependency properties.
DependencyInfopropsOf (Dependency d)
 Get dependency properties.
unsigned countNodes () const
unsigned countDependencies () const

Protected Types

typedef
boost::multi_index_container
< NodeMappingInfo,
boost::multi_index::indexed_by
< boost::multi_index::hashed_unique
< boost::multi_index::tag
< IDTag >, > > > 
NodeMapping
typedef NodeMapping::index
< IDTag >::type 
NodeIDIndex
typedef std::vector< NodeNodeList

Protected Member Functions

Node createNode (ID id)
 Creates a node and updates the node mapping.
void createNodesAndIntraRuleDependencies (const std::vector< ID > &idb, std::vector< ID > &createdAuxRules, HeadBodyHelper &hbh)
 Creates nodes for rules and external atoms.
void createNodesAndIntraRuleDependenciesForRule (ID idrule, std::vector< ID > &createdAuxRules, HeadBodyHelper &hbh)
 Creates edges for dependencies within rules.
void createNodesAndIntraRuleDependenciesForRuleAddHead (ID idat, const Rule &rule, Node nrule, HeadBodyHelper &hbh)
 Updates the graph after recognizing a head atom.
void createNodesAndIntraRuleDependenciesForBody (ID idlit, ID idrule, const Tuple &body, Node nrule, HeadBodyHelper &hbh, std::vector< ID > &createdAuxRules, bool inAggregateBody=false)
 Updates the graph after recognizing a body atom.
void createAuxiliaryRuleIfRequired (const Tuple &body, ID idlit, ID idat, Node neatom, const ExternalAtom &eatom, const PluginAtom *pluginAtom, std::vector< ID > &createdAuxRules, HeadBodyHelper &hbh)
 This method creates an auxiliary rule for the eatom wrt a rule body (not a rule!).
ID createAuxiliaryRuleHeadPredicate (ID forEAtom)
 Create auxiliary rule head predicate (in registry) and return ID.
ID createAuxiliaryRuleHead (ID idauxpred, const std::list< ID > &variables)
 Create auxiliary rule head (in registry) and return ID.
ID createAuxiliaryRule (ID head, const std::list< ID > &body)
 Create auxiliary rule (in registry) and return ID.
void createExternalPredicateInputDependencies (const HeadBodyHelper &hbh)
 Create "externalPredicateInput" dependencies.
void createExternalPredicateInputDependenciesForInput (bool nonmonotonic, const NodeMappingInfo &ni_eatom, ID predicate, const HeadBodyHelper &hbh)
 Create "externalPredicateInput" dependencies.
void createUnifyingDependencies (const HeadBodyHelper &hbh)
 Build all unifying dependencies ("{positive,negative}{Rule,Constraint}", "unifyingHead").
void createHeadHeadUnifyingDependencies (const HeadBodyHelper &hbh)
 Create "unifyingHead" dependencies.
void createHeadBodyUnifyingDependencies (const HeadBodyHelper &hbh)
 Create "{positive,negative}{Rule,Constraint}" dependencies.
virtual void writeGraphVizNodeLabel (std::ostream &o, Node n, bool verbose) const
 Writes a single node in dot format.
virtual void writeGraphVizDependencyLabel (std::ostream &o, Dependency dep, bool verbose) const
 Writes a single dependency in dot format.

Protected Attributes

ProgramCtxctx
 ProgramCtx.
RegistryPtr registry
 Registry used for resolving IDs.
Graph dg
 Instance of the internal graph.
NodeMapping nm
 See boost::graph.

Private Member Functions

 DependencyGraph (const Dependency &other)
 Copy-constructor.

Detailed Description

Implements the rule dependency graph.

Definition at line 74 of file DependencyGraph.h.


Member Typedef Documentation

typedef Graph::edge_descriptor DependencyGraph::Dependency

Definition at line 179 of file DependencyGraph.h.

typedef Traits::edge_iterator DependencyGraph::DependencyIterator

Definition at line 181 of file DependencyGraph.h.

typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, NodeInfo, DependencyInfo> DependencyGraph::Graph

Definition at line 175 of file DependencyGraph.h.

typedef Graph::vertex_descriptor DependencyGraph::Node

Definition at line 178 of file DependencyGraph.h.

typedef NodeMapping::index<IDTag>::type DependencyGraph::NodeIDIndex [protected]

Definition at line 207 of file DependencyGraph.h.

typedef Traits::vertex_iterator DependencyGraph::NodeIterator

Definition at line 180 of file DependencyGraph.h.

typedef std::vector<Node> DependencyGraph::NodeList [protected]

Definition at line 210 of file DependencyGraph.h.

typedef boost::multi_index_container< NodeMappingInfo, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::tag<IDTag>, > > > DependencyGraph::NodeMapping [protected]

Definition at line 206 of file DependencyGraph.h.

typedef Traits::out_edge_iterator DependencyGraph::PredecessorIterator

Definition at line 182 of file DependencyGraph.h.

typedef Traits::in_edge_iterator DependencyGraph::SuccessorIterator

Definition at line 183 of file DependencyGraph.h.

typedef boost::graph_traits<Graph> DependencyGraph::Traits

Definition at line 176 of file DependencyGraph.h.


Constructor & Destructor Documentation

DependencyGraph::DependencyGraph ( const Dependency other) [private]

Copy-constructor.

Not implemented on purpose because forbidden to use.

Parameters:
otherOther graph.

Constructor.

Parameters:
ctxSee DependencyGraph::ctx.
registrySee DependencyGraph::registry.

Definition at line 100 of file DependencyGraph.cpp.

Destructor.

Definition at line 106 of file DependencyGraph.cpp.


Member Function Documentation

unsigned DependencyGraph::countDependencies ( ) const [inline]

Definition at line 403 of file DependencyGraph.h.

References dg.

unsigned DependencyGraph::countNodes ( ) const [inline]

Definition at line 401 of file DependencyGraph.h.

References dg.

Referenced by ComponentGraph::calculateComponents().

ID DependencyGraph::createAuxiliaryRule ( ID  head,
const std::list< ID > &  body 
) [protected]

Create auxiliary rule (in registry) and return ID.

Parameters:
headHead atom ID.
bodyRule body.
Returns:
ID of the auxiliary rule.

Definition at line 612 of file DependencyGraph.cpp.

References Rule::body, Rule::head, ID::isExternalAtom(), Rule::kind, ID::MAINKIND_RULE, ID::PROPERTY_AUX, ID::PROPERTY_EXTERNALINPUTAUX, ID::PROPERTY_RULE_EXTATOMS, registry, and ID::SUBKIND_RULE_REGULAR.

Referenced by createAuxiliaryRuleIfRequired().

ID DependencyGraph::createAuxiliaryRuleHead ( ID  idauxpred,
const std::list< ID > &  variables 
) [protected]

Create auxiliary rule head (in registry) and return ID.

Parameters:
idauxprePredicate to use in the auxiliary rule.
variablesVariable to pass from the rule body to the head.
Returns:
ID of the auxiliary rule.

Definition at line 576 of file DependencyGraph.cpp.

References ID::MAINKIND_ATOM, RawPrinter::print(), ID::PROPERTY_AUX, ID::PROPERTY_EXTERNALINPUTAUX, registry, ID::SUBKIND_ATOM_ORDINARYN, OrdinaryAtom::text, and Atom::tuple.

Referenced by createAuxiliaryRuleIfRequired().

Create auxiliary rule head predicate (in registry) and return ID.

Parameters:
forEAtomID of the external atom to create an auxiliary rule for.
Returns:
ID of the auxiliary rule for forEAtom.

Definition at line 570 of file DependencyGraph.cpp.

References registry.

Referenced by createAuxiliaryRuleIfRequired().

void DependencyGraph::createAuxiliaryRuleIfRequired ( const Tuple body,
ID  idlit,
ID  idat,
Node  neatom,
const ExternalAtom eatom,
const PluginAtom pluginAtom,
std::vector< ID > &  createdAuxRules,
HeadBodyHelper hbh 
) [protected]

This method creates an auxiliary rule for the eatom wrt a rule body (not a rule!).

* for each eatom in the rule with variable inputs: * create auxiliary input predicate for its input * create auxiliary rule collecting its input, use as dependencies all positive literals (including eatoms) in the rule (this potentially creates many aux rules (cf.

This way we can use the method both for grounding aggregate bodies as well as rule bodies.

* For each eatom in the rule with variable inputs: * create auxiliary input predicate for its input * create auxiliary rule collecting its input, use as dependencies all positive literals (including eatoms) in the rule (this potentially creates many aux rules (cf. extatom2.hex)).

Parameters:
bodyRule body.
idlitBody literal.
idatHead predicate.
neatomNode of external atom eatom.
eatomID of the external atom to create auxiliary rules for.
createdAuxRulesContainer to receive the auxiliary input rules.
hbhInformation about heads and bodies.

extatom2.hex))

Definition at line 357 of file DependencyGraph.cpp.

References ExternalAtom::auxInputMapping, ExternalAtom::auxInputMask, ExternalAtom::auxInputPredicate, PluginAtom::CONSTANT, createAuxiliaryRule(), createAuxiliaryRuleHead(), createAuxiliaryRuleHeadPredicate(), createNodesAndIntraRuleDependenciesForRule(), ctx, Logger::DBG, DBGLOG, DBGLOG_SCOPE, dg, DependencyGraph::DependencyInfo::externalConstantInput, PluginAtom::getInputType(), getNode(), ExternalAtom::inputs, Logger::Instance(), ProgramCtx::liberalSafetyChecker, LOG, RawPrinter::print(), Printer::printmany(), printrange(), printvector(), registry, Atom::tuple, and PluginAtom::TUPLE.

Referenced by createNodesAndIntraRuleDependenciesForBody().

void DependencyGraph::createDependencies ( const std::vector< ID > &  idb,
std::vector< ID > &  createdAuxRules 
)

Creates all dependencies and auxiliary input rules.

Parameters:
idbIDB of the program.
createdAuxRulesContainer to receive the auxiliary input rules.

Definition at line 111 of file DependencyGraph.cpp.

References createExternalPredicateInputDependencies(), createNodesAndIntraRuleDependencies(), and createUnifyingDependencies().

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_FIXTURE_TEST_CASE().

void DependencyGraph::createExternalPredicateInputDependenciesForInput ( bool  nonmonotonic,
const NodeMappingInfo ni_eatom,
ID  predicate,
const HeadBodyHelper hbh 
) [protected]

Create "externalPredicateInput" dependencies.

Parameters:
nonmonotonicSpecifies whether to create a monotonic or nonmonotonic dependency.
ni_eatomSee boost::graph.
predicateInput predicate.
createdAuxRulesContainer to receive the auxiliary input rules.

Definition at line 698 of file DependencyGraph.cpp.

References dg, DependencyGraph::DependencyInfo::externalNonmonotonicPredicateInput, DependencyGraph::DependencyInfo::externalPredicateInput, DependencyGraph::NodeMappingInfo::id, DependencyGraph::HeadBodyHelper::infos, LOG, LOG_SCOPE, DependencyGraph::NodeMappingInfo::node, and propsOf().

Referenced by createExternalPredicateInputDependencies().

Create "{positive,negative}{Rule,Constraint}" dependencies.

Parameters:
createdAuxRulesContainer to receive the auxiliary input rules.

Definition at line 898 of file DependencyGraph.cpp.

References DBGLOG, DBGLOG_SCOPE, DependencyGraph::HeadBodyHelper::infos, LOG, LOG_SCOPE, DependencyGraph::DependencyInfo::negativeRule, DependencyGraph::DependencyInfo::positiveConstraint, DependencyGraph::DependencyInfo::positiveRegularRule, printrange(), printvector(), and registry.

Referenced by createUnifyingDependencies().

Create "unifyingHead" dependencies.

Parameters:
createdAuxRulesContainer to receive the auxiliary input rules.

Definition at line 788 of file DependencyGraph.cpp.

References DBGLOG, DBGLOG_SCOPE, DependencyGraph::DependencyInfo::disjunctive, DependencyGraph::HeadBodyHelper::infos, LOG_SCOPE, printvector(), registry, and DependencyGraph::DependencyInfo::unifyingHead.

Referenced by createUnifyingDependencies().

Creates a node and updates the node mapping.

Parameters:
idNode to create.
Returns:
New node in the graph.

Definition at line 526 of file DependencyGraph.h.

References DBGLOG, dg, and nm.

Referenced by createNodesAndIntraRuleDependenciesForBody(), and createNodesAndIntraRuleDependenciesForRule().

void DependencyGraph::createNodesAndIntraRuleDependencies ( const std::vector< ID > &  idb,
std::vector< ID > &  createdAuxRules,
HeadBodyHelper hbh 
) [protected]

Creates nodes for rules and external atoms.

Create "positiveExternal" and "negativeExternal" dependencies. Create "externalConstantInput" dependencies and auxiliary rules. Fills HeadBodyHelper (required for efficient unification).

Parameters:
idbIDB of the program.
createdAuxRulesContainer to receive the auxiliary input rules.
hbhInformation about heads and bodies.

Definition at line 128 of file DependencyGraph.cpp.

References createNodesAndIntraRuleDependenciesForRule(), DBGLOG, and DBGLOG_SCOPE.

Referenced by createDependencies().

void DependencyGraph::createNodesAndIntraRuleDependenciesForBody ( ID  idlit,
ID  idrule,
const Tuple body,
Node  nrule,
HeadBodyHelper hbh,
std::vector< ID > &  createdAuxRules,
bool  inAggregateBody = false 
) [protected]
void DependencyGraph::createNodesAndIntraRuleDependenciesForRule ( ID  idrule,
std::vector< ID > &  createdAuxRules,
HeadBodyHelper hbh 
) [protected]

Creates edges for dependencies within rules.

Parameters:
idruleID of the rule to create the dependencies for.
createdAuxRulesContainer to receive the auxiliary input rules.
hbhInformation about heads and bodies.

Definition at line 324 of file DependencyGraph.cpp.

References ID::address, Rule::body, createNode(), createNodesAndIntraRuleDependenciesForBody(), createNodesAndIntraRuleDependenciesForRuleAddHead(), DBGLOG, DBGLOG_VSCOPE, Rule::head, ID::isRule(), and registry.

Referenced by createAuxiliaryRuleIfRequired(), and createNodesAndIntraRuleDependencies().

Build all unifying dependencies ("{positive,negative}{Rule,Constraint}", "unifyingHead").

Parameters:
createdAuxRulesContainer to receive the auxiliary input rules.

Definition at line 732 of file DependencyGraph.cpp.

References createHeadBodyUnifyingDependencies(), and createHeadHeadUnifyingDependencies().

Referenced by createDependencies().

Get dependencies (to predecessors) = arcs from this node to others.

Parameters:
NodeSome node of the graph.
Returns:
Pair of begin and end iterator.

Definition at line 357 of file DependencyGraph.h.

References dg.

Referenced by ComponentGraph::calculateComponents().

Get dependency info given dependency.

Parameters:
depSome dependency of the graph.
Returns:
DependencyInfo of dep.

Definition at line 350 of file DependencyGraph.h.

References dg.

Referenced by writeGraphVizDependencyLabel().

const Graph& DependencyGraph::getInternalGraph ( ) const [inline]

Retrieves the internal graph.

Returns:
Internal graph.

Definition at line 323 of file DependencyGraph.h.

References dg.

Referenced by ComponentGraph::calculateComponents().

Node DependencyGraph::getNode ( ID  id) const [inline]

Definition at line 327 of file DependencyGraph.h.

References nm.

Referenced by createAuxiliaryRuleIfRequired().

const NodeInfo& DependencyGraph::getNodeInfo ( Node  node) const [inline]

Get node info given node.

Parameters:
NodeSome node of the graph.
Returns:
NodeInfo of node.

Definition at line 344 of file DependencyGraph.h.

References dg.

Referenced by ComponentGraph::calculateComponents(), writeGraphViz(), and writeGraphVizNodeLabel().

std::pair<NodeIterator, NodeIterator> DependencyGraph::getNodes ( ) const [inline]

Get range over all nodes.

Parameters:
NodeSome node of the graph.
Returns:
NodeInfo of node.

Definition at line 338 of file DependencyGraph.h.

References dg.

Get provides (dependencies to successors) = arcs from other nodes to this one.

Parameters:
NodeSome node of the graph.
Returns:
Pair of begin and end iterator.

Definition at line 364 of file DependencyGraph.h.

References dg.

const NodeInfo& DependencyGraph::propsOf ( Node  n) const [inline]

Get node properties.

Parameters:
NodeSome node of the graph.
Returns:
NodeInfo of n.

Definition at line 382 of file DependencyGraph.h.

References dg.

Referenced by ComponentGraph::calculateComponents(), and createExternalPredicateInputDependenciesForInput().

Get node properties.

Parameters:
NodeSome node of the graph.
Returns:
NodeInfo of n.

Definition at line 387 of file DependencyGraph.h.

References dg.

const DependencyInfo& DependencyGraph::propsOf ( Dependency  d) const [inline]

Get dependency properties.

Parameters:
dSome dependency of the graph.
Returns:
DependencyInfo of d.

Definition at line 392 of file DependencyGraph.h.

References dg.

Get dependency properties.

Parameters:
dSome dependency of the graph.
Returns:
DependencyInfo of d.

Definition at line 397 of file DependencyGraph.h.

References dg.

Node DependencyGraph::sourceOf ( Dependency  d) const [inline]

Get source of dependency = node that depends.

Parameters:
dSome depndency of the graph.
Returns:
Source of d.

Definition at line 370 of file DependencyGraph.h.

References dg.

Referenced by ComponentGraph::calculateComponents(), and writeGraphViz().

Node DependencyGraph::targetOf ( Dependency  d) const [inline]

Get target of dependency = node upon which the source depends.

Parameters:
dSome dependency of the graph.
Returns:
Target of d.

Definition at line 376 of file DependencyGraph.h.

References dg.

Referenced by ComponentGraph::calculateComponents(), and writeGraphViz().

void DependencyGraph::writeGraphViz ( std::ostream &  o,
bool  verbose 
) const [virtual]

Output graph as graphviz source (dot file).

Parameters:
oStream to print the graph to.
verboseTrue to include more information.

Definition at line 1042 of file DependencyGraph.cpp.

References graphviz::escape(), getNodeInfo(), DependencyGraph::NodeInfo::id, ID::isRule(), sourceOf(), targetOf(), writeGraphVizDependencyLabel(), and writeGraphVizNodeLabel().

void DependencyGraph::writeGraphVizNodeLabel ( std::ostream &  o,
Node  n,
bool  verbose 
) const [protected, virtual]

Writes a single node in dot format.

Parameters:
oStream to write to.
nNode to output.
verboseTrue to include more detailed information.

Definition at line 998 of file DependencyGraph.cpp.

References ID::address, getNodeInfo(), DependencyGraph::NodeInfo::id, ID::kind, RawPrinter::print(), registry, and ID::SUBKIND_SHIFT.

Referenced by writeGraphViz().


Field Documentation

ProgramCtx.

Definition at line 286 of file DependencyGraph.h.

Referenced by createAuxiliaryRuleIfRequired().


The documentation for this class was generated from the following files: