shortest-path

Neo4j Shortest Path for specific node labels in-between the path

时光怂恿深爱的人放手 提交于 2021-02-19 00:53:06
问题 I'm looking for a hint to solve the following issue: Given a Neo4j DB with two node types applied as labels :Address and :Milestone (one for each node) Between the different nodes there are directed :LEADS_TO relationships. Given the following pattern (I skipped the [ ] for the relations): Pattern 1: (a:Address)->(:Milestone)->(:Milestone)<-(:Milestone)<-(:Milestone)<-(b:Address) Pattern 2: (a:Address)->(:Milestone)->(c:Address)<-(:Milestone)<-(b:Address) I'm looking for a query that only

Algorithm for locating the closest destination(s) to source(s) and resolving conflicts in case a single destination is mapped to multiple sources

跟風遠走 提交于 2021-02-11 08:22:06
问题 Problem Statement: Given a matrix of people(denoted by small alphabets) and bikes(denoted by capital alphabets), find the nearest bike for a given person. How will you change your solution if you have to find bikes for a set of people? (assuming multiple bikes can be at the same distance from 1 person)? I know Dijkstra's algorithm and Bellman Ford's algorithm, but curious about the implementation here. Or can it be solved by BFS(Breadth First Search)? 回答1: To assign a single bike to a single

Algorithm for locating the closest destination(s) to source(s) and resolving conflicts in case a single destination is mapped to multiple sources

大兔子大兔子 提交于 2021-02-11 08:16:56
问题 Problem Statement: Given a matrix of people(denoted by small alphabets) and bikes(denoted by capital alphabets), find the nearest bike for a given person. How will you change your solution if you have to find bikes for a set of people? (assuming multiple bikes can be at the same distance from 1 person)? I know Dijkstra's algorithm and Bellman Ford's algorithm, but curious about the implementation here. Or can it be solved by BFS(Breadth First Search)? 回答1: To assign a single bike to a single

A BFS Algorithm for Weighted Graphs - To Find Shortest Distance

社会主义新天地 提交于 2021-02-08 04:56:07
问题 I've seen quite a few posts (viz. post1, post2, post3) on this topic but none of the posts provides an algorithm to back up respective queries. Consequently I'm not sure to accept the answers to those posts. Here I present a BFS based shortest-path (single source) algorithm that works for non-negative weighted graph. Can anyone help me understand why BFS (in light of below BFS based algorithm) are not used for such problems (involving weighted graph)! The Algorithm: SingleSourceShortestPath

A BFS Algorithm for Weighted Graphs - To Find Shortest Distance

别说谁变了你拦得住时间么 提交于 2021-02-08 04:55:28
问题 I've seen quite a few posts (viz. post1, post2, post3) on this topic but none of the posts provides an algorithm to back up respective queries. Consequently I'm not sure to accept the answers to those posts. Here I present a BFS based shortest-path (single source) algorithm that works for non-negative weighted graph. Can anyone help me understand why BFS (in light of below BFS based algorithm) are not used for such problems (involving weighted graph)! The Algorithm: SingleSourceShortestPath

Return All Nodes in Shortest Path as Object List

假如想象 提交于 2021-02-07 07:17:34
问题 I have the following Cypher Query which works fine in the Neo4j 2.0.0. MATCH (ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd)) RETURN p The following Query in Neo4jClient gives the error: Function Evaluation Timed out. var pathsQuery = client.Cypher .Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]

What algorithm can I use to find the shortest path between specified node types in a graph?

一个人想着一个人 提交于 2021-02-06 19:56:45
问题 This is the problem: I have n points (p1, p2, p3, .. pn), each of them can connect to any other with a determined cost x. Each point belongs to one of a set of point-types (for example "A" "B" "C" "D"...). The input of the method is the path I want to follow, for example "A-B-C-A-D-B". The output is the shortest path connecting the points of the type I give in input so for example "p1-p4-p32-p83-p43-p12" where p1 is an A-type, p4 a B-type, p32 a C-type, p83 an A-type, p43 a D-type and p12 a B

Finding the shortest path in a graph without any negative prefixes

时光毁灭记忆、已成空白 提交于 2021-02-05 13:52:21
问题 Find the shortest path from source to destination in a directed graph with positive and negative edges, such that at no point in the path the sum of edges coming before it is negative. If no such path exists report that too. I tried to use modified Bellman Ford, but could not find the correct solution. I would like to clarify a few points : yes there can be negative weight cycles. n is the number of edges. Assume that a O(n) length path exists if the problem has a solution. +1/-1 edge weights

Shortest path taking into consideration the weight on tinkergraph in Java

无人久伴 提交于 2021-01-29 08:16:16
问题 I'm trying to find the shortest path taking into consideration the weights properties on the edges my work is on TinkerGraph and i want to do it in java. gremlin is not very helpful for me g.V().has(id1). repeat(both().simplePath()). until(has(id2)).as("path"). map(unfold().coalesce(values("weight"), constant(0)). sum()).as("cost"). select("cost","path").next().get("path"); this gives me the shortest path without taking into consideration the weight property on the edges . EDITED: my example:

Find least colorful path in a graph

限于喜欢 提交于 2021-01-29 03:09:27
问题 The problem i'm trying to solve is this: Given a graph G = (V,E) such that every edge is colored in one of 10 colors, and two vertices: s, t. I need to find an algorithm that produces a (shortest) path from s to t, that goes over a minimal amount of colors. My idea was to duplicate the graph 10 times: The first duplicate will include only edges of one color The second will include only edges of two colors... and so on. Also, I connect an outer node: s' to every "s" node in every duplicate.