Skip to content

Commit 2cd8c21

Browse files
authored
Merge pull request #272 from JuliaRobotics/twig/biadjacency
Interface tests pass except for a few compares and renamed to BiadjacencyMatrix
2 parents 3a2418c + b9b04be commit 2cd8c21

22 files changed

+281
-193
lines changed

src/BigData/BigData.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include("services/FileDataStore.jl")
1010

1111
export AbstractDataStore
1212

13-
export GeneralBigDataEntry, MongodbBigDataEntry, FileBigDataEntry
13+
export AbstractBigDataEntry, GeneralBigDataEntry, MongodbBigDataEntry, FileBigDataEntry
1414
export InMemoryDataStore, FileDataStore
1515

1616
export getBigData, addBigData!, updateBigData!, deleteBigData!, listStoreEntries

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ end
3636
# Accessors
3737
getLabelDict(dfg::CloudGraphsDFG) = dfg.labelDict
3838
getDescription(dfg::CloudGraphsDFG) = dfg.description
39-
setDescription(dfg::CloudGraphsDFG, description::String) = dfg.description = description
39+
setDescription!(dfg::CloudGraphsDFG, description::String) = dfg.description = description
4040
getAddHistory(dfg::CloudGraphsDFG) = dfg.addHistory
4141
getSolverParams(dfg::CloudGraphsDFG) = dfg.solverParams
42-
function setSolverParams(dfg::CloudGraphsDFG, solverParams::T)::T where T <: AbstractParams
42+
function setSolverParams!(dfg::CloudGraphsDFG, solverParams::T)::T where T <: AbstractParams
4343
return dfg.solverParams = solverParams
4444
end
4545

@@ -163,7 +163,7 @@ function getFactor(dfg::CloudGraphsDFG, factorId::Int64)::DFGFactor
163163
factor = dfg.rebuildFactorMetadata!(dfg, factor)
164164
# GUARANTEED never to bite us in the future...
165165
# ... TODO: refactor if changed: https://github.com/JuliaRobotics/IncrementalInference.jl/issues/350
166-
solverData(factor).fncargvID = factor._variableOrderSymbols
166+
getSolverData(factor).fncargvID = factor._variableOrderSymbols
167167

168168
# Add to cache
169169
push!(dfg.factorCache, factor.label=>factor)

src/Common.jl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ Related
114114
ls, lsf
115115
"""
116116
sortDFG(vars::Vector{Symbol})::Vector{Symbol} = sortVarNested(vars)
117-
118117
"""
119118
$SIGNATURES
120119
@@ -137,7 +136,7 @@ function getfnctype(data::GenericFunctionNodeData)
137136
return data.fnc.usrfnc!
138137
end
139138
function getfnctype(fact::DFGFactor; solveKey::Symbol=:default)
140-
data = solverData(fact) # TODO , solveKey=solveKey)
139+
data = getSolverData(fact) # TODO , solveKey=solveKey)
141140
return getfnctype(data)
142141
end
143142
function getfnctype(dfg::T, lbl::Symbol; solveKey::Symbol=:default) where T <: AbstractDFG
@@ -153,7 +152,7 @@ Notes
153152
- Replaces older `getfnctype`.
154153
"""
155154
getFactorType(data::GenericFunctionNodeData) = data.fnc.usrfnc!
156-
getFactorType(fct::DFGFactor) = getFactorType(solverData(fct))
155+
getFactorType(fct::DFGFactor) = getFactorType(getSolverData(fct))
157156
function getFactorType(dfg::G, lbl::Symbol) where G <: AbstractDFG
158157
getFactorType(getFactor(dfg, lbl))
159158
end
@@ -464,3 +463,29 @@ function hasTagsNeighbors(dfg::InMemoryDFGTypes,
464463
alltags = union( (ls(dfg, sym) .|> x->getTags(getNeiFnc(dfg,x)))... )
465464
length(filter(x->x in alltags, tags)) >= (matchAll ? length(tags) : 1)
466465
end
466+
467+
468+
469+
#Natural Sorting
470+
# Adapted from https://rosettacode.org/wiki/Natural_sorting
471+
# split at digit to not digit change
472+
splitbynum(x::AbstractString) = split(x, r"(?<=\D)(?=\d)|(?<=\d)(?=\D)")
473+
#parse to Int
474+
numstringtonum(arr::Vector{<:AbstractString}) = [(n = tryparse(Int, e)) != nothing ? n : e for e in arr]
475+
#natural less than
476+
function natural_lt(x::T, y::T) where T <: AbstractString
477+
xarr = numstringtonum(splitbynum(x))
478+
yarr = numstringtonum(splitbynum(y))
479+
for i in 1:min(length(xarr), length(yarr))
480+
if typeof(xarr[i]) != typeof(yarr[i])
481+
return isa(xarr[i], Int)
482+
elseif xarr[i] == yarr[i]
483+
continue
484+
else
485+
return xarr[i] < yarr[i]
486+
end
487+
end
488+
return length(xarr) < length(yarr)
489+
end
490+
491+
natural_lt(x::Symbol, y::Symbol) = natural_lt(string(x),string(y))

src/CommonAccessors.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ $SIGNATURES
5858
5959
Return the internal ID for a variable.
6060
"""
61-
getInternalId(v::DataLevel1) = v._dfgNodeParams._internalId
61+
getInternalId(v::DataLevel2) = v._dfgNodeParams._internalId
62+
63+
getInternalId(v::Union{DFGVariableSummary, DFGFactorSummary}) = v._internalId

