Skip to content

Commit 728d0fb

Browse files
authored
Merge pull request #223 from JuliaRobotics/bug/4Q19_isvariable_isfactor
isVariable and isFactor
2 parents 8a4ed78 + cf47bc0 commit 728d0fb

File tree

9 files changed

+64
-8
lines changed

9 files changed

+64
-8
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ end
7070
"""
7171
$SIGNATURES
7272
73-
Return whether `sym::Symbol` represents a variable vertex in the graph.
73+
Return whether `sym::Symbol` represents a variable in the graph dfg.
7474
"""
7575
isVariable(dfg::CloudGraphsDFG, sym::Symbol)::Bool =
76-
"VARIABLE" in _getNodeTags(dfg.neo4jInstance, [dfg.userId, dfg.robotId, dfg.sessionId, String(sym)])
76+
_getNodeCount(dfg.neo4jInstance, ["VARIABLE", dfg.userId, dfg.robotId, dfg.sessionId, String(sym)]) == 1
7777

7878
"""
7979
$SIGNATURES
8080
81-
Return whether `sym::Symbol` represents a factor vertex in the graph.
81+
Return whether `sym::Symbol` represents a factor in the graph dfg.
8282
"""
8383
isFactor(dfg::CloudGraphsDFG, sym::Symbol)::Bool =
84-
"FACTOR" in _getNodeTags(dfg.neo4jInstance, [dfg.userId, dfg.robotId, dfg.sessionId, String(sym)])
84+
_getNodeCount(dfg.neo4jInstance, ["FACTOR", dfg.userId, dfg.robotId, dfg.sessionId, String(sym)]) == 1
8585

8686
"""
8787
$(SIGNATURES)

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ function exists(dfg::GraphsDFG, node::N) where N <: DFGNode
6363
end
6464
exists(dfg::GraphsDFG, nId::Symbol) = haskey(dfg.labelDict, nId)
6565

66+
function isVariable(dfg::GraphsDFG, sym::Symbol)
67+
return exists(dfg, sym) && dfg.g.vertices[dfg.labelDict[sym]].dfgNode isa DFGVariable
68+
end
69+
70+
function isFactor(dfg::GraphsDFG, sym::Symbol)
71+
return exists(dfg, sym) && dfg.g.vertices[dfg.labelDict[sym]].dfgNode isa DFGFactor
72+
end
6673

6774
"""
6875
$(SIGNATURES)

src/LightDFG/LightDFG.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import ...DistributedFactorGraphs: setSolverParams,
2222
addFactor!,
2323
getSolverParams,
2424
exists,
25+
isVariable,
26+
isFactor,
2527
getDescription,
2628
updateVariable!,
2729
updateFactor!,

src/LightDFG/services/LightDFG.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ exists(dfg::LightDFG, nId::Symbol) = haskey(dfg.g.labels, nId)
4545

4646
exists(dfg::LightDFG, node::DFGNode) = exists(dfg, node.label)
4747

48+
function isVariable(dfg::LightDFG{P,V,F}, sym::Symbol) where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
49+
return haskey(dfg.g.variables, sym)
50+
end
51+
52+
function isFactor(dfg::LightDFG{P,V,F}, sym::Symbol) where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
53+
return haskey(dfg.g.factors, sym)
54+
end
4855

4956

5057
"""

src/SymbolDFG/SymbolDFG.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import ...DistributedFactorGraphs: setSolverParams,
1616
addFactor!,
1717
getSolverParams,
1818
exists,
19+
isVariable,
20+
isFactor,
1921
getDescription,
2022
updateVariable!,
2123
updateFactor!,

src/SymbolDFG/services/SymbolDFG.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ exists(dfg::SymbolDFG, nId::Symbol) = haskey(dfg.g.fadjdict, nId)
2727

2828
exists(dfg::SymbolDFG, node::DFGNode) = exists(dfg, node.label)
2929

30+
function isVariable(dfg::SymbolDFG{P,V,F}, sym::Symbol) where {P <:AbstractParams, V <: DFGNode, F <: DFGNode}
31+
return haskey(dfg.g.variables, sym)
32+
end
3033

34+
function isFactor(dfg::SymbolDFG{P,V,F}, sym::Symbol) where {P <:AbstractParams, V <: DFGNode, F <: DFGNode}
35+
return haskey(dfg.g.factors, sym)
36+
end
3137

3238
"""
3339
$(SIGNATURES)

