IterOrbit
Subgraph isomorphism with iterative graphlet-orbit filtering
Loading...
Searching...
No Matches
SearchEngine.h
Go to the documentation of this file.
1
3
4#ifndef SEARCH_ENGINE_H
5#define SEARCH_ENGINE_H
6
7#include <cstdint>
8#include "AppGraph.h"
9#include "FilterEngine.h"
10#include "Symmetry.h"
11
14using Mapping = std::vector<int>;
15
25public:
41 SearchEngine(const AppGraph& data, const AppGraph& pattern,
42 const CandidateSets& candidates, const std::vector<int>& order,
43 const std::unordered_map<int, int>& pivot, bool induced, bool cbj,
44 bool count_only = false, bool edge_orbit_filter = false,
45 const SymmetryBreaking* symmetry = nullptr);
46
50 void setMatchLimit(long long limit, bool store) { match_limit = limit; store_matches = store; }
51
53 void run();
54
56 const std::vector<Mapping>& getMatches() const { return matches; }
59 long long getMatchCount() const { return match_count; }
61 bool limitReached() const { return stopped; }
63 const std::vector<long long>& getNodesPerDepth() const { return nodes_per_depth; }
65 const std::vector<long long>& getLocalCandidatesPerDepth() const { return local_per_depth; }
67 long long getIndexEntriesBefore() const { return index_entries_before; }
69 long long getIndexEntriesAfter() const { return index_entries_after; }
71 bool countOverflowed() const { return count_overflow; }
72
73private:
77 struct BackwardEdge {
78 int from_u;
79 std::vector<uint32_t> offsets;
80 std::vector<uint32_t> targets;
81 };
82
84 void backtrack(int depth);
86 int backtrack_cbj(int depth);
90 bool computeLocalCandidates(int depth);
93 long long countLastLevel(int depth, uint64_t* used_by) const;
96 bool inducedConflict(int u, int v, int& conflict_u) const;
97 uint64_t* conflicts(int depth) { return conflict_bits.data() + static_cast<size_t>(depth) * conflict_words; }
98 void setConflict(uint64_t* set, int d) const { set[d >> 6] |= uint64_t{1} << (d & 63); }
99 void mergeConflicts(int target_depth, int source_depth);
100
103 const std::vector<int>& order;
107 long long match_count = 0;
108 long long match_limit = 0;
109 bool store_matches = true;
110 bool stopped = false;
111
114 std::vector<int> fast_mapping;
116 std::vector<int> fast_mapping_local_index;
118 std::vector<int> fast_inverse_mapping;
120 std::vector<uint8_t> in_use;
121
123 std::vector<std::vector<int>> candidate_lists;
125 std::vector<std::vector<BackwardEdge>> backward_edges;
127 std::vector<std::vector<int>> backward_non_neighbors;
130 std::vector<std::vector<int>> local_candidates;
132 std::vector<int> intersect_buffer;
134 std::vector<int> identity;
136 std::vector<const int*> local_ptr;
138 std::vector<size_t> local_len;
139
142 std::vector<std::vector<int>> smaller_depths;
145 bool count_overflow = false;
146 long long index_entries_before = 0;
147 long long index_entries_after = 0;
148
149 std::vector<long long> nodes_per_depth;
150 std::vector<long long> local_per_depth;
151
153 std::vector<int> order_position;
155 size_t conflict_words = 0;
158 std::vector<uint64_t> conflict_bits;
160 std::vector<uint64_t> backward_masks;
161
162 std::vector<Mapping> matches;
163};
164#endif
The graph type shared by the pattern, the data graph and its induced subgraphs.
Iterative orbit filtering: candidate sets and Algorithm 1 (IterOrbitFilter) of the paper.
std::unordered_map< int, std::vector< int > > CandidateSets
A candidate assignment: pattern node ID -> the data node IDs it may be mapped to.
Definition FilterEngine.h:13
std::vector< int > Mapping
One embedding: the data node ID each pattern vertex is mapped to, indexed by pattern node ID (pattern...
Definition SearchEngine.h:14
Symmetry-breaking constraints for counting embeddings.
Definition AppGraph.h:32
Backtracking enumeration of the embeddings of the pattern, within the candidate sets.
Definition SearchEngine.h:24
std::vector< int > intersect_buffer
The second buffer of that swap.
Definition SearchEngine.h:132
bool limitReached() const
Whether the search stopped at the match limit.
Definition SearchEngine.h:61
const std::vector< int > & order
Definition SearchEngine.h:103
void run()
Runs the search.
Definition SearchEngine.cpp:392
void backtrack(int depth)
Chronological backtracking from depth.
Definition SearchEngine.cpp:522
std::vector< std::vector< int > > candidate_lists
Per pattern vertex, its candidates sorted by data node ID.
Definition SearchEngine.h:123
std::vector< int > fast_inverse_mapping
Data node ID -> the pattern node ID mapped to it (-1 if none).
Definition SearchEngine.h:118
std::vector< uint64_t > backward_masks
Backjumping: per depth, the bitset of the depths of order[depth]'s backward neighbours.
Definition SearchEngine.h:160
bool stopped
Definition SearchEngine.h:110
std::vector< int > identity
0, 1, 2, ...: "every candidate", for a vertex with no backward neighbour.
Definition SearchEngine.h:134
const std::vector< long long > & getLocalCandidatesPerDepth() const
Local candidates computed at each order depth, summed over the visits.
Definition SearchEngine.h:65
bool computeLocalCandidates(int depth)
Computes the local candidates of order[depth] from the index (local_ptr, local_len).
Definition SearchEngine.cpp:419
long long countLastLevel(int depth, uint64_t *used_by) const
Counts the embeddings completed at the last pattern vertex without visiting each one; the pattern ver...
Definition SearchEngine.cpp:492
long long getIndexEntriesAfter() const
Entries of the candidate-space index after the edge-orbit filter.
Definition SearchEngine.h:69
std::vector< size_t > local_len
Per depth, the number of local candidates.
Definition SearchEngine.h:138
long long getMatchCount() const
The number of embeddings, saturated at INT64_MAX (see countOverflowed()); with a match limit,...
Definition SearchEngine.h:59
std::vector< long long > local_per_depth
Definition SearchEngine.h:150
bool enable_cbj
Definition SearchEngine.h:105
std::vector< int > fast_mapping
The partial embedding: pattern node ID -> data node ID (-1 if unmapped).
Definition SearchEngine.h:114
void setMatchLimit(long long limit, bool store)
Enumeration with a match limit (the protocol of Sun and Luo): without count_only, visit the embedding...
Definition SearchEngine.h:50
bool store_matches
Definition SearchEngine.h:109
std::vector< const int * > local_ptr
Per depth, the local candidates, as positions in the candidate list.
Definition SearchEngine.h:136
std::vector< uint64_t > conflict_bits
Backjumping: one conflict set per depth, a bitset in which bit d stands for the pattern vertex at dep...
Definition SearchEngine.h:158
std::vector< int > fast_mapping_local_index
Pattern node ID -> position of its image in its candidate list.
Definition SearchEngine.h:116
uint64_t symmetry_multiplier
The factor the final count is multiplied by (SymmetryBreaking::multiplier).
Definition SearchEngine.h:144
const AppGraph & data_graph
Definition SearchEngine.h:101
std::vector< int > order_position
Pattern node ID -> depth in the matching order.
Definition SearchEngine.h:153
std::vector< std::vector< int > > local_candidates
Per depth, a buffer for the intersection; swapped with intersect_buffer instead of copied (see comput...
Definition SearchEngine.h:130
const AppGraph & pattern_graph
Definition SearchEngine.h:102
long long match_limit
Definition SearchEngine.h:108
bool countOverflowed() const
Whether the count exceeded 64 bits and was saturated.
Definition SearchEngine.h:71
bool inducedConflict(int u, int v, int &conflict_u) const
Under induced semantics: whether mapping u to v puts an edge between the images of two non-adjacent p...
Definition SearchEngine.cpp:478
const std::vector< long long > & getNodesPerDepth() const
Search-tree nodes visited at each order depth.
Definition SearchEngine.h:63
bool count_overflow
Definition SearchEngine.h:145
long long match_count
Definition SearchEngine.h:107
std::vector< std::vector< int > > smaller_depths
Symmetry breaking: per depth, the earlier depths whose image must have a smaller data node ID than th...
Definition SearchEngine.h:142
int backtrack_cbj(int depth)
Backtracking with conflict-directed backjumping. Returns the depth to return to.
Definition SearchEngine.cpp:563
std::vector< std::vector< int > > backward_non_neighbors
Per depth, the earlier pattern vertices not adjacent to order[depth] (induced search).
Definition SearchEngine.h:127
bool is_induced
Definition SearchEngine.h:104
uint64_t * conflicts(int depth)
Definition SearchEngine.h:97
std::vector< uint8_t > in_use
Data node ID -> whether some pattern vertex is mapped to it.
Definition SearchEngine.h:120
bool count_only
Definition SearchEngine.h:106
long long getIndexEntriesBefore() const
Entries of the candidate-space index before the edge-orbit filter.
Definition SearchEngine.h:67
void setConflict(uint64_t *set, int d) const
Definition SearchEngine.h:98
size_t conflict_words
Backjumping: the number of 64-bit words in one conflict set.
Definition SearchEngine.h:155
void mergeConflicts(int target_depth, int source_depth)
Definition SearchEngine.cpp:386
const std::vector< Mapping > & getMatches() const
The embeddings found (empty with count_only, or when not stored).
Definition SearchEngine.h:56
long long index_entries_after
Definition SearchEngine.h:147
std::vector< std::vector< BackwardEdge > > backward_edges
Per depth, the index along each backward edge of order[depth].
Definition SearchEngine.h:125
std::vector< long long > nodes_per_depth
Definition SearchEngine.h:149
long long index_entries_before
Definition SearchEngine.h:146
std::vector< Mapping > matches
Definition SearchEngine.h:162
The index along one backward edge of the pattern vertex at some depth: for the i-th candidate of from...
Definition SearchEngine.h:77
std::vector< uint32_t > targets
Definition SearchEngine.h:80
std::vector< uint32_t > offsets
Definition SearchEngine.h:79
int from_u
Definition SearchEngine.h:78
Symmetry-breaking constraints for counting embeddings (Grochow and Kellis).
Definition Symmetry.h:17