Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to use PathFinder and omit any type of link? (Read 4143 times)
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
How to use PathFinder and omit any type of link?
Oct 30th, 2009 at 9:46pm
Print Post  
Hi!

I have 2 types of links (property of my derived class). I need to test if there is path between two nodes, but consisting only from kkRelationship type links.

How to omit kkNote type or whats the most effective and fastest way (speed is really important for me) how to do that? Im using this code now:

Code
Select All
'finds out if there is connection (consisting only of relations links) between 2 nodes
    Private Function IsPathBetweenNodes(ByVal IoStartingNode As DiagramNode, ByVal IoEndingNode As DiagramNode) As Boolean
        Dim LoPathFinder As New PathFinder(Me.fcDiagram, True)
        Dim LoPath As Path = LoPathFinder.FindShortestPath(IoStartingNode, IoEndingNode)
        Dim LbResult As Boolean = True

        If LoPath IsNot Nothing Then
            For Each LoLink In LoPath.Links
                Select Case LoLink.GetType.Name
                    Case "ClsMMLinkNode"
                        Dim LoMMLinkNode As ClsMMLinkNode = CType(LoLink, ClsMMLinkNode)
                        Select Case LoMMLinkNode.MMTypeOfLink
                            Case GeTypeOfLink.kkRelationship
                                'do nothing
                            Case GeTypeOfLink.kkNote
                                LbResult = False
                                Exit For
                            Case Else
                                Debug.Print("CHYBA!!! - IsPathBetweenNodes - Select Case LoMMLinkNode.MMTypeOfLink")
                        End Select
                    Case Else
                        Debug.Print("CHYBA!!! - IsPathBetweenNodes - Select Case LoLink.GetType.Name")
                End Select
            Next
        Else
            LbResult = False
        End If

        Return LbResult
    End Function
 



Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use PathFinder and omit any type of lin
Reply #1 - Nov 1st, 2009 at 9:31am
Print Post  
Hi,

Enable the IgnoreLayout property of kkNote links and the PathFinder will ignore them.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to use PathFinder and omit any type of lin
Reply #2 - Nov 1st, 2009 at 11:01am
Print Post  
Hi Stoyo!

Thx for ur suggestion.

But now I need to test this:
- if there is path consisted only from kkRelationship links (parameter IeTypeOfLinks=kkRelationship)
- if there is path length 1 consisted only from kkNote links (parameter IeTypeOfLinks=kkNote)

So it seems I need to set IgnoreLayout property everytime when I need to find path - first case for kkRelationship links and in second case for kkNote links. And it seems its more complicated as my present solution when Im looking for shortest path:

- if Im checking path consisted only from kkRelationship links, I test if in finded shortest path is kkNote link. If yes, I know path is not consisted only from kkRelationship.
- if Im checking path length 1 (coz Im checking direct path between 2 nodes) consisted only from kkNote links, I test if in finded shortest path (length 1) is kkNote link. If no, I know path is not consisted only from kkNote.


