PGX 20.1.1
Documentation

Degree Centrality Algorithms

PGX 20.1.1 has three different algorithms for degree centrality. One for centrality based on out-degree, one for centrality based on in-degree and one for centrality based on the sum of those two.


In-Degree Centrality

Category ranking and walking

Algorithm ID pgx_builtin_k7b_indegree_centrality

Time Complexity O(V) with V = number of vertices

Space Requirement O(V) with V = number of vertices

Javadoc


In-Degree centrality returns the sum of the number of incoming edges for each vertex in the graph.

Signature

Input Argument Type Comment
G graph
Output Argument Type Comment
ic nodeProp vertex property holding the degree centrality value for each vertex in the graph.

Code

/*
 * Copyright (C) 2013 - 2020 Oracle and/or its affiliates. All rights reserved.
 */
package oracle.pgx.algorithms;

import oracle.pgx.algorithm.annotations.GraphAlgorithm;
import oracle.pgx.algorithm.PgxGraph;
import oracle.pgx.algorithm.VertexProperty;
import oracle.pgx.algorithm.annotations.Out;

@GraphAlgorithm
public class IndegreeCentrality {
  public void indegreeCentrality(PgxGraph g, @Out VertexProperty<Integer> indegreeCentrality) {
    g.getVertices().forEach(n ->
        indegreeCentrality.set(n, (int) n.getInDegree())
    );
  }
}
/*
 * Copyright (C) 2013 - 2020 Oracle and/or its affiliates. All rights reserved.
 */

proc indegree_centrality(graph G; nodeProp<int> ic) {

  foreach (n: G.nodes) {
    n.ic = n.inDegree();
  }
}

Out-Degree Centrality

Category ranking and walking

Algorithm ID pgx_builtin_k7a_outdegree_centrality

Time Complexity O(V) with V = number of vertices

Space Requirement O(V) with V = number of vertices

Javadoc


Out-Degree centrality returns the sum of the number of outgoing edges for each vertex in the graph.

Signature

Input Argument Type Comment
G graph
Output Argument Type Comment
oc nodeProp vertex property holding the degree centrality value for each vertex in the graph.

Code

/*
 * Copyright (C) 2013 - 2020 Oracle and/or its affiliates. All rights reserved.
 */
package oracle.pgx.algorithms;

import oracle.pgx.algorithm.annotations.GraphAlgorithm;
import oracle.pgx.algorithm.PgxGraph;
import oracle.pgx.algorithm.VertexProperty;
import oracle.pgx.algorithm.annotations.Out;

@GraphAlgorithm
public class OutdegreeCentrality {
  public void outdegreeCentrality(PgxGraph g, @Out VertexProperty<Integer> outdegreeCentrality) {
    g.getVertices().forEach(n ->
        outdegreeCentrality.set(n, (int) n.getOutDegree())
    );
  }
}
/*
 * Copyright (C) 2013 - 2020 Oracle and/or its affiliates. All rights reserved.
 */

proc outdegree_centrality(graph G; nodeProp<int> oc) {

  foreach (n: G.nodes) {
    n.oc = n.degree();
  }
}

Degree Centrality

Category ranking and walking

Algorithm ID pgx_builtin_k7c_degree_centrality

Time Complexity O(V) with V = number of vertices

Space Requirement O(V) with V = number of vertices

Javadoc


Degree centrality counts the number of outgoing and incoming edges for each vertex in the graph.

Signature

Input Argument Type Comment
G graph
Output Argument Type Comment
dc nodeProp vertex property holding the degree centrality value for each vertex in the graph.

Code

/*
 * Copyright (C) 2013 - 2020 Oracle and/or its affiliates. All rights reserved.
 */
package oracle.pgx.algorithms;

import oracle.pgx.algorithm.annotations.GraphAlgorithm;
import oracle.pgx.algorithm.PgxGraph;
import oracle.pgx.algorithm.VertexProperty;
import oracle.pgx.algorithm.annotations.Out;

@GraphAlgorithm
public class DegreeCentrality {
  public void degreeCentrality(PgxGraph g, @Out VertexProperty<Integer> degreeCentrality) {
    g.getVertices().forEach(n ->
        degreeCentrality.set(n, (int) (n.getOutDegree() + n.getInDegree()))
    );
  }
}
/*
 * Copyright (C) 2013 - 2020 Oracle and/or its affiliates. All rights reserved.
 */

proc degree_centrality(graph G; nodeProp<int> dc) {

  foreach (n: G.nodes) {
    n.dc = n.degree() + n.inDegree();
  }
}