graph-theory

Finding the minimal subgraph that contains all negative cycles

会有一股神秘感。 提交于 2020-01-01 06:14:25
问题 I'm stuck at the following problem: Given a weighted digraph G, I'd like to construct the minimal subgraph of G that contains all negative (simple) cycles of G. I do know how to find a negative cycle using Bellman-Ford, and I know that the number of simple cycles in a directed graph is exponential. One naive way to approach the problem would be to simply iterate all simple cycles and pick those that are negative, but I have the feeling that there might be a polynomial-time algorithm. Most

Add a edge to direct acyclic graph with other restrictions

跟風遠走 提交于 2020-01-01 05:48:11
问题 I have a DAG. I have this operation to add a edge between two nodes. If A is reachable from B, then B is A's parent. If A is reachable from B without going though another node, then B is A's direct parent. Requirements for this graph are: No cycles. For any node, there is a list of direct parents P[1],P[2],P[3]... P[i] is not a parent of P[j] for any i and j. If adding a edge, requirement 1 is not met, the edge is not constructed. If adding a edge, requirement 2 is not met, the edge is

Enumerating cycles in a graph using Tarjan's algorithm

断了今生、忘了曾经 提交于 2020-01-01 05:37:08
问题 I'm trying to determine the cycles in a directed graph using Tarjan's algorithm, presented in his research paper "Enumeration of the elementary circuits of a directed graph" from Septermber 1972. I'm using Python to code the algorithm, and an adjacency list to keep track of the relationships between nodes. So in "G" below, node 0 points to node 1, node 1 points to nodes 4,6,7... etc. G = [[1], [4, 6, 7], [4, 6, 7], [4, 6, 7], [2, 3], [2, 3], [5, 8], [5, 8], [], []] N = len(G) points = []

How to minimize total cost of shortest path tree

扶醉桌前 提交于 2020-01-01 03:11:06
问题 I have a directed acyclic graph with positive edge-weights. It has a single source and a set of targets (vertices furthest from the source). I find the shortest paths from the source to each target. Some of these paths overlap. What I want is a shortest path tree which minimizes the total sum of weights over all edges. For example, consider two of the targets. Given all edge weights equal, if they share a single shortest path for most of their length, then that is preferable to two mostly non

Implementing a randomly generated maze using Prim's Algorithm

时间秒杀一切 提交于 2019-12-31 22:39:12
问题 I am trying to implement a randomly generated maze using Prim's algorithm. I want my maze to look like this: however the mazes that I am generating from my program look like this: I'm currently stuck on correctly implementing the steps highlighted in bold: Start with a grid full of walls. Pick a cell, mark it as part of the maze. Add the walls of the cell to the wall list. While there are walls in the list: **1. Pick a random wall from the list. If the cell on the opposite side isn't in the

List of C++ libraries for Graph Theory [closed]

穿精又带淫゛_ 提交于 2019-12-31 21:53:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm going to start a scientific project about automata and graph theory, and I'm searching for a graph library that supports features like: directed/undirected graphs graph isomorphism test (i.e. is graph g1 isomorphic w.r.t. g2?) subgraph isomorphism test (i.e. is a graph g1 isomorphic to a subgraph of g2?)

Clique problem algorithm design

陌路散爱 提交于 2019-12-31 10:44:12
问题 One of the assignments in my algorithms class is to design an exhaustive search algorithm to solve the clique problem. That is, given a graph of size n , the algorithm is supposed to determine if there is a complete sub-graph of size k . I think I've gotten the answer, but I can't help but think it could be improved. Here's what I have: Version 1 input : A graph represented by an array A[0,... n -1], the size k of the subgraph to find. output : True if a subgraph exists, False otherwise

Algorithm to find 'maximal' independent set in a simple graph

非 Y 不嫁゛ 提交于 2019-12-31 03:00:52
问题 in words, can someone post directions towards finding the 'maximal' independent set in a simple graph? I read up something from ETH site which said one can find such in O(n) by simply picking a random vertex v and than scanning the rest and attempting to find if there's an edge from v to the rest. Thanks 回答1: Yes, by definition, a maximal indpendent set is an independent set to which no more vertices can be added without violating the 'independence' condition. So just picking vertices till

Finding all cycles in an undirected graph

谁都会走 提交于 2019-12-30 08:29:46
问题 If I have an undirected graph, how can I get a list of all cycles? For example, from the following graph, I would want the cycles: (a,b,d,e,c) (a,b,c) (b,d,e) 回答1: You presumably want only simple cycles (those that don't repeat a vertex), or there's an infinite number of them. Even then, there can be an exponential number of cycles. Perhaps this isn't the problem you really want to solve? 回答2: this is not possible in polynomial time as if possible then we could use this to find all cycles and

Completeness of depth-first search

夙愿已清 提交于 2019-12-30 07:53:31
问题 I quote from Artificial Intelligence: A Modern Approach: The properties of depth-first search depend strongly on whether the graph-search or tree-search version is used. The graph-search version, which avoids repeated states and redundant paths, is complete in finite state spaces because it will eventually expand every node. The tree-search version, on the other hand, is not complete [...]. Depth-first tree search can be modified at no extra memory cost so that it checks new states against