knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::DependencyGraph Class Reference

#include <DependencyGraph.h>

Public Member Functions

 DependencyGraph ()=default
 
 ~DependencyGraph ()
 
 DependencyGraph (const DependencyGraph &other)=delete
 
void operator+= (const DependencyNodePtr &node)
 
void insert (const DependencyNodePtr &node)
 
void insert (const FirstOrderLiteralPtr &literal)
 
void insert (const std::vector< FirstOrderLiteralPtr > &literals)
 
template<typename Iterator >
void insert (Iterator begin, Iterator end)
 
auto begin () const
 
auto end () const
 
auto numNodes () const
 
auto numGroups () const
 
 DependencyGraph ()=default
 
 ~DependencyGraph ()
 
 DependencyGraph (const DependencyGraph &other)=delete
 
void operator+= (const DependencyNodePtr &node)
 
void insert (const DependencyNodePtr &node)
 
void insert (const FirstOrderLiteralPtr &literal)
 
void insert (const std::vector< FirstOrderLiteralPtr > &literals)
 
template<typename Iterator >
void insert (Iterator begin, Iterator end)
 
auto begin () const
 
auto end () const
 
auto numNodes () const
 
auto numGroups () const
 

Protected Attributes

std::list< DependencyNodePtrnodes_
 
std::list< DependencyGroupgroups_
 

Detailed Description

A graph capturing a dependency relation between literals in a formula. Two literals are viewed as dependant in case they share a free variable. Here, labeled literals are considered.

Definition at line 75 of file DependencyGraph.h.

Constructor & Destructor Documentation

◆ DependencyGraph() [1/4]

knowrob::DependencyGraph::DependencyGraph ( )
default

◆ ~DependencyGraph() [1/2]

DependencyGraph::~DependencyGraph ( )

Definition at line 20 of file DependencyGraph.cpp.

21 {
22  for (auto &node : nodes_) {
23  node->neighbors_.clear();
24  }
25  nodes_.clear();
26  groups_.clear();
27 }
std::list< DependencyGroup > groups_
std::list< DependencyNodePtr > nodes_

◆ DependencyGraph() [2/4]

knowrob::DependencyGraph::DependencyGraph ( const DependencyGraph other)
delete

◆ DependencyGraph() [3/4]

knowrob::DependencyGraph::DependencyGraph ( )
default

◆ ~DependencyGraph() [2/2]

knowrob::DependencyGraph::~DependencyGraph ( )

◆ DependencyGraph() [4/4]

knowrob::DependencyGraph::DependencyGraph ( const DependencyGraph other)
delete

Member Function Documentation

◆ begin() [1/2]

auto knowrob::DependencyGraph::begin ( ) const
inline
Returns
begin iterator over literals in a path.

Definition at line 128 of file DependencyGraph.h.

128 { return groups_.begin(); }

◆ begin() [2/2]

auto knowrob::DependencyGraph::begin ( ) const
inline
Returns
begin iterator over literals in a path.

Definition at line 128 of file DependencyGraph.h.

128 { return groups_.begin(); }

◆ end() [1/2]

auto knowrob::DependencyGraph::end ( ) const
inline
Returns
end iterator over literals in a path.

Definition at line 133 of file DependencyGraph.h.

133 { return groups_.end(); }

◆ end() [2/2]

auto knowrob::DependencyGraph::end ( ) const
inline
Returns
end iterator over literals in a path.

Definition at line 133 of file DependencyGraph.h.

133 { return groups_.end(); }

◆ insert() [1/8]

void DependencyGraph::insert ( const DependencyNodePtr node)

Add a new node to the graph and compute dependency relation with other nodes.

Parameters
nodea dependency node.

Definition at line 45 of file DependencyGraph.cpp.

46 {
47  nodes_.push_back(newNode);
48 
49  // find the modal node groups that have a shared variable with newNode.
50  std::list<std::list<DependencyGroup>::iterator > dependencies;
51  for(auto it=groups_.begin(); it!=groups_.end(); ++it) {
52  if(has_intersection(it->variables_, newNode->variables())) {
53  dependencies.push_back(it);
54  }
55  }
56 
57  DependencyGroup *newNodeGroup = nullptr;
58  if(dependencies.empty()) {
59  // the literal does not have a shared variable with an existing group.
60  // create a new one with just the literal as a member.
61  auto &newGroup = groups_.emplace_back();
62  newNodeGroup = &newGroup;
63  }
64  else if(dependencies.size()==1) {
65  // add to group
66  auto &group = *dependencies.front();
67  newNodeGroup = &group;
68  }
69  else {
70  // merge multiple groups into one
71  auto &newGroup = groups_.emplace_back();
72  for(auto groupIterator : dependencies) {
73  newGroup += *groupIterator;
74  groups_.erase(groupIterator);
75  }
76  newNodeGroup = &newGroup;
77  }
78  // update neighbor relation based on shared variables with other nodes
79  for(auto &x : newNodeGroup->member_) {
80  if(has_intersection(x->variables(), newNode->variables())) {
81  x->neighbors_.push_back(newNode);
82  newNode->neighbors_.push_back(x);
83  }
84  }
85  // finally add the new node to the group
86  newNodeGroup->member_.push_back(newNode);
87  newNodeGroup->variables_.insert(newNode->variables().begin(), newNode->variables().end());
88 }
std::list< DependencyNodePtr > member_
std::set< std::string_view > variables_

