mbojan / rgraph6

Encoding graphs in graph6, sparse6, and digraph6 formats
https://mbojan.github.io/rgraph6/
GNU General Public License v3.0
12 stars 3 forks source link

Sparse6 bug? #22

Closed mbojan closed 3 years ago

mbojan commented 3 years ago
  set.seed(666)
  g <- igraph::sample_gnp(10, 0.1, directed=FALSE) %>%
    igraph::delete_graph_attr("name") %>%
    igraph::delete_graph_attr("type") %>%
    igraph::delete_graph_attr("loops") %>%
    igraph::delete_graph_attr("p")

  s6 <- as_sparse6(g)
  edgelist_from_sparse6(s6)
  expect_true(
    igraph::identical_graphs(g, igraph_from_text(s6)[[1]])  
  )
schochastics commented 3 years ago

hmm looks like an issue when the vertex with the highest id is an isolate. line 91-93 and 95 in as_sparse6.R

mbojan commented 3 years ago

Indeed, I think the current code here

https://github.com/mbojan/rgraph6/blob/017715950822a917605a2fcac81d7c9482cb8df8/R/as_sparse6.R#L38

and further down here

https://github.com/mbojan/rgraph6/blob/017715950822a917605a2fcac81d7c9482cb8df8/R/as_sparse6.R#L67

silently assumes the network is connected by taking the network size beeing the max vertex id appearing in the edgelist.

I think the as_sparse6.matrix() requires an extra argument for the size of the vertex set.

mbojan commented 3 years ago

I'm adding:

  1. obligatory n argument to as_sparse6.matrix() expecting network size
  2. edgelist_from_sparse6() returns the edge list with gorder attribute storing the network size

Ad 1. I don't think to make sense for n to have any default Ad 2. The attribute is consumed by igraph- and network-making functions.