IterOrbit
Subgraph isomorphism with iterative graphlet-orbit filtering
Loading...
Searching...
No Matches
AppGraph.h
Go to the documentation of this file.
1
3
4#ifndef APP_GRAPH_H
5#define APP_GRAPH_H
6
7#include <memory>
8#include <string>
9#include <vector>
10#include <unordered_set>
11#include "Escape/Graph.h"
12
23struct LabelIndex {
25 int max_label = -1;
28 std::vector<size_t> nlf_offsets;
29 std::vector<int> nlf_label, nlf_count;
30};
31
32class AppGraph {
33public:
35 Escape::CGraph* c_graph = nullptr;
37 std::vector<int> original_node_ids;
39 std::vector<int> fast_node_to_idx;
41 std::vector<int> fast_labels;
43 std::shared_ptr<const LabelIndex> label_index;
44
46 void buildLabelIndex();
47 AppGraph() = default;
48 ~AppGraph();
49 AppGraph(const AppGraph& other);
50 AppGraph& operator=(const AppGraph& other);
51 AppGraph(AppGraph&& other) noexcept;
52 AppGraph& operator=(AppGraph&& other) noexcept;
53
55 inline int get_node_idx(int node_id) const {
56 if (node_id >= 0 && static_cast<size_t>(node_id) < fast_node_to_idx.size()) {
57 return fast_node_to_idx[node_id];
58 }
59 return -1;
60 }
61
63 inline int get_label_fast(int node_id) const {
64 if (node_id >= 0 && static_cast<size_t>(node_id) < fast_labels.size()) {
65 return fast_labels[node_id];
66 }
67 return -1;
68 }
69
73 bool readFromFile(const std::string& filepath);
74
77 bool buildFromLabelsAndEdges(const std::vector<int>& vertex_labels,
78 const std::vector<std::pair<int, int>>& edges);
79
81 int degree(int node_id) const;
83 bool hasEdge(int u, int v) const;
85 std::vector<int> getNeighbors(int node_id) const;
86
89 static AppGraph createSubgraph(const AppGraph& original, const std::unordered_set<int>& node_subset);
91 static AppGraph createSubgraph(const AppGraph& original, const std::vector<int>& sorted_ids);
92
93private:
94 void build(const std::vector<int>& vertex_ids, const std::vector<int>& vertex_labels,
95 const std::vector<std::pair<int, int>>& edges);
96 void clear();
97 void copy_from(const AppGraph& other);
98};
99
100#endif
Definition AppGraph.h:32
int get_node_idx(int node_id) const
Internal index of a node ID, or -1 if the vertex is not in this graph.
Definition AppGraph.h:55
std::shared_ptr< const LabelIndex > label_index
Built by buildLabelIndex() (the data graph's); null otherwise. Shared by copies.
Definition AppGraph.h:43
~AppGraph()
Definition AppGraph.cpp:9
void copy_from(const AppGraph &other)
Definition AppGraph.cpp:51
bool readFromFile(const std::string &filepath)
Reads a graph in the "t / v / e" text format: a line v <id> <label> [...] per vertex and a line e <u>...
Definition AppGraph.cpp:95
bool buildFromLabelsAndEdges(const std::vector< int > &vertex_labels, const std::vector< std::pair< int, int > > &edges)
Builds the graph from memory.
Definition AppGraph.cpp:130
void build(const std::vector< int > &vertex_ids, const std::vector< int > &vertex_labels, const std::vector< std::pair< int, int > > &edges)
Definition AppGraph.cpp:141
Escape::CGraph * c_graph
Adjacency in CSR form, indexed by internal index; neighbour lists are sorted. Owned.
Definition AppGraph.h:35
bool hasEdge(int u, int v) const
Whether node IDs u and v are adjacent in this graph.
Definition AppGraph.cpp:220
std::vector< int > getNeighbors(int node_id) const
Neighbours of a node ID, as node IDs.
Definition AppGraph.cpp:231
std::vector< int > fast_labels
Node ID -> label, or -1 if the vertex is not in this graph.
Definition AppGraph.h:41
std::vector< int > fast_node_to_idx
Node ID -> internal index, or -1 if the vertex is not in this graph.
Definition AppGraph.h:39
std::vector< int > original_node_ids
Node IDs in ascending order; the position of an ID is its internal index.
Definition AppGraph.h:37
AppGraph()=default
static AppGraph createSubgraph(const AppGraph &original, const std::unordered_set< int > &node_subset)
The subgraph of original induced by node_subset (node IDs): those vertices and every edge of original...
Definition AppGraph.cpp:245
void clear()
Definition AppGraph.cpp:13
void buildLabelIndex()
Builds label_index.
Definition AppGraph.cpp:188
int degree(int node_id) const
Degree of a node ID in this graph (0 if absent).
Definition AppGraph.cpp:214
int get_label_fast(int node_id) const
Label of a node ID, or -1 if the vertex is not in this graph.
Definition AppGraph.h:63
AppGraph & operator=(const AppGraph &other)
Definition AppGraph.cpp:26
A vertex-labelled, undirected graph: the pattern, the data graph, or an induced subgraph of the data ...
Definition AppGraph.h:23
std::vector< size_t > nlf_offsets
Vertex v has nlf_count[i] neighbours of label nlf_label[i], for i in [nlf_offsets[v],...
Definition AppGraph.h:28
std::vector< int > nlf_label
Definition AppGraph.h:29
std::vector< int > nlf_count
Definition AppGraph.h:29
int max_label
Largest label, -1 if the graph is empty.
Definition AppGraph.h:25