Graph.jl error in a_star() function

I want to get shortest distance between two edges.

using Graphs,GraphRecipes ,Plots,Karnak,NetworkLayout,Colors,SimpleWeightedGraphs

    add_edge!(G, 1, 2,2000)
    add_edge!(G, 1, 3,1800)
    add_edge!(G, 1, 4,1500)
    add_edge!(G, 2, 3,500)
	add_edge!(G, 3, 4,500)
	add_edge!(G, 3, 5,600)
	add_edge!(G, 4, 5,800)
	@drawsvg begin
    drawgraph(G,vertexlabels=["NR","NER","ER","WR","SR"],vertexfillcolors = (vtx) -> distinguishable_colors(nv(G), transform=tritanopic)[degree(G, vtx)],
    vertexshapesizes = 20,)
	end 600 400

MethodError: no method matching SimpleWeightedGraphs.SimpleWeightedEdge{Int64, Float64}(::Int64, ::Int64)

Closest candidates are:

SimpleWeightedGraphs.SimpleWeightedEdge{T, U}(::Any, ::Any, !Matched::Any) where {T<:Integer, U<:Real} at ~/.julia/packages/SimpleWeightedGraphs/8bXKJ/src/simpleweightededge.jl:7

    a_star_impl!(::SimpleWeightedGraphs.SimpleWeightedGraph{Int64, Float64}, ::Int64, ::DataStructures.PriorityQueue{Int64, Float64, Base.Order.ForwardOrdering}, ::Vector{Bool}, ::Vector{Float64}, ::Vector{Int64}, ::SparseArrays.SparseMatrixCSC{Float64, Int64}, ::Graphs.var"#110#111"{Float64}, ::Type{SimpleWeightedGraphs.SimpleWeightedEdge{Int64, Float64}})@astar.jl:37
    a_star(::SimpleWeightedGraphs.SimpleWeightedGraph{Int64, Float64}, ::Int64, ::Int64, ::SparseArrays.SparseMatrixCSC{Float64, Int64}, ::Function, ::Type{SimpleWeightedGraphs.SimpleWeightedEdge{Int64, Float64}})@astar.jl:94
    top-level scope@Local: 1[inlined]


See picture below :blush:

HI there!
Using a_star with SimpleWeightedGraphs.jl used to be a bit tricky because you had to specify the edgetype_to_return (see the documentation).
This issue is now fixed on the main branch of SimpleWeightedGraphs.jl, but I haven’t yet gotten around to a release (will do it soon)

1 Like

Please tell me time by which you will do update in release.

1 Like

Please update release of SimpleWeightedGraphs.jl

I just need to work on the docs first, it should be done by the end of next week

1 Like

@raman_kumar By the way, you could always use the package manager to add the “master” branch of a package, until a new release is made:

using Graphs, Karnak, Colors

using Pkg
Pkg.add(name="SimpleWeightedGraphs", rev="master")  #  <---
using SimpleWeightedGraphs

    add_edge!(G, 1, 2, 2000)
    add_edge!(G, 1, 3, 1800)
    add_edge!(G, 1, 4, 1500)
    add_edge!(G, 2, 3, 500)
	add_edge!(G, 3, 4, 500)
	add_edge!(G, 3, 5, 600)
	add_edge!(G, 4, 5, 800)
	@drawsvg begin
            vertexfillcolors = (vtx) -> 
                    transform=tritanopic)[degree(G, vtx)],
            edgelabels = (n, s, d, f, t) -> 
                text(string(get_weight(G, s, d)), 
                    midpoint(f, t)),
            vertexshapesizes = 20)
	end 600 400


In Pluto notebook it shows error :blush:
Pkg.add disables Pluto’s built-in package manager.

You need to activate a temporary environment, like this: 🎁 Package management · fonsp/Pluto.jl Wiki · GitHub

1 Like

astar edges of shortest path not getting plotted properly & tritanopic vertexlabels issue on using greedy_color() function.

    import Pkg
    # activate a temporary environment
        Pkg.PackageSpec(name="SimpleWeightedGraphs", rev="master"),
    using Graphs,GraphRecipes ,SimpleWeightedGraphs,Karnak,NetworkLayout,Colors

    add_edge!(G, 1, 2,2000)
    add_edge!(G, 1, 3,1800)
    add_edge!(G, 1, 4,1500)
    add_edge!(G, 2, 3,500)
	add_edge!(G, 3, 4,500)
	add_edge!(G, 3, 5,600)
	add_edge!(G, 4, 5,800)
	gc = greedy_color(G)
    dcolors = distinguishable_colors(gc.num_colors)
	@drawsvg begin
    drawgraph(G,vertexlabels=["NR","NER","ER","WR","SR"],vertexfillcolors = dcolors[gc.colors], edgelabels = (n, s, d, f, t) -> text(string(get_weight(G, s, d)),midpoint(f, t)),
    vertexshapesizes = 20,)
