Questions tagged [transitive-closure]

Use this tag for the transitive closure of a relationship or when related to graph theory.

References:

Wikipedia
Wolfram MathWorld

148 questions
1
vote
1 answer

Why does my prolog rule get stuck in infinite recursion

My code works for its intended purpose but always gets stuck in a loop at the end giving me an error saying "Stack limit exceeded." My code is…
1
vote
2 answers

Prolog order of clauses causes pathfinding to fail

I am developing a path finding algorithm in Prolog, giving all nodes accessible by a path from a starting node. To avoid duplicate paths, visited nodes are kept in a list. Nodes and neighbors are defined as…
jdfauw
  • 647
  • 3
  • 11
  • 22
1
vote
1 answer

Transitive closure in bidirected graph

I have a big structure with items and relations between the items. I need to find all transitive relations for all items. I duplicate all links and use transitive closure. E.g.: A --- B --- C E --- F --- G | | D As a result I…
1
vote
1 answer

Prolog List Represented Graph Traversal

I am attempting to traverse a graph I have constructed in prolog. The Graph is represent as a list of transitions of the form: next(FromState, ToState, Symbol) where FromState and ToState are nodes of the graph that are represented as:…
jewelltaylor9430
  • 109
  • 1
  • 15
1
vote
2 answers

Prolog find non related graph nodes

I have the following graph: My goal is to get all the direct connections of a certain node and all of the nodes that are not connected with a certain node for example: connections(1,X). X=3; X=4; X=5; X=6. noConnections(1,X). X=2. This is my…
I'm not human
  • 544
  • 1
  • 9
  • 30
1
vote
1 answer

Grouping of two variables in r

I have a data frame like below. dat <- data.frame(v1=c("a","b","c","c","a","w","f"), v2=c("z","a","a","w","p","e","h")) v1 v2 1 a z 2 b a 3 c a 4 c w 5 a p 6 w e 7 f h I want to add a group column based on whether…
cyrusjan
  • 637
  • 1
  • 8
  • 23
1
vote
0 answers

graph_tool: transitive closure of undirected graphs

I was wondering what the best way to compute the transitive closure of an undirected graph in the python library graph_tool is. My solution so far is to create a directed graph from the original one and use the transitive_closure method on that: …
1
vote
0 answers

Retrieving parent and child in transitive SPARQL query

I am looking for a way to return both the parent and child in a transitive SPARQL query, and only the relations that make up the path. The following query returns the parents and intermediate object pairs leading up to http://example.com/child, but…
Ben Pennell
  • 449
  • 1
  • 3
  • 13
1
vote
3 answers

Ordering in transitive SPARQL query

Is it possible to guarantee that the results of a transitive query in SPARQL come back in the order in which they were walked? So, given some simple data: ex:contains
Ben Pennell
  • 449
  • 1
  • 3
  • 13
1
vote
2 answers

Prolog - ERROR: Out of local stack in linux

I have a very simple program in swipl edge(X,Y) :- edge(X,Z),edge(Z,Y). edge(a,b). edge(a,f). edge(b,c). edge(c,d). edge(g,c). edge(f,g). edge(f,c). edge(f,e). edge(c,e). edge(e,d). But when Ι make a query edge(a,c). Ι get a Out of local stack…
1
vote
1 answer

Prolog: check transitivity for simple facts

My intention was to implement a simple example (just for myself) of transitivity in Prolog. These are my facts: trust_direct(p1, p2). trust_direct(p1, p3). trust_direct(p2, p4). trust_direct(p2, p5). trust_direct(p5, p6). trust_direct(p6,…
daniel451
  • 10,626
  • 19
  • 67
  • 125
1
vote
1 answer

Directed Graph In Prolog

can someone please elaborate upon the functionality/conditions of travel(A,B,Visited,Path) and travel(A,B,P,[B|P]) .. this code finds the path between path A and B in a graph…
user6943086
1
vote
0 answers

Reachability with Graphs

A few months ago, I had taken part in a contest on CodeForces, and I've been trying different solutions to solve it since. The problem basically consists of inputs containing nodes and edges of a directed graph. Basically, if: A is pointing to B,…
1
vote
1 answer

SWI-Prolog: findall/3 not finding all solutions?

I'm trying to solve this Pebble Solitaire problem, and this is part of my code: % Base case play(List, X) :- count_pebbles(List, X). %%%%%%%%%%%%%% % JUMP RIGHT % %%%%%%%%%%%%%% % oo-XXXXXXXXX play( [111, 111, 45|Tail], X) :- …
Mossmyr
  • 909
  • 2
  • 10
  • 26
1
vote
0 answers

Prolog transitive closure: maze pathfinder

I'm interested in implementing a simple Prolog program that performs path finding queries on maze structures. /* i_ -> intersections */ i_(c,b). /* horizontal adjacencies */ i_(g,h). i_(h,i). i_(i,g). i_(a,d). /* vertical adjacencies…
David Shaked
  • 3,171
  • 3
  • 20
  • 31