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
2
votes
2 answers

All simple paths from a vertex to all other reachable nodes

I am completely new to Prolog and was looking into graphs. I found a problem online that asks me to specify a node and then list all simple paths reachable from that node. There is no goal node, just try all possibilities and return all those…
2
votes
1 answer

Boost BGL Transitive reduction

I try to use the transitive_reduction of boost, but I don't know how to use it. I have a graph defined with : typedef boost::adjacency_list Graph; typedef Graph::vertex_descriptor…
Muby
  • 77
  • 1
  • 8
2
votes
1 answer

No termination of predicate

I have some program about a graph with black and white vertices: black(root). black(v1). black(v3). black(v4). edge(root,root). edge(v1,root). edge(v2,v1). edge(v3,v1). edge(v4,v3). edge(v5,v2). edge(v5,v4). edge(v6,v5). vertex(X) :-…
Yuval Simon
  • 335
  • 1
  • 10
2
votes
2 answers

Prolog : eliminating cycles from indirect relation

I have a list of user facts defined as: user(@michael). user(@ana). user(@bob). user(@george). user(@john). and so on. Furthermore, I have a set of facts as: follows(@michael,@ana). follows(@ana,@bob). follows(@bob,@michael). I am trying to write…
na899
  • 163
  • 1
  • 2
  • 9
2
votes
1 answer

Prolog compiler return error

I have this hypothetical program to check if a path exists from point A to B. /*city rules*/ edge(phx, tuc). edge(tuc, ccg). edge(ccg, sf). connected(C1, C2) :- edge(C1, C2). connected(C1, C2) :- edge(C1, X), connected(X, C2). the…
ryan
  • 625
  • 3
  • 10
  • 23
2
votes
4 answers

Prolog Infinite loop (cyclic graph)

this might be a simple problem but I need to do it differently. The problem is that I have to find in prolog the possible routes of airflights. I have this knowledge base from_to(fresno,seattle). from_to(fresno,albany). …
2
votes
2 answers

Prolog, Determine if graph is acyclic

I need to define a predicate acyclic/1 that takes a graph in as input and determine if that graph is acyclic. So from my understanding graph1(a,b). graph1(b,c). graph1(c,a). Will return no and graph2(a,b). graph2(b,c). will return yes I…
2
votes
2 answers

Prolog out of local stack space/ infinite recursion

I have read other similar questions and answers on this site, but can't seem to find the answer to my particular problem. I am trying to encode a maze in Prolog. From region 0, you can move freely to regions 1 or region 3. From region 3, you can…
2
votes
2 answers

How to use list to record path from A to B?

If I have a map with nodes 1,2,...,n, I want to know if I can go from n1 to n2, I can use the following code: path(1,2). path(3,5). ..... get_to(A,B) :- path(A,B). get_to(A,B) :- path(A,C),get_to(C,B). But how can record the path from A to B and…
祝堅志
  • 21
  • 3
2
votes
0 answers

Prolog Family Tree Blood Relations, Recursion?

I need a recursive function that finds all blood relatives in a family tree. But I honestly have no idea how to implement this in Prolog. My current understanding for a solution, would be to search the current branch for a match and proceed to the…
2
votes
2 answers

ERROR: Out of local stack in my Prolog code

I cannot figure out why the following query from the given Prolog code generates the error Out of local stack. Prolog code: likes(g,c). likes(c,a). likes(c,b). likes(b,a). likes(b,d). likes(X,Z) :- likes(X,Y), likes(Y,Z). the query ?-…
Rasoul
  • 3,758
  • 5
  • 26
  • 34
2
votes
2 answers

Reachability constraint in SWI/CLP(FD)

I'm trying to determine that shape of a directed graph by solving constraints on presence of nodes and arcs, e.g., binary variable V1V2 is 1 if there is an arc from node V1 to V2. I would like to express the reachability constraint (or,…
2
votes
1 answer

Prolog definition which detects a path

Context, first. I have the following bi-directional graph. Represented in Prolog like this: relation(a,c). relation(b,d). relation(c,d). relation(d,e). relation(e,f). connection(X,Y) :- relation(X,Y). connection(X,Y) :- relation(Y,X). So I have…
SealCuadrado
  • 749
  • 1
  • 10
  • 21
2
votes
2 answers

How can I prevent duplicates in prolog

My multiple solution problem arises due to Prolog's backtracking looping through the goals. Whilst I understand that, technically, each solution provided is correct, it is not useful to me. Is there a method to remove duplicates? Here is my code so…
Danny Rancher
  • 1,923
  • 3
  • 24
  • 43
2
votes
2 answers

Compute transitive closure

I have my data of pairwise DNA sequences showing similarity in the following way.. AATGCTA|1 AATCGTA|2 AATCGTA|2 AATGGTA|3 AATGGTA|3 AATGGTT|8 TTTGGTA|4 ATTGGTA|5 ATTGGTA|5 CCTGGTA|9 CCCGGTA|6 GCCGGTA|7 GGCGGTA|10 AATCGTA|2 GGCGGTA|10 …
bala
  • 553
  • 4
  • 7