big update
gec.lisp
Sun Jan 7 17:49:57 PST 2007 kilian.sprotte@gmail.com
* big update
The API resembles much more the original gecode one.
Added support for finite sets.
Can now use BAB search.
--- old-gecol/gec.lisp 2014-07-25 06:03:04.000000000 -0700
+++ new-gecol/gec.lisp 2014-07-25 06:03:04.000000000 -0700
@@ -29,50 +29,26 @@
(in-package :gecol)
-(defun gec-dom-var-set (space x dom level)
- (let ((n (length dom)))
- (with-foreign-object (xs :int n)
- (dotimes (i n)
- (setf (mem-aref xs :int i) (nth i dom)))
- (%gec-dom-var-set space x xs n level))))
-
-(defun gec-linear-var (space res type list level)
- (let ((n (length list)))
- (with-foreign-object (xs :int n)
- (dotimes (i n)
- (setf (mem-aref xs :int i) (nth i list)))
- (%gec-linear-var space res type xs n level))))
-
-(defun gec-linear-const (space res type list level)
- (let ((n (length list)))
- (with-foreign-object (xs :int n)
- (dotimes (i n)
- (setf (mem-aref xs :int i) (nth i list)))
- (%gec-linear-const space res type xs n level))))
-
-(defun gec-distinct (space list level)
- (let ((n (length list)))
- (with-foreign-object (xs :int n)
- (dotimes (i n)
- (setf (mem-aref xs :int i) (nth i list)))
- (%gec-distinct space xs n level))))
-
-(defun gec-element-vars (space list ind var level)
- (let ((n (length list)))
- (with-foreign-object (xs :int n)
- (dotimes (i n)
- (setf (mem-aref xs :int i) (nth i list)))
- (%gec-element-vars space xs n ind var level))))
-
-(defun gec-element-const (space list ind var level)
- (let ((n (length list)))
- (with-foreign-object (xs :int n)
- (dotimes (i n)
- (setf (mem-aref xs :int i) (nth i list)))
- (%gec-element-const space xs n ind var level))))
+;;; GecolSpace
+(defun make-gecolspace (&key
+ (intnum 0)
+ (intmin 0)
+ (intmax 2)
+ (boolnum 0)
+ (setnum 0)
+ (bab-intvar-ind 0)
+ (bab-intreltype :irt->))
+ (%make-gecolspace intnum intmin intmax boolnum setnum bab-intvar-ind bab-intreltype))
+
+;;; DFS
+(defun make-dfs-space-int-int-stop (space &key (c-d 1) (a-d 1) (stop (cffi:null-pointer)))
+ (%make-dfs-space-int-int-stop space c-d a-d stop))
+
+;;; BAB
+(defun make-bab-space-int-int-stop (space &key (c-d 1) (a-d 1) (stop (cffi:null-pointer)))
+ (%make-bab-space-int-int-stop space c-d a-d stop))
;;; Sets
-
(defun gec-fs-enumerate-lower-bound (set)
(unless (zerop (gec-fs-glb-size set))
(iter
@@ -107,3 +83,34 @@
(setf (cffi:mem-aref ,array :int i) elt))
,@body))))
+(defcstruct var-arg-array
+ "actually a lispy version of it, made up for wrapping the original VarArgArray"
+ (size :int)
+ (array :pointer))
+
+(export 'with-var-arg-array)
+;;; TODO - we will use this /a lot/. So you should
+;;; try to make the generated code as small as possible.
+(defmacro with-var-arg-array ((list var &key (type :pointer)) &body body)
+ (check-type var symbol)
+ (let ((=list= (gensym "LIST")))
+ `(let* ((,=list= ,list)
+ (list-len (length ,=list=)))
+ (with-foreign-object (array* ,type list-len)
+ (iter
+ (for elt in ,=list=)
+ (for i upfrom 0)
+ (setf (mem-aref array* ,type i) elt))
+ (with-foreign-object (,var 'var-arg-array)
+ (with-foreign-slots ((size array) ,var var-arg-array)
+ (setf size list-len
+ array array*)
+ ,@body))))))
+
+(defun gec-minus (space a b c)
+ "a - b = c"
+ (with-var-arg-array ('(1 -1) coeffs :type :int)
+ (with-var-arg-array ((list a b) a-b)
+ (gecol:linear-intargs-intvarargs-intreltype-intvar-intconlevel
+ space coeffs a-b :irt-= c :icl-def))))
+