Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

BoundsError happens when an Int edge is added from a larger vertex to a smaller one. #114

Open
bicycle1885 opened this issue Aug 13, 2014 · 2 comments

Comments

@bicycle1885
Copy link

using Graphs
g = adjlist(Int)
add_vertex!(g, 1)
add_vertex!(g, 3)
add_edge!(g, 3, 1)

This code throws the following error:

~/tmp $ julia hello.jl
ERROR: BoundsError()
 in add_edge! at /Users/kenta/.julia/v0.3/Graphs/src/adjacency_list.jl:58
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start at /Users/kenta/vendor/julia/usr/lib/julia/sys.dylib
while loading /Users/kenta/tmp/hello.jl, in expression starting on line 6

I'm using the revision 3231261 on Julia 0.3.

The problem is apparently the implementation of vertex_index, which ignores the actual location of a vertex in the graph.

The next case also throws an error:

g = adjlist(Int)
add_vertex!(g, 3)
add_vertex!(g, 4)
add_edge!(g, 3, 4)
ERROR: BoundsError()
 in add_edge! at /Users/kenta/.julia/v0.3/Graphs/src/adjacency_list.jl:58
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start at /Users/kenta/vendor/julia/usr/lib/julia/sys.dylib
while loading /Users/kenta/tmp/hello.jl, in expression starting on line 12

Maybe I'm misunderstand the usage of this library.

@bicycle1885
Copy link
Author

Ah, now I understand my misconception of the usage.
Vertices should have an index associated with it and these indices should be added sequentially from 1.
Integer's subtypes (Int, in this case) are already qualified as vertex type and its index is defined as itself.
Hence any codes which add integer vertices separately into a graph cause an unexpected behavior like BoundsError.

Please close this issue if my understanding is right.

And new users like me will really need some hello-world examples and expected use case of this library in the documentation.

@lindahua
Copy link
Contributor

In general, we should not relax the requirement of consecutive indexing a bit. But this may require more careful thoughts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants