Skip to content

Latest commit

 

History

History
51 lines (41 loc) · 1.88 KB

pgx_builtin_k7c_degree_centrality.md

File metadata and controls

51 lines (41 loc) · 1.88 KB

Degree Centrality

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

Signature

Input Argument Type Comment
G graph the graph.
Output Argument Type Comment
dc vertexProp vertex property holding the degree centrality value for each vertex in the graph.
Return Value Type Comment
void None

Code

/*
 * Copyright (C) 2013 - 2025 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;
import oracle.pgx.algorithm.ControlFlow;

@GraphAlgorithm
public class DegreeCentrality {
  public void degreeCentrality(PgxGraph g, @Out VertexProperty<Integer> degreeCentrality) {
    long numberOfStepsEstimatedForCompletion = g.getNumVertices();
    ControlFlow.setNumberOfStepsEstimatedForCompletion(numberOfStepsEstimatedForCompletion);
    g.getVertices().forEach(n ->
        degreeCentrality.set(n, (int) (n.getOutDegree() + n.getInDegree()))
    );
  }
}