graph-algorithm

Finding all possible paths of n length in hexagonal grid

别来无恙 提交于 2019-11-30 17:21:57
问题 Assume that a function takes s (origin hexagon), f (target hexagon) and n (length of the path) values as parameters and outputs list of all possible paths that has n length. To visualize the problem please check the figure below: Let's say our origin ( s ) is the red dotted hex (2, 3) and the target ( f ) is the blue dotted one (5, 2) . We want to reach blue dotted hex in 5 steps ( n = 5 ). Also consider that if a walk reaches a specific hex, it may stay in that hex as well in the next step.

shortest paths & geodesics

[亡魂溺海] 提交于 2019-11-30 12:41:44
问题 given a mesh made entirely of quads, where every vertex has valence n (with n >= 3), and does not lie on the same plane, I need to find the distance of every vertex in the mesh from a closed set of seed vertices. That is, given one or more mesh vertices (a seed set), I need to build a distance map that stores the distance of each mesh vertex from the seed set (which will have distance 0 from themselves). after spending some time searching for possible solutions, I got the following picture: 1

Relaxation of an edge in Dijkstra's algorithm

雨燕双飞 提交于 2019-11-30 10:44:56
What does relaxation of an edge mean in the context of graph theory ? I came across this while studying up on Dijkstra's algorithm for single source shortest path. krjampani Here's a nice description of the Algorithm that also explains the notion of relaxation. The notion of "relaxation" comes from an analogy between the estimate of the shortest path and the length of a helical tension spring, which is not designed for compression. Initially, the cost of the shortest path is an overestimate, likened to a stretched out spring. As shorter paths are found, the estimated cost is lowered, and the

How to implement Prim's algorithm with a Fibonacci heap?

こ雲淡風輕ζ 提交于 2019-11-30 10:23:09
问题 I know Prim's algorithm and I know its implementation but always I skip a part that I want to ask now. It was written that Prim's algorithm implementation with Fibonacci heap is O(E + V log(V)) and my question is: what is a Fibonacci heap in brief? How is it implemented? And How can you implement Prim's algorithm with a Fibonacci heap? 回答1: A Fibonacci heap is a fairly complex priority queue that has excellent amoritzed asymptotic behavior on all its operations - insertion, find-min, and

minimum connected subgraph containing a given set of nodes

。_饼干妹妹 提交于 2019-11-30 08:13:36
I have an unweighted, connected graph. I want to find a connected subgraph that definitely includes a certain set of nodes, and as few extras as possible. How could this be accomplished? Just in case, I'll restate the question using more precise language. Let G(V,E) be an unweighted, undirected, connected graph. Let N be some subset of V. What's the best way to find the smallest connected subgraph G'(V',E') of G(V,E) such that N is a subset of V'? Approximations are fine. I can't think of an efficient algorithm to find the optimal solution, but assuming that your input graph is dense, the

Topological sort of cyclic graph with minimum number of violated edges

流过昼夜 提交于 2019-11-30 07:03:06
I am looking for a way to perform a topological sorting on a given directed unweighted graph, that contains cycles. The result should not only contain the ordering of vertices, but also the set of edges, that are violated by the given ordering. This set of edges shall be minimal. As my input graph is potentially large, I cannot use an exponential time algorithm. If it's impossible to compute an optimal solution in polynomial time, what heuristic would be reasonable for the given problem? David Eisenstat Eades, Lin, and Smyth proposed A fast and effective heuristic for the feedback arc set

Detecting cycles in an adjacency matrix

◇◆丶佛笑我妖孽 提交于 2019-11-30 06:51:22
Let A be the adjacency matrix for the graph G = (V,E) . A(i,j) = 1 if the nodes i and j are connected with an edge, A(i,j) = 0 otherwise. My objective is the one of understanding whether G is acyclic or not. A cycle is defined in the following way: i and j are connected: A(i,j) = 1 j and k are connected: A(j,k) = 1 k and i are connected: A(k,i) = 1 I have implemented a solution which navigates the matrix as follows: Start from an edge (i,j) Select the set O of edges which are outgoing from j , i.e., all the 1s in the j -th row of A Navigate O in a DFS fashion If one of the paths generated from

Stable topological sort

女生的网名这么多〃 提交于 2019-11-30 06:05:26
Let say I have a graph where the nodes is stored in a sorted list. I now want to topological sort this graph while keeping the original order where the topological order is undefined. Are there any good algorithms for this? One possibility is to compute the lexicographically least topological order. The algorithm is to maintain a priority queue containing the nodes whose effective in-degree (over nodes not yet processed) is zero. Repeatedly dequeue the node with the least label, append it to the order, decrement the effective in-degrees of its successors, enqueue the ones that now have in

How to keep track of depth in breadth first search?

廉价感情. 提交于 2019-11-30 04:53:42
I have a tree as input to the breadth first search and I want to know as the algorithm progresses at which level it is? # Breadth First Search Implementation graph = { 'A':['B','C','D'], 'B':['A'], 'C':['A','E','F'], 'D':['A','G','H'], 'E':['C'], 'F':['C'], 'G':['D'], 'H':['D'] } def breadth_first_search(graph,source): """ This function is the Implementation of the breadth_first_search program """ # Mark each node as not visited mark = {} for item in graph.keys(): mark[item] = 0 queue, output = [],[] # Initialize an empty queue with the source node and mark it as explored queue.append(source)

shortest paths & geodesics

十年热恋 提交于 2019-11-30 03:46:59
given a mesh made entirely of quads, where every vertex has valence n (with n >= 3), and does not lie on the same plane, I need to find the distance of every vertex in the mesh from a closed set of seed vertices. That is, given one or more mesh vertices (a seed set), I need to build a distance map that stores the distance of each mesh vertex from the seed set (which will have distance 0 from themselves). after spending some time searching for possible solutions, I got the following picture: 1) it is not trivial, and different approaches have been developed during the last 20 years or so 2)