Skip to content

Representation of self-loops and the calculation of degrees #17

@szhorvat

Description

@szhorvat

This is a verbatim copy of the post I wrote here.


I am writing to ask whether the graphNEL class of the graph package supports self-loops. If yes, how should self-loops in undirected graphs be represented? Should they appear once or twice in the adjacency list?

As an example, consider the following way to construct a graph:

gn <- graphNEL(nodes=c('A','B'), edgeL=list(A=c('A','B'), B=c('A')), edgemode='undirected')

The undirected graph I intend to represent is the following:

image

I.e., there are two connected vertices, and one of them has a single-self loop.

B has degree 1 and A has degree 3. However, the degree function indicates a degree of 2 for A:

> degree(gn)
A B 
2 1

Is this intentional or is it a bug? If intentional, this would be a highly unusual definition for the idea of "degree" that does not possess many of the usual properties of the more commonly known degree concept. For example, the degrees no longer sum up to twice the number of edges. Such a definition is not invalid, but it is unusual enough that it should be pointed out explicitly in the documentation.

Or is it perhaps the case that self-loops are supposed to be included twice in the adjacency list when creating undirected graphs?

gn <- graphNEL(nodes=c('A','B'), edgeL=list(A=c('A', 'A', 'B'), B=c('A')), edgemode='undirected')

It would be great if these issues could be clarified in the documentation.

This issue came up while investigating a bug report for igraph's as_graphnel() function: igraph/rigraph#575

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions