61 for (
NodeId node = 1; node <= source.
size(); ++node) {
65 for (
const auto& edge: source.
code().
codes)
68 const_cast< LabelData&
>(source.
label(node_map[edge->i], node_map[edge->j])));
72 for (
const auto node:
nodes()) {
73 for (
const auto next:
parents(node)) {
78 if (edge_code < *(
code().codes.front())) {
80 }
else if (edge_code == (*
code().codes.front())) {
85 for (
const auto next:
children(node)) {
90 if (edge_code < *(
code().codes.front())) {
92 }
else if (edge_code == (*
code().codes.front())) {
102 std::string result = std::format(
"digraph {} {{\n", name);
104 for (
const auto& arc:
arcs())
105 result += std::format(
"{} -> {};\n",
label(arc.tail()).
id,
label(arc.head()).id);
125 if (
_rec_(p, node_map, u, nei))
return true;
127 for (
const auto nei:
parents(u))
129 if (
_rec_(p, node_map, u, nei))
return true;
133 if (
_rec_(p, node_map, v, nei))
return true;
135 for (
const auto nei:
parents(v))
137 if (
_rec_(p, node_map, v, nei))
return true;
160 data = &(
label(u, v));
162 data = &(
label(v, u));
179 if (
size_t depth = p.
code().
codes.size() - 1;
182 }
else if (*(p.
code().
codes.back()) == *(
code().codes[depth])) {
183 std::list< NodeId > r_path;
186 for (
const auto node: r_path) {
188 if (
_rec_(p, node_map, node_map.
first(node), nei))
return true;
191 if (
_rec_(p, node_map, node_map.
first(node), nei))
return true;
205 std::vector< std::pair< NodeId, NodeId > > stack;
206 stack.emplace_back(a_u, a_v);
210 while (!stack.empty()) {
212 u = stack.back().first;
213 v = stack.back().second;
216 if ((u == 0) && (v == 0)) {
237 else data = &(
label(v, u));
254 if (
size_t depth = p.
code().
codes.size() - 1;
257 }
else if (*(p.
code().
codes.back()) == *(
code().codes[depth])) {
258 std::list< NodeId > r_path;
262 for (
const auto node: r_path) {
263 for (
const auto nei:
children(node)) {
264 stack.emplace_back(node_map.
first(node), nei);
267 for (
const auto nei:
parents(node)) {
268 stack.emplace_back(node_map.
first(node), nei);
285 while (r_path.front() != 1) {
286 for (
const auto par:
parents(r_path.front())) {
287 if (par < r_path.front()) {
288 r_path.push_front(par);
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of nodes which consists in the node and its parents returns the set of children of a ...
The base class for all directed edges.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
void eraseFirst(const T1 &first)
Erases an association containing the given first element.
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Exception : operation not allowed.
std::vector< EdgeCode * > codes
The vector containing the EdgeCode composing this DFSCode.
bool _expandCodeIsMinimal_(NodeId u, NodeId v)
Returns true if the expand code by adding and edge betwenne u and v is minimal with respect to code.
const ArcSet & arcs() const
bool isMinimal()
Returns the DFSCode of this Pattern.
NodeId addNodeWithLabel(LabelData &l)
Insert a node with the given LabelData.
Size size() const
Returns the number of nodes in this Pattern.
virtual std::string toDot() const
to friendly display the content of the graph in the DOT syntax
void pop_back()
Remove the last EdgeCode of this pattern.
DFSCode & code()
Returns the DFSCode of this Pattern.
ArcProperty< std::pair< LabelData *, EdgeCode * > > _arc_map_
Mapping between edges in this Pattern and their respective LabelData.
Pattern()
Default constructor.
void remove(NodeId node)
Remove a node if it has no neighbors, raise an OperationNotAllowed otherwise.
void addArc(NodeId i, NodeId j, LabelData &l)
Add an arc to this Pattern.
void rightmostPath(std::list< NodeId > &r_path) const
Fill r_path with the rightmost path of this Pattern. The list is supposed empty.
const NodeGraphPart & nodes() const
bool _rec_(Pattern &p, Bijection< NodeId, NodeId > &node_map, NodeId u, NodeId v)
Recurisve method used by expandCodeIsMinimal.
LabelData & label(NodeId node)
Returns the LabelData assigned to node.
bool _not_rec_(Pattern &p, Bijection< NodeId, NodeId > &node_map, NodeId u, NodeId v)
A non recursive bugged version of rec.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Headers of the Pattern class.
Inline implementation of the Pattern class.
represent a DFS code used by gspan.
Inner class to handle data about labels in this interface graph.
Idx id
An unique identifier for this label.