Fork me on GitHub
Martynas M14:03:50

Hey. Is there a way to do a square root when using a finite domain lvar? It can be lossful but it's fine.

Martynas M14:03:25

I think that finding data for a specific standard deviation is not the best problem for the solver. But maybe I'm just mistaken. I get this as one of my errors and it doesn't get more understandable from here... Error printing return value (StackOverflowError) at clojure.lang.Numbers/hasheq ( Probably the search space is too deep...


👋 I’m new to logic programming and am looking solve a constraint problem that is think is best modeled as a finite domain. • Given a set of mentors and mentees • Each mentee can have a list of mentor preferences • I want to find all solutions to matching mentees with their mentor preferences. • Each mentor can only be a mentor for one mentee My thinking was to look at this as a finite domain (translating names to numbers) and using a lvarfor each mentor. By using (fd/distinct (vec lmentors)) I was hoping to solve for “each mentor only gets to have a single mentee”. Problem: As the number of lvars becomes large (say ~40) then running (fd/distinct (vec lmentors)) is very slow. If I remove this constraint the program finds solutions immediately. Are there ways to optimize this or just program this smarter? core logic:

(let [lmentors (repeatedly (count mentees) lvar) ;; one lvar for each mentee to match
      solutions (pldb/with-db db ;; db pre populated with mentee, mentor and preferences relations
                  (run 1 [q]
                    (== q (vec ;; q is [[mentee1 lvar-mentor2] [mentee2 lvar-mentor2] ... ] 
                           (map vector (keys mentees) lmentors)))
                    (everyg #(fd/in % mentor-domain) lmentors)
                    (fd/distinct (vec lmentors))
                      (fn [tee tor]
                        (fresh [tors]
                          (mentee tee)
                          (mentor tor)
                          (preferences tee tors)
                          (membero tor tors)))
                      (keys mentees)

  (map keyword-solution solutions))
Full sample (seems to work at small scale)


core.logic is pretty bad at doing set stuff, needs clp(set)