Main Content

isConnected

Check if factor graph is connected

Since R2022a

Description

The isConnected function returns a logical flag that indicates whether the factor graph, or a partial factor graph built from specified pose nodes, contains a path between every pair of nodes.

connected = isConnected(fg) returns a logical flag indicating whether the specified factor graph contains a path between every pair of nodes associated with it.

example

connected = isConnected(fg,poseNodeIDs) returns a logical flag indicating whether a partial factor graph comprised of the specified pose nodes IDs poseNodeIDs, and related factors and non-pose nodes, contains a path between every pair of nodes. For more information, see Factor Graph Connectivity.

Examples

collapse all

Create a factor graph.

fg = factorGraph;
poseIDs1 = generateNodeID(fg,2,"factorTwoPoseSE3")
poseIDs1 = 2×2

     0     1
     1     2

poseFactors1 = factorTwoPoseSE3(poseIDs1);
addFactor(fg,poseFactors1);

Check the connectivity.

isConnected(fg)
ans = logical
   1

The graph is connected because there is a path between every node pair of graph. For example, you can reach node 2 from node 0 by going through node 1.

Next try to add a disconnected node. Generate a node ID for a GPS factor.

gpsID = generateNodeID(fg,1,"factorGPS")
gpsID = 
3

Create the GPS factor and add it to the factor graph.

gpsFactor = factorGPS(gpsID);
addFactor(fg,gpsFactor);

Check the connectivity. Note that because the new node specified by the GPS factor is not connected to any of the previous nodes, there is a disconnect.

isConnected(fg)
ans = logical
   0

Add another factor between node 2 and node 3 to resolve this disconnect.

poseFactors2 = factorTwoPoseSE3([2 3]);
addFactor(fg,poseFactors2);

Check the connectivity to verify the graph is connected again.

isConnected(fg)
ans = logical
   1

Input Arguments

collapse all

Factor graph, specified as a factorGraph object.

IDs of pose nodes to check for connection within the factor graph, specified as an N-element row vector of nonnegative integers. N is the total number of nodes to check.

The pose nodes specified by poseNodeIDs must all be of type "POSE_SE2", or must all be of type "POSE_SE3". The specified pose nodes must also be unique. For example, poseNodeIDs cannot be [1 2 1] because node ID 1 not unique in this vector.

The specified pose nodes in the factor graph must form a connected factor graph. For more information, see Factor Graph Connectivity.

Output Arguments

collapse all

Graph is connected in factor graph or in the partial factor graph, returned as 1 (true) if the factor graph contains a path between every pair of specified nodes and 0 (false) if it does not contain a path between every pair of specified nodes.

More About

collapse all

Extended Capabilities

expand all

Version History

Introduced in R2022a

expand all

See Also

Objects