Skip to content
Library: graphlib (degree-weighted)

Graph Library (graphlib) — Degree Algorithms (Weighted) Extension

A library extension to graphlib containing various neighbor and degree relations for weighted graphs.

Module: rel:graphlib

View source
rel:graphlib[G]

This section of the graph library supports weighted degrees and weighted degree statistics:

AlgorithmDescription
weighted_degreeThe sum of weights connected to a node.
weighted_indegreeThe sum of weights on incoming edges to a node.
weighted_outdegreeThe sum of weights on outgoing edges from a node.
min_weighted_degreeSmallest weighted degree in the graph.
max_weighted_degreeLargest weighted degree in the graph.
average_weighted_degreeAverage weighted degree in the graph.
min_weighted_indegreeSmallest weighted indegree in the graph.
max_weighted_indegreeLargest weighted indegree in the graph.
average_weighted_indegreeAverage weighted indegree in the graph.
min_weighted_outdegreeSmallest weighted outdegree in the graph.
max_weighted_outdegreeLargest weighted outdegree in the graph.
average_weighted_outdegreeAverage weighted outdegree in the graph.
weighted_degree_statisticsCompute various weighted degree statistics.

weighted_degree

View source
weighted_degree(u, d)

Compute the sum of the weights of each edge connected to a node in a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
uG:nodeA node in G.
dIntThe weighted degree of u in G.

Explanation

weighted_degree can be used to get the sum of weights connected to a node for each node in G or to check whether node u has weighted degree d in G. If G is directed, it is the sum of weights on incoming and outgoing edges from a node. If the degree of a node that doesn’t exist in G is queried, Rel returns the empty relation.

Examples

Compute the weighted_degree of nodes in a weighted, directed graph:

