Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Validating connection (Read 3354 times)
Hai
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 63
Joined: Jan 7th, 2009
Validating connection
Feb 9th, 2009 at 8:34am
Print Post  
Hi all

I'm using your control to create a WorkFlow visual represantation.
I would like to create a loop over all nodes and links that will ensure that all elements (but first and last) are connected and I have no loose ends.

Can you please direct me how to acheave this goal ?

Thx

Hai
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Validating connection
Reply #1 - Feb 9th, 2009 at 10:10am
Print Post  
Hi Hai,

Using the classic graph connectivity DFS algorithm:

Code
Select All
int FindConnectedComponents()
{
	Dictionary<DiagramNode, int> nodeConnMap = new Dictionary<DiagramNode, int>();
	int component = 0;

	foreach (DiagramNode node in diagram.Nodes)
	{
		if (!nodeConnMap.ContainsKey(node))
		{
			TraverseComponent(nodeConnMap, node, component);
			component++;
		}
	}

	return component;
}

void TraverseComponent(Dictionary<DiagramNode, int> nodeConnMap, DiagramNode node, int component)
{
	nodeConnMap[node] = component;

	foreach (DiagramLink l in node.OutgoingLinks)
	{
		DiagramNode child = l.Destination;
		if (!nodeConnMap.ContainsKey(child))
			TraverseComponent(nodeConnMap, child, component);
	}

	foreach (DiagramLink l in node.IncomingLinks)
	{
		DiagramNode child = l.Origin;
		if (!nodeConnMap.ContainsKey(child))
			TraverseComponent(nodeConnMap, child, component);
	}
}
 



If FindComponents returns a value greater than 1, then the workflow graph is not entirely connected. You might make nodeConnMap an out argument to get more information on connectivity from the method. You will know that there is a path between a pair of nodes if they have the same value in the dictionary. You could remove the loop over IncomingLinks if you want to treat the graph as directed.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint