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;
207 static void*
operator new(
size_t s) =
delete;
209 static void operator delete(
void* p) =
delete;
312 for (
int i=0; i<n; i++)
329 x = r.alloc<
View>(n);
330 for (
int i=0; i<n; i++)
489 static void*
operator new(
size_t s) =
delete;
491 static void operator delete(
void* p) =
delete;
501 template<
class ViewX,
class ViewY>
509 template<
class ViewX,
class ViewY>
517 template<
class ViewX,
class ViewY>
614 template<
class InputIterator>
715 template<
class InputIterator>
802 template<
class InputIterator>
803 VarArgArray(InputIterator first, InputIterator last);
875 template<
class Char,
class Traits,
class Var>
876 std::basic_ostream<Char,Traits>&
884 template<
class Char,
class Traits,
class View>
885 std::basic_ostream<Char,Traits>&
892 template<
class Char,
class Traits,
class T>
893 std::basic_ostream<Char,Traits>&
943 assert((i >= 0) && (i <
size()));
950 assert((i >= 0) && (i <
size()));
957 assert(
n==0 || start <
n);
964 s = (
n-start)/inc + ((
n-start) % inc == 0 ? 0 : 1);
966 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
968 for (
int i=0; i<r.size(); i++, start+=inc)
1027 for (
int i=0; i<
n; i++)
1037 for (
int i=0; i<
n; i++)
1048 for (
int i=0; i<x.
size(); i++)
1050 for (
int i=0; i<y.
size(); i++)
1051 r[x.
size()+i] = y[i];
1056 typename ArrayTraits<VarArray<Var>>::ArgsType
1059 for (
int i=0; i<x.
size(); i++)
1061 for (
int i=0; i<y.
size(); i++)
1062 r[x.
size()+i] = y[i];
1067 typename ArrayTraits<VarArray<Var>>::ArgsType
1070 for (
int i=0; i<x.
size(); i++)
1072 for (
int i=0; i<y.
size(); i++)
1073 r[x.
size()+i] = y[i];
1078 typename ArrayTraits<VarArray<Var>>::ArgsType
1081 for (
int i=0; i<x.
size(); i++)
1088 typename ArrayTraits<VarArray<Var>>::ArgsType
1092 for (
int i=0; i<y.
size(); i++)
1102 template<
class View>
1106 template<
class View>
1110 x = (n>0) ? home.
alloc<
View>(n) :
nullptr;
1112 template<
class View>
1116 x = (n>0) ? r.alloc<
View>(n) :
nullptr;
1119 template<
class View>
1124 for (
int i=0; i<n; i++)
1130 template<
class View>
1134 x = r.alloc<
View>(n);
1135 for (
int i=0; i<n; i++)
1142 template<
class View>
1147 template<
class View>
1154 template<
class View>
1160 template<
class View>
1166 template<
class View>
1169 assert((i >= 0) && (i <
size()));
1173 template<
class View>
1176 assert((i >= 0) && (i <
size()));
1180 template<
class View>
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>
1231 x[i]=x[0]; x++; n--;
1234 template<
class View>
1240 template<
class View>
1247 template<
class View>
1254 template<
class View>
1258 x[i].cancel(home,p,pc);
1259 x[i]=x[0]; x++; n--;
1262 template<
class View>
1266 x[i].cancel(home,p,pc);
1270 template<
class View>
1275 for (
int j=0; j<i; j++)
1280 template<
class View>
1285 for (
int j=i+1; j<n; j++)
1290 template<
class View>
1294 x[i].cancel(home,a);
1295 x[i]=x[0]; x++; n--;
1298 template<
class View>
1302 x[i].cancel(home,a);
1306 template<
class View>
1311 for (
int j=0; j<i; j++)
1316 template<
class View>
1321 for (
int j=i+1; j<n; j++)
1326 template<
class View>
1332 for (
int i=0; i<n; i++)
1333 x[i].
update(home, y.x[i]);
1339 template<
class View>
1343 for (
int i=0; i<n; i++)
1347 template<
class View>
1350 for (
int i=0; i<n; i++)
1354 template<
class View>
1357 for (
int i=0; i<n; i++)
1361 template<
class View>
1364 for (
int i=0; i<n; i++)
1368 template<
class View>
1371 for (
int i=0; i<n; i++)
1375 template<
class View>
1378 for (
int i=0; i<n; i++)
1384 template<
class View>
1392 for (
int i=0; i<n; i++)
1398 for (
int i=1; i<j; i++)
1404 template<
class View>
1409 for (
int i=0; i<n; i++)
1415 template<
class View>
1422 for (
int i=0; i<n; i++) {
1423 o[i].
x = x[i]; o[i].
i = i;
1427 int* bkt = r.alloc<
int>(n);
1430 for (
int i=1; i<n; i++) {
1431 if (o[i-1].x != o[i].x)
1438 for (
int i=0; i<n; i++)
1439 if (!seen.
get(
static_cast<unsigned int>(bkt[i]))) {
1440 x[j++]=x[i]; seen.
set(
static_cast<unsigned int>(bkt[i]));
1453 template<
class ViewX,
class ViewY>
1456 if ((x.size() == 0) || (y.
size() == 0))
1459 void** px = r.alloc<
void*>(x.size());
1461 for (
int i=0; i<x.
size(); i++)
1462 if (!x[i].
assigned() && x[i].varimp())
1463 px[j++] = x[i].varimp();
1466 void** py = r.alloc<
void*>(y.
size());
1468 for (
int i=0; i<y.
size(); i++)
1469 if (!y[i].
assigned() && y[i].varimp())
1470 py[k++] = y[i].varimp();
1476 template<
class ViewX,
class ViewY>
1479 if (y.assigned() || !y.varimp())
1481 for (
int i=0; i<x.
size(); i++)
1482 if (!x[i].
assigned() && x[i].varimp() && (x[i].varimp() == y.varimp()))
1487 template<
class ViewX,
class ViewY>
1493 template<
class View>
1499 void** px = r.alloc<
void*>(x.size());
1501 for (
int i=0; i<x.
size(); i++)
1502 if (!x[i].
assigned() && x[i].varimp())
1503 px[j++] = x[i].varimp();
1518 heap.alloc<T>(
static_cast<unsigned int>(
n)) : &
onstack[0];
1527 if (newCapacity <=
n+i)
1558 :
n(static_cast<int>(aa.
size())),
1561 heap.copy<T>(
a,aa.data(),
n);
1567 :
n(static_cast<int>(aa.
size())),
1570 for (
const T& x : aa)
1604 assert((i>=0) && (i <
n));
1611 assert((i>=0) && (i <
n));
1663 template<
class T>
template<
class A>
1666 assert(
n==0 || start <
n);
1673 s = (
n-start)/inc + ((
n-start) % inc == 0 ? 0 : 1);
1675 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1676 A r(std::min(maxN,s));
1677 for (
int i=0; i<r.size(); i++, start+=inc)
1678 new (&r[i]) T(
a[start]);
1682 template<
class T>
template<
class A>
1687 return static_cast<A&
>(*this);
1691 template<
class InputIterator>
1695 while (first != last) {
1702 template<
class T>
template<
class A>
1706 for (
int i=0; i<x.
size(); i++)
1707 new (&
a[
n++]) T(x[i]);
1708 return static_cast<A&
>(*this);
1711 template<
class T>
template<
class A>
1715 for (
int i=0; i<
n; i++)
1716 new (&r[i]) T(
a[i]);
1717 for (
int i=0; i<x.
n; i++)
1718 new (&r[
n+i]) T(x.
a[i]);
1722 template<
class T>
template<
class A>
1726 for (
int i=0; i<
n; i++)
1727 new (&r[i]) T(
a[i]);
1750 for (
int i=0; i<
n; i++)
1770 template<
class InputIterator>
1818 return xa.template
concat
1851 template<
class InputIterator>
1860 for (
int i=0; i<x.
size(); i++)
1907 return xa.template
concat
1914 for (
int i=0; i<
n; i++)
1928 if ((x.
size() == 0) || (y.
size() == 0))
1931 void** px = r.alloc<
void*>(x.
size());
1933 for (
int i=0; i<x.
size(); i++)
1935 px[j++] = x[i].varimp();
1938 void** py = r.alloc<
void*>(y.
size());
1940 for (
int i=0; i<y.
size(); i++)
1942 py[k++] = y[i].varimp();
1953 for (
int i=0; i<x.
size(); i++)
1954 if (x[i].varimp() == y.varimp())
1971 void** px = r.alloc<
void*>(x.
size());
1973 for (
int i=0; i<x.
size(); i++)
1975 px[j++] = x[i].varimp();
1992 for (
int i=0; i<
n; i++)
2004 template<
class Char,
class Traits,
class Var>
2005 std::basic_ostream<Char,Traits>&
2008 std::basic_ostringstream<Char,Traits> s;
2009 s.copyfmt(os); s.width(0);
2013 for (
int i=1; i<x.
size(); i++)
2017 return os << s.str();
2020 template<
class Char,
class Traits,
class View>
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 T>
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();
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.
Occurrence 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 occurrence 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.
#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)
Archive & operator<<(Archive &e, FloatNumBranch nl)
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
int PropCond
Type for propagation conditions.
Gecode::IntArgs i({1, 2, 3, 4})