// Create a directed, weighted graph with three nodes and three edges.
def W = {
    (1, 2, 1.0);
    (2, 1, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the weighted degree of nodes in G.
def output = mylib:weighted_degree
//output> (1, 0.0)
//        (2, 1.0)
//        (3, 1.0)
 
// Compute the weighted outdegree of node 1.
def output = mylib:weighted_degree[1]
//output> 0.0

See Also

weighted_indegree and weighted_outdegree.

weighted_indegree

View source
weighted_indegree(u, d)

Compute the sum of edge weights going into a node in a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
uG:nodeA node in G.
dIntThe weighted indegree of u in G.

Explanation

weighted_indegree can be used to get the sum of weights coming into each node in G or to check whether node u has sum of weights d coming into it in G. If G is undirected, it is identical to weighted_degree. If the weighted_indegree of a node that doesn’t exist in G is queried, Rel returns the empty relation.

Examples

Compute the weighted_indegree of nodes in a weighted, directed graph:

// Create a directed, weighted graph with three nodes and three edges.
def W = {
    (1, 2, 1.0);
    (2, 1, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the weighted indegree of nodes in G.
def output = mylib:weighted_indegree
//output> (1, -1.0)
//        (2, 1.0)
//        (3, 1.0)
 
// Compute the weighted indegree of node 1.
def output = mylib:weighted_indegree[1]
//output> 0.0

See Also

weighted_degree and weighted_outdegree.

weighted_outdegree

View source
weighted_outdegree(u, d)

Compute the sum of edge weights leaving a node in a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
uG:nodeA node in G.
dIntThe weighted outdegree of u in G.

Explanation

weighted_outdegree can be used to get the sum of weights on edges leaving each node in G or to check whether node u has weighted outdegree d in G. If G is undirected, it is identical to weighted_degree. If the outdegree of a node that doesn’t exist in G is queried, Rel returns the empty relation.

Examples

Compute the weighted_outdegree of nodes in a weighted, directed graph:

def W = {
(1, 2, 1.0);
(2, 1, -1.0);
(2, 3, 1.0)
}
def G = create\_graph\[{(:weight, W)}, {(:is\_weighted) ; (:is\_directed)}]
@inline def mylib = rel:graphlib\[G]
 
// Compute the weighted outdegree of nodes in G.
def output = mylib:weighted\_outdegree
//output> (1, 1.0)
//        (2, 0.0)
//        (3, 0.0)
 
// Compute the weighted outdegree of node 1.
def output = mylib:weighted\_outdegree\[1]
//output> 1.0

See Also

weighted_degree and weighted_indegree.

weighted_degree_sequence

View source
weighted_degree_sequence(i, d)

Compute the weighted degree sequence of a weighted graph in decreasing order.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
iIntAn index.
dIntA weighted degree in G.

Explanation

The weighted degree sequence of a graph is the list of the weighted degrees of all the nodes in a graph arranged from highest to lowest. weighted_degree_sequence returns index and weighted degree pairs, where index is the position of the corresponding weighted degree in the weighted degree sequence. As an example: (1, 15.3) means that degree value 15.3 is the highest degree in this degree sequence.

Examples

// Create a directed, weighted graph with three nodes and three edges.
def W = {
    (1, 2, 1.0);
    (2, 1, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the weighted degree sequence of nodes in G.
def output = mylib:weighted_degree_sequence
//output> (1, 1.0)
//        (2, 1.0)
//        (3, 0.0)
 
// Compute the highest weighted degree in G.
def output = mylib:weighted_degree_sequence[1]
//output> 1.0

See Also

weighted_degree, weighted_indegree_sequence, and weighted_outdegree_sequence.

weighted_indegree_sequence

View source
weighted_indegree_sequence(i, d)

Compute the weighted indegree sequence of a weighted graph in decreasing order.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
iIntAn index.
dIntA weighted indegree in G.

Explanation

The weighted indegree sequence of a graph is the list of the weighted indegrees of all the nodes in a graph arranged from highest to lowest. weighted_indegree_sequence returns index and indegree pairs, where index is the position of the corresponding weighted indegree in the weighted indegree sequence. As an example: (1, 15.3) means that indegree value 15.3 is the highest weighted indegree in this weighted indegree sequence.

Examples

// Create a directed, weighted graph with three nodes and three edges.
def W = {
    (1, 2, 1.0);
    (2, 1, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the weighted indegree sequence of nodes in G.
def output = mylib:weighted_indegree_sequence
//output> (1, 1.0)
//        (2, 1.0)
//        (3, -1.0)
 
// Compute the highest weighted indegree of a node.
def output = mylib:weighted_indegree_sequence[1]
//output> 1.0

See Also

weighted_degree, weighted_degree_sequence, and weighted_outdegree_sequence.

weighted_outdegree_sequence

View source
weighted_outdegree_sequence(i, d)

Compute the weighted outdegree sequence of a weighted graph in decreasing order.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
iIntAn index.
dIntA weighted outdegree in G.

Explanation

The weighted outdegree sequence of a graph is the list of the weighted outdegrees of all the nodes in a graph arranged from highest to lowest. weighted_outdegree_sequence returns index and weighted outdegree pairs, where index is the position of the corresponding weighted outdegree in the weighted outdegree sequence. As an example: (1, 15.3) means that outdegree value 15.3 is the highest weighted outdegree in this outdegree sequence.

Examples

// Create a directed, weighted graph with three nodes and three edges.
def W = {
    (1, 2, 1.0);
    (2, 1, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the weighted outdegree sequence of nodes in G.
def output = mylib:weighted_outdegree_sequence
//output> (1, 1.0)
//        (2, 1.0)
//        (3, 0.0)
 
// Compute the highest weighted outdegree in G.
def output = mylib:weighted_outdegree_sequence[1]
//output> 1.0

See Also

weighted_degree, weighted_degree_sequence, and weighted_indegree_sequence.

min_weighted_degree

View source
min_weighted_degree(d)

Compute the minimum weighted degree of weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dIntThe minimum weighted degree of G.

Examples

def W = {
    (1, 2, 1.0);
    (1, 3, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the minimum weighted degree of the graph.
def output = mylib:min_weighted_degree
 
// Check if 0.0 is the minimum weighted degree of the graph.
def output = my_graphlib:min_weighted_degree(0.0)
//output> ()  // true

See Also

average_weighted_degree, min_weighted_indegree, max_weighted_indegree, average_weighted_indegree, min_weighted_outdegree, max_weighted_outdegree, and average_weighted_outdegree.

max_weighted_degree

View source
max_weighted_degree
max_weighted_degree(d)

Compute the maximum weighted degree of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dIntThe maximum weighted degree of G.

Examples

def W = {
    (1, 2, 1.0);
    (1, 3, -1.0);
    (2, 3, 2.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the maximum weighted degree of the graph.
def output = mylib:max_weighted_degree
//output> 3.0
 
// Check if 2.0 is the maximum weighted degree of the graph.
def output = my_graphlib:max_weighted_degree(3.0)
//output> ()  // true

See Also

average_weighted_degree, min_weighted_indegree, max_weighted_indegree, average_weighted_indegree, min_weighted_outdegree, max_weighted_outdegree, and average_weighted_outdegree.

average_weighted_degree

View source
average_weighted_degree(d)

Compute the average weighted degree of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dFloatThe average weighted degree of G.

Examples

def W = {
    (1, 2, 1.0);
    (1, 3, -1.0);
    (2, 3, 2.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the average weighted degree of the graph.
def output = mylib:average_weighted_degree
//output> 0.5
 
// Check that 0.5 is the average weighted degree of the graph.
def output = my_graphlib:average_weighted_degree(0.5)
//output> ()  // true

See Also

average_weighted_degree, min_weighted_indegree, max_weighted_indegree, average_weighted_indegree, min_weighted_outdegree, max_weighted_outdegree, and average_weighted_outdegree.

min_weighted_indegree

View source
min_weighted_indegree(d)

Compute the minimum weighted indegree of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dIntThe minimum weighted indegree of G.

Examples

def W = {
    (1, 2, 1.0);
    (1, 3, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the minimum weighted indegree of the graph.
def output = mylib:min_weighted_indegree
//output> 0.0
 
// Check that 0.0 is the minimum weighted indegree of the graph.
def output = my_graphlib:min_weighted_indegree(0.0)
//output> ()  // true

See Also

average_weighted_degree, max_weighted_indegree, average_weighted_indegree, min_weighted_outdegree, max_weighted_outdegree, and average_weighted_outdegree.

max_weighted_indegree

View source
 max_weighted_indegree(d)

Compute the maximum weighted indegree of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dIntThe maximun weighted indegree of G.

Examples

 def W = {
     (1, 2, 1.0);
     (1, 3, -1.0);
     (2, 3, 1.0)
 }
 def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
 @inline def mylib = rel:graphlib[G]
 
 // Compute the maximum weighted indegree of the graph.
 def output = mylib:max_weighted_indegree
 //output> 1.0
 
 // Check that 1.0 is the maximum weighted indegree of the graph.
 def output = my_graphlib:max_weighted_indegree(1.0)
 //output> ()  // true

See Also

average_weighted_degree, min_weighted_indegree, average_weighted_indegree, min_weighted_outdegree, max_weighted_outdegree, and average_weighted_outdegree.

average_weighted_indegree

View source
average_weighted_indegree(d)

Compute the average weighted indegree of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dFloatThe average weighted indegree of G.

Examples

def W = {
    (1, 2, 1.0);
    (1, 3, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the average weighted indegree of the graph.
def output = mylib:average_weighted_indegree
//output> 0.5
 
// Check that 0.5 is the average weighted indegree of the graph.
def output = my_graphlib:average_weighted_indegree(0.5)
//output> ()  // true

See Also

average_weighted_degree, min_weighted_indegree, max_weighted_indegree, min_weighted_outdegree, max_weighted_outdegree, and average_weighted_outdegree.

min_weighted_outdegree

View source
min_weighted_outdegree(d)

Compute the minimum weighted outdegree of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dIntThe minimum weighted outdegree of G.

Examples

def W = {
    (1, 2, 1.0);
    (1, 3, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the minimum weighted outdegree of the graph.
def output = mylib:min_weighted_outdegree
//output> 0.0
 
// Check that 0.0 is the minimum weighted outdegree of the graph.
def output = my_graphlib:min_weighted_outdegree(0.0)
//output> ()  // true

See Also

average_weighted_degree, min_weighted_indegree, max_weighted_indegree, max_weighted_outdegree, and average_weighted_outdegree.

max_weighted_outdegree

View source
max_weighted_outdegree(d)

Compute the maximum weighted outdegree of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dIntThe maximum outdegree of G.

Examples

def W = {
    (1, 2, 1.0);
    (1, 3, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the maximum weighted outdegree of the graph.
def output = mylib:max_weighted_outdegree
//output> 1.0
 
// Check that 1.0 is the maximum weighted outdegree of the graph.
def output = my_graphlib:max_weighted_outdegree(3.5)
//output> ()  // true

See Also

average_weighted_degree, min_weighted_indegree, max_weighted_indegree, min_weighted_outdegree, and average_weighted_outdegree.

average_weighted_outdegree

View source
average_weight_outdegree(d)

Compute the average weighted outdegree of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
dFloatThe average weighted outdegree of G.

Examples

def W = {
    (1, 2, 1.0);
    (1, 3, -1.0);
    (2, 3, 1.0)
}
def G = create_graph[{(:weight, W)}, {(:is_weighted) ; (:is_directed)}]
@inline def mylib = rel:graphlib[G]
 
// Compute the average weighted outdegree of the graph.
def output = mylib:average_weighted_outdegree
//output> 0.5
 
// Check that 0.5 is the average weighted outdegree of the graph.
def output = my_graphlib:average_weighted_outdegree(0.5)
//output> ()  // true

See Also

average_weighted_degree, min_weighted_indegree, max_weighted_indegree, min_weighted_outdegree, and max_weighted_outdegree.

weighted_degree_statistics

View source
weighted_degree_statistics(name, p)

Compute the weighted degree statistics of a weighted graph.

Supported Graph Types

Graph TypeSupported
UndirectedYes
DirectedYes
WeightedYes
UnweightedNo

Parameters

ParameterTypeDescription
nameRelNameA weighted degree statistics name.
pFloatA weighted degree statistic of G.

Explanation

weighted_degree_statistics can be used to compute several weighted degree statistics of G, covering the average, minimum, and maximum of the weighted degrees, indegrees, and outdegrees.

See Also

average_weighted_degree, min_weighted_indegree, max_weighted_indegree, min_weighted_outdegree, and average_weighted_outdegree.

Was this doc helpful?