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
0
votes
1 answer

Length and Path in Graphs Prolog (avoid infinite recursion for cycles)

node(a). node(b). node(c). node(d). node(e). node(f). node(g). node(h). edge(a,b). edge(b,c). edge(c,a). edge(c,e). edge(c,d). edge(d,e). edge(d,h). edge(e,g). edge(g,e). edge(e,f). edge(f,g). parent(X,Y):-edge(X,Y). child(X,Y):-parent(Y,X). path(X,Y…
0
votes
0 answers

Compute time to transitive closure

I have a time-stamped dataset like the following t = c("2006-01-02 09:09:38 UTC", "2006-01-04 08:45:34 UTC", "2006-01-10 12:55:41 UTC", "2006-01-20 09:33:54 UTC", "2006-02-02 11:36:06 UTC", "2006-02-15 08:51:03 UTC", "2007-06-07…
EffeBi
  • 41
  • 3
0
votes
0 answers

prolog find facts and query for family tree

I need the help to find the prolog code for the below : ancestors(x,y) using only a is_a(x,y) where X is a Y image related to question attached below animal tree question
MJaber
  • 11
  • 2
0
votes
1 answer

Performance of the transitive closure query in Neo4j

I am trying to compute the transitive closure of an undirected graph in Neo4j using the following Cypher Query ("E" is the label that every edge of the graph has): MATCH (a) -[:E*]- (b) WHERE ID(a) < ID(b) RETURN DISTINCT a, b I tried to execute…
0
votes
0 answers

Family relation in Prolog

I don't understand how to remove the infinite loop.When trying to find…
Sidwa
  • 41
  • 1
  • 10
0
votes
1 answer

In Prolog, how to make comparison when order is defined in a chain of predicates?

Having the following definition: biggerThan(a,b). biggerThan(b,c). biggerThan(c,d). How to define a rule is_bigger(X,Y), such that is_bigger(a,c) and is_bigger(a,d) will return true. Besides, I am very new to Prolog. Did the title properly…
0
votes
1 answer

How to stop printing the same value twice in prolog?

I have this facts or database in prolog to see if the educations is the same or less than. for example highschool <= highschool is true and highschool <= phd is true too, but masters <= highschool is false. edu_less(high_school,…
David Andvett
  • 133
  • 4
  • 10
0
votes
0 answers

MySQL Closure Tables: How to pull data in the correct oreder when there are multiple parents for a child?

I am using closure tables in a similar way to this answer. I have the following two tables: CREATE TABLE `part` ( `id` int(11) NOT NULL, `name` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`), ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Which is the…
0
votes
1 answer

(Prolog) How to find if a connection exists between 2 predicates

This is what I have so far. I need to show that if two stations are connected via a third station, they are connected to each…
user2338241
  • 7
  • 1
  • 2
0
votes
1 answer

Transitive reduction - Error with code - Python

So I am trying to write a code to do transitive reduction of Acyclic graph. So the elements are: (3, 5), (5, 2), (2, 1), (4, 2), (3, 1), (4, 1) This is what I have written so far: graph = [[3, 5],[5, 2],[2, 1],[4, 2],[3, 1],[4, 1]] for i in…
user3624406
  • 29
  • 1
  • 7
0
votes
1 answer

creep error in Prolog when I find a route

I'm learning Prolog, and I'm getting creep error when I try to find a route. I think what I did is recursion because that's the way to find a route when there's not a straight path. Here is the…
mary jerson
  • 51
  • 10
0
votes
1 answer

Checking if graph is connected

I am checking if the graph is connected and for some reason getting false when it should be true. allConnected([]). allConnected(A|L) :- checkConnect(A,L), allConnected(L). checkConnect([],[]). checkConnect(X, Head|Y) :- isConnected(X,Head),…
John Smith
  • 45
  • 1
  • 5
0
votes
2 answers

Calculate reachability for every vertex from adjacency list

Given an adjacency list Map> for a DAG, I want to calculate the reachability of every vertex (i.e. if there there is path from u to v). static Map> reachability(Map> adjList) {} I know it…
0
votes
1 answer

prolog recursive searching with contraints

I have a house with rooms that are defined with connections for when you can go from one room to another…
JJ1
  • 17
  • 2
  • 5
0
votes
1 answer

getting out of local stack at prolog

p(0,0). p(0,1). p(0,2). p(0,3). p(0,4). p(1,1). p(1,2). p(1,3). p(1,4). p(1,0). p(2,0). p(2,1). p(2,2). p(2,3). p(2,4). p(3,0). p(3,1). p(3,2). p(3,3). p(3,4). p(4,0). p(4,1). p(4,2). p(4,3). p(4,4). adjacent(p(X,Y),p(X,Z)) :- p(X,Y), …
1 2 3
9
10