0
votes

I am trying to model a graph using core.logic and would like to match all nodes that have edges to two other nodes. I have come up with the below but it returns two results instead of the desired one, as [2 3 4] and [2 4 3] are equivalent. How would I constrain the query to only return the desired result?

(use 'clojure.core.logic.pldb)

(db-rel edge a b)

(def g
  (db
   [edge 1 2]
   [edge 2 3]
   [edge 3 4]
   [edge 2 4]))

(with-db g
  (run* [q]
    (fresh [x y z]
      (edge x y)
      (edge x z)
      (!= y z)
      (== q [x y z]))))
1

1 Answers

0
votes

Assuming you don't care which of the two results you get, then the easiest thing to do is to replace the (run* [q] call with (run 1 [q], where the 1 indicates you only want one result returned.