This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

## 2022-03-12

## Channels

- # babashka (37)
- # beginners (27)
- # biff (1)
- # calva (18)
- # cider (45)
- # clj-on-windows (5)
- # cljsrn (1)
- # clojure (90)
- # clojure-art (3)
- # clojure-uk (1)
- # clojurescript (7)
- # core-logic (4)
- # datomic (4)
- # events (2)
- # fulcro (3)
- # hyperfiddle (23)
- # leiningen (66)
- # malli (1)
- # meander (7)
- # nrepl (1)
- # off-topic (9)
- # pathom (1)
- # re-frame (15)
- # reitit (19)
- # remote-jobs (1)
- # shadow-cljs (103)

👋 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
I first https://clojurians.slack.com/archives/C0566T2QY/p1647097346744699 with https://gist.github.com/krukow/9ab5a708458e4d3d758032b081a5707a: My thinking was to look at this as a finite domain (translating names to numbers) and using a `lvar`

for 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))`

in core.logic very slow. If I remove this constraint the program finds solutions immediately.
**Question**: I’ve tried to model this in datomic too (local dev). However, I find myself unable to write a query that (a) finds **all** solutions (a seq of “valid mentee-mentor matchings”); and (b) modeling the solution constraint that each mentor may only appear once in the entire solution set (i.e. something similar to fd/distinct). Is it possible to ask datomic to solve this constraint problem or should I be looking to something else?
Data setup: https://gist.github.com/krukow/070c51827fd3da25aa24a01ee7045011

@U606MT4CX in a typical sql database we call that a "one to many relationship" You validate it at write time when you don't break that invariant in datomic, in sql you would have to first create the table that broke that constraint, then write it. So it would take two steps not one.

Or i'm confused. I didn't understand a good bit of your question.

Thanks for the reply. I was hoping to use datomic to solve the constraint problem for me - but I don’t think it’s the right tool for the job. I think I need more general constraint solving. I found https://choco-solver.org/docs/ and it seems to do the trick 🙂