# Graph.jl error in a\_star() function

**URL:** <https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455>\
**Category:** Graphs\
**Tags:** graphs\
**Created:** [March 22, 2023, 3:45pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455 "2023-03-22T15:45:04Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 22, 2023, 3:45pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/1 "2023-03-22T15:45:04Z")

</div>

I want to get shortest distance between two edges.

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

begin
	G=SimpleWeightedGraph(5)
    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
    background("grey10")
    sethue("aquamarine")
    drawgraph(G,vertexlabels=["NR","NER","ER","WR","SR"],vertexfillcolors = (vtx) -> distinguishable_colors(nv(G), transform=tritanopic)[degree(G, vtx)],
    vertexshapesizes = 20,)
	end 600 400
end

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

    reconstruct_path!@astar.jl:15[inlined]
    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
    a_star@astar.jl:81[inlined]
    top-level scope@Local: 1[inlined]

a_star(G,2,4)

```

_See_ picture below 😊

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/3/23f0a887910e316b90216e0bb32441eef0616162.png)

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 22, 2023, 4:03pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/2 "2023-03-22T16:03:07Z")

</div>

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](https://juliagraphs.org/Graphs.jl/dev/algorithms/shortestpaths/#Graphs.a_star-Union%7BTuple%7BE%7D,%20Tuple%7BU%7D,%20Tuple%7BT%7D,%20Tuple%7BAbstractGraph%7BU%7D,%20Integer,%20Integer%7D,%20Tuple%7BAbstractGraph%7BU%7D,%20Integer,%20Integer,%20AbstractMatrix%7BT%7D%7D,%20Tuple%7BAbstractGraph%7BU%7D,%20Integer,%20Integer,%20AbstractMatrix%7BT%7D,%20Any%7D,%20Tuple%7BAbstractGraph%7BU%7D,%20Integer,%20Integer,%20AbstractMatrix%7BT%7D,%20Any,%20Type%7BE%7D%7D%7D%20where%20%7BT,%20U,%20E%3C:AbstractEdge%7D)).  
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)

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 22, 2023, 4:07pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/3 "2023-03-22T16:07:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 26, 2023, 5:35pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/4 "2023-03-26T17:35:04Z")

</div>

Please update release of SimpleWeightedGraphs.jl

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 26, 2023, 8:25pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/5 "2023-03-26T20:25:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [March 27, 2023, 8:49am UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/6 "2023-03-27T08:49:00Z")

</div>

@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:

```julia
using Graphs, Karnak, Colors

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

begin
    G=SimpleWeightedGraph(5)
    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
        background("grey10")
        sethue("aquamarine")
        drawgraph(G,vertexlabels=["NR","NER","ER","WR","SR"],
            vertexfillcolors = (vtx) -> 
                distinguishable_colors(nv(G), 
                    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
end

```

 ![Screenshot 2023-03-27 at 09.48.04](https://global.discourse-cdn.com/julialang/original/3X/b/5/b50a2bd121e01dc94961bf109539fdaf931b778a.png)

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 27, 2023, 11:27am UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/7 "2023-03-27T11:27:28Z")

</div>

In Pluto notebook it shows error 😊  
_Pkg.add disables Pluto’s built-in package manager._

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/a/da505b1826ba079bd518f9281e7580662b29d0cf.png)

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 27, 2023, 11:40am UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/8 "2023-03-27T11:40:38Z")

</div>

You need to activate a temporary environment, like this: [🎁 Package management · fonsp/Pluto.jl Wiki · GitHub](https://github.com/fonsp/Pluto.jl/wiki/%F0%9F%8E%81-Package-management#pattern-the-pkg-cell)

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 27, 2023, 4:30pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/9 "2023-03-27T16:30:17Z")

</div>

🤔  
astar edges of shortest path not getting plotted properly & tritanopic vertexlabels issue on using [greedy\_color()](https://docs.juliahub.com/Karnak/DWiej/0.3.0/basics/#Graph-coloring) function.

```julia
begin
    import Pkg
    # activate a temporary environment
    Pkg.activate(mktempdir())
    Pkg.add([
        Pkg.PackageSpec(name="SimpleWeightedGraphs", rev="master"),
		 Pkg.PackageSpec(name="GraphRecipes"),Pkg.PackageSpec(name="NetworkLayout")])
    using Graphs,GraphRecipes ,SimpleWeightedGraphs,Karnak,NetworkLayout,Colors
end

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/5/d57816230c3199cb6ebb51015bf28df53a6b4755.png)

```julia
begin
	G=SimpleWeightedGraph(5)
    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)
	astar=a_star(G,1,5)
	gc = greedy_color(G)
    dcolors = distinguishable_colors(gc.num_colors)
	@drawsvg begin
    background("grey10")
    sethue("aquamarine")
    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,)
		
		sethue("red")
drawgraph(G,vertexshapes = :none,layout=stress,edgelist=astar,edgegaps=0,
	edgestrokeweights=5)
	end 600 400
end

```

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [March 27, 2023, 5:02pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/10 "2023-03-27T17:02:48Z")

</div>

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:

 ![Screenshot 2023-03-27 at 18.01.34](https://global.discourse-cdn.com/julialang/original/3X/b/4/b45e5963ee19a09ddf88576d42e9209a912f51b2.png)

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 27, 2023, 5:13pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/11 "2023-03-27T17:13:39Z")

</div>

Vertex labels not visible properly – tritanopic vertexlabels issue on using [greedy\_color()](https://docs.juliahub.com/Karnak/DWiej/0.3.0/basics/#Graph-coloring) function. How can i put this Graph on the map of India ? I am working on Electricity transmission grid optimisation.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [March 27, 2023, 5:16pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/12 "2023-03-27T17:16:05Z")

</div>

> [@raman\_kumar](#):
>
> How can i put this Graph on the map of India ?

Sorry I have no idea. 😔

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [March 28, 2023, 8:43am UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/14 "2023-03-28T08:43:06Z")

</div>

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… 🙂

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

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [April 3, 2023, 2:22pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/15 "2023-04-03T14:22:15Z")

</div>

Now i am getting this error. 🥸

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

julia> using Pkg

julia> Pkg.update()
    Updating registry at `~/.julia/registries/General.toml`
    Updating git-repo `https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl.git`
ERROR: LoadError: UndefVarError: libcuda not defined
Stacktrace:
 [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/sys.so -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[])

cd("/home/raman/.julia/packages/CUDA_Runtime_jll/CKzlt/.pkg")
include("/home/raman/.julia/packages/CUDA_Runtime_jll/CKzlt/.pkg/select_artifacts.jl")
' --startup-file=no x86_64-linux-gnu-libgfortran5-cxx11-libstdcxx29-julia_version+1.8.3`, ProcessExited(1)) [1]

Stacktrace:
  [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

julia> 

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [April 3, 2023, 2:36pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/16 "2023-04-03T14:36:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [April 3, 2023, 4:47pm UTC](https://discourse.julialang.org/t/graph-jl-error-in-a-star-function/96455/17 "2023-04-03T16:47:04Z")

</div>

Yes , Master branch code is working fine and i was able to use a\_star function properly. Thanks 😃
