Fork me on GitHub

👋 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 with 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)) 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:

Drew Verlee20:03:34

@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.

Drew Verlee20:03:12

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 and it seems to do the trick 🙂