44#include <initializer_list>
72 bool duplicates(
void** p,
int n,
void** q,
int m);
78 template<
class Var>
class VarArray;
79 template<
class Var>
class VarArgArray;
206 static void*
operator new(size_t)
throw();
207 static void operator delete(
void*,size_t);
310 for (
int i=0; i<n; i++)
327 x =
r.alloc<
View>(n);
328 for (
int i=0; i<n; i++)
486 static void*
operator new(size_t)
throw();
487 static void operator delete(
void*,size_t);
497 template<
class ViewX,
class ViewY>
505 template<
class ViewX,
class ViewY>
513 template<
class ViewX,
class ViewY>
610 template<
class InputIterator>
711 template<
class InputIterator>
798 template<
class InputIterator>
799 VarArgArray(InputIterator first, InputIterator last);
871 template<
class Char,
class Traits,
class Var>
872 std::basic_ostream<Char,Traits>&
880 template<
class Char,
class Traits,
class View>
881 std::basic_ostream<Char,Traits>&
888 template<
class Char,
class Traits,
class T>
889 std::basic_ostream<Char,Traits>&
939 assert((i >= 0) && (i <
size()));
946 assert((i >= 0) && (i <
size()));
953 assert(
n==0 || start <
n);
960 s = (
n-start)/inc + ((
n-start) % inc == 0 ? 0 : 1);
962 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
964 for (
int i=0; i<
r.size(); i++, start+=inc)
1023 for (
int i=0; i<
n; i++)
1033 for (
int i=0; i<
n; i++)
1047 VarArray<Var>::operator
delete(
void*,size_t) {
1054 for (
int i=0; i<
x.size(); i++)
1056 for (
int i=0; i<
y.size(); i++)
1057 r[
x.size()+i] =
y[i];
1062 typename ArrayTraits<VarArray<Var>>::ArgsType
1065 for (
int i=0; i<
x.size(); i++)
1067 for (
int i=0; i<
y.size(); i++)
1068 r[
x.size()+i] =
y[i];
1073 typename ArrayTraits<VarArray<Var>>::ArgsType
1076 for (
int i=0; i<
x.size(); i++)
1078 for (
int i=0; i<
y.size(); i++)
1079 r[
x.size()+i] =
y[i];
1084 typename ArrayTraits<VarArray<Var>>::ArgsType
1087 for (
int i=0; i<
x.size(); i++)
1094 typename ArrayTraits<VarArray<Var>>::ArgsType
1098 for (
int i=0; i<
y.size(); i++)
1108 template<
class View>
1112 template<
class View>
1116 x = (n>0) ? home.
alloc<
View>(n) :
nullptr;
1118 template<
class View>
1122 x = (n>0) ?
r.alloc<
View>(n) :
nullptr;
1125 template<
class View>
1130 for (
int i=0; i<n; i++)
1136 template<
class View>
1140 x =
r.alloc<
View>(n);
1141 for (
int i=0; i<n; i++)
1148 template<
class View>
1153 template<
class View>
1160 template<
class View>
1166 template<
class View>
1172 template<
class View>
1175 assert((i >= 0) && (i <
size()));
1179 template<
class View>
1182 assert((i >= 0) && (i <
size()));
1186 template<
class View>
1192 template<
class View>
1198 template<
class View>
1204 template<
class View>
1210 template<
class View>
1216 template<
class View>
1222 template<
class View>
1228 template<
class View>
1234 template<
class View>
1237 x[i]=x[0]; x++; n--;
1240 template<
class View>
1246 template<
class View>
1253 template<
class View>
1260 template<
class View>
1264 x[i].cancel(home,p,pc);
1265 x[i]=x[0]; x++; n--;
1268 template<
class View>
1272 x[i].cancel(home,p,pc);
1276 template<
class View>
1281 for (
int j=0; j<i; j++)
1286 template<
class View>
1291 for (
int j=i+1; j<n; j++)
1296 template<
class View>
1300 x[i].cancel(home,a);
1301 x[i]=x[0]; x++; n--;
1304 template<
class View>
1308 x[i].cancel(home,a);
1312 template<
class View>
1317 for (
int j=0; j<i; j++)
1322 template<
class View>
1327 for (
int j=i+1; j<n; j++)
1332 template<
class View>
1338 for (
int i=0; i<n; i++)
1345 template<
class View>
1349 for (
int i=0; i<n; i++)
1353 template<
class View>
1356 for (
int i=0; i<n; i++)
1360 template<
class View>
1363 for (
int i=0; i<n; i++)
1367 template<
class View>
1370 for (
int i=0; i<n; i++)
1374 template<
class View>
1377 for (
int i=0; i<n; i++)
1381 template<
class View>
1384 for (
int i=0; i<n; i++)
1390 template<
class View>
1398 for (
int i=0; i<n; i++)
1404 for (
int i=1; i<j; i++)
1410 template<
class View>
1415 for (
int i=0; i<n; i++)
1421 template<
class View>
1428 for (
int i=0; i<n; i++) {
1429 o[i].
x = x[i]; o[i].
i = i;
1433 int* bkt =
r.alloc<
int>(n);
1436 for (
int i=1; i<n; i++) {
1437 if (o[i-1].x != o[i].x)
1444 for (
int i=0; i<n; i++)
1445 if (!seen.
get(bkt[i])) {
1446 x[j++]=x[i]; seen.
set(bkt[i]);
1454 template<
class View>
1460 template<
class View>
1462 ViewArray<View>::operator
delete(
void*,size_t) {
1470 template<
class ViewX,
class ViewY>
1473 if ((x.size() == 0) || (
y.size() == 0))
1476 void** px =
r.alloc<
void*>(x.size());
1478 for (
int i=0; i<x.
size(); i++)
1479 if (!x[i].
assigned() && x[i].varimp())
1480 px[j++] = x[i].varimp();
1483 void** py =
r.alloc<
void*>(
y.size());
1485 for (
int i=0; i<
y.size(); i++)
1487 py[k++] =
y[i].varimp();
1493 template<
class ViewX,
class ViewY>
1496 if (
y.assigned() || !
y.varimp())
1498 for (
int i=0; i<x.
size(); i++)
1499 if (!x[i].
assigned() && x[i].varimp() && (x[i].varimp() ==
y.varimp()))
1504 template<
class ViewX,
class ViewY>
1510 template<
class View>
1516 void** px =
r.alloc<
void*>(x.size());
1518 for (
int i=0; i<x.
size(); i++)
1519 if (!x[i].
assigned() && x[i].varimp())
1520 px[j++] = x[i].varimp();
1535 heap.alloc<T>(
static_cast<unsigned int>(
n)) : &
onstack[0];
1544 if (newCapacity <=
n+i)
1575 :
n(static_cast<int>(aa.
size())),
1577 heap.copy<T>(
a,&aa[0],
n);
1583 :
n(static_cast<int>(aa.
size())),
1586 for (
const T&
x : aa)
1620 assert((i>=0) && (i <
n));
1627 assert((i>=0) && (i <
n));
1679 template<
class T>
template<
class A>
1682 assert(
n==0 || start <
n);
1689 s = (
n-start)/inc + ((
n-start) % inc == 0 ? 0 : 1);
1691 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1692 A
r(std::min(maxN,s));
1693 for (
int i=0; i<
r.size(); i++, start+=inc)
1694 new (&
r[i]) T(
a[start]);
1698 template<
class T>
template<
class A>
1703 return static_cast<A&
>(*this);
1707 template<
class InputIterator>
1711 while (first != last) {
1718 template<
class T>
template<
class A>
1722 for (
int i=0; i<
x.size(); i++)
1723 new (&
a[
n++]) T(
x[i]);
1724 return static_cast<A&
>(*this);
1727 template<
class T>
template<
class A>
1731 for (
int i=0; i<
n; i++)
1732 new (&
r[i]) T(
a[i]);
1733 for (
int i=0; i<
x.n; i++)
1734 new (&
r[
n+i]) T(
x.a[i]);
1738 template<
class T>
template<
class A>
1742 for (
int i=0; i<
n; i++)
1743 new (&
r[i]) T(
a[i]);
1766 for (
int i=0; i<
n; i++)
1786 template<
class InputIterator>
1834 return xa.template
concat
1867 template<
class InputIterator>
1876 for (
int i=0; i<
x.size(); i++)
1923 return xa.template
concat
1930 for (
int i=0; i<
n; i++)
1944 if ((
x.size() == 0) || (
y.size() == 0))
1947 void** px =
r.alloc<
void*>(
x.size());
1949 for (
int i=0; i<
x.size(); i++)
1951 px[j++] =
x[i].varimp();
1954 void** py =
r.alloc<
void*>(
y.size());
1956 for (
int i=0; i<
y.size(); i++)
1958 py[k++] =
y[i].varimp();
1969 for (
int i=0; i<
x.size(); i++)
1970 if (
x[i].varimp() ==
y.varimp())
1987 void** px =
r.alloc<
void*>(
x.size());
1989 for (
int i=0; i<
x.size(); i++)
1991 px[j++] =
x[i].varimp();
2008 for (
int i=0; i<
n; i++)
2020 template<
class Char,
class Traits,
class Var>
2021 std::basic_ostream<Char,Traits>&
2024 std::basic_ostringstream<Char,Traits> s;
2025 s.copyfmt(os); s.width(0);
2029 for (
int i=1; i<
x.size(); i++)
2033 return os << s.str();
2036 template<
class Char,
class Traits,
class View>
2037 std::basic_ostream<Char,Traits>&
2040 std::basic_ostringstream<Char,Traits> s;
2041 s.copyfmt(os); s.width(0);
2045 for (
int i=1;
i<
x.size();
i++)
2049 return os << s.str();
2052 template<
class Char,
class Traits,
class T>
2053 std::basic_ostream<Char,Traits>&
2056 std::basic_ostringstream<Char,Traits> s;
2057 s.copyfmt(os); s.width(0);
2061 for (
int i=1;
i<
x.size();
i++)
2065 return os << s.str();
Base-class for argument arrays.
const T & const_reference
Type of a constant reference to the value type.
T * allocate(int n)
Allocate memory for n elements.
static const int onstack_size
const ArgArrayBase< T > & operator=(const ArgArrayBase< T > &a)
Initialize from view array a (copy elements)
int onstack[onstack_size]
const T * const_pointer
Type of a read-only pointer to the value type.
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
T value_type
Type of the view stored in this array.
ArgArrayBase(int n)
Allocate array with n elements.
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
const_iterator end(void) const
Return a read-only iterator past the end of the array.
void resize(int i)
Resize to hold at least i additional elements.
~ArgArrayBase(void)
Destructor.
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
ArgArrayBase(std::initializer_list< T > a)
Initialize from initializer list a.
A concat(const ArgArrayBase< T > &x) const
Return this array concatenated with x.
A concat(const T &x) const
Return this array concatenated with x.
A & append(const ArgArrayBase< T > &x)
Append x to the end of the array.
ArgArrayBase(InputIterator first, InputIterator last)
Initialize from InputIterator begin and end.
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
T * iterator
Type of the iterator used to iterate through this array's elements.
ArgArrayBase(const std::vector< T > &a)
Initialize from vector a.
A slice(int start, int inc=1, int n=-1)
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
T & operator[](int i)
Return element at position i.
T * pointer
Type of a pointer to the value type.
A & append(const T &x)
Insert a new element x at the end of the array (increase size by 1)
T & reference
Type of a reference to the value type.
iterator end(void)
Return an iterator past the end of the array.
const T * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
iterator begin(void)
Return an iterator at the beginning of the array.
ArgArrayBase(const ArgArrayBase< T > &a)
Initialize from argument array a (copy elements)
ArgArrayBase(void)
Allocate empty array.
int size(void) const
Return size of array (number of elements)
std::reverse_iterator< const T * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
Argument array for non-primitive types.
ArgArray(InputIterator first, InputIterator last)
Initialize from InputIterator first and last.
ArgArray(const ArgArray< T > &a)
Initialize from argument array a (copy elements)
ArrayTraits< ArgArray< T > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
ArgArray(int n)
Allocate array with n elements.
ArgArray(std::initializer_list< T > a)
Initialize from initializer list a.
ArgArray(int n, const T *e)
Allocate array with n elements and initialize with elements from array e.
friend ArrayTraits< ArgArray< T > >::ArgsType operator+(const ArgArray< T > &x, const ArgArray< T > &y)
Insert a new element x at the end of the array (increase size by 1)
ArgArray(const std::vector< T > &a)
Initialize from vector a.
ArgArray & operator=(const ArgArray &)=default
Assignment operator.
ArrayTraits< ArgArray< T > >::ArgsType & operator<<(const T &x)
Insert a new element x at the end of the array (increase size by 1)
Traits of arrays in Gecode.
FloatValImpType x
Implementation of float value.
Occurence information for a view.
bool operator<(const ViewOcc &y) const
Sorting order.
int i
The original index in the array.
Base-class for propagators.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
bool get(unsigned int i) const
Access value at bit i.
void set(unsigned int i)
Set bit i.
Argument array for variables.
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Test whether array x together with array y contains at least one variable being the same.
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
VarArgArray & operator=(const VarArgArray &)=default
Assignment operator.
bool assigned(void) const
Test if all variables are assigned.
ArrayTraits< VarArgArray< Var > >::ArgsType & operator<<(const Var &x)
Insert a new element x at the end of the array (increase size by 1)
friend ArrayTraits< VarArgArray< Var > >::ArgsType operator+(const VarArgArray< Var > &x, const VarArgArray< Var > &y)
Insert a new element x at the end of the array (increase size by 1)
bool same(Var x, VarArgArray< Var > y)
Test whether array y contains variable x.
bool same(VarArgArray< Var > x, Var y)
Test whether array x contains variable y.
VarArgArray(void)
Allocate empty array.
bool assigned(void) const
Test if all variables are assigned.
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
const Var & const_reference
Type of a constant reference to the value type.
const VarArray< Var > & operator=(const VarArray< Var > &a)
Initialize from variable array a (share elements)
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
VarArray(void)
Default constructor (array of size 0)
std::reverse_iterator< Var * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
const_iterator end(void) const
Return a read-only iterator past the end of the array.
int size(void) const
Return size of array (number of elements)
Var value_type
Type of the variable stored in this array.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
iterator begin(void)
Return an iterator at the beginning of the array.
const Var * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Var * pointer
Type of a pointer to the value type.
VarArray(Space &home, int m)
Allocate array with m variables.
Var & reference
Type of a reference to the value type.
std::reverse_iterator< const Var * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
Var & operator[](int i)
Return variable at position i.
VarArray(Space &home, const VarArgArray< Var > &)
Initialize from variable argument array a (copy elements)
iterator end(void)
Return an iterator past the end of the array.
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
const Var * const_pointer
Type of a read-only pointer to the value type.
Var * iterator
Type of the iterator used to iterate through this array's elements.
VarArray(const VarArray< Var > &a)
Initialize from variable array a (share elements)
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Base class for variables.
void cancel(Space &home, Advisor &a)
Cancel subscription of advisor a.
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
bool same(const View &y) const
Test whether array contains a view being the same as y.
void drop_fst(int i, Space &home, Propagator &p, PropCond pc)
Drop views from positions 0 to i-1 from array.
const View & const_reference
Type of a constant reference to the value type.
void move_fst(int i, Space &home, Propagator &p, PropCond pc)
Move view from position 0 to position i (shift elements to the left)
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Test whether array x together with array y contains shared views.
View * iterator
Type of the iterator used to iterate through this array's elements.
void subscribe(Space &home, Advisor &a)
Subscribe advisor a to variable.
View & reference
Type of a reference to the value type.
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
View value_type
Type of the view stored in this array.
View & operator[](int i)
Return view at position i.
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
const View * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
void drop_lst(int i, Space &home, Propagator &p, PropCond pc)
Drop assigned views from positions i+1 to size()-1 from array.
ViewArray(Space &home, const ViewArray< View > &a)
Initialize from view array a (copy elements)
void drop_fst(int i)
Drop views from positions 0 to i-1 from array.
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
bool shared(ViewArray< ViewX > x, ViewY y)
Test whether array x contains a view shared with y.
void drop_fst(int i, Space &home, Advisor &a)
Drop views from positions 0 to i-1 from array.
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
void move_fst(int i, Space &home, Advisor &a)
Move view from position 0 to position i (shift elements to the left)
void move_lst(int i, Space &home, Advisor &a)
Move view from position size()-1 to position i (truncate array by one)
ViewArray(const ViewArray< View > &a)
Initialize from view array a (share elements)
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
const ViewArray< View > & operator=(const ViewArray< View > &a)
Initialize from view array a (share elements)
const View * const_pointer
Type of a read-only pointer to the value type.
iterator begin(void)
Return an iterator at the beginning of the array.
std::reverse_iterator< const View * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
ViewArray(Region &r, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
void unique(void)
Remove all duplicate views from array (changes element order)
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
void drop_lst(int i)
Drop views from positions i+1 to size()-1 from array.
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
void drop_lst(int i, Space &home, Advisor &a)
Drop assigned views from positions i+1 to size()-1 from array.
void move_lst(int i)
Move view from position size()-1 to position i (truncate array by one)
const_iterator end(void) const
Return a read-only iterator past the end of the array.
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
bool assigned(void) const
Test if all variables are assigned.
ViewArray(void)
Default constructor (array of size 0)
void move_lst(int i, Space &home, Propagator &p, PropCond pc)
Move view from position size()-1 to position i (truncate array by one)
iterator end(void)
Return an iterator past the end of the array.
ViewArray(Region &r, const ViewArray< View > &a)
Initialize from view array a (copy elements)
bool same(void) const
Test whether array has multiple occurence of the same view.
ViewArray(Region &r, int m)
Allocate array with m views.
ViewArray(Space &home, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
ViewArray(Space &home, int m)
Allocate array with m views.
void move_fst(int i)
Move view from position 0 to position i (shift elements to the left)
bool shared(ViewX x, ViewArray< ViewY > y)
Test whether array y contains a view shared with x.
View * pointer
Type of a pointer to the value type.
bool shared(ViewArray< View > x)
Test whether array x contains shared views.
void size(int n)
Decrease size of array (number of elements)
Heap heap
The single global heap.
void update(const NoOffset &)
Integer-precision integer scale view.
#define GECODE_KERNEL_EXPORT
bool duplicates(void **p, int n)
Check whether p has duplicates among its n elements (changes p)
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Gecode toplevel namespace
FloatVal operator+(const FloatVal &x)
Post propagator for SetVar SetOpType SetVar SetRelType r
Archive & operator<<(Archive &e, FloatNumBranch nl)
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Post propagator for SetVar SetOpType SetVar y
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
int PropCond
Type for propagation conditions.
Post propagator for SetVar x
Gecode::IntArgs i({1, 2, 3, 4})