Recursive network coding

Leo,

Oops! Didn't realize you had an attachment.

How do the links work?

Code:
ARCID	GRID_CODE  FromNode	ToNode
1	3	    6   	3
2	4	    7		4
3	2	    8		2
4	6	    9		10
5	5	   13		5

Wayne
 
I should have left out GRID_CODE. It is not important for this project. ARCID is important.

Streams flow from the "FromNode" to the "ToNode" downstream. Each record represents a stream segment. Sometimes more than one stream segment has the same "ToNode" because sometime streams flow together. In fact, the way that this data is set up every node is a stream confluence. It is analgous to a tree branch. In this example there may be some stream fragments because I simply truncated a 100,000 record file to make it small.

Leo
 
Leo,

Well, OK, but there are no terminators, all front/back pointers point to something.
There's no end to a list.

Take the first record in the list (1, 3, 6, 3)

Does that mean:

ARCID (This node) = 1
The Parent node has ARCID = 6
The Child node has ARCID = 3

Something doesn't seem right here.

Even if a node has more than one child/parent, you can traverse it
with recordsets.

First, I gotta understand the data.

Wayne
 
Actually, that is close but not right. The grid_code is a hint as to how this data was created. Imagine a (huge) grid with each cell numbered consecutivly starting with 1 in the top left corner.
E.G.

Code:
 1,  2,  3,  4,  5
 6,  7,  8,  9, 10
11, 12, 13, 14, 15
16, 17, 18, 19, 20
21, 22, 23, 24, 25

Now imagine a stream that flows over the grid and passes through 1, 7, 12, 17, and 23. That stream would have:
ARCID = 1 (could be anything (a, b, 1234)... this is just an indentifier)
FromNode = 1
ToNode = 23

If a second stream on the grid flows over 5, 9, 14, 18 and then runs into the first stream at 23 then:
ARCID = 2
FromNode = 5
ToNode = 23

So... "FromNode" and "ToNode" do not point to the 'ARCID.' They point to each other.

Leo
 
Last edited:
Wayne,
I am still trying and this one still has me stumped. Thanks for the note about recordsets. I will try to do some more reading on those to see if I can get a solution. Thanks for your help.

Leo
 
Leo,

You have a tree-structure to traverse, not a single-theaded linked list.
If You use a DLookUp to traverse the nodes, you will only process a
random choice when you arrive at each node.

You have to use a Recordset, like VBA and I did earlier in this thread.
See the earlier attached DB for an example.

Which presents the question - Do you want the complete lineage of ALL
possible paths?

That's definitely possible, not quite sure how you'd use it though.

Need more info.

Wayne
 
Yes, I am looking for the complete list of all segments in an upstream path (all the possible tree branches).

What I really need to do is test if one record is upstream of another record. Both will be randomly selected by another part of the script. If one is upstream of the other record then a seperate analysis needs to be done. I guess ideally I would like to know if I have a randomly selected stream segment (record a) and I randomly select another (record b) then if "record b" is upstream of "record a" return "true", if not, return "false."

I figured that an easy way to test if "b" was upstream would be to create a list of record's "a" parents and see if "b" was in that list. If you know an easier/quicker way then I would like to know. :-)

I have downloaded the earlier script and am looking in to it. Thanks agin for your help. Although this is hard for me without a strong VBA background it is kind of fun. Like a puzzle! ha

Thanks again for your tips and help,
Leo
 
Leo,


Quick stab at it.

Hope it gets you started, have to go now.

I'll check back in a few.

Code:
Private Sub cmdSolve_Click()
Dim blnReturnStatus As Boolean

blnReturnStatus = FindNode(Me.StartNode, Me.TargetNode)

If blnReturnStatus Then
   MsgBox ("The node is present!")
Else
   MsgBox ("The node is NOT present!")
End If

End Sub


Public Function FindNode(SourceNode As Long, DesiredNode As Long) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
'
' For the SourceNode, do the following
' 1) If the SourceNode is the Desired Node, exit with TRUE Status
' 2) If there are no children, exit with FALSE status
' 3) For each child, call the function with the child as the new SourceNode
' 
If SourceNode = DesiredNode Then
   FindNode = True
   Exit Function
End If

Set dbs = CurrentDb
sql = "SELECT * from YourTable WHERE StartNode = " & SourceNode

Set rst = dbs.OpenRecordset(sql)

If rst.EOF = True And rst.BOF = True Then
   FindDist = False ' <-- No children
   Exit Function
End If

' Now process each child

While Not rst.EOF And Not rst.BOF
   If FindNode(rst!StartNode, DesiredNode) Then
      FindNode = True
      Exit Function
   rst.MoveNext
   Wend
FindNode = False
End Function

Wayne
 

Users who are viewing this thread

Back
Top Bottom