There are a few ways to do it. I prefer to make arrays of the vertices and then the edges and enter them into the graph function. For example:
mat=rand(4,4)
nnodes = size(mat, 1)
nedges = nnodes * (nnodes - 1)
vlist = Array(KeyVertex{Int64}, nnodes)
for i = 1:nnodes
vlist[i] = KeyVertex(i, i)
end
ecounter = 1
elist = Array(ExEdge{typeof(vlist[1])}, nedges)
for i = 1:nnodes
for j = 1:nnodes
if i != j
elist[ecounter] = ExEdge(ecounter, vlist[i], vlist[j])
elist[ecounter].attributes["distance"] = mat[i, j]
ecounter += 1
end
end
end
g = graph(vlist, elist, is_directed = true)