graph-algorithm

How can a find a face containing a predefined point when i have a planar graph embedded on a plane

孤人 提交于 2020-01-15 06:00:10
问题 I have a planar graph embedded on a plane (plane graph ) and want to search its faces. The graph is not connected but consists of several connected graphs, which are not separately adressable (e.g. a subgraph can be contained in the face of another graph) I want to find the polygons (faces) which include a certain 2d point. The polygons are formed by the faces of the graphs. As the number of faces is quite big I would like to avoid to determine them beforehand. What is the general complexity

Shortest path between two vertices when exactly one edge weight can be reduced by 50%?

六月ゝ 毕业季﹏ 提交于 2020-01-13 05:24:06
问题 This is an interview question I came across: You are given a the map of airplanes between the cities in a country, basically a directed graph was given with weights as the cost of planes between the cities. You were also given a single coupon to get 50% on any single flight. Find the minimum cost with which you can travel between two cities? 回答1: The base algorithm for this problem is Dijkstra's algorithm for shortest paths. However, we need to find a way to include the coupon. We can do this

How can I correct the error ' AttributeError: 'dict_keys' object has no attribute 'remove' '?

旧时模样 提交于 2020-01-10 18:58:46
问题 I was trying shortest path finder using dijkstra algorithm but It seems not working. Can't figure out what the problem is. Here are the code and the error message. (I'm working on Python 3.5. https://www.youtube.com/watch?v=LHCVNtxb4ss) graph = { 'A': {'B': 10, 'D': 4, 'F': 10}, 'B': {'E': 5, 'J': 10, 'I': 17}, 'C': {'A': 4, 'D': 10, 'E': 16}, 'D': {'F': 12, 'G': 21}, 'E': {'G': 4}, 'F': {'E': 3}, 'G': {'J': 3}, 'H': {'G': 3, 'J': 3}, 'I': {}, 'J': {'I': 8}, } def dijkstra(graph, start, end):

How can I correct the error ' AttributeError: 'dict_keys' object has no attribute 'remove' '?

↘锁芯ラ 提交于 2020-01-10 18:58:15
问题 I was trying shortest path finder using dijkstra algorithm but It seems not working. Can't figure out what the problem is. Here are the code and the error message. (I'm working on Python 3.5. https://www.youtube.com/watch?v=LHCVNtxb4ss) graph = { 'A': {'B': 10, 'D': 4, 'F': 10}, 'B': {'E': 5, 'J': 10, 'I': 17}, 'C': {'A': 4, 'D': 10, 'E': 16}, 'D': {'F': 12, 'G': 21}, 'E': {'G': 4}, 'F': {'E': 3}, 'G': {'J': 3}, 'H': {'G': 3, 'J': 3}, 'I': {}, 'J': {'I': 8}, } def dijkstra(graph, start, end):

Python Dijkstra k shortest paths

怎甘沉沦 提交于 2020-01-10 08:59:13
问题 I'm trying to make a small public transport routing application. My data is represented in a following structure: graph = {'A': {'B':3, 'C':5}, 'B': {'C':2, 'D':2}, 'C': {'D':1}, 'D': {'C':3}, 'E': {'F':8}, 'F': {'C':2}} Where: graph dict key is a node subdict key is an edge between 2 nodes subdict value is an edge weight I was using find_shortest_path algorithm described here https://www.python.org/doc/essays/graphs/ but it is rather slow because of recursion and has no support of weights.

Dijkstra's (or other shortest path algorithm) where end node can be start node

时间秒杀一切 提交于 2020-01-07 07:11:13
问题 The traditional* implementation of Dijkstra's does not handle this case well. I think I've come up with some solutions that will work, but they are not particularly elegant**. Is this is a known problem with a standard solution? This is assuming the non-trivial solution i.e. a path like A->B->C->A rather than just A->A. * When I say traditional I mean marking each node as visited. ** Storing the number of times each node has been visited and basing the terminating conditions on whether the

Cheapest cost traversal on Complete graph

亡梦爱人 提交于 2020-01-05 11:54:22
问题 I was wondering if there is an algorithm which: given a fully connected graph of n-nodes (with different weights)... will give me the cheapest cycle to go from node A (a start node) to all other nodes, and return to node A? Is there a way to alter an algorithm like Primm's to accomplish this? Thanks for your help EDIT: I forgot to mention I'm dealing with a undirected graph so the in-degree = out-degree for each vertex. 回答1: Can you not modify Dijkstra, to find you the shortest path to all

Cheapest cost traversal on Complete graph

你。 提交于 2020-01-05 11:53:41
问题 I was wondering if there is an algorithm which: given a fully connected graph of n-nodes (with different weights)... will give me the cheapest cycle to go from node A (a start node) to all other nodes, and return to node A? Is there a way to alter an algorithm like Primm's to accomplish this? Thanks for your help EDIT: I forgot to mention I'm dealing with a undirected graph so the in-degree = out-degree for each vertex. 回答1: Can you not modify Dijkstra, to find you the shortest path to all

Cheapest cost traversal on Complete graph

最后都变了- 提交于 2020-01-05 11:53:22
问题 I was wondering if there is an algorithm which: given a fully connected graph of n-nodes (with different weights)... will give me the cheapest cycle to go from node A (a start node) to all other nodes, and return to node A? Is there a way to alter an algorithm like Primm's to accomplish this? Thanks for your help EDIT: I forgot to mention I'm dealing with a undirected graph so the in-degree = out-degree for each vertex. 回答1: Can you not modify Dijkstra, to find you the shortest path to all

Finding a minimum/maximum weight Steiner tree

喜夏-厌秋 提交于 2020-01-05 07:38:54
问题 I asked this question on reddit, but haven't converged on a solution yet. Since many of my searches bring me to Stack Overflow, I decided I would give this a try. Here is a simple formulation of my problem: Given a weighted undirected graph G(V,E,w) and a subset of vertices S in G, find the min/max weight tree that spans S. Adding vertices is not allowed. An extension of the basic model is adding edges with 0 weight, and vertices that must be excluded. This seems similar to the question asked