breadth-first-search

Retrieving all paths in an OWL class hierarchy with SPARQL and Jena

丶灬走出姿态 提交于 2019-12-06 11:17:02
问题 I have an RDF graph of with a hierarchy three levels deep. I want to retrieve all the paths starting from the root of the class hierarchy (i.e., owl:Thing ) down to classes in the third level without using a reasoner. For instance, I would like the path C 1 → C 2 → C 3 is a path, where each C i is a class at the i th level of the hierarchy. I need to retrieve all the paths in the RDF graph using the breadth first search algorithm with no considerations to the object

Breadth-First search in Java

两盒软妹~` 提交于 2019-12-06 10:53:13
问题 I am having to run a breadth-first search in Java for an assignment. I have a 5x5 grid of tiles (24 in total - 1 tile is left 'blank'). The point of the search is to rearrange the tiles by moving the 'blank' up, down, left or right to eventually rearrange the tiles into the correct order. To do this search, I have created an Arraylist 'queue'. I have a method that takes the state at index 0 of this arraylist, finds each of the legal moves that can follow and then adds them each to the end of

Do any POSIX functions or glibc extensions implement a breadth-first file tree walk?

淺唱寂寞╮ 提交于 2019-12-05 21:36:54
I am writing a daemon that utilizes inotify to monitor file access and it is critical that I don't miss anything on a recursive search. I found this interesting idea and have begun to implement it. ftw() and ftw64() do not use a breadth-first algorithm, its more "pre-order". nftw() gives me the option of depth-first, but I'm worried about races in upper leaves. I'm hoping that I'm missing something, perhaps a GNU extension? Or am I just looking at implementing my own with type safe call backs (something I'd really rather not do) ? Or, is my understanding of the advantages of breadth-first over

Finding all possible paths in graph

大兔子大兔子 提交于 2019-12-05 18:08:57
I'm looking for some algorithm which will help me find all possible paths in a graph. Everything I found so far is not fully satisfying. Let's imagine we have a graph (tree) like this one: And let's use some algorithm like Breadth-First Search or Depth-First Search . In return we'll get something like 1, 2, 4, (2), 5, (2), 6, (2), (1), 3, 7, 8, (7), 9 Which is how we go through this tree and this is not what I'm looking for. I'd love to get all paths, like: 1 1, 2 1, 2, 4 1, 2, 5 1, 2, 6 1, 3 1, 3, 7 1, 3, 7, 8 1, 3, 7, 9 The thing is that I want just to specify root node and algorithm should

How to get the path between 2 nodes using Breadth-First Search?

谁说我不能喝 提交于 2019-12-05 12:18:21
问题 I am trying to find a path between two nodes in a graph , where the edges are unweighted . I am using a Breadth First Search , which stops when it finds the target, in order to find the existence of a path, but I am not sure how to get the path itself. I tried looking at the list of visited nodes, but this did not seem to help. I saw someone answer this question using prolog, but I am a C++ programmer. I also looked at Dijkstras algorithm , but this seems like over kill, since a simple

Lazy, breadth-first traversal of a Rose Tree?

笑着哭i 提交于 2019-12-05 08:04:45
I'm trying to refactor a component that currently produces a Seq[X] using a fairly expensive recursive algorithm so that it produces a Stream[X] instead, so X 's can be loaded/calculated on-demand, and the producer doesn't have to try to guess beforehand how much digging it'll have to do to satisfy the consumer. From what I've read, this is an ideal use for an "unfold", so that's the route I've been trying to take. Here's my unfold function, derived from David Pollak's example , which has been vetted by a certain Mr. Morris: def unfold[T,R](init: T)(f: T => Option[(R,T)]): Stream[R] = f(init)

Implementing BFS in Java

萝らか妹 提交于 2019-12-05 03:27:39
I am a beginner in Java, and I need some help. I am trying to implement Breadth First Search algorithm to solve a puzzle game (Unblock Me a game on Android). I am done with the GUI, but I am stuck with the algorithm. So far I can count the available moves of each block, which supposed to be the children nodes of the root node. Each node (linkedlist) has the position of each block, and all the nodes are being stored in a Set. What I need now is to mark each node as visited, so I don't get into an infinite loop. I would appreciate any kind of help, and please correct me if I am mistaken with

How do I stop the breadth-first search using Boost Graph Library when using a custom visitor?

若如初见. 提交于 2019-12-05 02:39:26
Say I found the node that meets my criteria and I need to stop the search. The solution is to throw an exception of your known type - then catch it on the calling side. From the FAQ : How do I perform an early exit from an algorithm such as BFS? Create a visitor that throws an exception when you want to cut off the search, then put your call to breadth_first_search inside of an appropriate try/catch block. This strikes many programmers as a misuse of exceptions, however, much thought was put into the decision to have exceptions has the preferred way to exit early. See boost email discussions

Difference between BFS and DFS

落花浮王杯 提交于 2019-12-05 02:22:49
问题 I am reading about DFS in Introduction to Algorithms by Cormen. Following is text snippet. Unlike BFS, whose predecessor subgraph forms a tree, the predecessor subgrpah produced by DFS may be composed of several trees, because search may be repeated from multiple sources. In addition to above notes, following is mentioned. It may seem arbitrary that BFS is limited to only one source where as DFS may search from multiple sources. Although conceptually, BFS could proceed from mutilple sources

Changing attribute values of nodes in a network during breadth first search in R

倾然丶 夕夏残阳落幕 提交于 2019-12-04 19:53:33
I have created a random (Erdos-Renyi) network that has 100 nodes. I have set an attribute value for all 100 nodes as 0. I find the node with the maximum degree (the most neighbors), and change its attribute value from 0 to 1. Then, using the node as the root node, I do a breadth first search (BFS) on the network. Here is my code to do this so far: # Loads the igraph package library(igraph) # Creates a random (Erdos-Renyi) network with 100 nodes and edges with p = 0.2 graph <- erdos.renyi.game(100, 0.2, type = c("gnp", "gnm"), directed = FALSE, loops = FALSE) # Sets the attributes of all the