PythonMRFListener.setWhenEdgeAdded
- PythonMRFListener.setWhenEdgeAdded(pyfunc)
Set the function called when an edge is added (it replaces the function previously set for this event on this listener).
- Parameters:
pyfunc (
callable) – a function (i: int, j: int) called when the edge between i and j is added (the order of i and j is not specified)- Raises:
pyagrum.InvalidArgument – if
pyfuncis not callable- Return type:
None
Example
import pyagrum as gum
mrf = gum.fastMRF("A--B;C")
edges = []
listener = mrf.addStructureListener(whenNodeAdded=lambda i, name: None)
listener.setWhenEdgeAdded(lambda i, j: edges.append({i, j})) # the order of i and j is not specified
mrf.addFactor(["B", "C"])
edges
# [{1, 2}]
Class