Skip to content

Commit b1a87c3

Browse files
authored
Merge pull request #486 from JuliaRobotics/feat/2Q20/fctsbetween
getVariableLabelNumber, findFactorsBetweenNaive
2 parents 0cb9675 + b9d5d57 commit b1a87c3

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/Common.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Related
5757
ls, lsf
5858
"""
5959
sortDFG(vars::Vector{<:DFGNode}; by=getTimestamp, kwargs...) = sort(vars; by=by, kwargs...)
60-
sortDFG(vars::Vector{Symbol}; lt=natural_lt, kwargs...)::Vector{Symbol} = sort(vars; lt=lt, kwargs...)
60+
sortDFG(vars::Vector{Symbol}; lt=natural_lt, kwargs...) = sort(vars; lt=lt, kwargs...)
6161

6262
##==============================================================================
6363
## Validation of session, robot, and user IDs.
@@ -77,3 +77,23 @@ function isValidLabel(id::Union{Symbol, String})::Bool
7777
end
7878
return all(t -> t != uppercase(id), _invalidIds) && match(_validLabelRegex, id) != nothing
7979
end
80+
81+
82+
"""
83+
$SIGNATURES
84+
85+
Small utility to return `::Int`, e.g. `0` from `getVariableLabelNumber(:x0)`
86+
87+
Examples
88+
--------
89+
```julia
90+
getVariableLabelNumber(:l10) # 10
91+
getVariableLabelNumber(:x1) # 1
92+
getVariableLabelNumber(:x1_10, "x1_") # 10
93+
```
94+
95+
DevNotes
96+
- make prefix Regex based for longer -- i.e. `:apriltag578`, `:lm1_4`
97+
98+
"""
99+
getVariableLabelNumber(vs::Symbol, prefix=string(vs)[1]) = parse(Int, string(vs)[(length(prefix)+1):end])

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export DFGFactor, DFGFactorSummary, SkeletonDFGFactor
9292
# Common
9393
export getSolvable, setSolvable!, isSolvable
9494
export getInternalId
95+
export getVariableLabelNumber
9596

9697
# accessors
9798
export getLabel, getTimestamp, setTimestamp, setTimestamp!, getTags, setTags!
@@ -161,6 +162,7 @@ export packVariableNodeData, unpackVariableNodeData
161162
export getSolvedCount, isSolved, setSolvedCount!, isInitialized
162163

163164
export getNeighborhood, getNeighbors, _getDuplicatedEmptyDFG
165+
export findFactorsBetweenNaive
164166
export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
165167
# Big Data
166168
##------------------------------------------------------------------------------

src/services/AbstractDFG.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,41 @@ function deepcopyGraph(::Type{T},
938938
return destDFG
939939
end
940940

941+
942+
943+
##==============================================================================
944+
## Automated Graph Searching
945+
##==============================================================================
946+
947+
"""
948+
$SIGNATURES
949+
950+
Relatively naive function counting linearly from-to
951+
952+
DevNotes
953+
- Convert to using LightGraphs shortest path methods instead.
954+
"""
955+
function findFactorsBetweenNaive(dfg::AbstractDFG, from::Symbol, to::Symbol, assertSingles::Bool=false)
956+
@info "findFactorsBetweenNaive is naive linear number method -- improvements welcome"
957+
SRT = getVariableLabelNumber(from)
958+
STP = getVariableLabelNumber(to)
959+
prefix = string(from)[1]
960+
@assert prefix == string(to)[1] "from-to prefixes must match, one is $prefix, other $(string(to)[1])"
961+
prev = from
962+
fctlist = Symbol[]
963+
for num in (SRT+1):STP
964+
next = Symbol(prefix,num)
965+
fct = intersect(ls(dfg, prev),ls(dfg,next))
966+
!assertSingles ? nothing : @assert length(fct) == 1 "assertSingles=true, won't return multiple factors joining variables at this time"
967+
union!(fctlist, fct)
968+
prev = next
969+
end
970+
971+
return fctlist
972+
end
973+
974+
975+
941976
##==============================================================================
942977
## Subgraphs and Neighborhoods
943978
##==============================================================================

0 commit comments

Comments
 (0)