@@ -235,11 +235,20 @@ end
235
235
List the DFGVariables in the DFG.
236
236
Optionally specify a label regular expression to retrieves a subset of the variables.
237
237
"""
238
- function getVariables (dfg:: GraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[]):: Vector{DFGVariable}
239
- variables = map (v -> v. dfgNode, filter (n -> n. dfgNode isa DFGVariable, Graphs. vertices (dfg. g)))
238
+ function getVariables (dfg:: GraphsDFG ,
239
+ regexFilter:: Union{Nothing, Regex} = nothing ;
240
+ tags:: Vector{Symbol} = Symbol[],
241
+ solvable:: Int = 0 ):: Vector{DFGVariable}
242
+ #
243
+ variables = map (v -> v. dfgNode, filter (n -> (n. dfgNode isa DFGVariable) && (solvable != 0 ? solvable <= isSolvable (n. dfgNode) : true ), Graphs. vertices (dfg. g)))
244
+ # filter on solvable
245
+
246
+ # filter on regex
240
247
if regexFilter != nothing
241
248
variables = filter (v -> occursin (regexFilter, String (v. label)), variables)
242
249
end
250
+
251
+ # filter on tags
243
252
if length (tags) > 0
244
253
mask = map (v -> length (intersect (v. tags, tags)) > 0 , variables )
245
254
return variables[mask]
252
261
List the DFGFactors in the DFG.
253
262
Optionally specify a label regular expression to retrieves a subset of the factors.
254
263
"""
255
- function getFactors (dfg:: GraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ):: Vector{DFGFactor}
256
- factors = map (v -> v. dfgNode, filter (n -> n. dfgNode isa DFGFactor, Graphs. vertices (dfg. g)))
264
+ function getFactors (dfg:: GraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; solvable:: Int = 0 ):: Vector{DFGFactor}
265
+ factors = map (v -> v. dfgNode, filter (n -> (n. dfgNode isa DFGFactor) && (solvable != 0 ? solvable <= isSolvable (n. dfgNode) : true ), Graphs. vertices (dfg. g)))
266
+
257
267
if regexFilter != nothing
258
268
factors = filter (f -> occursin (regexFilter, String (f. label)), factors)
259
269
end
@@ -272,15 +282,14 @@ end
272
282
$(SIGNATURES)
273
283
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
274
284
"""
275
- function getNeighbors (dfg:: GraphsDFG , node:: T ; ready :: Union{Nothing, Int} = nothing , backendset :: Union{Nothing, Int} = nothing ):: Vector{Symbol} where T <: DFGNode
285
+ function getNeighbors (dfg:: GraphsDFG , node:: T ; solvable :: Int = 0 ):: Vector{Symbol} where T <: DFGNode
276
286
if ! haskey (dfg. labelDict, node. label)
277
287
error (" Variable/factor with label '$(node. label) ' does not exist in the factor graph" )
278
288
end
279
289
vert = dfg. g. vertices[dfg. labelDict[node. label]]
280
290
neighbors = in_neighbors (vert, dfg. g) # Don't use out_neighbors! It enforces directiveness even if we don't want it
281
291
# Additional filtering
282
- neighbors = ready != nothing ? filter (v -> v. dfgNode. ready == ready, neighbors) : neighbors
283
- neighbors = backendset != nothing ? filter (v -> v. dfgNode. backendset == backendset, neighbors) : neighbors
292
+ neighbors = solvable != 0 ? filter (v -> solvable <= isSolvable (v. dfgNode), neighbors) : neighbors
284
293
# Variable sorting (order is important)
285
294
if node isa DFGFactor
286
295
order = intersect (node. _variableOrderSymbols, map (v-> v. dfgNode. label, neighbors))
@@ -293,15 +302,14 @@ end
293
302
$(SIGNATURES)
294
303
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
295
304
"""
296
- function getNeighbors (dfg:: GraphsDFG , label:: Symbol ; ready :: Union{Nothing, Int} = nothing , backendset :: Union{Nothing, Int} = nothing ):: Vector{Symbol} where T <: DFGNode
305
+ function getNeighbors (dfg:: GraphsDFG , label:: Symbol ; solvable :: Int = 0 ):: Vector{Symbol} where T <: DFGNode
297
306
if ! haskey (dfg. labelDict, label)
298
307
error (" Variable/factor with label '$(label) ' does not exist in the factor graph" )
299
308
end
300
309
vert = dfg. g. vertices[dfg. labelDict[label]]
301
310
neighbors = in_neighbors (vert, dfg. g) # Don't use out_neighbors! It enforces directiveness even if we don't want it
302
311
# Additional filtering
303
- neighbors = ready != nothing ? filter (v -> v. dfgNode. ready == ready, neighbors) : neighbors
304
- neighbors = backendset != nothing ? filter (v -> v. dfgNode. backendset == backendset, neighbors) : neighbors
312
+ neighbors = solvable != 0 ? filter (v -> isSolvable (v. dfgNode) >= solvable, neighbors) : neighbors
305
313
# Variable sorting when using a factor (function order is important)
306
314
if vert. dfgNode isa DFGFactor
307
315
vert. dfgNode. _variableOrderSymbols
@@ -312,49 +320,14 @@ function getNeighbors(dfg::GraphsDFG, label::Symbol; ready::Union{Nothing, Int}=
312
320
return map (n -> n. dfgNode. label, neighbors)
313
321
end
314
322
315
- # function _copyIntoGraph!(sourceDFG::GraphsDFG, destDFG::GraphsDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false)::Nothing
316
- # # Split into variables and factors
317
- # verts = map(id -> sourceDFG.g.vertices[sourceDFG.labelDict[id]], variableFactorLabels)
318
- # sourceVariables = filter(n -> n.dfgNode isa DFGVariable, verts)
319
- # sourceFactors = filter(n -> n.dfgNode isa DFGFactor, verts)
320
- #
321
- # # Now we have to add all variables first,
322
- # for variable in sourceVariables
323
- # if !haskey(destDFG.labelDict, variable.dfgNode.label)
324
- # addVariable!(destDFG, deepcopy(variable.dfgNode))
325
- # end
326
- # end
327
- # # And then all factors to the destDFG.
328
- # for factor in sourceFactors
329
- # if !haskey(destDFG.labelDict, factor.dfgNode.label)
330
- # # Get the original factor variables (we need them to create it)
331
- # neighVarIds = getNeighbors(sourceDFG, factor.dfgNode.label) #OLD: in_neighbors(factor, sourceDFG.g)
332
- # # Find the labels and associated neighVarIds in our new subgraph
333
- # factVariables = DFGVariable[]
334
- # for neighVarId in neighVarIds
335
- # if haskey(destDFG.labelDict, neighVarId)
336
- # push!(factVariables, getVariable(destDFG, neighVarId))
337
- # #otherwise ignore
338
- # end
339
- # end
340
- #
341
- # # Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
342
- # if includeOrphanFactors || length(factVariables) == length(neighVarIds)
343
- # addFactor!(destDFG, factVariables, deepcopy(factor.dfgNode))
344
- # end
345
- # end
346
- # end
347
- # return nothing
348
- # end
349
-
350
323
"""
351
324
$(SIGNATURES)
352
325
Retrieve a deep subgraph copy around a given variable or factor.
353
326
Optionally provide a distance to specify the number of edges should be followed.
354
327
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
355
328
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
356
329
"""
357
- function getSubgraphAroundNode (dfg:: GraphsDFG{P} , node:: T , distance:: Int64 = 1 , includeOrphanFactors:: Bool = false , addToDFG:: GraphsDFG = GraphsDFG {P} ()):: GraphsDFG where {P <: AbstractParams , T <: DFGNode }
330
+ function getSubgraphAroundNode (dfg:: GraphsDFG{P} , node:: T , distance:: Int64 = 1 , includeOrphanFactors:: Bool = false , addToDFG:: GraphsDFG = GraphsDFG {P} (); solvable :: Int = 0 ):: GraphsDFG where {P <: AbstractParams , T <: DFGNode }
358
331
if ! haskey (dfg. labelDict, node. label)
359
332
error (" Variable/factor with label '$(node. label) ' does not exist in the factor graph" )
360
333
end
@@ -368,7 +341,7 @@ function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, in
368
341
for (key, node) in curList
369
342
neighbors = in_neighbors (node, dfg. g) # Don't use out_neighbors! It enforces directiveness even if we don't want it
370
343
for neighbor in neighbors
371
- if ! haskey (neighborList, neighbor. dfgNode. label)
344
+ if ! haskey (neighborList, neighbor. dfgNode. label) && ( isSolvable (neighbor . dfgNode) >= solvable)
372
345
push! (neighborList, neighbor. dfgNode. label => neighbor)
373
346
push! (newNeighbors, neighbor. dfgNode. label => neighbor)
374
347
end
0 commit comments