Assigning Values in Core.Logic

51 views
Skip to first unread message

Ashton Kemerling

unread,
Sep 18, 2014, 9:56:00 PM9/18/14
to clo...@googlegroups.com
I can't tell if I'm being silly, but I'm having issues figuring out how to record the results of my computation in Core.Logic.

The basic idea is that I'm trying to determine if a schedule a user has requested is solvable or not. I'm trying to find out how to assign to each hash-map what resource I determined can be used for it. The following case is simplistic, but I need to get this code working before attempting to generalize what the user has requested.

(defn solve [types reservations]
  (let [reservations (map #(assoc % :assigned-resource (l/lvar)) reservations)
        resources (flatten (map :resources types))
        vars (repeatedly (count reservations) l/lvar)
        resource-vars (take (count by-resource) vars)

        ]
    (l/run 1 [q]
           (l/== q vars)
           ;; 
           (l/everyg #(l/membero % reservations) resource-vars)
           (l/everyg #(l/fresh [resource]
                               (l/membero resource resources)
                               (l/== % (l/partial-map {:resource resource}))
                               ;; Somehow assign resource to :assigned-resource here.
                               )
                     resource-vars)


           (l/distincto resource-vars)
           )))

Ashton Kemerling

unread,
Sep 18, 2014, 10:19:15 PM9/18/14
to clojure
Aha, I believe the "is" method has solved my dilemma.

--
Ashton Kemerling

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages