graph-theory

Finding all paths between a set of vertices in a DAG

Deadly 提交于 2019-12-24 04:21:01
问题 Given a graph G= (V, E) that is: directed, acyclic, non-weighted, may have more than one edge between two vertices (thus, source and destination are not enough to determine an edge). And given a set of vertices, let's call them vSet ; that contains a vertex vRoot ; I need to find ALL paths pSet between vSet elements respecting the following: any vertex that appears as a source for some path in pSet must be reachable from vRoot. any path in pSet must has its source and destination from vSet ,

Finding most efficient path between two nodes in an interval graph

拜拜、爱过 提交于 2019-12-24 03:20:05
问题 I have interval data: A = (0,50) B = (20,500) C = (80,420) .... And realized that there's an associated graph with this data, the interval graph I'd like to find the most efficient path to go from A to G (assume I know all of the positive vertex weights, wa, wb, wc...). I need to start at A and go to G, so the minimum spanning tree must be bound between these points. One of the constraints in our application is that the interval starting at A and ending at G must be covered in full (no gaps).

Using Dijkstra to detect multiple shortest paths

本秂侑毒 提交于 2019-12-24 00:36:48
问题 Given a weighted directed graph, how can the Dijkstra algorithm be modified to test for the presence of multiple lowest-cost paths between a given pair of nodes? My current algorithm is as follows: (credit to Weiss) /** * Single-source weighted shortest-path algorithm. (Dijkstra) * using priority queues based on the binary heap */ public void dijkstra( String startName ) { PriorityQueue<Path> pq = new PriorityQueue<Path>( ); Vertex start = vertexMap.get( startName ); if( start == null ) throw

Single-source shortest path with distance and weight for each edge

旧巷老猫 提交于 2019-12-23 19:15:46
问题 Suppose there's an undirected graph and each edge that connects any two nodes has two weights (i.e. distance and cost). I want to get the shortest path, but also make sure I do not go beyond a certain cost. I've tried implementing Djikstra's and simply backtracking (for lack of a better term) if I exceed the cost, until I traverse the entire graph. However, I'm looking for a faster solution than this. I've also attempted to use a function that creates a weight given the distance and cost of

Representing a network in Python

两盒软妹~` 提交于 2019-12-23 13:09:07
问题 I have a vertices such as dic = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'n':6, 'm':7, 'g':8} and i have two columns as follows represent the relationship between the vertices : a a b d e f c f n f m g I want to associate each vertex in the first column with the corresponding vertex in the second column by an edge. So a with a is represent a loop. b with d is fine. e , c and n they are sharing the same vertex f . Instead to say e with f , c with f and n with f we can say e , c and n

How can the number of strongly connected components of a graph change if a new edge is added

随声附和 提交于 2019-12-23 11:59:08
问题 Exercise: 22.5-1 CLRS How can the number of strongly connected components of a graph change if a new edge is added? Somewhere the answer given is If a new edge is added, one of two things could happen. 1) If the new edge connects two vertices that belong to a strongly connected component, the number of strongly connected components will remain the same. 2) If, instead, the edge connects two strongly connected components, and the edge is in the reverse direction of an existing path between the

Modeling network as directed graph

拈花ヽ惹草 提交于 2019-12-23 10:39:35
问题 I have a network that could look like this: Basically, I want to know the minimum number of green circles that can disconnect the source and drain if removed/disabled. (in this case 1) I have already succesfully implemented the Edmonds-Karp algrorithm, but I don't know how to model the network with directed edges, so I get the desired result. If I just replace each connection between the nodes with two opposite directed edges with capacity 1, I get a max flow of 2 with EdmondsKarp, but I only

Modeling network as directed graph

旧巷老猫 提交于 2019-12-23 10:37:06
问题 I have a network that could look like this: Basically, I want to know the minimum number of green circles that can disconnect the source and drain if removed/disabled. (in this case 1) I have already succesfully implemented the Edmonds-Karp algrorithm, but I don't know how to model the network with directed edges, so I get the desired result. If I just replace each connection between the nodes with two opposite directed edges with capacity 1, I get a max flow of 2 with EdmondsKarp, but I only

Creating a graph with edges of different colours in Mathematica

这一生的挚爱 提交于 2019-12-23 10:26:32
问题 I want to create a graph (Graph Theory) where certain edges have a different colour to other edges, which would be used to highlight a path in the graph from one vertex to another. Here are some examples which have different coloured edges http://demonstrations.wolfram.com/AGraphTheoryInterpretationOfTheSumOfTheFirstNIntegers/ and http://demonstrations.wolfram.com/Ramsey336/. I looked at source code for these but those solutions seem complicated. I need a simple example to work from. I reckon

Strange edge placement in Graphviz Dot

拜拜、爱过 提交于 2019-12-23 10:16:56
问题 I have a module that automatically outputs (in dot format) functions written in some kind of assembly language (the IR of my compiler). The nodes are the basic blocks printed using the 'record' shape. The problem is that the edges take a strange route, for example: digraph { node [shape = record]; n0[label="{<name> entry | <body> store i, 0\nstore sum, 0\ngoto test | {<target> target}}"]; n1[label="{<name> test | <body> t2 = load i\nif t4, body, done | {<true> true | <false> false}}"] n2