Skip to content

Identical graphs not considered identical depending on argument vertices in graph_from_dataframe #349

@mkoohafkan

Description

@mkoohafkan

Graphs with the same vertices and edgelist are not considered identical when the vertex order of the argument vertices does not match the order that they occur in the edgelist:

# sample data
set.seed(50)
library(igraph)

edges = unique(cbind(
  sample(100:200, 10),
  sample(100:200, 10)
))

vertices = unique(as.vector(edges))

# identical
g1 = graph_from_data_frame(edges, TRUE)
g2 = graph_from_data_frame(edges, TRUE, vertices)
identical_graphs(g1, g2)
## TRUE

# not identical
g3 = graph_from_data_frame(edges, TRUE, sort(vertices))
identical_graphs(g1, g3)
## FALSE

This also occurs if the vertices are named:

char.edges = cbind(
  paste0("OID", edges[,1]),
  paste0("OID", edges[,2])
)
char.vertices = paste0("OID", vertices)

cg1 = graph_from_data_frame(char.edges, TRUE)
cg2 = graph_from_data_frame(char.edges, TRUE, char.vertices)
identical_graphs(cg1, cg2)
## TRUE
cg3 = graph_from_data_frame(char.edges, TRUE, sort(char.vertices))
identical_graphs(cg1, cg3)
## FALSE

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions