Created
October 30, 2012 17:04
-
-
Save arosequist/3981557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns clj-demo.overlay | |
(:refer-clojure :exclude [==]) | |
(:require [clojure.core.logic :refer :all])) | |
(defrel person id) | |
(defrel task id start end duration) | |
(facts person [['A] ['B]]) | |
(facts task [[1 0 10 5] | |
[2 0 10 9] | |
[3 0 11 3]]) | |
(defne personso | |
[q] | |
([[]]) | |
([[[_ p _ _] . r]] | |
(person p) | |
(personso r))) | |
(defne time-intervalso | |
[q] | |
([[]]) | |
([[[t _ s e] . r]] | |
(fresh [ts te td] | |
(task t ts te td) | |
(project [ts te td] | |
(infd s e (interval ts te)) | |
(+fd s td e)) | |
(time-intervalso r)))) | |
(run 1 [q] | |
(fresh [p1 s1 e1 ; p = person, s = start time, e = end time | |
p2 s2 e2 | |
p3 s3 e3] | |
(== q [[1 p1 s1 e1] | |
[2 p2 s2 e2] | |
[3 p3 s3 e3]]) | |
(personso q) | |
(time-intervalso q) | |
(conde | |
[(!= p1 p2)] | |
[(<=fd s2 s1) (<=fd e2 s1)] | |
[(<=fd e1 s2) (<=fd e1 e2)]) | |
(conde | |
[(!= p1 p3)] | |
[(<=fd s3 s1) (<=fd e3 s1)] | |
[(<=fd e1 s3) (<=fd e1 e3)]) | |
(conde | |
[(!= p3 p2)] | |
[(<=fd s2 s3) (<=fd e2 s3)] | |
[(<=fd e3 s2) (<=fd e3 e2)]))) | |
; => ([[1 A 0 5] [2 B 0 9] [3 A 5 8]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment