``````

In [2]:

require("Graphs")
using Graphs
function getParents(g, vertex)
res = Set()
for edge in g.edges
s = edge.source
t = edge.target
if (t.label == vertex) push!(res, s)
end
end
return res
end

function getChildren(g, vertex)
res = Set()
for edge in g.edges
s = edge.source
t = edge.target
if (s.label == vertex) push!(res, t)
end
end
return res
end

``````
``````

Out[2]:

getChildren (generic function with 1 method)

``````
``````

In [3]:

pairs = [(1,3), (2,3), (3,4), (3,5)]

gd = graph(ExVertex[], ExEdge{ExVertex}[], is_directed=false)
V = vertices(gd)
map((edg) -> add_edge!(gd, V[edg[1]], V[edg[2]]), pairs)

# GenericIncidenceList is best for the graph
priority = topological_sort_by_dfs(gd)
for vertex in priority
idx = vertex.index
# can now access in V[idx]
end

# So you just go through it topologically

#eds = Edge{Int}[Edge(i,p[1],p[2]) for (i,p) in enumerate(pairs)]
#gd = simple_edgelist(5, eds)

#gd = simple_inclist(length(pairs))
#for i = 1 : length(pairs)
#    a = pairs[i]
#end

``````
``````

In [4]:

type FactorGraph
Graph::GenericGraph{ExVertex,ExEdge{ExVertex},Array{ExVertex,1},Array{ExEdge{ExVertex},1},Array{Array{ExEdge{ExVertex},1},1}}
Variables #is a list of hashmaps: Each one contains the
Factors #

end

``````
``````

In [9]:

``````
``````

In [168]:

edges(gd)

``````
``````

Out[168]:

4-element Array{ExEdge{ExVertex},1}:
edge [1]: vertex [1] "1" -- vertex [3] "3"
edge [2]: vertex [2] "2" -- vertex [3] "3"
edge [3]: vertex [3] "3" -- vertex [4] "4"
edge [4]: vertex [3] "3" -- vertex [5] "5"

``````
``````

In [186]:

``````
``````

In [187]:

gd.edges

``````
``````

Out[187]:

4-element Array{ExEdge{ExVertex},1}:
edge [1]: vertex [1] "1" -- vertex [3] "3"
edge [2]: vertex [2] "2" -- vertex [3] "3"
edge [3]: vertex [3] "3" -- vertex [4] "4"
edge [4]: vertex [3] "3" -- vertex [5] "5"

``````
``````

In [189]:

typeof(gd)

``````
``````

Out[189]:

GenericGraph{ExVertex,ExEdge{ExVertex},Array{ExVertex,1},Array{ExEdge{ExVertex},1},Array{Array{ExEdge{ExVertex},1},1}} (constructor with 1 method)

``````
``````

In [164]:

getChildren(g2, "3")

``````
``````

Out[164]:

Set{Any}({vertex [5] "5",vertex [4] "4"})

``````
``````

In [150]:

``````
``````