drawgraph(G,vertexshapes = :none,layout=stress,edgelist=astar,edgegaps=0,
	end 600 400

Remember to use the same layout algorithm for each drawgraph() call if you build up a graph in layers like this. Your red graph chooses the Stress algorithm, the aquamarine graph uses the default layout algorithm (which isn’t Stress).

With the same layout algorithm:

1 Like

Vertex labels not visible properly – tritanopic vertexlabels issue on using greedy_color() function. How can i put this Graph on the map of India ? I am working on Electricity transmission grid optimisation.

Sorry I have no idea. :pensive:

Hi @raman. If you look closely at what your code is doing, you’ll see that you’re drawing vertex label shapes using a range of strong differentiated colours (distinguishable_colors()), but on top of them you’re drawing the vertex label text in black (automaticallly chosen to contrast with “aquamarine”). There aren’t many text colours that stay visible when drawn on any coloured background!

There are basically two ways to fix this; either change the way you choose the shapes’ colours (vertexfillcolors), or change the way you choose the vertex label text colours (vertexlabeltextcolors). For example, choose a set of darker shape colours and lighter text label colours, or the other way round. Or you could calculate each text label colour to contrast with the shape’s colour. To do this, you can calculate the “luminance” of the shape’s colour and use that to select a contrasting text colour. Alternatively, perhaps re-consider why you want coloured shapes at all… :slight_smile:

The documentation shows some ideas for how to draw arrows on undirected graphs - directed graphs get arrows automatically.

Now i am getting this error. :disguised_face:

    ~  julia                                                            ✔ 
   _       _ _(_)_     |  Documentation:
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.3 (2022-11-14)
 _/ |\__'_|_|_|\__'_|  |  Official release
|__/                   |

julia> using Pkg

julia> Pkg.update()
    Updating registry at `~/.julia/registries/General.toml`
    Updating git-repo ``
ERROR: LoadError: UndefVarError: libcuda not defined
 [1] cuda_toolkit_tag()
   @ Main ~/.julia/packages/CUDA_Runtime_jll/CKzlt/.pkg/platform_augmentation.jl:50
 [2] augment_platform!(platform::Platform)
   @ Main ~/.julia/packages/CUDA_Runtime_jll/CKzlt/.pkg/platform_augmentation.jl:137
 [3] top-level scope
   @ ~/.julia/packages/CUDA_Runtime_jll/CKzlt/.pkg/select_artifacts.jl:11
 [4] include(fname::String)
   @ Base.MainInclude ./client.jl:476
 [5] top-level scope
   @ none:5
in expression starting at /home/raman/.julia/packages/CUDA_Runtime_jll/CKzlt/.pkg/select_artifacts.jl:11
ERROR: failed process: Process(`/opt/julia-1.8.3/bin/julia -Cnative -J/opt/julia-1.8.3/lib/julia/ -g1 -O0 --color=no --history-file=no --startup-file=no --compiled-modules=yes --project=/home/raman/.julia/environments/v1.8/Project.toml --eval 'append!(empty!(Base.DEPOT_PATH), ["/home/raman/.julia", "/opt/julia-1.8.3/local/share/julia", "/opt/julia-1.8.3/share/julia"])
append!(empty!(Base.DL_LOAD_PATH), String[])

' --startup-file=no x86_64-linux-gnu-libgfortran5-cxx11-libstdcxx29-julia_version+1.8.3`, ProcessExited(1)) [1]

  [1] pipeline_error
    @ ./process.jl:565 [inlined]
  [2] read(cmd::Cmd)
    @ Base ./process.jl:449
  [3] collect_artifacts(pkg_root::String; platform::Base.BinaryPlatforms.Platform)
    @ Pkg.Operations /opt/julia-1.8.3/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:630
  [4] download_artifacts(env::Pkg.Types.EnvCache; platform::Base.BinaryPlatforms.Platform, julia_version::VersionNumber, verbose::Bool, io::Base.TTY)
    @ Pkg.Operations /opt/julia-1.8.3/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:662
  [5] up(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}, level::Pkg.Types.UpgradeLevel; skip_writing_project::Bool)
    @ Pkg.Operations /opt/julia-1.8.3/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:1367
  [6] up(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; level::Pkg.Types.UpgradeLevel, mode::Pkg.Types.PackageMode, update_registry::Bool, skip_writing_project::Bool, kwargs::Base.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})
    @ Pkg.API /opt/julia-1.8.3/share/julia/stdlib/v1.8/Pkg/src/API.jl:341
  [7] up(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::Base.Pairs{Symbol, Pkg.Types.PackageMode, Tuple{Symbol}, NamedTuple{(:mode,), Tuple{Pkg.Types.PackageMode}}})
    @ Pkg.API /opt/julia-1.8.3/share/julia/stdlib/v1.8/Pkg/src/API.jl:156
  [8] up(; name::Nothing, uuid::Nothing, version::Nothing, url::Nothing, rev::Nothing, path::Nothing, mode::Pkg.Types.PackageMode, subdir::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Pkg.API /opt/julia-1.8.3/share/julia/stdlib/v1.8/Pkg/src/API.jl:171
  [9] up()
    @ Pkg.API /opt/julia-1.8.3/share/julia/stdlib/v1.8/Pkg/src/API.jl:162
 [10] top-level scope
    @ REPL[2]:1


Did you try this in an empty environment with just (the master branch of) SimpleWeightedGraphs.jl, instead of your default Julia 1.8.3 environment?

Yes , Master branch code is working fine and i was able to use a_star function properly. Thanks :smiley:

1 Like