graph-algorithm

Shortest path algorithm (eg. Dijkstra's) for 500+ waypoints/nodes?

江枫思渺然 提交于 2019-12-12 21:18:41
问题 I've asked about a shortest path algorithm here: 2D waypoint pathfinding: combinations of WPs to go from curLocation to targetLocation (To understand my situation, please read that question as well as this one.) It appears that the Dijkstra shortest path algorithm would be able to do what I need. However, I have about 500 to 1000 nodes in my routes map. The implementations I have seen so far limited the amount of nodes to something under 50. My question is: should I still use the Dijkstra

How do I mutate a structure I am looping over?

依然范特西╮ 提交于 2019-12-12 15:14:10
问题 This question is motivated by this CodinGame puzzle. I am implementing a basic pathfinding algorithm using Dijkstra's method. It uses a boundary HashMap and a finished HashMap to hold pathfinding-related node info. In a particular loop, I find the highest-valued node in boundary , remove the node, add the node to finished , and add/update the node's neighbors' info in boundary . Attempting to mutate boundary while looping over it is making Rust's borrow checker queasy, but the logic of the

Directed Acyclic Graph with multi-parent nodes

余生长醉 提交于 2019-12-12 09:21:33
问题 Given: A directed acyclic graph with weighted edges, where a node can have multiple parents. Problem: For each child of root node, find a minimum-cost(sum of weights) path from such a child to some leaf which can be reached. A node can only be present in one such min-cost paths. Example graph: In the above graph, for node 2, all the available paths are: 2 -> 5 2 -> 1 -> 9 -> 6 2 -> 1 -> 10 -> 6 Among which 2 -> 1 -> 10 -> 6 has minimum cost of 3.5 Similarly, for node 4, all the available

Find a monotonic shortest path in a graph in O(E logV)

半世苍凉 提交于 2019-12-12 08:53:55
问题 Problem 34 of creative problems from this page. Monotonic shortest path. Given an edge-weighted digraph, find a monotonic shortest path from s to every other vertex. A path is monotonic if the weight of every edge on the path is either strictly increasing or strictly decreasing. Partial solution : relax edges in ascending order and find a best path; then relax edges in descending order and find a best path. My question: Suppose we are relaxing edges in descending order and we have an option

Implementing Bron–Kerbosch algorithm in python

旧巷老猫 提交于 2019-12-12 08:15:11
问题 for a college project I'm trying to implement the Bron–Kerbosch algorithm, that is, listing all maximal cliques in a given graph. I'm trying to implement the first algorithm (without pivoting) , but my code doesn't yield all the answers after testing it on the Wikipedia's example , my code so far is : # dealing with a graph as list of lists graph = [[0,1,0,0,1,0],[1,0,1,0,1,0],[0,1,0,1,0,0],[0,0,1,0,1,1],[1,1,0,1,0,0],[0,0,0,1,0,0]] #function determines the neighbors of a given vertex def N

Find ALL possible paths between two nodes in a directed labeled graph [duplicate]

China☆狼群 提交于 2019-12-12 04:33:31
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Find the paths between two given nodes? Given a directed graph, how to find ALL the possible paths between two nodes and return those paths. If not in Java, please recommend me with the algorithm for it. I searched and what I found is using BFS or DFS, but I'm not able to see which is better in my case. And how to keep track of all paths not only the shortest one. For example, given the following graph: 1 -> 2 1

Eliminating vertices from a graph [closed]

跟風遠走 提交于 2019-12-12 02:55:02
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . From Skiena's Book, Design a linear-time algorithm to eliminate each vertex v of degree 2 from a graph by replacing edges (u,v) and (v,w) by an edge (u,w). We also seek to eliminate multiple copies of edges by

Build an undirected weighted graph by matching N vertices

别来无恙 提交于 2019-12-12 01:33:11
问题 Problem: I want to suggest the top 10 most compatible matches for a particular user, by comparing his/her 'interests' with interests of all others. I'm building an undirected weighted graph between users, where the weight = match score between the two users. I already have a set of N users: S. For any user U in S, I have a set of interests I. After a long time (a week?) I create a new user U with a set of interests and add it to S. To generate a graph for this new user, I'm comparing interest

Quickly creating a list of structs in a new struct

孤街醉人 提交于 2019-12-11 23:23:08
问题 I'm trying to build a few primitive objects to store a graph: Vertex = Struct.new(:parent, :rank) Graph = Struct.new(:vertexes, :edges) Edge = Struct.new(:weight, :endpoints) The idea here is that :endpoints (and :parent ) are Vertexes, and, naturally, Graph stores lists of Vertexes and Edges. I tried to set this up, and I ran into trouble: [47] pry(main)> t_graph = Graph.new() => #<struct Graph vertexes=nil, edges=nil> [48] pry(main)> t_graph[:vertexes] = Array.new(Vertex.new()) TypeError:

Given a directed graph, find out whether there is a route between two nodes

醉酒当歌 提交于 2019-12-11 22:30:20
问题 I'm trying to solve this problem and i'm fairly new to graphs. I tried BFS to figure this out but i'm not getting the right answer. What am i doing wrong? Also, is there a better way of doing this, other than the approach i am using. public static boolean isThereARoute(int[][] graph ,gNode n1 , gNode n2 ) { // where can we move? - anywhere where the value of x and y is 1 - else can't move // Start with node 1 and then traverse either BFS or DFS to see if the n2 is in the path anywhere //