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>
795 template<
class InputIterator>
796 VarArgArray(InputIterator first, InputIterator last);
865 template<
class Char,
class Traits,
class Var>
866 std::basic_ostream<Char,Traits>&
874 template<
class Char,
class Traits,
class View>
875 std::basic_ostream<Char,Traits>&
882 template<
class Char,
class Traits,
class T>
883 std::basic_ostream<Char,Traits>&
933 assert((i >= 0) && (i <
size()));
940 assert((i >= 0) && (i <
size()));
947 assert(
n==0 || start <
n);
954 s = (
n-start)/inc + ((
n-start) % inc == 0 ? 0 : 1);
956 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
958 for (
int i=0; i<r.size(); i++, start+=inc)
1017 for (
int i=0; i<
n; i++)
1027 for (
int i=0; i<
n; i++)
1041 VarArray<Var>::operator
delete(
void*,size_t) {
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(bkt[i])) {
1440 x[j++]=x[i]; seen.
set(bkt[i]);
1448 template<
class View>
1454 template<
class View>
1456 ViewArray<View>::operator
delete(
void*,size_t) {
1464 template<
class ViewX,
class ViewY>
1467 if ((x.size() == 0) || (y.
size() == 0))
1470 void** px = r.alloc<
void*>(x.size());
1472 for (
int i=0; i<x.
size(); i++)
1473 if (!x[i].
assigned() && x[i].varimp())
1474 px[j++] = x[i].varimp();
1477 void** py = r.alloc<
void*>(y.
size());
1479 for (
int i=0; i<y.
size(); i++)
1480 if (!y[i].
assigned() && y[i].varimp())
1481 py[k++] = y[i].varimp();
1487 template<
class ViewX,
class ViewY>
1490 if (y.assigned() || !y.varimp())
1492 for (
int i=0; i<x.
size(); i++)
1493 if (!x[i].
assigned() && x[i].varimp() && (x[i].varimp() == y.varimp()))
1498 template<
class ViewX,
class ViewY>
1504 template<
class View>
1510 void** px = r.alloc<
void*>(x.size());
1512 for (
int i=0; i<x.
size(); i++)
1513 if (!x[i].
assigned() && x[i].varimp())
1514 px[j++] = x[i].varimp();
1529 heap.alloc<T>(
static_cast<unsigned int>(
n)) : &
onstack[0];
1538 if (newCapacity <=
n+i)
1569 :
n(static_cast<int>(aa.
size())),
1571 heap.copy<T>(
a,&aa[0],
n);
1577 :
n(static_cast<int>(aa.
size())),
1580 for (
const T& x : aa)
1614 assert((i>=0) && (i <
n));
1621 assert((i>=0) && (i <
n));
1673 template<
class T>
template<
class A>
1676 assert(
n==0 || start <
n);
1683 s = (
n-start)/inc + ((
n-start) % inc == 0 ? 0 : 1);
1685 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1686 A r(std::min(maxN,s));
1687 for (
int i=0; i<r.size(); i++, start+=inc)
1688 new (&r[i]) T(
a[start]);
1692 template<
class T>
template<
class A>
1697 return static_cast<A&
>(*this);
1701 template<
class InputIterator>
1705 while (first != last) {
1712 template<
class T>
template<
class A>
1716 for (
int i=0; i<x.
size(); i++)
1717 new (&
a[
n++]) T(x[i]);
1718 return static_cast<A&
>(*this);
1721 template<
class T>
template<
class A>
1725 for (
int i=0; i<
n; i++)
1726 new (&r[i]) T(
a[i]);
1727 for (
int i=0; i<x.
n; i++)
1728 new (&r[
n+i]) T(x.
a[i]);
1732 template<
class T>
template<
class A>
1736 for (
int i=0; i<
n; i++)
1737 new (&r[i]) T(
a[i]);
1760 for (
int i=0; i<
n; i++)
1780 template<
class InputIterator>
1828 return xa.template
concat
1861 template<
class InputIterator>
1870 for (
int i=0; i<x.
size(); i++)
1917 return xa.template
concat
1924 for (
int i=0; i<
n; i++)
1938 if ((x.
size() == 0) || (y.
size() == 0))
1941 void** px = r.alloc<
void*>(x.
size());
1943 for (
int i=0; i<x.
size(); i++)
1945 px[j++] = x[i].varimp();
1948 void** py = r.alloc<
void*>(y.
size());
1950 for (
int i=0; i<y.
size(); i++)
1952 py[k++] = y[i].varimp();
1963 for (
int i=0; i<x.
size(); i++)
1964 if (x[i].varimp() == y.varimp())
1981 void** px = r.alloc<
void*>(x.
size());
1983 for (
int i=0; i<x.
size(); i++)
1985 px[j++] = x[i].varimp();
2002 for (
int i=0; i<
n; i++)
2014 template<
class Char,
class Traits,
class Var>
2015 std::basic_ostream<Char,Traits>&
2018 std::basic_ostringstream<Char,Traits> s;
2019 s.copyfmt(os); s.width(0);
2023 for (
int i=1; i<x.
size(); i++)
2027 return os << s.str();
2030 template<
class Char,
class Traits,
class View>
2031 std::basic_ostream<Char,Traits>&
2034 std::basic_ostringstream<Char,Traits> s;
2035 s.copyfmt(os); s.width(0);
2039 for (
int i=1;
i<x.
size();
i++)
2043 return os << s.str();
2046 template<
class Char,
class Traits,
class T>
2047 std::basic_ostream<Char,Traits>&
2050 std::basic_ostringstream<Char,Traits> s;
2051 s.copyfmt(os); s.width(0);
2055 for (
int i=1;
i<x.
size();
i++)
2059 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.
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 , .
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)
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})