All Questions
Tagged with graph-algorithm or graph-theory
7,320 questions
Advice
0
votes
1
replies
18
views
Double Vertex Graph for Train Networks
I came across one of OpenTrack's manuals. I couldn't find a more up to date version, this is the latest screenshot I could find.
Is the description vertex-vertex-edge-vertex-vertex actually correct?
...
0
votes
1
answer
236
views
+50
Trouble implementing the Cooper–Harvey–Kennedy algorithm for finding immediate postdominators in C++
I'm trying to implement the Cooper–Harvey–Kennedy algorithm from this paper in C++. The original is used to find dominators, however in my case I need to find the postdominators. For this, I am aware ...
1
vote
0
answers
27
views
Finding Minimum Weight Strongly Connected Subgraph with Edge Coverage Constraint
I have a directed graph representing a road network where:
Some edges are bidirectional (two-way streets) and some are unidirectional (one-way streets)
The graph has geometry (represents physical ...
0
votes
2
answers
181
views
Reconstructing a 2D grid graph from an unordered adjacency list
My unordered adjacency list of nodes with their 2D coordinates:
adjacency_list = [[1, 4], [0, 2, 5], [1, 3, 7], [2, 6, 12],
[5, 0, 11], [4, 1, 7, 13], [3, 15, 8],
[...
7
votes
3
answers
293
views
How to find the longest elementary path in a graph?
The problem is to find the longest sequence of numbers from 1 to 100 such that each number is either multiple or divisor or the previous, and with no repetition. For example, 50 25 5 35 7 63 21 is a ...
0
votes
4
answers
589
views
Answer sum of values on tree path, with updates, efficiently
You are given an unweighted tree with N nodes and each node starts with value 0. There will be Q queries. The 1st type of query will change the value at a node to a new value. The 2nd type of query ...
3
votes
0
answers
109
views
Efficient creation of Hasse diagrams with networkx
In python, with networkx, I have a large list li = [o1, o2, ...] of objects of a class Myclass. The class has a partial ordering for objects defined through the method __lt__. This is a strict ...
3
votes
3
answers
110
views
Iterative graph traversal: non-BFS and non-DFS ordering
Consider this traversal algorithm in pseudocode:
Traverse(G, v):
S is stack
stack.push(v)
label v as visited
while S is not empty:
v = S.pop()
for all w in G....
3
votes
1
answer
72
views
How to efficiently find shortest and longest paths between node types in Dgraph?
I'm trying to find the shortest and longest path between two node types across the entire graph in Dgraph, similar to how it's done using APOC in Neo4j.
In Neo4j, I can use a single query like this:
...
2
votes
2
answers
87
views
Graph traversal: find final destination
I have a table in SQL Server that represents nodes directions. Each node can either go into another node or stay as it is. I need to resolve the final node to which each node should go.
Here is an ...
7
votes
1
answer
103
views
How to extend a spanning tree into a bridgeless subgraph in O(V+E) time?
I'm working on the following problem:
Given an undirected graph G = (V, E), represented as an adjacency list, design an efficient algorithm to construct a subgraph H = (V, E') such that:
E' is a ...
1
vote
0
answers
47
views
Data race detection for simple send/wait signals
For a computer game, I would like to find the data races between tasks of NPCs. The execution / task graph is generated by the user.
The synchronization mechanisms consist of simple send/wait commands ...
1
vote
0
answers
60
views
osmnx detect road intersections with osm data
I am working on crash analysis using OSM data, to analyze pedestrian crashes with respect to type of intersections such as:
4-way: X-junctions
3-way: T-junctions, Y-junctions
multi-leg junctions
...
1
vote
2
answers
214
views
Tracking the number of connected components when adding and removing edges
I'm working with an undirected graph where I need to frequently add and remove edges. I also need to efficiently determine the number of connected components after each operation.
For adding edges, I'...
1
vote
0
answers
72
views
How to find the shortest path in a multigraph with dynamic edge costs based on bus line changes?
I'm working with a multigraph in JavaScript where each edge represents a bus route and includes both a weight (e.g., travel time or distance) and a busLine identifier.
I want to calculate the shortest ...
1
vote
0
answers
51
views
DSU with Union Find for graph puzzle - JUnit test failing when trying to cover overlapping index in grid
I am using Disjoint Set Union (DSU) and Union Find to solve a graph problem.
The entry point function takes an input string with coordinates defined by (line number, char number), starting at the top ...
0
votes
0
answers
62
views
Removing nodes from adjacency matrix for CFD mesh network
How to reduce the number of nodes in my CFD mesh in Python?
For context, I have a 2D CFD mesh generated by Fluent and exported as a .msh.h5 file.
The file has the following structure:
├── meshes
│ └─...
4
votes
0
answers
107
views
Covering a complete graph with k-cliques
Is there an algorithmically efficient way to compute the following value?
Define f(n, k) to be the minimum number of k-cliques to cover all edges of a complete graph of size n.
For example, f(4, 3) = ...
2
votes
1
answer
109
views
For given edge, find all nodes the edge lies on any path from
I have undirected connected graph with one main node (denoted by M in examples below).
I am trying to find efficient algorithm to following specification:
input is set of edges (denoted by thick ...
1
vote
1
answer
38
views
Meaning of "visited" nodes in Anytime Dynamic A*
I am working on an implementation of the Anytime Dynamic A* algorithm as described here. I am ~50% of the way through an initial, basic implementation but am stuck at the following line:
In the ...
2
votes
2
answers
126
views
object defined in a function survives after program comes out of the function [closed]
I'm implementing a graph with C++. After reading a C++ tutorial, I thought that any object defined locally will only live in the most local scope. Say we define an int i in function f; outside the ...
0
votes
0
answers
57
views
Indirect and direct link in a tree
Suppose 3 sets of nodes, each corresponding to a distinct set in an undirected graph:
Set-A = {1, 2, 3, 4, 5}
Set-B = {6, 7, 8, 9, 10}
Set-C = {11, 12, 13, 14, 15}
The graph is defined by ...
2
votes
1
answer
201
views
Issues with Recursive Digraph Construction and Missing Loops in Python Code
I'm trying to write code to recursively generate directed graphs as described in the following process:
For G_1, we start with a single vertex with a self-loop.
For G_2, we take two copies of G_1, ...
0
votes
0
answers
47
views
Infinite execute in A* for 8 puzzle
This is the hint of my 8 puzzle problem (Tells player which tile they should move in this state). I tried to use the current board that the player are playing as an input(2D array) but it always ...
1
vote
1
answer
81
views
Algorithm for converting a planar graph represented by a list of faces to a list of points
The code I am writing is in C#, but pseudocode is also appreciated.
I have a function that generates a list of faces (which is an ordered list of nodes) of a planar graph. So the function signature ...
1
vote
1
answer
134
views
Node/edge attributed directed graph embedding
What is the format of node features that graph2vec and GL2vec in karateclub require? It does mention that there should be no string features but with or without it I am running into an error with the ...
3
votes
1
answer
46
views
Given graph constrain data, programmatically calculate coordinates of each vertex
I am given a bunch of graph contrain data:
Which vertex is connected to which vertex, optionally with length
Some angles
Angles and distances may be algebra relations
How can I use them to ...
5
votes
1
answer
80
views
Can bi-directional breadth-first search be used to enumerate ALL shortest paths between two specific nodes in an unweighted directed (acyclic?) graph?
It is alleged that the standard BFS can be extended to output all possible shortest paths between two given vertices in a directed unweighted graph (without loops? it does not seem to matter whether ...
1
vote
1
answer
53
views
Removing list duplicates given indices symmetry in python
In python, given a list mylist of lists el of integers, I would like to remove duplicates that are equivalent under specific permutations of the indices.
The question is more general but I have in ...
2
votes
0
answers
72
views
Is there a more efficient approach to generate all shortest paths from pre-calculated edges?
There exists a commentary about finding all the edges on any of the shortest paths between two given nodes of a DAG. Presume that I have found such edges as mentioned in this commentary, I can easily ...
1
vote
1
answer
114
views
What is an example of the worst-case scenario for the Bellman-Ford algorithm?
I am wondering what would the worst case look like for Bellman-Ford algorithm to have to traverse all edges V-1 time, cause most of the time it won't need V-1 iterations to find all shortest path. ...
2
votes
2
answers
69
views
Adjacency matrix not square error from square dataframe with networkx
I have code that aims to generate a graph from an adjacency matrix from a table correlating workers with their manager. The source is a table with two columns (Worker, manager). It still works ...
3
votes
1
answer
94
views
Path finding algorithm combining Field D* and Anytime D*
I am looking for a pathfinding algorithm that has a few properties:
Speed is very necessary, and once a goal is selected a suboptimal path needs to be made quickly, and then can be improved upon ...
0
votes
2
answers
162
views
How to efficiently detect cycles in a directed graph with millions of nodes?
Graph Representation:
I am using an adjacency list to represent a large directed graph with millions of nodes. Each node may have several outgoing edges, but the graph is sparse (few edges relative to ...
6
votes
4
answers
401
views
Maximum number of cars on m x n parking lot (single empty region with all marked cells adjacent to it)
The problem
I am trying to solve a competitive programming problem which goes like that:
Given an m x n rectangular grid, what the maximum number of cars than can be parked (each car takes 1 cell) so ...
3
votes
0
answers
93
views
Myers diff with a custom cost function
Myers diff algorithm treats insertion and removal equally at the same cost and treats equality at zero cost (free path).
I tried to alter this behavior with supplying a custom cost function which to ...
3
votes
0
answers
95
views
Modifying myers diff by identifying compound units and treating them as 1 single insertion or removal
Myers diff algorithm works at character level and identifies insertion, removal or no-operation at each step. So for example, comparing PQRSXRSYRSZ (old string presented horizontally) and PQRSARSXRSY (...
0
votes
0
answers
30
views
Multi-layer modularity metric
I am stuck with computing the extended modularity metric on a multi-layer graph. I am trying to derive the result of the middle graph in Figure 6 of the following article: https://www.nature.com/...
0
votes
0
answers
53
views
Finding the deviation from a navigation trajectory to it's ideal path
Background: I have recorded navigation trajectory positional x,y and its time point (50hz) data from a virtual reality navigation in an empty room.
Problem: I want to calculate how much the navigation ...
2
votes
1
answer
138
views
Graph traversal algorithm using shapely geometry points
I am trying to create a path planning algorithm for a robotic mower to cut all the grass in a defined area while avoiding obstacles or restricted areas. I am using the Python Shapely library to define ...
-1
votes
2
answers
103
views
How efficient is the below BFS implementation?
I am trying to learn BFS and trying to analyse BFS time complexity on my own. But I could not wrap my head around it. Below is my implementation of Graph data structure and BFS algorithm. Is the time ...
0
votes
0
answers
45
views
How to design a memory-efficient partitioning algorithm for task execution with shared dependencies?
I’m trying to design a partitioning algorithm to scale task execution in a resource-constrained environment. Here’s the situation:
Tasks consume data via a DAL (Data Access Layer), which could be a ...
3
votes
1
answer
427
views
Calculate an upper bound on a tree containing sum nodes, choice nodes, and requiring consistent choices
I have a graph containing sum nodes, choice nodes and point nodes. I'd like to maximize the number of points at the root of the graph.
The value you get for a point node is the number of points on ...
2
votes
2
answers
68
views
partition graphs by cutting 2 edges
I have an undirected graph. I wish to partition it in such a way as to identify the subgraphs that effectively have 2 bridges connecting them to the main network. There is no need to further subdivide ...
2
votes
1
answer
95
views
Segmenting Shortest Paths in Simple Virtual Reality Map Images
The goal is to segment the major paths by turns in a shortest path of a virtual reality map to know how much to score a person's navigation trajectory (blue line in image) based on how far they walked ...
2
votes
1
answer
249
views
Use Gurobi to create networkx.Graph that has highest edge connectivity
I have the following graph G
G is created using the following code
import networkx as nx
import matplotlib.pyplot as plt
G = nx.hoffman_singleton_graph()
pos = nx.spring_layout(G)
nx.draw(G, pos=pos)...
3
votes
1
answer
62
views
Is there a standard algorithm for removing redundant statements of ordering?
Supposing I have an ordering relation and some predicates:
A < B
A < C
B < C
The predicate A<C is redundant since it is implied by the other two.
Is there a standard algorithm for ...
1
vote
1
answer
54
views
How to manage monster collision range during calculating path by A* algorithm?
Pathfinder by A* algorithm working fine, the smoothing path algorithm is working excellent too.
The problem is: pathfinder grid is not equal to monster hitbox (collision range), the grid size and ...
5
votes
5
answers
315
views
Finding loops between numbers in a list of sets
I marked my answer as the answer because it is the one that is doing what I was wanting and anyone wanting to do the same thing should start there. But I would love to see a better answer (order of ...
0
votes
0
answers
29
views
Does Dijkastra's Algorithm work in undirected graph with negative weights? [duplicate]
programmer say that dijkastra algorithm doesn't work for negative graph weight but I think that it works for undirected graph in negative weights and (I know that it don't work for directed negative ...