If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > How do I model a directed graph?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-06, 04:12
thm thm is offline
Registered User
 
Join Date: Mar 2006
Posts: 1
Question How do I model a directed graph?

Hi all!

Any ideas on how to model a directed acyclic graph (DAG) i postgresql? I need the model to be efficient with respect to traversing the graph.

Please see the attached image for an example.

A typical query on the graph is to traverse backwards following all paths from a given node to it's "start nodes" (i.e. nodes with in-degree 0; the nodes named 'f' in the figure).

As an example, given the node 'c3' in the figure I'd like to be able to retrieve all "connecting" nodes, i.e. c1, c2, f1, f2, f3.

Anybody have experience with modeling graphs? I suspect I have to be careful not to run into performance problems on larger graphs (i.e. milions of nodes). As can be seen from the figure, any node can reference any number of nodes, and any node can be references by any number of nodes, i.e. a many-to-many between nodes.


Thank you!
Attached Thumbnails
How do I model a directed graph?-graph.jpg  
Reply With Quote
  #2 (permalink)  
Old 03-30-06, 16:35
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
I've never thought about modelling a network diagram like this. Maybe a self referencing, many-many relationship? You would have to explicitly exclude (maybe via trigger?) a node referencing itself.
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Reply With Quote
  #3 (permalink)  
Old 03-30-06, 17:00
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
They're already covering Section C now? I didn't think we were that far into the semester!

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On