IntSet + IntVar new functions; LubRanges - GlbRanges
Tue Feb 6 11:14:21 PST 2007 kilian.sprotte@gmail.com
* IntSet + IntVar new functions; LubRanges - GlbRanges
diff -rN -u old-gecol/ffi.lisp new-gecol/ffi.lisp
--- old-gecol/ffi.lisp 2014-08-01 08:57:09.000000000 -0700
+++ new-gecol/ffi.lisp 2014-08-01 08:57:09.000000000 -0700
@@ -104,6 +104,10 @@
(r :pointer)
(n :int))
+(defcfun* ("make_IntSet_intarray2_int" make-intset-intarray2-int) :pointer
+ (r :pointer)
+ (n :int))
+
(defcfun* ("IntSet_size" intset-size) :int
(intset :pointer))
@@ -133,10 +137,22 @@
(space :pointer)
(min :int)
(max :int))
-(defcfun* ("IntVar_assigned" intvar-assigned) :boolean
+(defcfun* ("IntVar_min" intvar-min) :int
+ (intvar :pointer))
+(defcfun* ("IntVar_max" intvar-max) :int
+ (intvar :pointer))
+(defcfun* ("IntVar_med" intvar-med) :int
(intvar :pointer))
(defcfun* ("IntVar_val" intvar-val) :int
(intvar :pointer))
+(defcfun* ("IntVar_size" intvar-size) :unsigned-int
+ (intvar :pointer))
+(defcfun* ("IntVar_width" intvar-width) :unsigned-int
+ (intvar :pointer))
+(defcfun* ("IntVar_degree" intvar-degree) :unsigned-int
+ (intvar :pointer))
+(defcfun* ("IntVar_assigned" intvar-assigned) :boolean
+ (intvar :pointer))
(defcfun* ("delete_IntVar" delete-intvar) :void
(intvar :pointer))
@@ -566,31 +582,31 @@
;;; Sets
+(defcfun gec-fs-make :pointer
+ "Make completely undetermined SetVar with empty
+greatest lower and full least upper bound.."
+ (space :pointer))
+
(defcfun gec-fs-make-const :pointer
- "Make constant SetVar of CARD with DOM (int array)."
+ "Make constant SetVar of CARD with DOM (IntSet)."
(space :pointer)
- (card :int)
(dom :pointer))
(defcfun gec-fs-make-bounds :pointer
"Make SetVar with lower-bound and upper-bound.
-The dom pointers are int arrays."
- (space :pointer)
- (lower-card :int)
- (lower-dom :pointer)
- (upper-card :int)
+The dom pointers are IntSets."
+ (space :pointer)
+ (lower-dom :pointer)
(upper-dom :pointer))
(defcfun gec-fs-make-lower-bound :pointer
"Make SetVar with lower-bound and empty upper-bound."
(space :pointer)
- (lower-card :int)
(lower-dom :pointer))
(defcfun gec-fs-make-upper-bound :pointer
"Make SetVar with empty lower-bound and given upper-bound."
(space :pointer)
- (upper-card :int)
(upper-dom :pointer))
(defcfun gec-fs-glb-size :unsigned-int
@@ -643,6 +659,57 @@
"Test whether this variable is assigned."
(set :pointer))
+(defcfun gec-fs-variable :pointer
+ "Return set variable implementation."
+ (set :pointer))
+
+;;
+
+(defcfun* ("make_LubRanges" make-LubRanges) :pointer
+ (v :pointer))
+
+(defcfun* ("LubRanges_min" LubRanges-min) :int
+ (r :pointer))
+
+(defcfun* ("LubRanges_max" LubRanges-max) :int
+ (r :pointer))
+
+(defcfun* ("LubRanges_width" LubRanges-width) :unsigned-int
+ (r :pointer))
+
+(defcfun* ("LubRanges_valid" LubRanges-valid) :boolean
+ (r :pointer))
+
+(defcfun* ("LubRanges_next" LubRanges-next) :void
+ (r :pointer))
+
+(defcfun* ("delete_LubRanges" delete-LubRanges) :void
+ (r :pointer))
+
+;;
+
+(defcfun* ("make_GlbRanges" make-GlbRanges) :pointer
+ (v :pointer))
+
+(defcfun* ("GlbRanges_min" GlbRanges-min) :int
+ (r :pointer))
+
+(defcfun* ("GlbRanges_max" GlbRanges-max) :int
+ (r :pointer))
+
+(defcfun* ("GlbRanges_width" GlbRanges-width) :unsigned-int
+ (r :pointer))
+
+(defcfun* ("GlbRanges_valid" GlbRanges-valid) :boolean
+ (r :pointer))
+
+(defcfun* ("GlbRanges_next" GlbRanges-next) :void
+ (r :pointer))
+
+(defcfun* ("delete_GlbRanges" delete-GlbRanges) :void
+ (r :pointer))
+
+
;;
(defcfun*
diff -rN -u old-gecol/gec.lisp new-gecol/gec.lisp
--- old-gecol/gec.lisp 2014-08-01 08:57:09.000000000 -0700
+++ new-gecol/gec.lisp 2014-08-01 08:57:09.000000000 -0700
@@ -50,6 +50,7 @@
;;; Sets
(defun gec-fs-enumerate-lower-bound (set)
+ (error "dont use")
(unless (zerop (gec-fs-glb-size set))
(iter
(for potential-elt from (gec-fs-glb-max set)
@@ -58,6 +59,7 @@
(collect potential-elt at beginning)))))
(defun gec-fs-enumerate-upper-bound (set)
+ (error "dont use")
(unless (zerop (gec-fs-lub-size set))
(iter
(for potential-elt from (gec-fs-lub-max set)
@@ -67,9 +69,10 @@
(defun gec-fs-value (set)
"Assumes that SET is assigned."
+ ;; FIXME better check this
(gec-fs-enumerate-lower-bound set))
-;;; TODO this needs to be optimized (dont iterate over list twice, if possible)
+;;; FIXME this needs to be optimized (dont iterate over list twice, if possible)
(defmacro with-list-as-int-array ((list array size) &body body)
(check-type array symbol)
(check-type size symbol)
@@ -89,7 +92,7 @@
(array :pointer))
(export 'with-var-arg-array)
-;;; TODO - we will use this /a lot/. So you should
+;;; FIXME - 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)
diff -rN -u old-gecol/glue.cpp new-gecol/glue.cpp
--- old-gecol/glue.cpp 2014-08-01 08:57:09.000000000 -0700
+++ new-gecol/glue.cpp 2014-08-01 08:57:09.000000000 -0700
@@ -57,7 +57,7 @@
ints.update(this, share, s.ints);
bools.update(this, share, s.bools);
sets.update(this, share, s.sets);
- // TODO maybe specialize GecolBABSpace
+ // FIXME maybe specialize GecolBABSpace
// so we dont always copy these
bab_intvar_ind = s.bab_intvar_ind;
bab_intreltype = s.bab_intreltype;
@@ -76,7 +76,7 @@
SetVarArray getSets () {
return sets;
}
- // TODO use here the 'more complicated' version
+ // FIXME use here the 'more complicated' version
// like in gecode examples?
void constrain(GecolSpace* latest) {
rel(this, this->getInts()[bab_intvar_ind], bab_intreltype, latest->getInts()[bab_intvar_ind]);
@@ -111,6 +111,7 @@
// IntSet
IntSet *make_IntSet_int_int(int n, int m);
IntSet *make_IntSet_intarray_int(const int r[], int n);
+ IntSet *make_IntSet_intarray2_int(const int r[][2], int n);
int IntSet_size(IntSet *intset);
int IntSet_min_int(IntSet *intset, int i);
int IntSet_max_int(IntSet *intset, int i);
@@ -120,8 +121,16 @@
void delete_IntSet(IntSet *intset);
// IntVar
IntVar *make_IntVar_Space_int_int(Space* home, int min, int max);
- bool IntVar_assigned(IntVar* intvar);
+ int IntVar_min(IntVar* intvar);
+ int IntVar_max(IntVar* intvar);
+ int IntVar_med(IntVar* intvar);
int IntVar_val(IntVar* intvar);
+ unsigned int IntVar_size(IntVar* intvar);
+ unsigned int IntVar_width(IntVar* intvar);
+ unsigned int IntVar_degree(IntVar* intvar);
+ bool IntVar_range(IntVar* intvar);
+ bool IntVar_assigned(IntVar* intvar);
+ bool IntVar_in_int(IntVar* intvar, const int n);
void delete_IntVar(IntVar *v);
// GecolSpace
GecolSpace* make_GecolSpace(int intnum, int intmin, int intmax, int boolnum, int setnum,
@@ -229,12 +238,11 @@
// Sets
- SetVar* gec_fs_make_const(GecolSpace* space, int card, int *dom);
- SetVar* gec_fs_make_bounds(GecolSpace* space,
- int lower_card, int *lower_dom,
- int upper_card, int *upper_dom);
- SetVar* gec_fs_make_lower_bound(GecolSpace* space, int lower_card, int *lower_dom);
- SetVar* gec_fs_make_upper_bound(GecolSpace* space, int upper_card, int *upper_dom);
+ SetVar* gec_fs_make(GecolSpace* space);
+ SetVar* gec_fs_make_const(GecolSpace* space, IntSet d);
+ SetVar* gec_fs_make_bounds(GecolSpace* space, IntSet ld, IntSet ud);
+ SetVar* gec_fs_make_lower_bound(GecolSpace* space, IntSet ld);
+ SetVar* gec_fs_make_upper_bound(GecolSpace* space, IntSet ud);
unsigned int gec_fs_glb_size(SetVar* set);
unsigned int gec_fs_lub_size(SetVar* set);
unsigned int gec_fs_unknown_size(SetVar* set);
@@ -247,6 +255,26 @@
bool gec_fs_contains(SetVar* set, int x);
bool gec_fs_not_contains(SetVar* set, int x);
bool gec_fs_assigned(SetVar* set);
+ Set::SetVarImp* gec_fs_variable(SetVar* set);
+ // SetView
+ // Set::SetView* make_SetView(SetVar* set);
+ // void delete_SetView(Set::SetView* v);
+ // LubRanges
+ Gecode::Set::LubRanges<Set::SetVarImp*>* make_LubRanges(Set::SetVarImp* v);
+ int LubRanges_min(Set::LubRanges<Set::SetVarImp*>* r);
+ int LubRanges_max(Set::LubRanges<Set::SetVarImp*>* r);
+ unsigned int LubRanges_width(Set::LubRanges<Set::SetVarImp*>* r);
+ bool LubRanges_valid(Set::LubRanges<Set::SetVarImp*>* r);
+ void LubRanges_next(Set::LubRanges<Set::SetVarImp*>* r);
+ void delete_LubRanges(Set::LubRanges<Set::SetVarImp*>* r);
+ // GlbRanges
+ Gecode::Set::GlbRanges<Set::SetVarImp*>* make_GlbRanges(Set::SetVarImp* v);
+ int GlbRanges_min(Set::GlbRanges<Set::SetVarImp*>* r);
+ int GlbRanges_max(Set::GlbRanges<Set::SetVarImp*>* r);
+ unsigned int GlbRanges_width(Set::GlbRanges<Set::SetVarImp*>* r);
+ bool GlbRanges_valid(Set::GlbRanges<Set::SetVarImp*>* r);
+ void GlbRanges_next(Set::GlbRanges<Set::SetVarImp*>* r);
+ void delete_GlbRanges(Set::GlbRanges<Set::SetVarImp*>* r);
void atmostOne_setvarargs_unsigned_int(Space *home, const lisp_SetVarArgs *x, unsigned int c);
void distinct_setvarargs_unsigned_int(Space *home, const lisp_SetVarArgs *x, unsigned int c);
@@ -305,6 +333,11 @@
return new IntSet(r,n);
}
+IntSet *make_IntSet_intarray2_int(const int r[][2], int n)
+{
+ return new IntSet(r,n);
+}
+
int IntSet_size(IntSet *intset)
{
return intset->size();
@@ -346,9 +379,19 @@
return new IntVar(home, min, max);
}
-bool IntVar_assigned(IntVar* intvar)
+int IntVar_min(IntVar* intvar)
{
- return intvar->assigned();
+ return intvar->min();
+}
+
+int IntVar_max(IntVar* intvar)
+{
+ return intvar->max();
+}
+
+int IntVar_med(IntVar* intvar)
+{
+ return intvar->med();
}
int IntVar_val(IntVar* intvar)
@@ -356,6 +399,36 @@
return intvar->val();
}
+unsigned int IntVar_size(IntVar* intvar)
+{
+ return intvar->size();
+}
+
+unsigned int IntVar_width(IntVar* intvar)
+{
+ return intvar->width();
+}
+
+unsigned int IntVar_degree(IntVar* intvar)
+{
+ return intvar->degree();
+}
+
+bool IntVar_range(IntVar* intvar)
+{
+ return intvar->range();
+}
+
+bool IntVar_assigned(IntVar* intvar)
+{
+ return intvar->assigned();
+}
+
+bool IntVar_in_int(IntVar* intvar, const int n)
+{
+ return intvar->in(n);
+}
+
void delete_IntVar(IntVar *v)
{
delete v;
@@ -1164,32 +1237,28 @@
// Sets
-SetVar* gec_fs_make_const(GecolSpace* space, int card, int *dom)
+SetVar* gec_fs_make(GecolSpace* space)
+{
+ return new SetVar(space);
+}
+
+SetVar* gec_fs_make_const(GecolSpace* space, IntSet d)
{
- IntSet d(dom, card);
return new SetVar(space, d, d);
}
-SetVar* gec_fs_make_bounds(GecolSpace* space,
- int lower_card, int *lower_dom,
- int upper_card, int *upper_dom)
+SetVar* gec_fs_make_bounds(GecolSpace* space, IntSet ld, IntSet ud)
{
- IntSet ld(lower_dom, lower_card);
- IntSet ud(upper_dom, upper_card);
return new SetVar(space, ld, ud);
}
-SetVar* gec_fs_make_lower_bound(GecolSpace* space,
- int lower_card, int *lower_dom)
+SetVar* gec_fs_make_lower_bound(GecolSpace* space, IntSet ld)
{
- IntSet ld(lower_dom, lower_card);
return new SetVar(space, ld, IntSet::empty);
}
-SetVar* gec_fs_make_upper_bound(GecolSpace* space,
- int upper_card, int *upper_dom)
+SetVar* gec_fs_make_upper_bound(GecolSpace* space, IntSet ud)
{
- IntSet ud(upper_dom, upper_card);
return new SetVar(space, IntSet::empty, ud);
}
@@ -1253,6 +1322,94 @@
return set->assigned();
}
+Set::SetVarImp* gec_fs_variable(SetVar* set)
+{
+ return set->variable();
+}
+
+// SetView
+// Set::SetView* make_SetView(SetVar* set)
+// {
+// return new Set::SetView(*set);
+// }
+//
+// void delete_SetView(Set::SetView* v)
+// {
+// delete v;
+// }
+
+// LubRanges
+Set::LubRanges<Set::SetVarImp*>* make_LubRanges(Set::SetVarImp* v)
+{
+ return new Set::LubRanges<Set::SetVarImp*>(v);
+}
+
+int LubRanges_min(Set::LubRanges<Set::SetVarImp*>* r)
+{
+ return r->min();
+}
+
+int LubRanges_max(Set::LubRanges<Set::SetVarImp*>* r)
+{
+ return r->max();
+}
+
+unsigned int LubRanges_width(Set::LubRanges<Set::SetVarImp*>* r)
+{
+ return r->width();
+}
+
+bool LubRanges_valid(Set::LubRanges<Set::SetVarImp*>* r)
+{
+ return r->operator ()();
+}
+
+void LubRanges_next(Set::LubRanges<Set::SetVarImp*>* r)
+{
+ r->operator ++();
+}
+
+void delete_LubRanges(Set::LubRanges<Set::SetVarImp*>* r)
+{
+ delete r;
+}
+
+// GlbRanges
+Set::GlbRanges<Set::SetVarImp*>* make_GlbRanges(Set::SetVarImp* v)
+{
+ return new Set::GlbRanges<Set::SetVarImp*>(v);
+}
+
+int GlbRanges_min(Set::GlbRanges<Set::SetVarImp*>* r)
+{
+ return r->min();
+}
+
+int GlbRanges_max(Set::GlbRanges<Set::SetVarImp*>* r)
+{
+ return r->max();
+}
+
+unsigned int GlbRanges_width(Set::GlbRanges<Set::SetVarImp*>* r)
+{
+ return r->width();
+}
+
+bool GlbRanges_valid(Set::GlbRanges<Set::SetVarImp*>* r)
+{
+ return r->operator ()();
+}
+
+void GlbRanges_next(Set::GlbRanges<Set::SetVarImp*>* r)
+{
+ r->operator ++();
+}
+
+void delete_GlbRanges(Set::GlbRanges<Set::SetVarImp*>* r)
+{
+ delete r;
+}
+
//////
void atmostOne_setvarargs_unsigned_int(Space *home, const lisp_SetVarArgs *x, unsigned int c)
diff -rN -u old-gecol/package.lisp new-gecol/package.lisp
--- old-gecol/package.lisp 2014-08-01 08:57:09.000000000 -0700
+++ new-gecol/package.lisp 2014-08-01 08:57:09.000000000 -0700
@@ -39,6 +39,7 @@
;; Ints
#:gec-minus
;; Sets
+ #:gec-fs-make
#:gec-fs-make-const
#:gec-fs-make-bounds
#:gec-fs-make-lower-bound
@@ -55,7 +56,8 @@
#:gec-fs-contains
#:gec-fs-not-contains
#:gec-fs-assigned
- ;;; Sets - lisp extensions
+ #:gec-fs-variable
+;;; Sets - lisp extensions
#:gec-fs-enumerate-lower-bound
#:gec-fs-enumerate-upper-bound
#:gec-fs-value