@@ -183,13 +183,16 @@ deleteFactor!(dfg::SymbolDFG, factor::DFGFactor)::DFGFactor = deleteFactor!(dfg,
183
183
List the DFGVariables in the DFG.
184
184
Optionally specify a label regular expression to retrieves a subset of the variables.
185
185
"""
186
- function getVariables (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[]):: Vector{DFGVariable}
186
+ function getVariables (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[], solvable :: Union{Nothing, Int} = nothing ):: Vector{DFGVariable}
187
187
188
188
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
189
189
variables = collect (values (dfg. g. variables))
190
190
if regexFilter != nothing
191
191
variables = filter (v -> occursin (regexFilter, String (v. label)), variables)
192
192
end
193
+ if solvable != nothing
194
+ variables = filter (v -> _isSolvable (dfg, v. label, solvable), variables)
195
+ end
193
196
if length (tags) > 0
194
197
mask = map (v -> length (intersect (v. tags, tags)) > 0 , variables )
195
198
return variables[mask]
@@ -211,27 +214,30 @@ Related
211
214
212
215
ls
213
216
"""
214
- getVariableIds (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[]):: Vector{Symbol} = map (v -> v. label, getVariables (dfg, regexFilter, tags= tags))
217
+ getVariableIds (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[], solvable :: Union{Nothing, Int} = nothing ):: Vector{Symbol} = map (v -> v. label, getVariables (dfg, regexFilter, tags= tags, solvable = solvable ))
215
218
216
219
# Alias
217
220
"""
218
221
$(SIGNATURES)
219
222
List the DFGVariables in the DFG.
220
223
Optionally specify a label regular expression to retrieves a subset of the variables.
221
224
"""
222
- ls (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[]):: Vector{Symbol} = getVariableIds (dfg, regexFilter, tags= tags)
225
+ ls (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[], solvable :: Union{Nothing, Int} = nothing ):: Vector{Symbol} = getVariableIds (dfg, regexFilter, tags= tags, solvable = solvable )
223
226
224
227
"""
225
228
$(SIGNATURES)
226
229
List the DFGFactors in the DFG.
227
230
Optionally specify a label regular expression to retrieves a subset of the factors.
228
231
"""
229
- function getFactors (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ):: Vector{DFGFactor}
232
+ function getFactors (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ; solvable :: Union{Nothing, Int} = nothing ):: Vector{DFGFactor}
230
233
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
231
234
factors = collect (values (dfg. g. factors))
232
235
if regexFilter != nothing
233
236
factors = filter (f -> occursin (regexFilter, String (f. label)), factors)
234
237
end
238
+ if solvable != nothing
239
+ factors = filter (f -> _isSolvable (dfg, f. label, solvable), factors)
240
+ end
235
241
return factors
236
242
end
237
243
240
246
Get a list of the IDs of the DFGFactors in the DFG.
241
247
Optionally specify a label regular expression to retrieves a subset of the factors.
242
248
"""
243
- getFactorIds (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ):: Vector{Symbol} = map (f -> f. label, getFactors (dfg, regexFilter))
244
-
245
- """
246
- $(SIGNATURES)
247
- List the DFGFactors in the DFG.
248
- Optionally specify a label regular expression to retrieves a subset of the factors.
249
- """
250
- # Alias
251
- lsf (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ):: Vector{Symbol} = getFactorIds (dfg, regexFilter)
252
-
253
- """
254
- $(SIGNATURES)
255
- Alias for getNeighbors - returns neighbors around a given node label.
256
- """
257
- function lsf (dfg:: SymbolDFG , label:: Symbol ):: Vector{Symbol}
258
- return getNeighbors (dfg, label)
259
- end
249
+ getFactorIds (dfg:: SymbolDFG , regexFilter:: Union{Nothing, Regex} = nothing ; solvable:: Union{Nothing, Int} = nothing ):: Vector{Symbol} = map (f -> f. label, getFactors (dfg, regexFilter, solvable= solvable))
260
250
261
251
"""
262
252
$(SIGNATURES)
@@ -273,10 +263,10 @@ Checks if the graph is not fully connected, returns true if it is not contiguous
273
263
"""
274
264
hasOrphans (dfg:: SymbolDFG ):: Bool = ! isFullyConnected (dfg)
275
265
276
- function _isready (dfg:: SymbolDFG , label:: Symbol , ready :: Int ):: Bool
266
+ function _isSolvable (dfg:: SymbolDFG , label:: Symbol , solvable :: Int ):: Bool
277
267
278
- haskey (dfg. g. variables, label) && (return dfg. g. variables[label]. solvable >= ready )
279
- haskey (dfg. g. factors, label) && (return dfg. g. factors[label]. solvable >= ready )
268
+ haskey (dfg. g. variables, label) && (return dfg. g. variables[label]. solvable >= solvable )
269
+ haskey (dfg. g. factors, label) && (return dfg. g. factors[label]. solvable >= solvable )
280
270
281
271
# TODO should this be a breaking error?
282
272
@error " Node not in factor or variable"
@@ -296,15 +286,15 @@ end
296
286
$(SIGNATURES)
297
287
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
298
288
"""
299
- function getNeighbors (dfg:: SymbolDFG , node:: DFGNode ; ready :: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol}
289
+ function getNeighbors (dfg:: SymbolDFG , node:: DFGNode ; solvable :: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol}
300
290
label = node. label
301
291
if ! haskey (dfg. g. fadjdict, label)
302
292
error (" Variable/factor with label '$(node. label) ' does not exist in the factor graph" )
303
293
end
304
294
305
295
neighbors_ll = copy (outneighbors (dfg. g, label))
306
296
# Additional filtering
307
- ready != nothing && filter! (lbl -> _isready (dfg, lbl, ready ), neighbors_ll)
297
+ solvable != nothing && filter! (lbl -> _isSolvable (dfg, lbl, solvable ), neighbors_ll)
308
298
backendset != nothing && filter! (lbl -> _isbackendset (dfg, lbl, backendset), neighbors_ll)
309
299
310
300
# Variable sorting (order is important)
@@ -321,14 +311,14 @@ end
321
311
$(SIGNATURES)
322
312
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
323
313
"""
324
- function getNeighbors (dfg:: SymbolDFG , label:: Symbol ; ready :: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol} where T <: DFGNode
314
+ function getNeighbors (dfg:: SymbolDFG , label:: Symbol ; solvable :: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol} where T <: DFGNode
325
315
if ! haskey (dfg. g. fadjdict, label)
326
316
error (" Variable/factor with label '$(label) ' does not exist in the factor graph" )
327
317
end
328
318
329
319
neighbors_ll = copy (outneighbors (dfg. g, label))
330
320
# Additional filtering
331
- ready != nothing && filter! (lbl -> _isready (dfg, lbl, ready ), neighbors_ll)
321
+ solvable != nothing && filter! (lbl -> _isSolvable (dfg, lbl, solvable ), neighbors_ll)
332
322
backendset != nothing && filter! (lbl -> _isbackendset (dfg, lbl, backendset), neighbors_ll)
333
323
334
324
# Variable sorting (order is important)
@@ -341,22 +331,6 @@ function getNeighbors(dfg::SymbolDFG, label::Symbol; ready::Union{Nothing, Int}=
341
331
342
332
end
343
333
344
- # Aliases
345
- """
346
- $(SIGNATURES)
347
- Retrieve a list of labels of the immediate neighbors around a given variable or factor.
348
- """
349
- function ls (dfg:: SymbolDFG , node:: T ):: Vector{Symbol} where T <: DFGNode
350
- return getNeighbors (dfg, node)
351
- end
352
- """
353
- $(SIGNATURES)
354
- Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
355
- """
356
- function ls (dfg:: SymbolDFG , label:: Symbol ):: Vector{Symbol} where T <: DFGNode
357
- return getNeighbors (dfg, label)
358
- end
359
-
360
334
# function _copyIntoGraph!(sourceDFG{AbstractParam,DFGVariable,DFGFactor}::SymbolDFG, destDFG{AbstractParam,DFGVariable,DFGFactor}::SymbolDFG, labels::Vector{Symbol}, includeOrphanFactors::Bool=false)::Nothing
361
335
function _copyIntoGraph! (sourceDFG:: SymbolDFG , destDFG:: SymbolDFG , labels:: Vector{Symbol} , includeOrphanFactors:: Bool = false ):: Nothing
362
336
@@ -454,9 +428,9 @@ Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}
454
428
Rows are all factors, columns are all variables, and each cell contains either nothing or the symbol of the relating factor.
455
429
The first row and first column are factor and variable headings respectively.
456
430
"""
457
- function getAdjacencyMatrix (dfg:: SymbolDFG ):: Matrix{Union{Nothing, Symbol}}
458
- varLabels = map (v-> v. label, getVariables (dfg))
459
- factLabels = map (f-> f. label, getFactors (dfg))
431
+ function getAdjacencyMatrix (dfg:: SymbolDFG ; solvable :: Union{Nothing, Int} = nothing ):: Matrix{Union{Nothing, Symbol}}
432
+ varLabels = map (v-> v. label, getVariables (dfg, solvable = solvable ))
433
+ factLabels = map (f-> f. label, getFactors (dfg, solvable = solvable ))
460
434
vDict = Dict (varLabels .=> [1 : length (varLabels)... ]. + 1 )
461
435
462
436
adjMat = Matrix {Union{Nothing, Symbol}} (nothing , length (factLabels)+ 1 , length (varLabels)+ 1 )
@@ -471,9 +445,9 @@ function getAdjacencyMatrix(dfg::SymbolDFG)::Matrix{Union{Nothing, Symbol}}
471
445
end
472
446
473
447
474
- function getAdjacencyMatrixSparse (dfg:: SymbolDFG ):: Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
475
- varLabels = collect ( keys ( dfg. g . variables) )
476
- factLabels = collect ( keys ( dfg. g . factors) )
448
+ function getAdjacencyMatrixSparse (dfg:: SymbolDFG ; solvable :: Union{Nothing, Int} = nothing ):: Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
449
+ varLabels = getVariableIds ( dfg, solvable = solvable )
450
+ factLabels = getFactorIds ( dfg, solvable = solvable )
477
451
478
452
vDict = Dict (varLabels .=> [1 : length (varLabels)... ])
479
453
0 commit comments