0

I am trying to solve some tasks regarding graph theory and network analysis using Prolog. Given a graph with nodes and connections:

connection(a, b).
connection(b, e).
connection(e, c).
connection(b, c).
connection(c, d).
connection(d, f).
connection(a, d).
connection(a, c).
connection(b, d).

I had to add predicates checking whether a node is connected to another. This is my code:

connected(X, Y) :- connection(X, Y).
connected(X, Y) :- connection(Y, X).

Now I have to write a predicate to check whether a certain graph is a clique or not. So by definition of a clique, whether all nodes are connected to each other or not.

If anyone has suggestions how to approach this, I would love to hear it.

false
  • 10,264
  • 13
  • 101
  • 209
XaP
  • 1
  • Checking for clique could be interpreted in different ways: 1) for every node check if it is connected to every other node - this would require you to list all nodes and check all nodes. 2) testing for a missing connection returns `false`. 3) listing all connections in a set and counting them. I personally would go with 2) – DuDa Jan 03 '22 at 06:47
  • Could you clarify a little bit: I'm wondering if you would like to return true tor connected(a,e). So I'm wondering if "connected" is relation when A-> B and B->C than A->C as well. – Armatorix Jan 04 '22 at 16:22

0 Answers0