graph-algorithm

Bellman-Ford Distance Vector Algorithm With Arbitrarily Many Nodes

你。 提交于 2020-01-04 15:15:52
问题 I'm trying to code a program for a class that simulates a router and so far I have the basics set up ("router" can send and receive packets through an emulated server to other "routers" connected to the server). Each packet contains only the distance vector for that router. When a router receives a packet it is supposed to update it's own distance vector accordingly using the Bellman-Ford algorithm. The problem I'm having is that I am finding myself unable to implement the actual algorithm

Extract All Possible Paths from Expression-Tree and evaluate them to hold TRUE

巧了我就是萌 提交于 2020-01-04 05:39:09
问题 This is a follow-up question of my previous one: Better Class-Structure for logical expression parsing and evaluation Brief introduction: rules as strings combinations of logical-and , logical-or , logical-negation and grouping by parenthesis of identifiers (ID's) Example: "{100} AND (({101} OR {102}) OR ({103} AND {104})) AND NOT ({105} OR {106})" This gets currently evaluated into a binary-tree of nodes, that looks like this: Code taken from here: How to parse a boolean expression and load

In the Boost Graph Library, why does adding an edge invalidate Edge iterators (and other questions)?

冷暖自知 提交于 2020-01-04 05:17:19
问题 A few questions about the chart in the BGL documentation labeled "Summary of Descriptor and Iterator Invalidation": Why does adding an edge invalidate the edge and adjacency iterators; why isn't every column of the add_edge() row "OK"? Wouldn't the in/out edge lists simply be appended? Why does removing an edge only invalidate an edge iterator if the graph is directed; why is the second to last column in the second row not simply "EL=vecS"? In the undirected graph case wouldn't removing an

how can a breadth-first-search-tree include a cross-edge?

我只是一个虾纸丫 提交于 2020-01-04 03:49:24
问题 Well, I know that a breadth-first-search-tree of an undirected graph can't have a back edge. But I'm wondering how can it even have a cross-edge? I'm not able to image a spanning tree of a graph G constructed out of OFS, that contains a cross-edge. 回答1: The process of building a spanning tree using BFS over an undirected graph would generate the following types of edges: Tree edges Cross edges (connecting vertices on different branches) A simple example: Imagine a triangle (a tri-vertice

Dijkstra's Algorithm and Cycles

北城余情 提交于 2020-01-03 10:57:20
问题 It's stated in a book that "Dijkstra's algorithm only works with Directed Acyclic Graphs". It appears the algorithm works for graphs with cycles too as long as there are no negative cycles. Is that correct? Edit 1: The book "Grokking Algorithms" -Aditya Bhargava. Chapter 7. Page 122. 回答1: I'm the author of Grokking Algorithms . Sorry for this error—Dijkstra's algorithm does work on graphs with cycles, as long as it is a positive weight cycle. I have updated the errata page to reflect this

Best Fit Algorithm To Evenly Place Matchups In Rounds

六月ゝ 毕业季﹏ 提交于 2020-01-03 04:33:05
问题 I need an algorithm that can take any number of match-ups like you can see below and group them by round evenly with each participate in it once if possible. I generated the match-ups below by round for 8 and 3 teams. I am having issues filling up my rounds and being left with an orphan game that cant go in the last round. Now the rounds are arbitrary but as you can tell each participate can be found in each round (1,2,3,4,5,6,7,8). Now these matchups can be deleted or added, and sorted

Algorithm for finding a spanning tree with weights of 1 and 2 only

混江龙づ霸主 提交于 2020-01-01 17:04:11
问题 Given a weighted, connected, simple undirected graph G with weights of only 1 and 2 on each edge, find the MST of G in O(V+E). Any ideas? Sorry for the phrasing of the question, I tried translating it as best as I could. 回答1: In Prim's algorithm you need a way of storing active edges such that you can access and delete the edge with lowest weight. Normally there are a wide range of weights and some kind of heap data structure is used to store the edges. However, in this case, the weights are

random algorithm over all topological sorts of a DAG?

混江龙づ霸主 提交于 2020-01-01 03:26:10
问题 Does anyone know of a random algorithm for generating a topological sort of a DAG, where each invocation of the algorithm has a non-zero probability of generating every valid topological sort of the DAG. It's crucial that the algorithm does not preclude any valid topological sort, because it's part of a larger algorithm that, given enough iterations, must be demonstrably capable of exploring all topological sorts of a given DAG. Does anyone know if such an algorithm has been developed?

A* Algorithm for very large graphs, any thoughts on caching shortcuts?

北战南征 提交于 2019-12-31 08:14:06
问题 I'm writing a courier/logistics simulation on OpenStreetMap maps and have realised that the basic A* algorithm as pictured below is not going to be fast enough for large maps (like Greater London). The green nodes correspond to ones that were put in the open set/priority queue and due to the huge number (the whole map is something like 1-2 million), it takes 5 seconds or so to find the route pictured. Unfortunately 100ms per route is about my absolute limit. Currently, the nodes are stored in

minimum connected subgraph containing a given set of nodes

一世执手 提交于 2019-12-30 02:44:06
问题 I have an unweighted, connected graph. I want to find a connected subgraph that definitely includes a certain set of nodes, and as few extras as possible. How could this be accomplished? Just in case, I'll restate the question using more precise language. Let G(V,E) be an unweighted, undirected, connected graph. Let N be some subset of V. What's the best way to find the smallest connected subgraph G'(V',E') of G(V,E) such that N is a subset of V'? Approximations are fine. 回答1: I can't think