graph_op.h 2.17 KB
Newer Older
Minjie Wang's avatar
Minjie Wang committed
1
2
3
4
5
6
7
8
9
10
// Graph operations
#ifndef DGL_GRAPH_OP_H_
#define DGL_GRAPH_OP_H_

#include "graph.h"

namespace dgl {

class GraphOp {
 public:
11
12
  /*!
   * \brief Return the line graph.
Minjie Wang's avatar
Minjie Wang committed
13
14
15
16
17
   *
   * If i~j and j~i are two edges in original graph G, then
   * (i,j)~(j,i) and (j,i)~(i,j) are the "backtracking" edges on
   * the line graph.
   *
18
   * \param graph The input graph.
Minjie Wang's avatar
Minjie Wang committed
19
   * \param backtracking Whether the backtracking edges are included or not
20
21
   * \return the line graph
   */
Minjie Wang's avatar
Minjie Wang committed
22
  static Graph LineGraph(const Graph* graph, bool backtracking);
Minjie Wang's avatar
Minjie Wang committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  /*!
   * \brief Return a disjoint union of the input graphs.
   *
   * The new graph will include all the nodes/edges in the given graphs.
   * Nodes/Edges will be relabled by adding the cumsum of the previous graph sizes
   * in the given sequence order. For example, giving input [g1, g2, g3], where
   * they have 5, 6, 7 nodes respectively. Then node#2 of g2 will become node#7
   * in the result graph. Edge ids are re-assigned similarly.
   *
   * \param graphs A list of input graphs to be unioned.
   * \return the disjoint union of the graphs
   */
  static Graph DisjointUnion(std::vector<const Graph*> graphs);

  /*!
   * \brief Partition the graph into several subgraphs.
   *
Minjie Wang's avatar
Minjie Wang committed
40
41
   * This is a reverse operation of DisjointUnion. The graph will be partitioned
   * into num graphs. This requires the given number of partitions to evenly
Minjie Wang's avatar
Minjie Wang committed
42
43
   * divides the number of nodes in the graph.
   * 
Minjie Wang's avatar
Minjie Wang committed
44
   * \param graph The graph to be partitioned.
Minjie Wang's avatar
Minjie Wang committed
45
46
47
   * \param num The number of partitions.
   * \return a list of partitioned graphs
   */
Minjie Wang's avatar
Minjie Wang committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  static std::vector<Graph> DisjointPartitionByNum(const Graph* graph, int64_t num);

  /*!
   * \brief Partition the graph into several subgraphs.
   *
   * This is a reverse operation of DisjointUnion. The graph will be partitioned
   * based on the given sizes. This requires the sum of the given sizes is equal
   * to the number of nodes in the graph.
   * 
   * \param graph The graph to be partitioned.
   * \param sizes The number of partitions.
   * \return a list of partitioned graphs
   */
  static std::vector<Graph> DisjointPartitionBySizes(const Graph* graph, IdArray sizes);
Minjie Wang's avatar
Minjie Wang committed
62
63
64
65
66
};

}  // namespace dgl

#endif  // DGL_GRAPH_OP_H_