Skip to content

Commit 291fb7b

Browse files
committed
Merge branch 'master' into jt/develop
2 parents 6de37a8 + da4eff0 commit 291fb7b

File tree

5 files changed

+108
-3
lines changed

5 files changed

+108
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.3.1"
3+
version = "0.3.2"
44

55
[deps]
66
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

src/DFGPlots/DFGPlots.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module DFGPlots
2+
3+
using Colors
4+
using LightGraphs
5+
using MetaGraphs
6+
using GraphPlot
7+
import GraphPlot: gplot
8+
9+
using ...DistributedFactorGraphs
10+
11+
export
12+
dfgplot,
13+
DFGPlotProps
14+
15+
struct DFGPlotProps
16+
nodefillc::NamedTuple{(:var,:fac),Tuple{RGB,RGB}}
17+
nodesize::NamedTuple{(:var,:fac),Tuple{Float64,Float64}}
18+
shape::NamedTuple{(:var,:fac),Tuple{Symbol,Symbol}} #not upported yet
19+
20+
layout::Function #spring_layout, spectral_layout
21+
drawlabels::Bool
22+
end
23+
24+
DFGPlotProps() = DFGPlotProps( (var=colorant"seagreen", fac=colorant"cyan3"),
25+
(var=1.0, fac=0.3),
26+
(var=:box, fac=:elipse),
27+
spring_layout,
28+
true)
29+
30+
31+
function dfgplot(dfg::LightGraphsDFG)
32+
33+
nodesize = [has_prop(dfg.g,i,:factor) ? 0.3 : 1.0 for i=vertices(dfg.g)]
34+
nodelabel = [has_prop(dfg.g,i,:factor) ? "" : string(get_prop(dfg.g,i,:label)) for i=vertices(dfg.g)]
35+
nodefillc = [has_prop(dfg.g,i,:factor) ? colorant"seagreen" : colorant"cyan3" for i=vertices(dfg.g)]
36+
37+
gplot(dfg.g, nodelabel=nodelabel, nodesize=nodesize, nodefillc=nodefillc, layout=spectral_layout)
38+
39+
end
40+
41+
function gplot(dfg::LightGraphsDFG; keyargs...)
42+
gplot(dfg.g; keyargs...)
43+
end
44+
45+
function dfgplot(dfg::AbstractDFG)
46+
# TODO implement convert functions
47+
@warn "TODO Implement convert"
48+
ldfg = LightGraphsDFG{AbstractParams}()
49+
DistributedFactorGraphs._copyIntoGraph!(dfg, ldfg, union(getVariableIds(dfg), getFactorIds(dfg)), true)
50+
51+
nodesize = [has_prop(ldfg.g,i,:factor) ? 0.3 : 1.0 for i=vertices(ldfg.g)]
52+
nodelabel = [has_prop(ldfg.g,i,:factor) ? "" : string(get_prop(ldfg.g,i,:label)) for i=vertices(ldfg.g)]
53+
nodefillc = [has_prop(ldfg.g,i,:factor) ? colorant"seagreen" : colorant"cyan3" for i=vertices(ldfg.g)]
54+
55+
gplot(ldfg.g, nodelabel=nodelabel, nodesize=nodesize, nodefillc=nodefillc, layout=spectral_layout)
56+
57+
end
58+
59+
end

src/DistributedFactorGraphs.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ function __init__()
8686
include("CloudGraphsDFG/CloudGraphsDFG.jl")
8787
end
8888
=#
89+
90+
@require GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" begin
91+
include("DFGPlots/DFGPlots.jl")
92+
@reexport using .DFGPlots
93+
end
94+
8995
end
9096

9197
#FIXME JT not sure how to handle this, is it not lightweitgh enought to always include?

src/NeedsAHome.jl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
export hasFactor, hasVariable, isInitialized
2+
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
33

