graph-algorithm

How to convert an undirected graph to a DAG?

久未见 提交于 2020-05-25 06:39:11
问题 The Wiki page says Any undirected graph may be made into a DAG by choosing a total order for its vertices and orienting every edge from the earlier endpoint in the order to the later endpoint. But I don't know how to get the total order of an undirected graph. Should I use DFS? If so, how would I proceed? More info : I'm working on an un-directed graph which has one source and one sink. I'm trying to direct these edges so that by following the edge direction I can get from the source to the

D* Lite search algorithm for robot path planning gets stuck in infinite loop. Why does my fix work and is it any slower?

谁说我不能喝 提交于 2020-05-08 17:22:32
问题 For a robotics project I've been working with I want to use the D* Lite (optimized version) from paper Koenig, 2002 for dynamic path planning for a changing occupancy grid / cost map. The idea of the D* Lite search algorithm, as described in the paper, is that it works by basically running A* search in reverse starting from the goal and attempting to work back to the start. The solver then gives out the current solution and waits for some kind of change in the weights or obstacles that it is

Finding cycles: DFS versus union-find?

南楼画角 提交于 2020-04-13 06:07:40
问题 DFS with coloring would take O(V+E) vs union find would take O(ElogV) reference: http://www.geeksforgeeks.org/detect-cycle-undirected-graph/ So union find approach is slower. If V = 100, E = 100, DFS = 200, Union find is 1,000. Is there a reason to use Union find? I personally like it because it produces a clean code. Or anything I missed that union find is better in real practice? 回答1: I suspect that you may be misinterpreting how big-O notation works. The notation O(V + E) doesn't mean "the

How to Pass Direceted Graph (adjacency list) into Dijkstra Algorithm Boost to find shortest path?

喜夏-厌秋 提交于 2020-02-16 04:06:23
问题 I have written this Class as a start to build My Algorithm, but I can see Before word on console, but not After ! what is my mistake in using Dijkstra Algorithm of Boost ?? #include <myalgorithm.h> #include<mygraphbuilder.h> //=============================================== using namespace std; using namespace boost; //=============================================== MyAlgorithm::MyAlgorithm()// Default constructor { } //=========================================================================

detecting mutual edges in a graph

时光怂恿深爱的人放手 提交于 2020-02-05 04:37:05
问题 I have an adjacency list representation of a graph but it is not symmetric i.e,. if a node A has an edge to B , it is not true that B has an edge with A . I guess this will be a directional graph (digraph). What is a good way to detect all the bidirectional paths from a node. I know I can use DFS to detect the paths from a node to another nodes of the graph. I guess what I am looking for is a bidirectional DFS where only the bidirectional edges are taken into account. So one way to do that is

Get the longest route traveled in a graph

久未见 提交于 2020-02-03 07:25:06
问题 I have an array of nodes that are connected to each other I have below network of nodes. Here 0 is the starting point, I want to travel as many nodes as possible with a node traveled only once. Also during a trip from 0 to destination node, I want to have only a single odd numbered node (like 1, 3, 5, 7). Now I need to find out the longest route I can travel from my beginning position 0. Example : int[] array = { 0, 9, 0, 2, 6, 8, 0, 8, 3, 0 }; In above graph, below are possibilities: 0 -> 6

Get the longest route traveled in a graph

馋奶兔 提交于 2020-02-03 07:22:02
问题 I have an array of nodes that are connected to each other I have below network of nodes. Here 0 is the starting point, I want to travel as many nodes as possible with a node traveled only once. Also during a trip from 0 to destination node, I want to have only a single odd numbered node (like 1, 3, 5, 7). Now I need to find out the longest route I can travel from my beginning position 0. Example : int[] array = { 0, 9, 0, 2, 6, 8, 0, 8, 3, 0 }; In above graph, below are possibilities: 0 -> 6

Optimize connection between nodes in a graph [duplicate]

亡梦爱人 提交于 2020-01-25 20:58:56
问题 This question already has answers here : Connect nodes to maximize total edge weight (5 answers) Closed 2 years ago . I am working on a problem which could be reduced to a graph optimization problem as below. A set of colored nodes are given. A set of rules are given about the cost contribution from the nodes. Ex. If a red node is not connected, cost is 100 If a red node connects to red node, cost is 10 If a red node connects to a blue node, cost is 20 Any node can have only 4 connections at

After subtracting a number from a sequence, how many of remaining numbers are positive? [closed]

牧云@^-^@ 提交于 2020-01-16 14:06:55
问题 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 6 years ago . I have a number sequence of length N . I will have to do Q operations on this number sequence. In each operation I will be given three integers P, Q, V with P ≤ Q ≤ N and will subtract V from every iᵗʰ integer, where P ≤ i ≤ Q . After each operation, I will be given another two integers X, Y with X ≤ Y ≤ N . I

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:11
问题 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