src/Deprecated.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ end
131131
Retrieve data structure stored in a variable.
132132
"""
133133
function getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData
134-
@warn "getData is deprecated, please use solverData()"
134+
@warn "getData is deprecated, please use getSolverData()"
135135
return v.solverDataDict[solveKey]
136136
end
137137

@@ -153,6 +153,12 @@ end
153153
Retrieve solver data structure stored in a factor.
154154
"""
155155
function data(f::DFGFactor)::GenericFunctionNodeData
156-
@warn "data() is deprecated, please use solverData()"
156+
@warn "data() is deprecated, please use getSolverData()"
157157
return f.data
158158
end
159+
160+
161+
getLabelDict(dfg::AbstractDFG) = error("getLabelDict is deprecated, consider using listing functions")
162+
163+
setSolverParams(args...) = error("setSolverParams is deprecated, use setSolverParams!")
164+
setDescription(args...) = error("setSolverParams is deprecated, use setDescription!")

src/DistributedFactorGraphs.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export MeanMaxPPE
9191
# AbstractDFG Interface
9292
#--------
9393
export setSerializationModule!, getSerializationModule
94-
export getLabelDict, getDescription, setDescription, getAddHistory, getSolverParams, setSolverParams
94+
export getDescription, setDescription!, getAddHistory, getSolverParams, setSolverParams!
9595
export getUserData, setUserData!, getRobotData, setRobotData!, getSessionData, setSessionData!
9696

9797
# Not sure these are going to work everywhere, TODO implement in cloud?
@@ -103,10 +103,12 @@ export exists, addVariable!, addFactor!, getVariable, getFactor, updateVariable!
103103
export getVariables, getVariableIds, getFactors, getFactorIds, ls, lsf
104104
export isFullyConnected, hasOrphans
105105
export getNeighbors, _getDuplicatedEmptyDFG, getSubgraphAroundNode, getSubgraph
106-
export getIncidenceMatrix, getIncidenceMatrixSparse
106+
export getBiadjacencyMatrix
107+
107108
export toDot, toDotFile
108109
# Deprecated
109110
export getAdjacencyMatrix, getAdjacencyMatrixSparse
111+
export getLabelDict, setSolverParams, setDescription
110112
#--------
111113

112114
# File import and export

