Skip to content

[BUG] isgraphical returns true for a non-graphical sequence #400

@dave-ck

Description

@dave-ck

Description of bug, expected and actual behavior
isgraphical returns true for a non-graphical sequence, namely [4,2,2,2,0]. It should return false on this input.

How to reproduce
Call the function isgraphical on input [4,2,2,2,0].

Code demonstrating bug

using Graphs

println(isgraphical([4,2,2,2])) # should print false, prints false
println(isgraphical([4,2,2,2,0])) # should print false, prints true
println(isgraphical([4,2,2,2,0]) == isgraphical([4,2,2,2])) # should definitely print true, prints false

Version information

Julia Version 1.10.4
Commit 48d4fd4843 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × AMD Ryzen 7 5800H with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)   
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS =

Output of ]status Graphs is [86223c79] Graphs v1.9.0.

Additional context
I at first thought the implementation allowed self-loops, in which case the sequence can be realized by (for example) the graph on vertices a,b,c,d,e with edges a-a, a-b, b-c, a-c, a-d, d-d.
However, [4,2,2,2] returns false (as it should if we disallow self-loops).
The implementation should be consistent (optionally with a flag to allow or disallow self-loops, if this is a needed feature).

If the bug is limited to cases where there is a vertex of degree zero, an easy fix would be to add the line

degs = [deg for deg in degs if deg > 0]

at the beginning of the function (e.g. after checking the sum of degrees is even, and before the sequence length is computed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions