directed-acyclic-graphs

Efficient algorithm for merging two DAGs

耗尽温柔 提交于 2019-12-09 04:42:32
问题 I have two weighted DAGs (directed acyclic graphs) and need to merge them into one, so I can get a topological ordering (it could be more than two in some cases). The problem is that the graphs are acyclic each, but can form a cycle together. Also, the graphs are large (100k+ nodes, 500k+ edges). Is there a clever way to merge the graphs? Equally good would be an algorithm to traverse all graphs "at once". Edit: By "merge" I mean combining all edges and vertices of both graphs together

Directed acyclic graph

血红的双手。 提交于 2019-12-08 10:28:44
问题 I have problems understanding the directed acyclic graph on page 9 http://mitpress.mit.edu/books/chapters/0262033844chap27.pdf Someone who can explain it? 回答1: If it's a general understanding you require, you could think of it this way. It's "directed" because it has a direction. "acyclic" because it goes one way. Then, think of the graph as a way to navigate one way, in a direction. If you consider this as applied to the storage of a dictionary as an example, it can be very useful. Rather

How can python write a dot file for GraphViz asking for some edges to be colored red?

允我心安 提交于 2019-12-07 22:41:12
问题 I am using python code (with python nested dicts) to write out a DOT file for GraphViz to draw my directed edge-weighted graph, thanks to DAWG's suggestions... nestedg={1: {2: 3, 3: 8, 5: -4}, 2: {4: 1, 5: 7}, 3: {2: 0.09}, 4: {1: 2, 3: -5}, 5: {4: 6}} with open('/tmp/graph.dot','w') as out: for line in ('digraph G {','size="16,16";','splines=true;'): out.write('{}\n'.format(line)) for start,d in nestedg.items(): for end,weight in d.items(): out.write('{} -> {} [ label="{}" ];\n'.format(start

c++ boost::graph get parent vertices from directed graph

不羁岁月 提交于 2019-12-07 21:01:47
问题 I have a directed graph (implemented via an adjacency_graph from the boost::graph library) and I'm trying to find the parent vertices of a certain vertex. In the past (via pygraph) I have simply reversed the digraph, then done a neighbours search, but it appears that reversing the graph with boost::reverse_graph turns my digraph into a bidirectional graph, and therefore I can't use the adjacent_vertices method anymore. Is there a better way to get the parent vertices? Thanks. Here's my

Directed graph linear algorithm

本秂侑毒 提交于 2019-12-07 20:36:30
I would like to know the best way to calculate the length of the shortest path between vertex s and every other vertex of the graph in linear time using dynamic programming. The graph is weighted DAG. What you can hope for is an algorithm linear in the number of edges and vertices, i.e. O(|E| + |V|) , which also works correctly in presence of negative weights. This is done by first computing a topological order and then 'exploring' the graph in the order given by this topological order. Some notation: let's call d'(s,v) the shortest distance from s to v and d(u,v) the length/weight of the arc

Data Structure to represent a DAG in Javascript

荒凉一梦 提交于 2019-12-07 09:57:50
问题 I have a string that I need to parse into a graph (DAG) data structure using javascript. Included in the data structure are a few attributes I should store, such as the node's id, name, and a label that is given to the link if one exists to another node. So, an example would be Node1 (id: 1, name: 'first') --('link name')--> Node2 (id:....) and so forth. Once the data structure is created I do not need to do any more operations on it other than read it (I will later use it to render a

Eliminating extraneous edges in directed acyclic graph while trying to find longest paths

扶醉桌前 提交于 2019-12-07 09:38:23
问题 I asked a question about finding subsequences in a variable amount of sets with no repeating characters. The solution was to create a matrix of each pair of letters, discard those that don't occur in each set, and then find the longest path in the directed acyclic graph. However, I don't want just the longest path, I want several of the longest paths (e.g. if it generates subsequences of lengths 10, 10, 9, 8, 8, 3, 3, 2, and 1, I may want to display the first 5 subsequences only). And so,

ReadOnlyCollection vs Liskov - How to correctly model immutable representations of a mutable collection

孤人 提交于 2019-12-06 18:22:01
问题 Liskov-substitution principle requires that subtypes must satisfy the contracts of super-types. In my understanding, this would entail that ReadOnlyCollection<T> violates Liskov. ICollection<T> 's contract exposes Add and Remove operations, but the read only subtype does not satisfy this contract. For example, IList<object> collection = new List<object>(); collection = new System.Collections.ObjectModel.ReadOnlyCollection<object>(collection); collection.Add(new object()); -- not supported

Dijkstra's algorithm on directed acyclic graph with negative edges

不问归期 提交于 2019-12-05 16:00:21
Will Dijkstra's algorithm work on a graph with negative edges if it is acyclic (DAG)? I think it would because since there are no cycles there cannot be a negative loop. Is there any other reason why this algorithm would fail? Thanks [midterm tomorrow] Consider the graph (directed 1 -> 2, 2-> 4, 4 -> 3, 1 -> 3, 3 -> 5 ): 1---(2)---3--(2)--5 | | (3) (2) | | 2--(-10)--4 The minimum path is 1 - 2 - 4 - 3 - 5 , with cost -3 . However, Dijkstra will set d[3] = 2, d[2] = 3 in the first step, then extract node 3 from its priority queue and set d[5] = 4 . Since node 3 was extracted from the priority

Eliminating extraneous edges in directed acyclic graph while trying to find longest paths

蓝咒 提交于 2019-12-05 15:55:23
I asked a question about finding subsequences in a variable amount of sets with no repeating characters. The solution was to create a matrix of each pair of letters, discard those that don't occur in each set, and then find the longest path in the directed acyclic graph. However, I don't want just the longest path, I want several of the longest paths (e.g. if it generates subsequences of lengths 10, 10, 9, 8, 8, 3, 3, 2, and 1, I may want to display the first 5 subsequences only). And so, since I'm not looking for only the longest path, in order to generate the resulting subsequences, rather