@@ -194,13 +194,16 @@ end
194
194
List the DFGVariables in the DFG.
195
195
Optionally specify a label regular expression to retrieves a subset of the variables.
196
196
"""
197
- function getVariables (dfg:: LightDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[]):: Vector{AbstractDFGVariable}
197
+ function getVariables (dfg:: LightDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[], solvable :: Int = 0 ):: Vector{AbstractDFGVariable}
198
198
199
199
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
200
200
variables = collect (values (dfg. g. variables))
201
201
if regexFilter != nothing
202
202
variables = filter (v -> occursin (regexFilter, String (v. label)), variables)
203
203
end
204
+ if solvable != 0
205
+ variables = filter (v -> _isSolvable (dfg, v. label, solvable), variables)
206
+ end
204
207
if length (tags) > 0
205
208
mask = map (v -> length (intersect (v. tags, tags)) > 0 , variables )
206
209
return variables[mask]
@@ -223,14 +226,15 @@ Related
223
226
ls
224
227
"""
225
228
226
- function getVariableIds (dfg:: LightDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[]):: Vector{Symbol}
229
+ function getVariableIds (dfg:: LightDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[], solvable :: Int = 0 ):: Vector{Symbol}
227
230
228
231
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
229
232
if length (tags) > 0
230
- return map (v -> v. label, getVariables (dfg, regexFilter, tags= tags))
233
+ return map (v -> v. label, getVariables (dfg, regexFilter, tags= tags, solvable = solvable ))
231
234
else
232
235
variables = collect (keys (dfg. g. variables))
233
236
regexFilter != nothing && (variables = filter (v -> occursin (regexFilter, String (v)), variables))
237
+ solvable != 0 && (variables = filter (vId -> _isSolvable (dfg, vId, solvable), variables))
234
238
return variables
235
239
end
236
240
end
@@ -240,12 +244,15 @@ end
240
244
List the DFGFactors in the DFG.
241
245
Optionally specify a label regular expression to retrieves a subset of the factors.
242
246
"""
243
- function getFactors (dfg:: LightDFG , regexFilter:: Union{Nothing, Regex} = nothing ):: Vector{AbstractDFGFactor}
247
+ function getFactors (dfg:: LightDFG , regexFilter:: Union{Nothing, Regex} = nothing ; solvable :: Int = 0 ):: Vector{AbstractDFGFactor}
244
248
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
245
249
factors = collect (values (dfg. g. factors))
246
250
if regexFilter != nothing
247
251
factors = filter (f -> occursin (regexFilter, String (f. label)), factors)
248
252
end
253
+ if solvable != 0
254
+ factors = filter (f -> _isSolvable (dfg, f. label, solvable), factors)
255
+ end
249
256
return factors
250
257
end
251
258
@@ -254,12 +261,15 @@ end
254
261
Get a list of the IDs of the DFGFactors in the DFG.
255
262
Optionally specify a label regular expression to retrieves a subset of the factors.
256
263
"""
257
- function getFactorIds (dfg:: LightDFG , regexFilter:: Union{Nothing, Regex} = nothing ):: Vector{Symbol}
264
+ function getFactorIds (dfg:: LightDFG , regexFilter:: Union{Nothing, Regex} = nothing ; solvable :: Int = 0 ):: Vector{Symbol}
258
265
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
259
266
factors = collect (keys (dfg. g. factors))
260
267
if regexFilter != nothing
261
268
factors = filter (f -> occursin (regexFilter, String (f)), factors)
262
269
end
270
+ if solvable != 0
271
+ factors = filter (fId -> _isSolvable (dfg, fId, solvable), factors)
272
+ end
263
273
return factors
264
274
end
265
275
@@ -271,7 +281,7 @@ function isFullyConnected(dfg::LightDFG)::Bool
271
281
return length (LightGraphs. connected_components (dfg. g)) == 1
272
282
end
273
283
274
- function _isready (dfg:: LightDFG , label:: Symbol , ready:: Int ):: Bool
284
+ function _isSolvable (dfg:: LightDFG , label:: Symbol , ready:: Int ):: Bool
275
285
276
286
haskey (dfg. g. variables, label) && (return dfg. g. variables[label]. solvable >= ready)
277
287
haskey (dfg. g. factors, label) && (return dfg. g. factors[label]. solvable >= ready)
294
304
$(SIGNATURES)
295
305
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
296
306
"""
297
- function getNeighbors (dfg:: LightDFG , node:: DFGNode ; ready :: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol}
307
+ function getNeighbors (dfg:: LightDFG , node:: DFGNode ; solvable :: Int = 0 , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol}
298
308
label = node. label
299
309
if ! exists (dfg, label)
300
310
error (" Variable/factor with label '$(node. label) ' does not exist in the factor graph" )
@@ -303,7 +313,7 @@ function getNeighbors(dfg::LightDFG, node::DFGNode; ready::Union{Nothing, Int}=n
303
313
neighbors_il = FactorGraphs. outneighbors (dfg. g, dfg. g. labels[label])
304
314
neighbors_ll = [dfg. g. labels[i] for i in neighbors_il]
305
315
# Additional filtering
306
- ready != nothing && filter! (lbl -> _isready (dfg, lbl, ready ), neighbors_ll)
316
+ solvable != 0 && filter! (lbl -> _isSolvable (dfg, lbl, solvable ), neighbors_ll)
307
317
backendset != nothing && filter! (lbl -> _isbackendset (dfg, lbl, backendset), neighbors_ll)
308
318
309
319
# Variable sorting (order is important)
@@ -320,15 +330,15 @@ end
320
330
$(SIGNATURES)
321
331
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
322
332
"""
323
- function getNeighbors (dfg:: LightDFG , label:: Symbol ; ready :: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol}
333
+ function getNeighbors (dfg:: LightDFG , label:: Symbol ; solvable :: Int = 0 , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol}
324
334
if ! exists (dfg, label)
325
335
error (" Variable/factor with label '$(label) ' does not exist in the factor graph" )
326
336
end
327
337
328
338
neighbors_il = FactorGraphs. outneighbors (dfg. g, dfg. g. labels[label])
329
339
neighbors_ll = [dfg. g. labels[i] for i in neighbors_il]
330
340
# Additional filtering
331
- ready != nothing && filter! (lbl -> _isready (dfg, lbl, ready ), neighbors_ll)
341
+ solvable != 0 && filter! (lbl -> _isSolvable (dfg, lbl, solvable ), neighbors_ll)
332
342
backendset != nothing && filter! (lbl -> _isbackendset (dfg, lbl, backendset), neighbors_ll)
333
343
334
344
# Variable sorting (order is important)
@@ -426,10 +436,10 @@ Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}
426
436
Rows are all factors, columns are all variables, and each cell contains either nothing or the symbol of the relating factor.
427
437
The first row and first column are factor and variable headings respectively.
428
438
"""
429
- function getAdjacencyMatrix (dfg:: LightDFG ):: Matrix{Union{Nothing, Symbol}}
439
+ function getAdjacencyMatrix (dfg:: LightDFG ; solvable :: Int = 0 ):: Matrix{Union{Nothing, Symbol}}
430
440
# TODO Why does it need to be sorted?
431
- varLabels = sort (collect ( keys ( dfg. g . variables) ))# ort(map(v->v.label, getVariables(dfg)))
432
- factLabels = sort (collect ( keys ( dfg. g . factors) ))# sort(map(f->f.label, getFactors(dfg)))
441
+ varLabels = sort (getVariableIds ( dfg, solvable = solvable ))# ort(map(v->v.label, getVariables(dfg)))
442
+ factLabels = sort (getFactorIds ( dfg, solvable = solvable ))# sort(map(f->f.label, getFactors(dfg)))
433
443
vDict = Dict (varLabels .=> [1 : length (varLabels)... ]. + 1 )
434
444
435
445
adjMat = Matrix {Union{Nothing, Symbol}} (nothing , length (factLabels)+ 1 , length (varLabels)+ 1 )
@@ -443,9 +453,9 @@ function getAdjacencyMatrix(dfg::LightDFG)::Matrix{Union{Nothing, Symbol}}
443
453
return adjMat
444
454
end
445
455
446
- function getAdjacencyMatrixSparse (dfg:: LightDFG ):: Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
447
- varLabels = collect ( keys ( dfg. g . variables) )
448
- factLabels = collect ( keys ( dfg. g . factors) )
456
+ function getAdjacencyMatrixSparse (dfg:: LightDFG ; solvable :: Int = 0 ):: Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
457
+ varLabels = getVariableIds ( dfg, solvable = solvable )
458
+ factLabels = getFactorIds ( dfg, solvable = solvable )
449
459
varIndex = [dfg. g. labels[s] for s in varLabels]
450
460
factIndex = [dfg. g. labels[s] for s in factLabels]
451
461
0 commit comments