big update
examples.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/examples.lisp 2014-04-18 11:42:02.000000000 -0700
+++ new-gecol/examples.lisp 2014-04-18 11:42:03.000000000 -0700
@@ -29,67 +29,106 @@
(in-package :cl-user)
+;; TODO maybe use gecol:intvar-assigned
(defun cartesian-product ()
- (let ((s (gecol:create-space 3 1 3 0 0)))
- (gecol:gec-branch-vars-min s)
- (let ((e (gecol:create-search-engine s)))
+ (let ((s (gecol:make-gecolspace :intnum 3 :intmin 1 :intmax 3)))
+ (gecol:with-var-arg-array ((loop for i below 3 collect (gecol:gecolspace-getint-int s i))
+ varargs)
+ (gecol:branch-intvarargs-bvarsel-bvalsel s varargs :bvar-none :bval-min))
+ (let ((e (gecol:make-dfs-space-int-int-stop s)))
(loop
- for sol = (gecol:search-next e)
+ for sol = (gecol:dfs-next e)
until (cffi:null-pointer-p sol)
do (format t "~a, ~a, ~a~%"
- (gecol:space-read-int sol 0)
- (gecol:space-read-int sol 1)
- (gecol:space-read-int sol 2))
- do (gecol:dispose-space sol))
- (gecol:dispose-search-engine e)
- (gecol:dispose-space s))))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 0))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 1))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 2)))
+ do (gecol:delete-gecolspace sol))
+ (gecol:delete-dfs e)
+ (gecol:delete-gecolspace s))))
(defun distinct ()
- (let ((s (gecol:create-space 3 1 3 0 0)))
- (gecol:gec-distinct s (list 0 1 2) :icl-def)
- (gecol:gec-branch-vars-min s)
- (let ((e (gecol:create-search-engine s)))
+ (let ((s (gecol:make-gecolspace :intnum 3 :intmin 1 :intmax 3)))
+ (gecol:with-var-arg-array ((loop for i below 3 collect (gecol:gecolspace-getint-int s i))
+ varargs)
+ (gecol:distinct-intvarargs-intconlevel s varargs :icl-def)
+ (gecol:branch-intvarargs-bvarsel-bvalsel s varargs :bvar-none :bval-min))
+ (let ((e (gecol:make-dfs-space-int-int-stop s)))
(loop
- for sol = (gecol:search-next e)
+ for sol = (gecol:dfs-next e)
until (cffi:null-pointer-p sol)
do (format t "~a, ~a, ~a~%"
- (gecol:space-read-int sol 0)
- (gecol:space-read-int sol 1)
- (gecol:space-read-int sol 2))
- do (gecol:dispose-space sol))
- (gecol:dispose-search-engine e)
- (gecol:dispose-space s))))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 0))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 1))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 2)))
+ do (gecol:delete-gecolspace sol))
+ (gecol:delete-dfs e)
+ (gecol:delete-gecolspace s))))
(defun sorted ()
- (let ((s (gecol:create-space 3 1 3 0 0)))
- (gecol:gec-rel-var s 0 :irt-< 1 :icl-def)
- (gecol:gec-rel-var s 1 :irt-< 2 :icl-def)
- (gecol:gec-branch-vars-min s)
- (let ((e (gecol:create-search-engine s)))
+ (let ((s (gecol:make-gecolspace :intnum 3 :intmin 1 :intmax 3)))
+ (gecol:rel-intvar-intreltype-intvar-intconlevel s
+ (gecol:gecolspace-getint-int s 0)
+ :irt-<
+ (gecol:gecolspace-getint-int s 1)
+ :icl-def)
+ (gecol:rel-intvar-intreltype-intvar-intconlevel s
+ (gecol:gecolspace-getint-int s 1)
+ :irt-<
+ (gecol:gecolspace-getint-int s 2)
+ :icl-def)
+
+ (gecol:with-var-arg-array ((loop for i below 3 collect (gecol:gecolspace-getint-int s i))
+ varargs)
+ (gecol:branch-intvarargs-bvarsel-bvalsel s varargs :bvar-none :bval-min))
+ (let ((e (gecol:make-dfs-space-int-int-stop s)))
(loop
- for sol = (gecol:search-next e)
+ for sol = (gecol:dfs-next e)
until (cffi:null-pointer-p sol)
do (format t "~a, ~a, ~a~%"
- (gecol:space-read-int sol 0)
- (gecol:space-read-int sol 1)
- (gecol:space-read-int sol 2))
- do (gecol:dispose-space sol))
- (gecol:dispose-search-engine e)
- (gecol:dispose-space s))))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 0))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 1))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 2)))
+ do (gecol:delete-gecolspace sol))
+ (gecol:delete-dfs e)
+ (gecol:delete-gecolspace s))))
(defun cartesian-product-distr-max ()
- (let ((s (gecol:create-space 3 1 3 0 0)))
- (gecol:gec-branch-vars-max s)
- (let ((e (gecol:create-search-engine s)))
+ "Like cartesian-product, but using a different branching."
+ (let ((s (gecol:make-gecolspace :intnum 3 :intmin 1 :intmax 3)))
+ (gecol:with-var-arg-array ((loop for i below 3 collect (gecol:gecolspace-getint-int s i))
+ varargs)
+ ;; branching
+ (gecol:branch-intvarargs-bvarsel-bvalsel s varargs :bvar-none :bval-max))
+ (let ((e (gecol:make-dfs-space-int-int-stop s)))
(loop
- for sol = (gecol:search-next e)
+ for sol = (gecol:dfs-next e)
until (cffi:null-pointer-p sol)
do (format t "~a, ~a, ~a~%"
- (gecol:space-read-int sol 0)
- (gecol:space-read-int sol 1)
- (gecol:space-read-int sol 2))
- do (gecol:dispose-space sol))
- (gecol:dispose-search-engine e)
- (gecol:dispose-space s))))
-
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 0))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 1))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 2)))
+ do (gecol:delete-gecolspace sol))
+ (gecol:delete-dfs e)
+ (gecol:delete-gecolspace s))))
+
+(defun distinct-minimal-third ()
+ "Like distinct, but minimizing the third variable."
+ (let ((s (gecol:make-gecolspace :intnum 3 :intmin 1 :intmax 3
+ :bab-intvar-ind 2 :bab-intreltype :irt-<)))
+ (gecol:with-var-arg-array ((loop for i below 3 collect (gecol:gecolspace-getint-int s i))
+ varargs)
+ (gecol:distinct-intvarargs-intconlevel s varargs :icl-def)
+ (gecol:branch-intvarargs-bvarsel-bvalsel s varargs :bvar-none :bval-min))
+ (let ((e (gecol:make-bab-space-int-int-stop s)))
+ (loop
+ for sol = (gecol:bab-next e)
+ until (cffi:null-pointer-p sol)
+ do (format t "~a, ~a, ~a~%"
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 0))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 1))
+ (gecol:intvar-val (gecol:gecolspace-getint-int sol 2)))
+ do (gecol:delete-gecolspace sol))
+ (gecol:delete-bab e)
+ (gecol:delete-gecolspace s))))