Hi. I am trying to create a program which would tell me the connection between some equipments in a network. For a example a connection between Switch1 and Switch10. I know that the path from Switch1 to Switch10 goes through some patches and other switches and these switches and patches have connections with some other switches and patches. I hope you get the idea. The connection between every to devices i define it manually. For example Switch1/port1 connects with Patch1/port1, Patch1/port2 connects with Switch2/port1. Having this information I want to determine the path between Switch1 and Switch10 for example. I know that I have to check all the connections for Switch1 with other switches and patches and then for those switches and patches the connections with other switches and patches and so on until one of them connects to Switch10 which is the destination. The idea is how to put this in a code because I have to create arrays of arrays of arrays. Also, every connection between to devices has a connection id, to identify it. At least this is how i see it. Any information and tips about how to do this would be helpful. Thank you.

7 Years
Discussion Span
Last Post by alexia_net

Lets see it from an OO point of view. If is a tree what you are describing … You have objects with some properties. Let’s say that one of them is id and of course parent id (for top objects it should be 0) witch is unique. Creating a list of these objects could help you knowing one of them to get all objects path to 0 (root) (self referenced tables or snakes). If this is not the case and it is not a tree there could be many ways around it… just determine what it is …


Hi. It is like a tree structure that's correct. There are several ways to be checked until I find the right one.

Edited by alexia_net: n/a


A tree structure is probably the wrong way to go about this. The data structure you describe would be more of a graph. Where each node can have 1:n connections to additional nodes. A tree structure is really best suite for parent-child kind of relationships.

http://en.wikipedia.org/wiki/Graph_(data_structure) has some general information on graph data structures and also provides some information on ways to represent your nodes in a graph as well as some common graph traversal algorithms.

Once you have solved your traversal across the graph you will be left with a resultant that can be represented as a doubly linked list (http://en.wikipedia.org/wiki/Doubly-linked_list) which will provide you with a bi directional set of nodes you iterate across. PHP's SPL actually has a data structure for doubly-linked lists already which is why I mention this.

Edited by mschroeder: n/a


Hi. I have managed to do it. The problem was how to put into a code, not what to actually do the job. But i have managed eventually. It took me some time. :) Thank you all.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.