◆ insert() [2/8]

void knowrob::DependencyGraph::insert ( const DependencyNodePtr node)

Add a new node to the graph and compute dependency relation with other nodes.

Parameters
nodea dependency node.

◆ insert() [3/8]

void DependencyGraph::insert ( const FirstOrderLiteralPtr literal)

Add a new node to the graph and compute dependency relation with other nodes.

Parameters
literala literal.

Definition at line 40 of file DependencyGraph.cpp.

41 {
42  insert(std::make_shared<DependencyNode>(literal));
43 }
void insert(const DependencyNodePtr &node)

◆ insert() [4/8]

void knowrob::DependencyGraph::insert ( const FirstOrderLiteralPtr literal)

Add a new node to the graph and compute dependency relation with other nodes.

Parameters
literala literal.

◆ insert() [5/8]

void DependencyGraph::insert ( const std::vector< FirstOrderLiteralPtr > &  literals)

Add a new node to the graph and compute dependency relation with other nodes.

Parameters
literalsset of literals considered in conjunction.

Definition at line 34 of file DependencyGraph.cpp.

35 {
36  for(auto &l : literals)
37  insert(std::make_shared<DependencyNode>(l));
38 }

◆ insert() [6/8]

void knowrob::DependencyGraph::insert ( const std::vector< FirstOrderLiteralPtr > &  literals)

Add a new node to the graph and compute dependency relation with other nodes.

Parameters
literalsset of literals considered in conjunction.

◆ insert() [7/8]

template<typename Iterator >
void knowrob::DependencyGraph::insert ( Iterator  begin,
Iterator  end 
)
inline

Insert a node for each iteration.

Template Parameters
Iteratoran iterator with ++ and * operator
Parameters
beginmarks begin of iteration
endmarks end of iteration

Definition at line 117 of file DependencyGraph.h.

117  {
118  while (begin != end) {
119  auto next = *begin;
120  insert(next);
121  ++begin;
122  }
123  }

◆ insert() [8/8]

template<typename Iterator >
void knowrob::DependencyGraph::insert ( Iterator  begin,
Iterator  end 
)
inline

Insert a node for each iteration.

Template Parameters
Iteratoran iterator with ++ and * operator
Parameters
beginmarks begin of iteration
endmarks end of iteration

Definition at line 117 of file DependencyGraph.h.

117  {
118  while (begin != end) {
119  auto next = *begin;
120  insert(next);
121  ++begin;
122  }
123  }

◆ numGroups() [1/2]

auto knowrob::DependencyGraph::numGroups ( ) const
inline
Returns
number of dependency groups among modalFrame labeled nodes.

Definition at line 143 of file DependencyGraph.h.

143 { return groups_.size(); }

◆ numGroups() [2/2]

auto knowrob::DependencyGraph::numGroups ( ) const
inline
Returns
number of dependency groups among modalFrame labeled nodes.

Definition at line 143 of file DependencyGraph.h.

143 { return groups_.size(); }

◆ numNodes() [1/2]

auto knowrob::DependencyGraph::numNodes ( ) const
inline
Returns
number of nodes with modalFrame label.

Definition at line 138 of file DependencyGraph.h.

138 { return nodes_.size(); }

◆ numNodes() [2/2]

auto knowrob::DependencyGraph::numNodes ( ) const
inline
Returns
number of nodes with modalFrame label.

Definition at line 138 of file DependencyGraph.h.

138 { return nodes_.size(); }

◆ operator+=() [1/2]

void DependencyGraph::operator+= ( const DependencyNodePtr node)

Same as insert(node).

Parameters
nodea dependency node.

Definition at line 29 of file DependencyGraph.cpp.

30 {
31  insert(node);
32 }

◆ operator+=() [2/2]

void knowrob::DependencyGraph::operator+= ( const DependencyNodePtr node)

Same as insert(node).

Parameters
nodea dependency node.

Member Data Documentation

◆ groups_

std::list< DependencyGroup > knowrob::DependencyGraph::groups_
protected

Definition at line 147 of file DependencyGraph.h.

◆ nodes_

std::list< DependencyNodePtr > knowrob::DependencyGraph::nodes_
protected

Definition at line 146 of file DependencyGraph.h.


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