src/services/AbstractDFG.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,32 @@ end
544544
"""
545545
$SIGNATURES
546546
547-
Return whether `sym::Symbol` represents a variable vertex in the graph.
547+
Return whether `sym::Symbol` represents a variable vertex in the graph DFG.
548+
Checks whether it both exists in the graph and is a variable.
549+
(If you rather want a quick for type, just do node isa DFGVariable)
548550
"""
549-
isVariable(dfg::G, sym::Symbol) where G <: AbstractDFG = exists(dfg, sym)
551+
function isVariable(dfg::G, sym::Symbol) where G <: AbstractDFG
552+
error("isVariable not implemented for $(typeof(dfg))")
553+
end
554+
# Alias - bit ridiculous but know it'll come up at some point. Does existential and type check.
555+
function isVariable(dfg::G, node::N)::Bool where {G <: AbstractDFG, N <: DFGNode}
556+
return isVariable(dfg, node.label)
557+
end
550558

551559
"""
552560
$SIGNATURES
553561
554-
Return whether `sym::Symbol` represents a factor vertex in the graph.
562+
Return whether `sym::Symbol` represents a factor vertex in the graph DFG.
563+
Checks whether it both exists in the graph and is a factor.
564+
(If you rather want a quicker for type, just do node isa DFGFactor)
555565
"""
556-
isFactor(dfg::G, sym::Symbol) where G <: AbstractDFG = exists(dfg, sym)
566+
function isFactor(dfg::G, sym::Symbol) where G <: AbstractDFG
567+
error("isFactor not implemented for $(typeof(dfg))")
568+
end
569+
# Alias - bit ridiculous but know it'll come up at some point. Does existential and type check.
570+
function isFactor(dfg::G, node::N)::Bool where {G <: AbstractDFG, N <: DFGNode}
571+
return isFactor(dfg, node.label)
572+
end
557573

558574
"""
559575
$SIGNATURES

test/iifInterfaceTests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ end
115115
@test exists(dfg, :a) == true
116116
@test exists(dfg, v1) == true
117117
@test exists(dfg, :nope) == false
118+
# isFactor and isVariable
119+
@test isFactor(dfg, f1.label)
120+
@test !isFactor(dfg, v1.label)
121+
@test isVariable(dfg, v1.label)
122+
@test !isVariable(dfg, f1.label)
123+
@test !isVariable(dfg, :doesntexist)
124+
@test !isFactor(dfg, :doesntexist)
125+
118126
# Sorting of results
119127
# TODO - this function needs to be cleaned up
120128
unsorted = [:x1_3;:x1_6;:l1;:april1] #this will not work for :x1x2f1

test/interfaceTests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ end
165165
@test isSolveInProgress(v1) == 1
166166
@test isSolveInProgress(f1) == 1
167167

168+
# isFactor and isVariable
169+
@test isFactor(dfg, f1.label)
170+
@test !isFactor(dfg, v1.label)
171+
@test isVariable(dfg, v1.label)
172+
@test !isVariable(dfg, f1.label)
173+
@test !isVariable(dfg, :doesntexist)
174+
@test !isFactor(dfg, :doesntexist)
175+
168176
# Session, robot, and user small data tests
169177
smallUserData = Dict{Symbol, String}(:a => "42", :b => "Hello")
170178
smallRobotData = Dict{Symbol, String}(:a => "43", :b => "Hello")

0 commit comments

Comments
 (0)