Code
Select All
 'finds out if there is already connection between 2 nodes consist of specified type of links
    Private Function IsPathBetweenNodes(ByVal IoStartingNode As DiagramNode, ByVal IoEndingNode As DiagramNode, ByVal IeTypeOfLinks As GeTypeOfLink) As Boolean
	  Dim LoPathFinder As New PathFinder(Me.fcDiagram, True)
	  Dim LoPath As Path = LoPathFinder.FindShortestPath(IoStartingNode, IoEndingNode)
	  Dim LbResult As Boolean = True

	  If LoPath IsNot Nothing Then
		Select Case IeTypeOfLinks
		    Case GeTypeOfLink.kkRelationship
			  'checking path consist of relationship links
			  For Each LoLink In LoPath.Links
				Select Case LoLink.GetType.Name
				    Case "ClsMMLinkNode"
					  Select Case CType(LoLink, ClsMMLinkNode).MMTypeOfLink
						Case GeTypeOfLink.kkNote
						    LbResult = False
						    Exit For
					  End Select
				    Case Else
					  Debug.Print("CHYBA!!! - IsPathBetweenNodes - IeTypeOfLinks=kkRelationship - Select Case LoLink.GetType.Name")
				End Select
			  Next
		    Case GeTypeOfLink.kkNote
			  'checking path length 1 consist of note links = if theres connection between 2 nodes
			  If LoPath.Length = 1 Then
				Dim LoLink As DiagramLink = LoPath.Links(0)
				Select Case LoLink.GetType.Name
				    Case "ClsMMLinkNode"
					  If CType(LoLink, ClsMMLinkNode).MMTypeOfLink = GeTypeOfLink.kkNote Then
						LbResult = True
					  Else
						LbResult = False
					  End If
				    Case Else
					  Debug.Print("CHYBA!!! - IsPathBetweenNodes - IeTypeOfLinks=kkNote - Select Case LoPath.Items(0).GetType.Name")
				End Select
			  Else
				LbResult = False
			  End If
		End Select
	  Else
		LbResult = False
	  End If

	  Return LbResult
    End Function
 



So another suggestion? Or am I wrong with setting IgnoreLayout property of links?

thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use PathFinder and omit any type of lin
Reply #3 - Nov 2nd, 2009 at 8:06am
Print Post  
Hi Mudo,

Yes, you will have to toggle the IgnoreLayout property if you need to find paths consisting of different types of links.

Your method might not work correctly if the nodes are connected by two different paths; if the first path returned contains a kkNote link, you might miss a second path that does not contain it.

If these are the only two scenarios you need to support, you can use the IgnoreLayout property and PathFinder for the first type of paths, and the node.Query method for the second type. E.g. query IoStartingNode for "outlinks/destination", check if the returned collection contains IoEndingNode, and check if its incoming link is a kkNote.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to use PathFinder and omit any type of lin
Reply #4 - Nov 2nd, 2009 at 11:33am
Print Post  
Hi Stoyo Smiley

1)
I havent explained one thing:
- there is hierarchy in my model, so every table can have only one incoming link kkRelationship type
- only one table is on the top
- no cycles

U can see it here
Code
Select All
http://i33.tinypic.com/2b8ln6.jpg
 



So Im pretty sure theres only one path between tables consisted of kkRelationship. Thats why I cant miss another path. In another post I asked u which method of PathFinder object can I use to find path if I know theres only one.
So in this case is FindShortestPath method the best solution?

With kkNote links is situation pretty nice. This link can be between note shape and every table in diagram. Im only checking if there are two kkNote link bewteen two same shapes/tables. And sufficient for this is to check path length 1.

I hope now its more clear Smiley

2)
Query method looks really nice and useful! I found out I can use it. In this case is more effective to use object PathFinder and check only length, what is easier and effective as to use another algorithm Query to check paths.

What do u think?

Really thx for ur advices, they were helpful Wink

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use PathFinder and omit any type of lin
Reply #5 - Nov 2nd, 2009 at 1:07pm
Print Post  
Hi,

1) In this picture if the upper note was connected to formular3 instead of formular2, and you call FindShortestPath(f, f3) without ignoring the kkNote links, it will return f->node->f3 as the shorter result instead of what you probably expect: f->f1->f2->f3.

If you don't wish to use IgnoreLayout, you might try assigning Weight values to the links. Keep the hierarchy links at their default value of 1, and set the kkNote links Weight to some number larger than what you expect will be the maximum number of links used in your graphs, say 1000. Now if you call the FindShortestPath overload that takes a useLinkWeights argument, it should return only kkRelationship paths when called with nodes from the hierarchy as arguments, and will return a kkNote path only if the origin or destination is a note node.

2) Query should be faster on large graphs. I suppose there won't be much difference in performance when called on smaller graphs.

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