src/FileDFG/services/FileDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function loadDFG(dst::String, iifModule, dfgLoadInto::G; loaddir=joinpath("/","t
138138
# PATCH - To update the fncargvID for factors, it's being cleared somewhere in rebuildFactorMetadata.
139139
# TEMPORARY
140140
# TODO: Remove in future
141-
map(f->solverData(f).fncargvID = f._variableOrderSymbols, getFactors(dfgLoadInto))
141+
map(f->getSolverData(f).fncargvID = f._variableOrderSymbols, getFactors(dfgLoadInto))
142142

143143
return dfgLoadInto
144144
end

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ end
1616
vertex_index(v::GraphsNode) = v.index
1717

1818
# Accessors
19-
getLabelDict(dfg::GraphsDFG) = dfg.labelDict
20-
getDescription(dfg::GraphsDFG) = dfg.description
21-
setDescription(dfg::GraphsDFG, description::String) = dfg.description = description
22-
getAddHistory(dfg::GraphsDFG) = dfg.addHistory
23-
getSolverParams(dfg::GraphsDFG) = dfg.solverParams
24-
function setSolverParams(dfg::GraphsDFG, solverParams::T) where T <: AbstractParams
25-
dfg.solverParams = solverParams
26-
end
19+
# getLabelDict(dfg::GraphsDFG) = dfg.labelDict
20+
# getDescription(dfg::GraphsDFG) = dfg.description
21+
# setDescription(dfg::GraphsDFG, description::String) = dfg.description = description
22+
# getAddHistory(dfg::GraphsDFG) = dfg.addHistory
23+
# getSolverParams(dfg::GraphsDFG) = dfg.solverParams
24+
# function setSolverParams(dfg::GraphsDFG, solverParams::T) where T <: AbstractParams
25+
# dfg.solverParams = solverParams
26+
# end
2727

2828
"""
2929
$(SIGNATURES)

src/LightDFG/LightDFG.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ using DocStringExtensions
66
import ...DistributedFactorGraphs: AbstractDFG, DFGNode, AbstractDFGVariable, AbstractDFGFactor, AbstractDFGSummary, AbstractParams, NoSolverParams, DFGVariable, DFGFactor
77

88
# import DFG functions to extend
9-
import ...DistributedFactorGraphs: setSolverParams,
9+
import ...DistributedFactorGraphs: setSolverParams!,
1010
getFactor,
11-
setDescription,
12-
getLabelDict,
11+
setDescription!,
12+
# getLabelDict,
1313
getUserData,
1414
setUserData!,
1515
getRobotData,
@@ -40,8 +40,7 @@ import ...DistributedFactorGraphs: setSolverParams,
4040
getNeighbors,
4141
getSubgraphAroundNode,
4242
getSubgraph,
43-
getIncidenceMatrix,
44-
getIncidenceMatrixSparse,
43+
getBiadjacencyMatrix,
4544
_getDuplicatedEmptyDFG,
4645
toDot,
4746
toDotFile

src/LightDFG/entities/LightDFG.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ LightDFG{T}(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariabl
5656
LightDFG(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}(); params::T=NoSolverParams(), kwargs...) where T =
5757
LightDFG{T,DFGVariable,DFGFactor}(g; params=params, kwargs...)
5858

59+
60+
LigthDFG(description::String,
61+
userId::String,
62+
robotId::String,
63+
sessionId::String,
64+
userData::Dict{Symbol, String},
65+
robotData::Dict{Symbol, String},
66+
sessionData::Dict{Symbol, String},
67+
solverParams::AbstractParams) =
68+
LigthDFG(FactorGraph{Int,DFGVariable,DFGFactor}(), description, userId, robotId, sessionId, userData, robotData, sessionData, Symbol[], solverParams)
69+
70+
5971
# Fully depcrecate nodeCounter and labelDict
6072
# Base.propertynames(x::LightDFG, private::Bool=false) =
6173
# (:g, :description, :userId, :robotId, :sessionId, :nodeCounter, :labelDict, :addHistory, :solverParams)

0 commit comments

Comments
 (0)