44
"""
55
$SIGNATURES
@@ -38,3 +38,37 @@ end
3838
function isInitialized(dfg::G, label::Symbol; key::Symbol=:default)::Bool where G <: AbstractDFG
3939
return isInitialized(getVariable(dfg, label), key=key)
4040
end
41+
42+
43+
"""
44+
$SIGNATURES
45+
46+
Return whether `sym::Symbol` represents a variable vertex in the graph.
47+
"""
48+
isVariable(dfg::G, sym::Symbol) where G <: AbstractDFG = hasVariable(dfg, sym)
49+
50+
"""
51+
$SIGNATURES
52+
53+
Return whether `sym::Symbol` represents a factor vertex in the graph.
54+
"""
55+
isFactor(dfg::G, sym::Symbol) where G <: AbstractDFG = hasFactor(dfg, sym)
56+
57+
"""
58+
$SIGNATURES
59+
60+
Return reference to the user factor in `<:AbstractDFG` identified by `::Symbol`.
61+
"""
62+
getFactorFunction(fcd::GenericFunctionNodeData) = fcd.fnc.usrfnc!
63+
getFactorFunction(fc::DFGFactor) = getFactorFunction(getData(fc))
64+
function getFactorFunction(dfg::G, fsym::Symbol) where G <: AbstractDFG
65+
getFactorFunction(getFactor(dfg, fsym))
66+
end
67+
68+
69+
"""
70+
$SIGNATURES
71+
72+
Display and return to console the user factor identified by tag name.
73+
"""
74+
showFactor(fgl::G, fsym::Symbol) where G <: AbstractDFG = @show getFactor(fgl,fsym)

test/interfaceTests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ end
131131
numNodes = 10
132132
dfg = testDFGAPI{NoSolverParams}()
133133
verts = map(n -> DFGVariable(Symbol("x$n")), 1:numNodes)
134+
#change ready and backendset for x7,x8 for improved tests on x7x8f1
135+
verts[7].ready = 1
136+
verts[8].backendset = 1
134137
map(v -> addVariable!(dfg, v), verts)
135138
map(n -> addFactor!(dfg, [verts[n], verts[n+1]], DFGFactor{Int, :Symbol}(Symbol("x$(n)x$(n+1)f1"))), 1:(numNodes-1))
136139
# map(n -> addFactor!(dfg, [verts[n], verts[n+2]], DFGFactor(Symbol("x$(n)x$(n+2)f2"))), 1:2:(numNodes-2))
@@ -147,12 +150,15 @@ map(n -> addFactor!(dfg, [verts[n], verts[n+1]], DFGFactor{Int, :Symbol}(Symbol(
147150
@test getNeighbors(dfg, getFactor(dfg, :x1x2f1)) == ls(dfg, getFactor(dfg, :x1x2f1))
148151
@test getNeighbors(dfg, :x1x2f1) == ls(dfg, :x1x2f1)
149152

150-
# TODO @Dehann, I don't know exactly what wil be in it, so testing with 0 and 1
151153
# ready and backendset
152154
@test getNeighbors(dfg, :x5, ready=1) == Symbol[]
153155
@test getNeighbors(dfg, :x5, ready=0) == [:x4x5f1,:x5x6f1]
154156
@test getNeighbors(dfg, :x5, backendset=1) == Symbol[]
155157
@test getNeighbors(dfg, :x5, backendset=0) == [:x4x5f1,:x5x6f1]
158+
@test getNeighbors(dfg, :x7x8f1, ready=0) == [:x8]
159+
@test getNeighbors(dfg, :x7x8f1, backendset=0) == [:x7]
160+
@test getNeighbors(dfg, :x7x8f1, ready=1) == [:x7]
161+
@test getNeighbors(dfg, :x7x8f1, backendset=1) == [:x8]
156162
@test getNeighbors(dfg, verts[1], ready=0) == [:x1x2f1]
157163
@test getNeighbors(dfg, verts[1], ready=1) == Symbol[]
158164
@test getNeighbors(dfg, verts[1], backendset=0) == [:x1x2f1]

0 commit comments

Comments
 (0)