Browse Source

Start adding types

Samuel W. Flint 4 years ago
parent
commit
50cc691533
3 changed files with 86 additions and 1 deletions
  1. 1 0
      lcsp.asd
  2. 19 1
      package.lisp
  3. 66 0
      types.lisp

+ 1 - 0
lcsp.asd

@@ -11,4 +11,5 @@
   :serial t
   :depends-on (#:alexandria)
   :components ((:file "package")
+               (:file "types")
                (:file "LCSP")))

+ 19 - 1
package.lisp

@@ -4,4 +4,22 @@
 
 
 (defpackage #:LCSP
-  (:use #:cl))
+  (:use #:cl)
+  (:export #:<csp>
+           #:name
+           #:variables
+           #:constraints
+           #:constraint-checks
+           #:<variable>
+           #:var-type
+           #:domain
+           #:<constraint>
+           #:adicity
+           #:problem
+           #:check-constraint
+           #:<constraint-extension>
+           #:nogoodsp
+           #:constraints-list
+           #:<constraint-intension>
+           #:constraint-function
+           #:<constraint-combined>))

+ 66 - 0
types.lisp

@@ -0,0 +1,66 @@
+;;;; types.lisp
+;;;;
+;;;; Copyright (c) 2020 Samuel W. Flint <swflint@flintfam.org>
+
+(in-package #:lcsp)
+
+;;; "lcsp" goes here.
+
+(defclass <csp> ()
+  ((name :reader name
+         :type 'symbol
+         :initarg :name)
+   (variables :reader variables
+              :type 'list
+              :initarg :variables)
+   (constraints :reader constraints
+                :type 'list
+                :initarg :constraints)
+   (constraint-checks :accessor constraint-checks
+                      :type 'integer
+                      :initform 0)))
+
+(defclass <variable> ()
+  ((name :accessor name
+         :type 'symbol
+         :initarg :name)
+   (type :accessor var-type
+         :type 'type-specifier
+         :initarg :type)
+   (domain :accessor domain)
+   (constraints-map :accessor constraints
+                    :type list
+                    :initarg :constraints-map)))
+
+(defclass <constraint> ()
+  ((adicity :reader constraint-adicity
+            :type 'integer)
+   (variables :reader variables
+              :initarg :variables
+              :type list)
+   (problem :reader problem
+            :initarg :problem
+            :type '<csp>)))
+
+(defmethod initialize-instance :after
+    ((instance <constraint>) &key &allow-other-keys)
+  (with-slots (variables adicity) instance
+    (setf adicity (length variables))))
+
+(defgeneric check-constraint (constraint &rest vvps))
+
+(defclass <constraint-extension> (<constraint>)
+  ((nogoodsp :reader nogoodsp
+             :initarg :nogoodsp)
+   (constraints-list :reader constraints-list
+                     :initarg :list)))
+
+(defclass <constraint-intension> (<constraint>)
+  ((function :reader constraint-function
+             :initarg :constraint-function)))
+
+(defclass <constraint-combined> (<constraint>)
+  ((constraints :reader constraints
+                :initarg constraints)))
+
+;;; End lcsp