graph-theory

Get visited edges in OrientDB's shortestPath()

北战南征 提交于 2019-12-03 14:11:36
I am new to OrientDB and I want to use the new shortestPath() method to get the edges that are between two vertices. What I do is: OSQLSynchQuery<T> sql = new OSQLSynchQuery<T>("select shortestpath(" + firstVertex + ", " + secondVertex + ").asString()"); List<ODocument> execute = db.query(sql); and what I can only get is [#-2:1{shortestpath:[#8:1, #8:3]} v0] . So, I wanted to know how could I extract the edges (well, only one edge in this case, because these two vertices are directly connected) from this output or from the output that I get without asString() : [#-2:1{shortestpath:[2]} v0]

Divide-And-Conquer Algorithm for Trees

北城以北 提交于 2019-12-03 13:30:31
I am trying to write a divide & conquer algorithm for trees. For the divide step I need an algorithm that partitions a given undirected Graph G=(V,E) with n nodes and m edges into sub-trees by removing a node . All subgraphs should have the property that they don't contain more than n/2 nodes (the tree should be split as equal as possible). First I tried to recursively remove all leaves from the tree to find the last remaining node, then I tried to find the longest path in G and remove the middle node of it. The given graph below shows that both approaches don't work: Is there some working

Algorithm for merging sets that share at least 2 elements

狂风中的少年 提交于 2019-12-03 12:44:32
问题 Given a list of sets: S_1 : [ 1, 2, 3, 4 ] S_2 : [ 3, 4, 5, 6, 7 ] S_3 : [ 8, 9, 10, 11 ] S_4 : [ 1, 8, 12, 13 ] S_5 : [ 6, 7, 14, 15, 16, 17 ] What the most efficient way to merge all sets that share at least 2 elements? I suppose this is similar to a connected components problem. So the result would be: [ 1, 2, 3, 4, 5, 6, 7, 14, 15, 16, 17] (S_1 UNION S_2 UNION S_5) [ 8, 9, 10, 11 ] [ 1, 8, 12, 13 ] (S_4 shares 1 with S_1, and 8 with S_3, but not merged because they only share one element

Don't understand closest pair heuristic from “The Algorithm Design Manual ”

删除回忆录丶 提交于 2019-12-03 11:47:02
问题 There is almost exactly the same question. But I still don't understand, how is this heuristic working and in what sequence vertexes are passed through. Also there is a picture in a book: That shows comparison of nearest-neghbor heuristic and what I believe is a closest-pair heuristic. From the picture I may assume that on the top picture, 0 point was selected first, but on the bottom picture there was selected the leftmost or the rightmost one. Because there is nothing said about first point

Efficient way to recursively calculate dominator tree?

瘦欲@ 提交于 2019-12-03 11:31:31
问题 I'm using the Lengauer and Tarjan algorithm with path compression to calculate the dominator tree for a graph where there are millions of nodes. The algorithm is quite complex and I have to admit I haven't taken the time to fully understand it, I'm just using it. Now I have a need to calculate the dominator trees of the direct children of the root node and possibly recurse down the graph to a certain depth repeating this operation. I.e. when I calculate the dominator tree for a child of the

crossing edges in the travelling salesman problem

青春壹個敷衍的年華 提交于 2019-12-03 11:19:06
Does there exist a travelling salesman problem where the optimal solution has edges that cross? The nodes are in an x-y plane, so crossing in this case means if you were to draw the graph, two line segments connecting four separate nodes would intersect. If two edges in a closed polygonal line cross, then there is a polygonal line with the same vertices but with smaller perimeter. This is a consequence of the triangle inequality. So, a solution to the TSP must be a simple polygon. See this article (Figure 4). If you consider a non-Euclidean metric like L1 (Manhattan distance), then it's pretty

Generate a DAG from a poset using stricly functional programming

試著忘記壹切 提交于 2019-12-03 10:55:16
Here is my problem: I have a sequence S of (nonempty but possibly not distinct) sets s_i, and for each s_i need to know how many sets s_j in S (i ≠ j) are subsets of s_i. I also need incremental performance: once I have all my counts, I may replace one set s_i by some subset of s_i and update the counts incrementally. Performing all this using purely functional code would be a huge plus (I code in Scala). As set inclusion is a partial ordering, I thought the best way to solve my problem would be to build a DAG that would represent the Hasse diagram of the sets, with edges representing

What are strongly connected components used for?

百般思念 提交于 2019-12-03 10:45:37
I have found several algorithms that explain how to find strongly connected components in a directed graph, but none explain why you would want to do this. What are some applications of strongly connected components? You should check out Tim Roughgarden's Introduction to Algorithms course on Coursera. For every algorithm he goes over, he explains some applications of it. Very useful, and makes one see the value of studying algorithms! The use of strongly connected components that I remember him saying is that one could use it to find groups of people who are more closely related in a huge set

Is there any implementation of bidirectional search for Dijkstra algorithm? [closed]

二次信任 提交于 2019-12-03 09:49:58
问题 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 3 years ago . I am looking for an implementation of bidirectional search (a.k.a. "meet in the middle" algorithm) for Dijkstra (or any other source-to-destination shortest path algorithm) in Java. As bidirectional search processing is trickier than it looks like (Graph Algorithms, p.26), I want to consider an existing

How do I run graphx with Python / pyspark?

久未见 提交于 2019-12-03 09:11:37
问题 I am attempting to run Spark graphx with Python using pyspark. My installation appears correct, as I am able to run the pyspark tutorials and the (Java) GraphX tutorials just fine. Presumably since GraphX is part of Spark, pyspark should be able to interface it, correct? Here are the tutorials for pyspark: http://spark.apache.org/docs/0.9.0/quick-start.html http://spark.apache.org/docs/0.9.0/python-programming-guide.html Here are the ones for GraphX: http://spark.apache.org/docs/0.9.0/graphx