transitive-closure-table

Finding the transitive closure of a graph

十年热恋 提交于 2020-01-14 01:36:49
问题 I am trying to calculate a transitive closure of a graph. Let`s consider this graph as an example (the picture depicts the graph, its adjacency and connectivity matrix): Using Warshall's algorithm, which i found on this page, I generate this connectivity matrix (=transitive closure?), that is different from the one in the picture: 01111 01111 01011 01111 01111 I have also tried using this applet which also gives me a different result: 01111 01111 01111 01111 01111 So I'm a little confused

Closure table equivalent for graph structures in SQL

元气小坏坏 提交于 2020-01-13 11:08:28
问题 This question How to store tree structure in sql? lead to the idea of a Closure table for storing trees that is optimal in many ways. The question is is there something along these lines for graph structures in SQL. I saw this paper which seems to outline a graph index structure but it's a bit over my head. Wondering if there is a sort of way to create a few auxiliary tables to handle common queries on graph data in SQL. 回答1: I did the presentation you linked to, and I've been asked about

Closure table equivalent for graph structures in SQL

烂漫一生 提交于 2020-01-13 11:08:12
问题 This question How to store tree structure in sql? lead to the idea of a Closure table for storing trees that is optimal in many ways. The question is is there something along these lines for graph structures in SQL. I saw this paper which seems to outline a graph index structure but it's a bit over my head. Wondering if there is a sort of way to create a few auxiliary tables to handle common queries on graph data in SQL. 回答1: I did the presentation you linked to, and I've been asked about

MySQL hierarchical data help - Closure Table Method

瘦欲@ 提交于 2020-01-12 07:48:06
问题 I'm trying to implement a system in MySQL to store hierarchical data. I've decided to go with the system implemented here as described by Bill Karwin starting on slide number 40. I'm trying to setup the database so the EntryPaths table is maintained automatically. Update: I've updated the database create SQL a bit. I've got things 1/2 working for an update, I think. After running the database create SQL try the following First see how this entry looks -- Example query to return a full library

What query would I use to obtain sibling records when using closure tables?

混江龙づ霸主 提交于 2019-12-24 12:27:53
问题 If I have the following schema & data and am employing the closure table pattern: +----+----------+------------+--------+ | id | ancestor | descendant | length | +----+----------+------------+--------+ | 1 | 2 | 2 | 0 | | 2 | 2 | 12 | 1 | | 3 | 2 | 13 | 1 | | 4 | 2 | 14 | 1 | | 5 | 2 | 15 | 1 | | 10 | 12 | 12 | 0 | | 11 | 13 | 13 | 0 | | 12 | 14 | 14 | 0 | | 13 | 15 | 15 | 0 | | 9 | 17 | 20 | 1 | | 8 | 17 | 19 | 1 | | 7 | 17 | 18 | 1 | | 6 | 17 | 17 | 0 | | 14 | 18 | 18 | 0 | | 15 | 19 | 19 |

How to determine Strahler number on a directed graph for a stream network

南笙酒味 提交于 2019-12-23 19:18:57
问题 Question / example / expected values I need to determine a Strahler number or Strahler stream order for a directed graph representing a stream network. I can derive information forwards and backwards using WITH RECURSIVE queries, but it seems I need to do something different to determine the Strahler number. For example, here is a 19 segment stream network with 10 tributaries and one outlet. The upstream portion of each segment is represented by a node ID. And the same data in a table

How do I query for all the nodes between two nodes in a tree?

丶灬走出姿态 提交于 2019-12-23 00:25:17
问题 I have a hierarchical database strucutre, e.g. columns ID and PARENT_ID defined for each row, with the top level rows having a NULL PARENT_ID . I have all the relationships from this table flattened into another table, e.g. if there were three records in a single hierarchy of grandparent, parent, grandchild, there would be 3 records: **ANCESTOR, DESCENDANT** grantparent, parent grandparent, grandchild parent, grandchild Rather than execute a hierarchical query to determine that the grandchild

codeigniter: closure table - add descendant

天涯浪子 提交于 2019-12-20 07:14:06
问题 I'm trying to add a new descendant, but having difficulties achieving it, it displays some error, Would be grateful if you could take time to review what I've done thus far. Here's Controller public function index() { $this->load->view('closure_view'); } public function add() { $add_new = array( 'ancestor' => $this->input->post('ancestor'), 'descendant' => $this->input->post('descendant'), 'lvl' => $this->input->post('lvl'), 'id' => $this->input->post('id') ); $cust_id = $this->closure->add(

How can I create a closure table using data from an adjacency list?

旧街凉风 提交于 2019-12-17 18:36:38
问题 I have a database containing a hierarchy of categories stored using the adjacency list model. The hierarchy is 3 levels deep (not including an imaginary root node) and contains approx 1700 nodes. Nodes in the 2nd and 3rd levels can have multiple parents. A additional table is used for the many-to-many relationship as below: CREATE TABLE dbo.Category( id int IDENTITY(1,1) NOT NULL, name varchar(255) NOT NULL, ) CREATE TABLE dbo.CategoryHierarchy( relId int IDENTITY(1,1) NOT NULL, catId int NOT

PostgreSQL pass data from recursive CTE onto function

点点圈 提交于 2019-12-17 16:40:23
问题 I have the following problem: I am trying to discover all possible paths from source node ( node_s ) to target node ( node_t ). The format of the original table with graph edges is simple: | node_x | node_y | strength | , where "node_x" -> "node_y" is a direct edge with strength of the edge being "weight". The idea is if at any point during the exploration of the paths we discover that a node among its children has target node_t , we record this path and stop exploring paths from this node,