# Specifying integer edge weights in SimpleWeightedGraph

**URL:** <https://discourse.julialang.org/t/specifying-integer-edge-weights-in-simpleweightedgraph/33315>\
**Category:** Graphs\
**Tags:** lightgraphs, metagraphs\
**Created:** [January 13, 2020, 8:57pm UTC](https://discourse.julialang.org/t/specifying-integer-edge-weights-in-simpleweightedgraph/33315 "2020-01-13T20:57:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkurchin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rkurchin/32/16039_2.png) [@rkurchin](https://discourse.julialang.org/u/rkurchin)\
**Post date:** [January 13, 2020, 8:57pm UTC](https://discourse.julialang.org/t/specifying-integer-edge-weights-in-simpleweightedgraph/33315/1 "2020-01-13T20:57:35Z")

</div>

Hi, I hope this is the right place to post this. It’s sort of a followup to [this question](https://discourse.julialang.org/t/implementing-crystal-graph-cnn-in-julia/33169/3) but on a somewhat different aspect.

In particular, I want to construct a SimpleWeightedGraph (which will eventually be passed to the constructor of a MetaGraph) that has integer edge weights. By default, they come out as Float64. In [the source code](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl/blob/master/src/simpleweightedgraph.jl), it seems like this should be possible:

```julia
"""
    SimpleWeightedGraph{T, U}
A type representing an undirected graph with weights of type `U`.
Note that adding or removing vertices or edges is not particularly performant;
see MetaGraphs.jl for possible alternatives.
"""
mutable struct SimpleWeightedGraph{T<:Integer, U<:Real} <: AbstractSimpleWeightedGraph{T, U}
    weights::SparseMatrixCSC{U,T}
    function SimpleWeightedGraph{T, U}(adjmx::SparseMatrixCSC{U, T}) where T<:Integer where U<:Real
        dima,dimb = size(adjmx)
        isequal(dima,dimb) || error("Adjacency / distance matrices must be square")
        issymmetric(adjmx) || error("Adjacency / distance matrices must be symmetric")
        new{T, U}(adjmx)
    end

end

```

However, when I try, it doesn’t seem to work. In particular, I’ve tried the following:

```julia
g = SimpleWeightedGraph(4, Integer)
g = SimpleWeightedGraph(4, Int64)
g = SimpleWeightedGraph(4, typeof(0))

```

among many others, and in all cases I get some variant of `MethodError: no method matching...` like so:

```julia
ERROR: MethodError: no method matching SimpleWeightedGraph(::Int64, ::Type{Integer})
Closest candidates are:
  SimpleWeightedGraph(::T<:Integer) where T<:Integer at /Users/rkurchin/.julia/packages/SimpleWeightedGraphs/yUFrc/src/simpleweightedgraph.jl:54
  SimpleWeightedGraph(::Type{T<:Integer}, ::Type{U<:Real}) where {U<:Real, T<:Integer} at /Users/rkurchin/.julia/packages/SimpleWeightedGraphs/yUFrc/src/simpleweightedgraph.jl:60
  SimpleWeightedGraph(::SimpleGraph{T<:Integer}, ::Type{U<:Real}) where {U<:Real, T<:Integer} at /Users/rkurchin/.julia/packages/SimpleWeightedGraphs/yUFrc/src/simpleweightedgraph.jl:63

```

I feel like this probably has a very simple answer, but I’ve run out of ideas. Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![rkurchin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rkurchin/32/16039_2.png) [@rkurchin](https://discourse.julialang.org/u/rkurchin)\
**Post date:** [January 13, 2020, 9:01pm UTC](https://discourse.julialang.org/t/specifying-integer-edge-weights-in-simpleweightedgraph/33315/2 "2020-01-13T21:01:43Z")

</div>

Oops, of course right after I posted this I figured out the solution!

```julia
g = SimpleWeightedGraph{Int64, Int64}(4)

```

Leaving this here for posterity. And perhaps once there’s more detailed documentation for these packages, an example like this can be included?
