aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::prm::gspan::DFSCode Class Reference

Reprensent a Depth First Search coding of a graph. More...

#include <agrum/PRM/gspan/DFSCode.h>

Public Attributes

std::vector< EdgeCode *> codes
 The vector containing the EdgeCode composing this DFSCode. More...
 

Public Member Functions

 DFSCode ()
 Default constructor. More...
 
 DFSCode (const DFSCode &source)
 Copy constructor. More...
 
 ~DFSCode ()
 Destructor. More...
 
DFSCodeoperator= (const DFSCode &source)
 Copy operator. More...
 
bool operator== (const DFSCode &code) const
 Equality operator. More...
 
bool operator!= (const DFSCode &code) const
 Difference operator. More...
 
bool operator< (const DFSCode &code) const
 Lesser than operator. More...
 
bool operator<= (const DFSCode &code) const
 Lesser or equal than operator. More...
 

Static Public Member Functions

static bool validNeighbors (EdgeCode *e1, EdgeCode *e2)
 Returns true of e2 is a valid neighbor for e1 (i.e. More...
 

Public Types

typedef std::vector< EdgeCode *>::iterator iterator
 Code alias. More...
 
typedef std::vector< EdgeCode *>::const_iterator const_iterator
 Code alias. More...
 

Detailed Description

Reprensent a Depth First Search coding of a graph.

A DFSCode is composed of EdgeCode. Each EdgeCode is either a forward edge or a backward edge.

Regarding memory allocation EdgeCode are shared between related DFSCode, so delete DFSCode in a bottom up fashion.

Definition at line 52 of file DFSCode.h.

Member Typedef Documentation

◆ const_iterator

Code alias.

Definition at line 130 of file DFSCode.h.

◆ iterator

Code alias.

Definition at line 127 of file DFSCode.h.

Constructor & Destructor Documentation

◆ DFSCode() [1/2]

INLINE gum::prm::gspan::DFSCode::DFSCode ( )

Default constructor.

Create an empty DFSCode.

Definition at line 34 of file DFSCode_inl.h.

References gum::prm::gspan::operator<<().

34  {
35  GUM_CONSTRUCTOR(DFSCode);
36  ;
37  }
DFSCode()
Default constructor.
Definition: DFSCode_inl.h:34
+ Here is the call graph for this function:

◆ DFSCode() [2/2]

INLINE gum::prm::gspan::DFSCode::DFSCode ( const DFSCode source)

Copy constructor.

Proceeds with a deep copy.

Definition at line 40 of file DFSCode_inl.h.

References gum::prm::gspan::operator<<().

40  {
41  GUM_CONS_CPY(DFSCode);
42 
43  for (const auto code: source.codes)
44  codes.push_back(new EdgeCode(*code));
45  }
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
DFSCode()
Default constructor.
Definition: DFSCode_inl.h:34
+ Here is the call graph for this function:

◆ ~DFSCode()

INLINE gum::prm::gspan::DFSCode::~DFSCode ( )

Destructor.

This will delete all children of this DFSCode, with their respective EdgeCode.

Definition at line 48 of file DFSCode_inl.h.

References gum::prm::gspan::operator<<().

48  {
49  GUM_DESTRUCTOR(DFSCode);
50 
51  for (const auto item: codes)
52  delete item;
53  }
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
DFSCode()
Default constructor.
Definition: DFSCode_inl.h:34
+ Here is the call graph for this function:

Member Function Documentation

◆ operator!=()

INLINE bool gum::prm::gspan::DFSCode::operator!= ( const DFSCode code) const

Difference operator.

Parameters
codeThe code tested for difference with this.
Returns
Returns true if this and code are different.

Definition at line 80 of file DFSCode_inl.h.

References gum::prm::gspan::operator<<().

80  {
81  if (codes.size() == from.codes.size()) {
82  for (size_t idx = 0; idx < codes.size(); ++idx) {
83  if ((*codes[idx]) != (*codes[idx])) { return true; }
84  }
85 
86  return false;
87  } else {
88  return true;
89  }
90  }
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
+ Here is the call graph for this function:

◆ operator<()

INLINE bool gum::prm::gspan::DFSCode::operator< ( const DFSCode code) const

Lesser than operator.

Parameters
codeThe code on which the test is made.
Returns
Returns true if this is lesser than code.

Definition at line 93 of file DFSCode_inl.h.

References gum::prm::gspan::operator<<().

93  {
94  DFSCode::const_iterator iter = codes.begin();
95  DFSCode::const_iterator jter = from.codes.begin();
96 
97  for (; (iter != codes.end()) && (jter != from.codes.end()); ++iter, ++jter) {
98  if ((**iter) != (**jter)) {
99  EdgeCode& alpha = **iter;
100  EdgeCode& beta = **jter;
101 
102  if (alpha.isBackward()) {
103  if (beta.isForward()) {
104  return true;
105  } else if (alpha.j < beta.j) {
106  // beta is a backward edge
107  return true;
108  } else if ((alpha.j == beta.j) && (alpha.l_ij < beta.l_ij)) {
109  return true;
110  }
111 
112  return false;
113  } else {
114  // alpha is a forward edge
115  if (beta.isBackward()) {
116  return false;
117  } else if (beta.i < alpha.i) {
118  // Beta is a forward edge
119  return true;
120  } else if (beta.i == alpha.i) {
121  if (alpha.l_i < beta.l_i) {
122  return true;
123  } else if (alpha.l_i == beta.l_i) {
124  if (alpha.l_ij < beta.l_ij) {
125  return true;
126  } else if (alpha.l_ij == beta.l_ij) {
127  return alpha.l_j < beta.l_j;
128  }
129  }
130  }
131 
132  return false;
133  }
134 
135  return (**iter) < (**jter);
136  }
137  }
138 
139  return false;
140  }
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
std::vector< EdgeCode *>::const_iterator const_iterator
Code alias.
Definition: DFSCode.h:130
+ Here is the call graph for this function:

◆ operator<=()

INLINE bool gum::prm::gspan::DFSCode::operator<= ( const DFSCode code) const

Lesser or equal than operator.

Parameters
codeThe code on which the test is made.
Returns
Returns true if this is lesser than code.

Definition at line 143 of file DFSCode_inl.h.

References gum::prm::gspan::operator<<().

143  {
144  DFSCode::const_iterator iter = codes.begin();
145  DFSCode::const_iterator jter = from.codes.begin();
146 
147  for (; (iter != codes.end()) && (jter != from.codes.end()); ++iter, ++jter) {
148  if ((**iter) != (**jter)) { return (**iter) < (**jter); }
149  }
150 
151  return codes.size() <= from.codes.size();
152  }
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
std::vector< EdgeCode *>::const_iterator const_iterator
Code alias.
Definition: DFSCode.h:130
+ Here is the call graph for this function:

◆ operator=()

INLINE DFSCode & gum::prm::gspan::DFSCode::operator= ( const DFSCode source)

Copy operator.

Proceeds with a deep copy.

Definition at line 56 of file DFSCode_inl.h.

References gum::prm::gspan::operator<<().

56  {
57  for (const auto item: codes)
58  delete item;
59 
60  for (const auto srcitem: source.codes)
61  codes.push_back(new EdgeCode(*srcitem));
62 
63  return *this;
64  }
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
+ Here is the call graph for this function:

◆ operator==()

INLINE bool gum::prm::gspan::DFSCode::operator== ( const DFSCode code) const

Equality operator.

Parameters
codeThe code tested for equality with this.
Returns
Returns true if this and code are equal.

Definition at line 67 of file DFSCode_inl.h.

References gum::prm::gspan::operator<<().

67  {
68  if (codes.size() == from.codes.size()) {
69  for (size_t idx = 0; idx < codes.size(); ++idx) {
70  if ((*codes[idx]) != (*codes[idx])) { return false; }
71  }
72 
73  return true;
74  } else {
75  return false;
76  }
77  }
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
+ Here is the call graph for this function:

◆ validNeighbors()

bool gum::prm::gspan::DFSCode::validNeighbors ( EdgeCode e1,
EdgeCode e2 
)
inlinestatic

Returns true of e2 is a valid neighbor for e1 (i.e.

it respect the neighborhood restriction) if e1 precedes e2 in a DFSCode.

Parameters
e1An EdgeCode.
e2Another EdgeCode.
Returns
Returns true of e2 is a valid neighbor for e1 (i.e. it respect the neighborhood restriction) if e1 precedes e2 in a DFSCode.

Definition at line 141 of file DFSCode.h.

141  {
142  if (e1->isBackward()) {
143  if (e2->isForward()) {
144  return (e2->i <= e1->i) && (e2->j = (e1->i + 1));
145  } else {
146  return (e2->i == e1->i) && (e1->j < e2->j);
147  }
148  } else {
149  // e1 is a forward edge
150  if (e2->isForward()) {
151  return (e2->i <= e1->j) && (e2->j == (e1->j + 1));
152  } else {
153  return (e2->i == e1->j) && (e2->j < e1->i);
154  }
155  }
156  }

Member Data Documentation

◆ codes

std::vector< EdgeCode* > gum::prm::gspan::DFSCode::codes

The vector containing the EdgeCode composing this DFSCode.

Definition at line 89 of file DFSCode.h.


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