Go to the documentation of this file.
44 #include <initializer_list>
46 namespace Gecode {
namespace Kernel {
158 int size(
void)
const;
174 slice(
int start,
int inc=1,
int n=-1);
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++)
338 int size(
void)
const;
475 bool same(
void)
const;
481 bool same(
const View&
y)
const;
486 static void*
operator new(size_t)
throw();
487 static void operator delete(
void*,size_t);
497 template<
class ViewX,
class ViewY>
498 bool shared(ViewArray<ViewX>
x, ViewArray<ViewY>
y);
505 template<
class ViewX,
class ViewY>
506 bool shared(ViewArray<ViewX>
x, ViewY
y);
513 template<
class ViewX,
class ViewY>
514 bool shared(ViewX
x, ViewArray<ViewY>
y);
522 bool shared(ViewArray<View>
x);
571 A
slice(
int start,
int inc=1,
int n=-1);
610 template<
class InputIterator>
616 int size(
void)
const;
711 template<
class InputIterator>
712 ArgArray(InputIterator first, InputIterator last);
718 slice(
int start,
int inc=1,
int n=-1);
795 template<
class InputIterator>
796 VarArgArray(InputIterator first, InputIterator last);
802 slice(
int start,
int inc=1,
int n=-1);
834 bool same(VarArgArray<Var>
x, VarArgArray<Var>
y);
842 bool same(VarArgArray<Var>
x, Var
y);
850 bool same(Var
x, VarArgArray<Var>
y);
858 bool same(VarArgArray<Var>
x);
865 template<
class Char,
class Traits,
class Var>
866 std::basic_ostream<Char,Traits>&
868 const VarArray<Var>&
x);
874 template<
class Char,
class Traits,
class View>
875 std::basic_ostream<Char,Traits>&
876 operator <<(std::basic_ostream<Char,Traits>& os,
const ViewArray<View>&
x);
882 template<
class Char,
class Traits,
class T>
883 std::basic_ostream<Char,Traits>&
884 operator <<(std::basic_ostream<Char,Traits>& os,
const ArgArrayBase<T>&
x);
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) {
1045 typename ArrayTraits<VarArray<Var>>::ArgsType
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++)
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>
1390 View*
y =
r.alloc<View>(
n);
1392 for (
int i=0;
i<
n;
i++)
1397 Support::quicksort<View>(
y,j);
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++) {
1425 Support::quicksort<Kernel::ViewOcc<View>>(o,
n);
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++)
1474 px[j++] =
x[
i].varimp();
1477 void** py =
r.alloc<
void*>(
y.size());
1479 for (
int i=0;
i<
y.size();
i++)
1481 py[k++] =
y[
i].varimp();
1487 template<
class ViewX,
class ViewY>
1492 for (
int i=0;
i<
x.size();
i++)
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++)
1514 px[j++] =
x[
i].varimp();
1528 return (
n > onstack_size) ?
1529 heap.
alloc<T>(
static_cast<unsigned int>(
n)) : &onstack[0];
1536 assert(
n+
i >= onstack_size);
1538 if (newCapacity <=
n+
i)
1540 T* newA = allocate(newCapacity);
1552 :
n(0),
capacity(onstack_size),
a(allocate(0)) {}
1557 :
n(n0),
capacity(
n < onstack_size ? onstack_size :
n),
a(allocate(
n)) {}
1562 :
n(aa.
n),
capacity(
n < onstack_size ? onstack_size :
n),
a(allocate(
n)) {
1569 :
n(static_cast<int>(aa.
size())),
1570 capacity(
n < onstack_size ? onstack_size :
n),
a(allocate(
n)) {
1577 :
n(static_cast<int>(aa.
size())),
1578 capacity(
n < onstack_size ? onstack_size :
n),
a(allocate(
n)) {
1580 for (
const T&
x : aa)
1598 capacity = (
n < onstack_size ? onstack_size :
n);
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);
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>
1704 :
n(0),
capacity(onstack_size),
a(allocate(0)) {
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>
1812 return x.template concat
1817 typename ArrayTraits<ArgArray<T>>::ArgsType
1819 return x.template concat
1824 typename ArrayTraits<ArgArray<T>>::ArgsType
1828 return xa.template concat
1861 template<
class InputIterator>
1870 for (
int i=0;
i<
x.size();
i++)
1901 return x.template concat
1906 typename ArrayTraits<VarArgArray<Var>>::ArgsType
1908 return x.template concat
1913 typename ArrayTraits<VarArgArray<Var>>::ArgsType
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++)
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();
iterator end(void)
Return an iterator past the end of the array.
T * pointer
Type of a pointer to the value type.
Var & operator[](int i)
Return variable at position i.
Post propagator for SetVar x
bool same(VarArgArray< Var > x)
static T * copy(T *d, const T *s, long unsigned int n)
Copy n objects starting at s to d.
~ArgArrayBase(void)
Destructor.
Post propagator for SetVar SetOpType SetVar y
const typedef View * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
void set(unsigned int i)
Set bit i.
void unique(void)
Remove all duplicate views from array (changes element order)
void resize(int i)
Resize to hold at least i additional elements.
Var * pointer
Type of a pointer to the value type.
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
const typedef Var * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
iterator end(void)
Return an iterator past the end of the array.
const VarArray< Var > & operator=(const VarArray< Var > &a)
Initialize from variable array a (share elements)
unsigned int size(I &i)
Size of all ranges of range iterator i.
ArgArray(void)
Allocate empty array.
void update(const NoOffset &)
Integer-precision integer scale view.
const typedef T * const_pointer
Type of a read-only pointer to the value type.
bool assigned(View x, int v)
Whether x is assigned to value v.
T value_type
Type of the view stored in this array.
bool assigned(void) const
Test if all variables are assigned.
const typedef Var * const_pointer
Type of a read-only pointer to the value type.
const FloatNum min
Smallest allowed float value.
Var value_type
Type of the variable stored in this array.
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
bool duplicates(void **p, int n)
Check whether p has duplicates among its n elements (changes p)
iterator end(void)
Return an iterator past the end of the array.
iterator begin(void)
Return an iterator at the beginning of the array.
ArrayTraits< ArgArray< T > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
FloatVal operator+(const FloatVal &x)
Var * x
Array of variables.
bool assigned(void) const
Test whether view is assigned.
static const int onstack_size
How many elements are possible inside array.
const typedef View & const_reference
Type of a constant reference to the value type.
View * pointer
Type of a pointer to the value type.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
T * allocate(int n)
Allocate memory for n elements.
int size(void) const
Return size of array (number of elements)
void move_fst(int i)
Move view from position 0 to position i (shift elements to the left)
bool assigned(void) const
Test if all variables are assigned.
View & reference
Type of a reference to the value type.
Var * iterator
Type of the iterator used to iterate through this array's elements.
Base class for variables.
Gecode toplevel namespace
int capacity
Allocated size of the array.
Base-class for propagators.
VarImp * x
Pointer to variable implementation.
Var & reference
Type of a reference to the value type.
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const ArgArrayBase< T > &x)
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const FloatView &x)
Print float variable view.
bool operator<(const ViewOcc &y) const
Sorting order.
int n
Number of variables (size)
void update(IntSet &y, Space &home, IntSet &py)
Node * x
Pointer to corresponding Boolean expression node.
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
void reschedule(Space &home, Propagator &p, IntSet &y)
Argument array for non-primitive types.
VarImp * varimp(void) const
Return variable implementation of variable.
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Test whether array x together with array y contains at least one variable being the same.
A & append(const T &x)
Insert a new element x at the end of the array (increase size by 1)
View * iterator
Type of the iterator used to iterate through this array's elements.
T & operator[](int i)
Return element at position i.
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
const typedef T & const_reference
Type of a constant reference to the value type.
Post propagator for SetVar SetOpType SetVar SetRelType r
Boolean integer variables.
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
FloatVal operator+(const FloatVal &x)
Arithmetic operator.
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
const ArgArrayBase< T > & operator=(const ArgArrayBase< T > &a)
Initialize from view array a (copy elements)
std::reverse_iterator< const Var * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
std::reverse_iterator< const View * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
const typedef T * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
const int capacity[n_warehouses]
Capacity of a single warehouse.
void move_lst(int i)
Move view from position size()-1 to position i (truncate array by one)
Base-class for argument arrays.
bool assigned(void) const
Test if all variables are assigned.
#define GECODE_KERNEL_EXPORT
A concat(const ArgArrayBase< T > &x) const
Return this array concatenated with x.
const ViewArray< View > & operator=(const ViewArray< View > &a)
Initialize from view array a (share elements)
void drop_fst(int i)
Drop views from positions 0 to i-1 from array.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Heap heap
The single global heap.
A slice(int start, int inc=1, int n=-1)
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
ViewArray(void)
Default constructor (array of size 0)
VarArgArray(void)
Allocate empty array.
int PropCond
Type for propagation conditions.
VarArray(void)
Default constructor (array of size 0)
const typedef Var & const_reference
Type of a constant reference to the value type.
bool get(unsigned int i) const
Access value at bit i.
T * iterator
Type of the iterator used to iterate through this array's elements.
void cancel(Space &home, Propagator &p, IntSet &y)
void drop_lst(int i)
Drop views from positions i+1 to size()-1 from array.
int size(void) const
Return size of array (number of elements)
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Test whether array x together with array y contains shared views.
ViewArray(Space &home, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
void free(T *b, long unsigned int n)
Delete n objects starting at b.
std::reverse_iterator< Var * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
int size(void) const
Return size of array (number of elements)
Traits of arrays in Gecode.
iterator begin(void)
Return an iterator at the beginning of the array.
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
std::reverse_iterator< const T * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
ArrayTraits< VarArgArray< Var > >::ArgsType & operator<<(const Var &x)
Insert a new element x at the end of the array (increase size by 1)
ViewArray(Region &r, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
Occurence information for a view.
View value_type
Type of the view stored in this array.
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
const unsigned int slice
Size of a slice in a portfolio and scale factor for restarts(in number of failures)
void subscribe(Space &home, Propagator &p, IntSet &y)
int n
Number of negative literals for node type.
ArrayTraits< ArgArray< T > >::ArgsType & operator<<(const T &x)
Insert a new element x at the end of the array (increase size by 1)
T onstack[onstack_size]
In-array storage for elements.
Argument array for variables.
T & 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.
Gecode::IntArgs i({1, 2, 3, 4})
int p
Number of positive literals for node type.
View & operator[](int i)
Return view at position i.
ArgArrayBase(void)
Allocate empty array.
int i
The original index in the array.
Archive & operator<<(Archive &e, FloatNumBranch nl)
iterator begin(void)
Return an iterator at the beginning of the array.
bool same(void) const
Test whether array has multiple occurence of the same view.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
const typedef View * const_pointer
Type of a read-only pointer to the value type.