# Is dijkstra\_shortest\_paths only supposed to handle integer weights?

**URL:** https://discourse.julialang.org/t/is-dijkstra-shortest-paths-only-supposed-to-handle-integer-weights/31761
**Category:** Graphs
**Tags:** lightgraphs
**Created:** [December 2, 2019, 3:43pm UTC](https://discourse.julialang.org/t/is-dijkstra-shortest-paths-only-supposed-to-handle-integer-weights/31761 "2019-12-02T15:43:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![HBreddam](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@HBreddam](https://discourse.julialang.org/u/HBreddam)
#### Post date: [December 2, 2019, 3:43pm UTC](https://discourse.julialang.org/t/is-dijkstra-shortest-paths-only-supposed-to-handle-integer-weights/31761/1 "2019-12-02T15:43:50Z")

</div>

Hi everyone,

I need to have float weight on a graph as it is used as a pricing problem for column generation.  
As far as i can see the dijkstra\_shortest\_paths should be able use float weight, but when i try the following:

```julia
g = MetaGraph(2,0)
add_edge!(g,1,2)
set_prop!(g,1,2,:weight,5.9)
dijkstra_shortest_paths(g,1)

```

I get an inexact error:

```julia
InexactError: Int64(5.9)
in top-level scope at graphs.jl:50
in dijkstra_shortest_paths at LightGraphs\HsNig\src\shortestpaths\dijkstra.jl:143
in dijkstra_shortest_paths at LightGraphs\HsNig\src\shortestpaths\dijkstra.jl:143 
in #dijkstra_shortest_paths#106 at base\none 
in #dijkstra_shortest_paths#105 at LightGraphs\HsNig\src\shortestpaths\dijkstra.jl:95
in getindex at MetaGraphs\V2aXW\src\MetaGraphs.jl:199
in Int64 at base\float.jl:709

```

I might be wrong but i shouldn’t the following part that fails be able to handle floats?:

```julia
function getindex(w::MetaWeights{T,U}, u::Integer, v::Integer)::U where T <: Integer where U <: Real
    _e = Edge(u, v)
    e = !w.directed && !LightGraphs.is_ordered(_e) ? reverse(_e) : _e
    !haskey(w.eprops, e) && return w.defaultweight
    return U(get(w.eprops[e], w.weightfield, w.defaultweight))
end

```

Is this a bug or should i fint another way to do what i need to do? If so, do anyone have suggestions what to use?

---

<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: [December 2, 2019, 3:53pm UTC](https://discourse.julialang.org/t/is-dijkstra-shortest-paths-only-supposed-to-handle-integer-weights/31761/2 "2019-12-02T15:53:29Z")

</div>

> [@HBreddam](#):
>
> g = MetaGraph(2,0)

`0.0` ?

---

<div class="post-metadata">

### Author: ![HBreddam](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@HBreddam](https://discourse.julialang.org/u/HBreddam)
#### Post date: [December 2, 2019, 5:54pm UTC](https://discourse.julialang.org/t/is-dijkstra-shortest-paths-only-supposed-to-handle-integer-weights/31761/3 "2019-12-02T17:54:54Z")

</div>

Wow, thanks! That seems to solve it 🙂
