using  Graphs
g  =  graph(collect(1:4),Edge{Int}[])
add_edge!(g,1,2)
add_vertex!(g,5)
delete vertex or edge is very expensive, so there are no those interfaces 
in Graphs.jl currently


在 2014年2月26日星期三 UTC+8下午9:06:29,Ed Scheinerman写道:
>
> Thanks. This helps some. Let me illustrate. I just want simple graphs with 
> integer-named vertices. This starts off well:
>
> julia> using Graphs
>
> julia> g = simple_graph(4)
> Directed Graph (4 vertices, 0 edges)
>
> julia> using Graphs
>
> julia> g = simple_graph(4,is_directed=false)
> Undirected Graph (4 vertices, 0 edges)
>
> julia> add_edge!(g,1,2)
> edge [1]: 1 -- 2
>
> But if I want to add an additional vertex, I get trouble:
>
> julia> add_vertex!(g,5)
> ERROR: no method push!(Range1{Int64},Int64)
>  in add_vertex! at /home/ers/.julia/Graphs/src/graph.jl:50
>
> And I can't figure out how to delete vertices!
>
>
>
> On Sunday, February 23, 2014 12:50:01 PM UTC-5, Uwe Korn wrote:
>>
>>
>> On Saturday, 22 February 2014 22:24:24 UTC, Ed Scheinerman wrote:
>>>
>>> I have looked through the documentation for the Graphs package here:
>>>  http://julialang.org/Graphs.jl/index.html  
>>> <http://julialang.org/Graphs.jl/index.html>
>>> But I'm finding it difficult to get started, even creating simple graphs 
>>> (undirected, no loops, no multiple edges). Adding vertices doesn't seem to 
>>> work. 
>>>
>>
>> For an adjacency list representation, this short snippet may be helpful:
>>
>> using Graphs
>>
>> # Create new graph
>> g = adjlist(KeyVertex{ASCIIString}, is_directed=false)
>>
>> # Add 2 vertices
>> v = add_vertex!(g, "v")
>> u = add_vertex!(g, "u")
>>
>> # Add an edge between them
>> add_edge!(g, v, u)
>>
>> # This will print:
>>
>> #   KeyVertex{ASCIIString}(1,"v")
>>
>> # which is the neighbour of u
>> println(out_neighbors(u, g))
>>
>>  
>>
>>> Is there a tutorial somewhere to help me get started? Thanks. 
>>>
>>
>> I'm not aware of a tutorial (which would be indeed very helpful) but I 
>> learnt how to use the Graphs package by looking at its tests like 
>> https://github.com/JuliaLang/Graphs.jl/blob/master/test/adjlist.jl which 
>> outline quite short how that package works.
>>
>

Reply via email to