-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeprecated.jl
More file actions
717 lines (642 loc) · 23.2 KB
/
Deprecated.jl
File metadata and controls
717 lines (642 loc) · 23.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
## ================================================================================
## Deprecated in v0.29
##=================================================================================
export FactorCompute
const FactorCompute = FactorDFG
#TODO maybe keep for Bloblet type assert later.
const MetadataTypes = Union{
Int,
Float64,
String,
Bool,
Vector{Int},
Vector{Float64},
Vector{String},
Vector{Bool},
}
function getHash(entry::Blobentry)
return error(
"Blobentry field :hash has been deprecated; use :crchash or :shahash instead",
)
end
function getMetadata(node)
return error(
"getMetadata(node::$(typeof(node))) is deprecated; metadata is now stored in bloblets. Use getBloblets instead.",
)
# return JSON.parse(base64decode(f.metadata), Dict{Symbol, MetadataTypes})
end
# getTimestamp
# setTimestamp is deprecated for now we can implement setTimestamp!(dfg, lbl, ts) later.
function setTimestamp(args...; kwargs...)
return error("setTimestamp is obsolete, use addVariable!(..., timestamp=...) instead.")
end
function setTimestamp!(args...; kwargs...)
return error(
"setTimestamp! is not implemented, use addVariable!(..., timestamp=...) instead.",
)
end
##------------------------------------------------------------------------------
## solveInProgress
##------------------------------------------------------------------------------
# getSolveInProgress and isSolveInProgress is deprecated for DFG v1.0, we can bring it back fully implemented when needed.
# """
# $SIGNATURES
# Which variables or factors are currently being used by an active solver. Useful for ensuring atomic transactions.
# DevNotes:
# - Will be renamed to `data.solveinprogress` which will be in VND, not AbstractGraphNode -- see DFG #201
# Related
# isSolvable
# """
function getSolveInProgress(
var::Union{VariableDFG, FactorCompute},
solveKey::Symbol = :default,
)
# Variable
if var isa VariableDFG
if haskey(refStates(var), solveKey)
return refStates(var)[solveKey].solveInProgress
else
return 0
end
end
# Factor
return getFactorState(var).solveInProgress
end
#TODO missing set solveInProgress and graph level accessor
function isSolveInProgress(
node::Union{VariableDFG, FactorCompute},
solvekey::Symbol = :default,
)
return getSolveInProgress(node, solvekey) > 0
end
function getTypeFromSerializationModule(::AbstractString)
return error(
"getTypeFromSerializationModule is obsolete, use DFG.parseStateKind or IIF.getTypeFromSerializationModule.",
)
end
## Version checking
#NOTE fixed really bad function but kept similar as fallback #TODO upgrade to use pkgversion(m::Module)
function _getDFGVersion()
return pkgversion(DistributedFactorGraphs)
end
function _versionCheck(node::Union{<:VariableDFG, <:FactorDFG})
if node._version.minor < _getDFGVersion().minor
@warn "This data was serialized using DFG $(node._version) but you have $(_getDFGVersion()) installed, there may be deserialization issues." maxlog =
10
end
end
refMetadata(node) = node.metadata
@deprecate packDistribution(d) pack(d)
@deprecate unpackDistribution(d) unpack(d)
function setDescription!(args...)
return error("setDescription! was removed and may be implemented later.")
end
# TODO find replacement.
function _getDuplicatedEmptyDFG(
dfg::GraphsDFG{P, V, F},
) where {P <: AbstractDFGParams, V <: AbstractGraphVariable, F <: AbstractGraphFactor}
Base.depwarn("_getDuplicatedEmptyDFG is deprecated.", :_getDuplicatedEmptyDFG)
newDfg = GraphsDFG{P, V, F}(;
agentLabel = getAgentLabel(dfg),
graphLabel = getGraphLabel(dfg),
solverParams = deepcopy(dfg.solverParams),
)
# DFG.setDescription!(newDfg, "(Copy of) $(DFG.getDescription(dfg))")
return newDfg
end
#Type gets confused with returning a DataType, Kind is an instance of StateType
@deprecate getVariableType(args...) getStateKind(args...)
function getVariableTypeName(v::VariableSummary)
Base.depwarn("getVariableTypeName is deprecated.", :getVariableTypeName)
return v.statekind
end
function getMetadata(dfg::AbstractDFG, label::Symbol, key::Symbol)
return getVariable(dfg, label).smallData[key]
end
function addMetadata!(dfg::AbstractDFG, label::Symbol, pair::Pair{Symbol, <:MetadataTypes})
v = getVariable(dfg, label)
haskey(v.smallData, pair.first) && throw(LabelExistsError("Metadata", pair.first))
push!(v.smallData, pair)
mergeVariable!(dfg, v)
return v.smallData #or pair TODO
end
function updateMetadata!(
dfg::AbstractDFG,
label::Symbol,
pair::Pair{Symbol, <:MetadataTypes};
warn_if_absent::Bool = true,
)
v = getVariable(dfg, label)
warn_if_absent &&
!haskey(v.smallData, pair.first) &&
@warn("$(pair.first) does not exist, adding.")
push!(v.smallData, pair)
mergeVariable!(dfg, v)
return v.smallData #or pair TODO
end
function deleteMetadata!(dfg::AbstractDFG, label::Symbol, key::Symbol)
v = getVariable(dfg, label)
pop!(v.smallData, key)
mergeVariable!(dfg, v)
return 1
end
function listMetadata(dfg::AbstractDFG, label::Symbol)
v = getVariable(dfg, label)
return collect(keys(v.smallData)) #or pair TODO
end
function emptyMetadata!(dfg::AbstractDFG, label::Symbol)
v = getVariable(dfg, label)
empty!(v.smallData)
mergeVariable!(dfg, v)
return v.smallData #or pair TODO
end
# """
# $(SIGNATURES)
# Function to generate source string - agentLabel|graphLabel|varLabel
# """
function buildSourceString(dfg::AbstractDFG, label::Symbol)
return "$(getAgentLabel(dfg))|$(getGraphLabel(dfg))|$label"
end
getAgentMetadata(args...) = error("getAgentMetadata is obsolete, use Bloblets instead.")
setAgentMetadata!(args...) = error("setAgentMetadata! is obsolete, use Bloblets instead.")
getGraphMetadata(args...) = error("getGraphMetadata is obsolete, use Bloblets instead.")
setGraphMetadata!(args...) = error("setGraphMetadata! is obsolete, use Bloblets instead.")
function updateAgentMetadata!(args...)
return error("updateAgentMetadata! is obsolete, use Bloblets instead.")
end
function updateGraphMetadata!(args...)
return error("updateGraphMetadata! is obsolete, use Bloblets instead.")
end
function deleteAgentMetadata!(args...)
return error("deleteAgentMetadata! is obsolete, use Bloblets instead.")
end
function deleteGraphMetadata!(args...)
return error("deleteGraphMetadata! is obsolete, use Bloblets instead.")
end
function emptyAgentMetadata!(args...)
return error("emptyAgentMetadata! is obsolete, use Bloblets instead.")
end
function emptyGraphMetadata!(args...)
return error("emptyGraphMetadata! is obsolete, use Bloblets instead.")
end
#TODO deprecate AbstractPackedObservation
abstract type AbstractPackedObservation end
const PackedObservation = AbstractPackedObservation
#TODO deprecate AbstractPackedBelief
abstract type AbstractPackedBelief end
const PackedBelief = AbstractPackedBelief
#TODO maybe replace with `listVariablesAddOrder` or using sort on `listVariables`
getAddHistory(dfg::AbstractDFG) = error("getAddHistory is deprecated.")
getAddHistory(dfg::GraphsDFG) = listVariables(dfg) #default listVariables on GraphsDFG is ordered
## Utility functions for getting type names and modules (from IncrementalInference)
_getmodule(t::T) where {T} = T.name.module
_getname(t::T) where {T} = T.name.name
function convertPackedType(t::Union{T, Type{T}}) where {T <: AbstractObservation}
return getfield(_getmodule(t), Symbol("Packed$(_getname(t))"))
end
function convertStructType(::Type{PT}) where {PT <: AbstractPackedObservation}
# see #668 for expanded reasoning. PT may be ::UnionAll if the type is of template type.
ptt = PT isa DataType ? PT.name.name : PT
moduleName = PT isa DataType ? PT.name.module : Main
symbolName = Symbol(string(ptt)[7:end])
return getfield(moduleName, symbolName)
end
@deprecate getBlobentry(fg::AbstractDFG, varlabel::Symbol, key::Symbol) getVariableBlobentry(
fg,
varlabel,
key,
)
@deprecate getBlobentries(fg::AbstractDFG, varlabel::Symbol; kwargs...) getVariableBlobentries(
fg,
varlabel;
kwargs...,
)
@deprecate addBlobentry!(fg::AbstractDFG, varlabel::Symbol, entry::Blobentry) addVariableBlobentry!(
fg,
varlabel,
entry,
)
@deprecate mergeBlobentry!(fg::AbstractDFG, varlabel::Symbol, entry::Blobentry) mergeVariableBlobentry!(
fg,
varlabel,
entry,
)
@deprecate deleteBlobentry!(fg::AbstractDFG, varlabel::Symbol, key::Symbol) deleteVariableBlobentry!(
fg,
varlabel,
key,
)
@deprecate listBlobentries(fg::AbstractDFG, varlabel::Symbol) listVariableBlobentries(
fg,
varlabel,
)
# """
# $SIGNATURES
# Determine if the variable or factor neighbors have the `tags:;Vector{Symbol}`, and `matchAll::Bool`.
# """
function hasTagsNeighbors(
dfg::AbstractDFG,
node_label::Symbol,
tags::Vector{Symbol};
matchAll::Bool = true,
)
#
Base.depwarn(
"hasTagsNeighbors is deprecated, use listNeighbors with whereTags instead",
:hasTagsNeighbors,
)
# assume only variables or factors are neighbors
alltags = union((listNeighbors(dfg, node_label) .|> x -> listTags(dfg, x))...)
return length(filter(x -> x in alltags, tags)) >= (matchAll ? length(tags) : 1)
end
#Obsolete PPEs
abstract type AbstractPointParametricEst end
function _ppe_obsolete()
return error(
"PPEs are obsolete and will be replaced soon (IIF.calcMeanMaxSuggested can be used in some cases), see #1133.",
)
end
getPPEMax(args...) = _ppe_obsolete()
getPPEMean(args...) = _ppe_obsolete()
getPPESuggested(args...) = _ppe_obsolete()
getLastUpdatedTimestamp(est::AbstractPointParametricEst) = _ppe_obsolete()
getPPE(args...) = _ppe_obsolete()
addPPE!(args...) = _ppe_obsolete()
addPPEs!(args...) = _ppe_obsolete()
updatePPE!(args...) = _ppe_obsolete()
deletePPE!(args...) = _ppe_obsolete()
listPPEs(args...) = _ppe_obsolete()
mergePPEs!(args...) = _ppe_obsolete()
getPPEDict(args...) = _ppe_obsolete()
getPPEs(args...) = _ppe_obsolete()
getVariablePPEDict(args...) = _ppe_obsolete()
getVariablePPE(args...) = _ppe_obsolete()
MeanMaxPPE(args...; kwargs...) = _ppe_obsolete()
getEstimateFields(args...) = _ppe_obsolete()
function getFactorState(args...)
return error(
"getFactorState is deprecated, use DFG.getRecipehyper or DFG.getRecipestate instead.",
)
end
function setTags!(node, tags::Union{Vector{Symbol}, Set{Symbol}})
Base.depwarn("setTags! is deprecated, use mergeTags! or addTags! instead.", :setTags!)
node.tags !== tags && empty!(node.tags)
return union!(node.tags, tags)
end
# """
# $(SIGNATURES)
# Get a matrix indicating relationships between variables and factors. Rows are
# all factors, columns are all variables, and each cell contains either nothing or
# the symbol of the relating factor. The first row and first column are factor and
# variable headings respectively.
# Note:
# - rather use getBiadjacencyMatrix
# - Returns either of `::Matrix{Union{Nothing, Symbol}}`
# """
# Deprecated in favor of getBiadjacencyMatrix as it is not efficient for large graphs.
function getAdjacencyMatrixSymbols(
dfg::AbstractDFG;
whereSolvable::Union{Nothing, Function} = nothing,
)
#
varLabels = sort(map(v -> v.label, getVariables(dfg; whereSolvable)))
factLabels = sort(map(f -> f.label, getFactors(dfg; whereSolvable)))
vDict = Dict(varLabels .=> [1:length(varLabels)...] .+ 1)
adjMat = Matrix{Union{Nothing, Symbol}}(
nothing,
length(factLabels) + 1,
length(varLabels) + 1,
)
# Set row/col headings
adjMat[2:end, 1] = factLabels
adjMat[1, 2:end] = varLabels
for (fIndex, factLabel) in enumerate(factLabels)
factVars = listNeighbors(dfg, getFactor(dfg, factLabel); solvable)
map(vLabel -> adjMat[fIndex + 1, vDict[vLabel]] = factLabel, factVars)
end
return adjMat
end
@deprecate findVariableNearTimestamp(args...; kwargs...) findVariablesNearTimestamp(
args...;
kwargs...,
)
function getVariable(dfg::AbstractDFG, label::Symbol, stateLabel::Symbol)
Base.depwarn("getVariable with stateLabel is deprecated", :getVariable)
#TODO DFG v1.x will maybe use getVariable(dfg, label; stateLabelFilter) instead.
return getVariable(dfg, label)
# return getVariable(dfg, label; stateLabelFilter = ==(stateLabel))
end
# Deprecated with new State serialization.
# """
# $SIGNATURES
# Default escalzation from coordinates to a group representation point. Override if defaults are not correct.
# E.g. coords -> se(2) -> SE(2).
# DevNotes
# - TODO Likely remove as part of serialization updates, see #590
# - Used in transition period for Serialization. This function will likely be changed or deprecated entirely.
# Related
# [`getCoordinates`](@ref)
# """
function getPoint(
::Type{T},
v::AbstractVector,
basis = ManifoldsBase.DefaultOrthogonalBasis(),
) where {T <: StateType}
Base.depwarn("getPoint is deprecated. Use get_vector and exp directly.", :getPoint)
M = getManifold(T)
p0 = getPointIdentity(T)
X = ManifoldsBase.get_vector(M, p0, v, basis)
return ManifoldsBase.exp(M, p0, X)
end
# """
# $SIGNATURES
# Default reduction of a variable point value (a group element) into coordinates as `Vector`. Override if defaults are not correct.
# DevNotes
# - TODO Likely remove as part of serialization updates, see #590
# - Used in transition period for Serialization. This function will likely be changed or deprecated entirely.
# Related
# [`getPoint`](@ref)
# """
function getCoordinates(
::Type{T},
p,
basis = ManifoldsBase.DefaultOrthogonalBasis(),
) where {T <: StateType}
Base.depwarn(
"getCoordinates is deprecated. Use log and get_coordinates directly.",
:getCoordinates,
)
M = getManifold(T)
p0 = getPointIdentity(T)
X = ManifoldsBase.log(M, p0, p)
return ManifoldsBase.get_coordinates(M, p0, X, basis)
end
# old merge and copy functions, will be replaced by cleaner merge!, sync!, and copyto! functions
# """
# $(SIGNATURES)
# Merger sourceDFG to destDFG given an optional list of variables and factors and distance.
# Notes:
# - Nodes already in the destination graph are updated from sourceDFG.
# - Orphaned factors (where the subgraph does not contain all the related variables) are not included.
# Related:
# - [`copyGraph!`](@ref)
# - [`getSubgraph`](@ref)
# - [`listNeighborhood`](@ref)
# - [`deepcopyGraph`](@ref)
# """
##==============================================================================
## Copy Functions #TODO replace with sync
##==============================================================================
"""
$(SIGNATURES)
Common function for copying nodes from one graph into another graph.
This is overridden in specialized implementations for performance.
Orphaned factors are not added, with a warning if verbose.
Set `overwriteDest` to overwrite existing variables and factors in the destination DFG.
NOTE: `copyGraphMetadata` is deprecated – use agent/graph Bloblets instead.
Related:
- [`deepcopyGraph`](@ref)
- [`deepcopyGraph!`](@ref)
- [`getSubgraph`](@ref)
- [`listNeighborhood`](@ref)
- [`mergeGraph!`](@ref)
"""
#
function copyGraph!(
destDFG::AbstractDFG,
sourceDFG::AbstractDFG,
variableLabels::AbstractVector{Symbol} = listVariables(sourceDFG),
factorLabels::AbstractVector{Symbol} = listFactors(sourceDFG);
copyGraphMetadata::Bool = false,
overwriteDest::Bool = false,
deepcopyNodes::Bool = false,
verbose::Bool = false,
showprogress::Bool = verbose,
)
# Split into variables and factors
sourceVariables = getVariables(sourceDFG, variableLabels)
sourceFactors = getFactors(sourceDFG, factorLabels)
# Now we have to add all variables first,
@showprogress desc = "copy variables" enabled = showprogress for variable in
sourceVariables
variableCopy = deepcopyNodes ? deepcopy(variable) : variable
if !hasVariable(destDFG, variable.label)
addVariable!(destDFG, variableCopy)
elseif overwriteDest
mergeVariable!(destDFG, variableCopy)
else
throw(LabelExistsError("Variable", variable.label))
end
end
# And then all factors to the destDFG.
@showprogress desc = "copy factors" enabled = showprogress for factor in sourceFactors
# Get the original factor variables (we need them to create it)
sourceFactorVariableIds = collect(factor.variableorder)
# Find the labels and associated variables in our new subgraph
factVariableIds = Symbol[]
for variable in sourceFactorVariableIds
if hasVariable(destDFG, variable)
push!(factVariableIds, variable)
end
end
# Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
if length(factVariableIds) == length(sourceFactorVariableIds)
factorCopy = deepcopyNodes ? deepcopy(factor) : factor
if !hasFactor(destDFG, factor.label)
addFactor!(destDFG, factorCopy)
elseif overwriteDest
mergeFactor!(destDFG, factorCopy)
else
throw(LabelExistsError("Factor", factor.label))
end
elseif verbose
@warn "Factor $(factor.label) will be an orphan in the destination graph, and therefore not added."
end
end
if copyGraphMetadata
error(
"copyGraphMetadata keyword has been removed – metadata APIs were replaced by Bloblets. " *
"Copy agent/graph Bloblets manually before calling copyGraph!",
)
end
return nothing
end
"""
$(SIGNATURES)
Copy nodes from one graph into another graph by making deepcopies.
see [`copyGraph!`](@ref) for more detail.
Related:
- [`deepcopyGraph`](@ref)
- [`getSubgraph`](@ref)
- [`listNeighborhood`](@ref)
- [`mergeGraph!`](@ref)
"""
#
function deepcopyGraph!(
destDFG::AbstractDFG,
sourceDFG::AbstractDFG,
variableLabels::Vector{Symbol} = ls(sourceDFG),
factorLabels::Vector{Symbol} = lsf(sourceDFG);
kwargs...,
)
return copyGraph!(
destDFG,
sourceDFG,
variableLabels,
factorLabels;
deepcopyNodes = true,
kwargs...,
)
end
"""
$(SIGNATURES)
Copy nodes from one graph into a new graph by making deepcopies.
see [`copyGraph!`](@ref) for more detail.
Related:
- [`deepcopyGraph!`](@ref)
- [`getSubgraph`](@ref)
- [`listNeighborhood`](@ref)
- [`mergeGraph!`](@ref)
"""
#
function deepcopyGraph(
::Type{T},
sourceDFG::AbstractDFG,
variableLabels::Vector{Symbol} = ls(sourceDFG),
factorLabels::Vector{Symbol} = lsf(sourceDFG);
graphLabel::Symbol = Symbol(getGraphLabel(sourceDFG), "_cp_$(string(uuid4())[1:6])"),
kwargs...,
) where {T <: AbstractDFG}
destDFG = T(;
solverParams = getSolverParams(sourceDFG),
graph = sourceDFG.graph,
agent = sourceDFG.agent,
graphLabel,
)
copyGraph!(
destDFG,
sourceDFG,
variableLabels,
factorLabels;
deepcopyNodes = true,
kwargs...,
)
return destDFG
end
function mergeGraph!(
destDFG::AbstractDFG,
sourceDFG::AbstractDFG,
variableLabels::Vector{Symbol},
factorLabels::Vector{Symbol} = lsf(sourceDFG),
distance::Int = 0;
whereSolvable = nothing,
whereTags = nothing,
kwargs...,
)
Base.depwarn(
"""
mergeGraph! with variableLabels, factorLabels, and distance is deprecated.
For now use function composition ending with mergeGraph!,
syncGraph!(Coming soon) will replace this functionality.
""",
:mergeGraph!,
)
# find neighbors at distance to add
sourceVariables, sourceFactors = listNeighborhood(
sourceDFG,
union(variableLabels, factorLabels),
distance;
whereSolvable,
whereTags,
)
copyGraph!(
destDFG,
sourceDFG,
sourceVariables,
sourceFactors;
deepcopyNodes = true,
overwriteDest = true,
kwargs...,
)
return destDFG
end
@deprecate buildSubgraph(args...; kwargs...) getSubgraph(args...; kwargs...)
#TODO deprecate
# - the verb is not correct and should be `list` as the function returns a list of factors
# - The noun is also not correct and algorithm details are used in the name
# - A better noun is maybe Path or simply listFactors with a fancy filter, something like:
# - [list/get]Path(dfg, from, to; algorithm...)
# the `search` verb can also come ito play, but it is more for knn search type functions.
function findFactorsBetweenNaive(args...)
return error("findFactorsBetweenNaive is obsolete, use DFG.findPath[s] instead.")
end
#TODO deprecate `is` is the correct verb, but rather isHomogeneous(path::Path) the form is isAdjective
"""
$SIGNATURES
Return (::Bool,::Vector{TypeName}) of types between two nodes in the factor graph
DevNotes
- Only works on LigthDFG at the moment.
Related
[`findShortestPathDijkstra`](@ref)
"""
#
function isPathFactorsHomogeneous(dfg::AbstractDFG, from::Symbol, to::Symbol)
# FIXME, must consider all paths, not just shortest...
pth = intersect(findShortestPathDijkstra(dfg, from, to), lsf(dfg))
types = getObservation.(dfg, pth) .|> typeof .|> x -> (x).name #TODO this might not be correct in julia 1.6
utyp = unique(types)
return (length(utyp) == 1), utyp
end
# deprecated use filter and path separately.
function findShortestPathDijkstra(
dfg::GraphsDFG,
from::Symbol,
to::Symbol;
whereVariableLabel::Union{Function, Nothing} = nothing,
whereFactorLabel::Union{Function, Nothing} = nothing,
whereVariableTags::Union{Function, Nothing} = nothing,
whereFactorTags::Union{Function, Nothing} = nothing,
whereVariableType::Union{Function, Nothing} = nothing,
whereFactorType::Union{Function, Nothing} = nothing,
whereSolvable::Union{Function, Nothing} = nothing,
initialized::Union{Nothing, Bool} = nothing,
)
Base.depwarn(
"findShortestPathDijkstra is deprecated, use findPath with `variableLabels`/`factorLabels` kwargs instead.",
:findShortestPathDijkstra,
)
any_active_filters = any(
.!isnothing.([whereVariableLabel, whereFactorLabel, whereVariableTags, whereFactorTags, whereVariableType, whereFactorType, initialized, whereSolvable]),
)
if any_active_filters
varList = listVariables(
dfg;
whereLabel = whereVariableLabel,
whereTags = whereVariableTags,
whereType = whereVariableType,
whereSolvable,
)
fctList = listFactors(
dfg;
whereLabel = whereFactorLabel,
whereTags = whereFactorTags,
whereType = whereFactorType,
whereSolvable,
)
varList = if initialized !== nothing
initmask = isInitialized.(dfg, varList) .== initialized
varList[initmask]
else
varList
end
restrict_labels = vcat(varList, fctList)
subdfg = DFG.getSubgraph(
GraphsDFG{NoSolverParams, VariableSkeleton, FactorSkeleton},
dfg,
restrict_labels,
)
return findPath(subdfg, from, to).path
else
return findPath(dfg, from, to).path
end
end