Generated on for Gecode by doxygen 1.17.0
array.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 * Guido Tack <tack@gecode.dev>
6 *
7 * Contributing authors:
8 * Gregory Crosswhite <gcross@phys.washington.edu>
9 *
10 * Copyright:
11 * Gregory Crosswhite, 2011
12 * Christian Schulte, 2003
13 * Guido Tack, 2004
14 *
15 * This file is part of Gecode, the generic constraint
16 * development environment:
17 * http://www.gecode.dev
18 *
19 * Permission is hereby granted, free of charge, to any person obtaining
20 * a copy of this software and associated documentation files (the
21 * "Software"), to deal in the Software without restriction, including
22 * without limitation the rights to use, copy, modify, merge, publish,
23 * distribute, sublicense, and/or sell copies of the Software, and to
24 * permit persons to whom the Software is furnished to do so, subject to
25 * the following conditions:
26 *
27 * The above copyright notice and this permission notice shall be
28 * included in all copies or substantial portions of the Software.
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 *
38 */
39
40#include <iostream>
41#include <iterator>
42#include <vector>
43#include <sstream>
44#include <initializer_list>
45
46namespace Gecode { namespace Kernel {
47
49 template<class View>
50 class ViewOcc {
51 public:
55 int i;
57 bool operator <(const ViewOcc& y) const;
58 };
59
60 template<class View>
61 forceinline bool
62 ViewOcc<View>::operator <(const ViewOcc& y) const {
63 return x < y.x;
64 }
65
68 bool duplicates(void** p, int n);
69
72 bool duplicates(void** p, int n, void** q, int m);
73
74}}
75
76namespace Gecode {
77
78 template<class Var> class VarArray;
79 template<class Var> class VarArgArray;
80
93 template<class A>
94 class ArrayTraits {};
95
111 template<class Var>
112 class VarArray {
113 protected:
115 int n;
118 public:
120
121
124 typedef Var& reference;
126 typedef const Var& const_reference;
128 typedef Var* pointer;
130 typedef const Var* const_pointer;
132 typedef Var* iterator;
134 typedef const Var* const_iterator;
136 typedef std::reverse_iterator<Var*> reverse_iterator;
138 typedef std::reverse_iterator<const Var*> const_reverse_iterator;
140
142
144
145 VarArray(void);
147 VarArray(Space& home, int m);
149 VarArray(Space& home, const VarArgArray<Var>&);
151 VarArray(const VarArray<Var>& a);
155
157
158
159 int size(void) const;
161
163
164
167 const Var& operator [](int i) const;
174 slice(int start, int inc=1, int n=-1);
176
178
179
182 const_iterator begin(void) const;
186 const_iterator end(void) const;
190 const_reverse_iterator rbegin(void) const;
194 const_reverse_iterator rend(void) const;
196
198 bool assigned(void) const;
199
201
202
203 void update(Space& home, VarArray<Var>& a);
205
207 static void* operator new(size_t s) = delete;
209 static void operator delete(void* p) = delete;
210 };
211
215 template<class T>
218
222 template<class T>
225
229 template<class T>
232
236 template<class T>
238 operator +(const VarArray<T>& x, const T& y);
239
243 template<class T>
245 operator +(const T& x, const VarArray<T>& y);
246
254 template<class View>
255 class ViewArray {
256 private:
258 int n;
260 View* x;
261 public:
263
264
267 typedef View& reference;
269 typedef const View& const_reference;
271 typedef View* pointer;
273 typedef const View* const_pointer;
275 typedef View* iterator;
277 typedef const View* const_iterator;
279 typedef std::reverse_iterator<View*> reverse_iterator;
281 typedef std::reverse_iterator<const View*> const_reverse_iterator;
283
285
286
289 ViewArray(Space& home, int m);
291 ViewArray(Region& r, int m);
293 ViewArray(const ViewArray<View>& a);
295 ViewArray(Space& home, const ViewArray<View>& a);
297 ViewArray(Region& r, const ViewArray<View>& a);
306 template<class Var>
308 : n(a.size()) {
309 // This may not be in the hpp file (to satisfy the MS compiler)
310 if (n>0) {
311 x = home.alloc<View>(n);
312 for (int i=0; i<n; i++)
313 x[i]=a[i];
314 } else {
315 x = nullptr;
316 }
317 }
318
324 template<class Var>
326 : n(a.size()) {
327 // This may not be in the hpp file (to satisfy the MS compiler)
328 if (n>0) {
329 x = r.alloc<View>(n);
330 for (int i=0; i<n; i++)
331 x[i]=a[i];
332 } else {
333 x = nullptr;
334 }
335 }
336
337
339
340
341 int size(void) const;
343 void size(int n);
345
347
348
351 const View& operator [](int i) const;
353
355
356
359 const_iterator begin(void) const;
363 const_iterator end(void) const;
367 const_reverse_iterator rbegin(void) const;
371 const_reverse_iterator rend(void) const;
373
375
376
383 void subscribe(Space& home, Propagator& p, PropCond pc,
384 bool schedule=true);
386 void cancel(Space& home, Propagator& p, PropCond pc);
388 void subscribe(Space& home, Advisor& a);
390 void cancel(Space& home, Advisor& a);
392 void reschedule(Space& home, Propagator& p, PropCond pc);
394
396
397
398 void update(Space& home, ViewArray<View>& a);
400
401
403
404
405 void move_fst(int i);
407 void move_lst(int i);
413 void move_fst(int i, Space& home, Propagator& p, PropCond pc);
419 void move_lst(int i, Space& home, Propagator& p, PropCond pc);
425 void move_fst(int i, Space& home, Advisor& a);
431 void move_lst(int i, Space& home, Advisor& a);
433
435
436
437 void drop_fst(int i);
439 void drop_lst(int i);
445 void drop_fst(int i, Space& home, Propagator& p, PropCond pc);
452 void drop_lst(int i, Space& home, Propagator& p, PropCond pc);
458 void drop_fst(int i, Space& home, Advisor& a);
464 void drop_lst(int i, Space& home, Advisor& a);
466
468 bool assigned(void) const;
469
471
472
477 bool same(void) const;
483 bool same(const View& y) const;
485 void unique(void);
487
489 static void* operator new(size_t s) = delete;
491 static void operator delete(void* p) = delete;
492 };
493
494
501 template<class ViewX, class ViewY>
509 template<class ViewX, class ViewY>
510 bool shared(ViewArray<ViewX> x, ViewY y);
517 template<class ViewX, class ViewY>
518 bool shared(ViewX x, ViewArray<ViewY> y);
525 template<class View>
527
528
540 template<class T>
542 protected:
544 int n;
548 T* a;
550 static const int onstack_size = 16;
554 T* allocate(int n);
556 void resize(int i);
558 template<class A>
559 A concat(const ArgArrayBase<T>& x) const;
561 template<class A>
562 A concat(const T& x) const;
564 template<class A>
565 A& append(const T& x);
567 template<class A>
568 A& append(const ArgArrayBase<T>& x);
574 template<class A>
575 A slice(int start, int inc=1, int n=-1);
576 public:
578
579
580 typedef T value_type;
582 typedef T& reference;
584 typedef const T& const_reference;
586 typedef T* pointer;
588 typedef const T* const_pointer;
590 typedef T* iterator;
592 typedef const T* const_iterator;
594 typedef std::reverse_iterator<T*> reverse_iterator;
596 typedef std::reverse_iterator<const T*> const_reverse_iterator;
598
600
601
604 explicit ArgArrayBase(int n);
610 ArgArrayBase(const std::vector<T>& a);
612 ArgArrayBase(std::initializer_list<T> a);
614 template<class InputIterator>
615 ArgArrayBase(InputIterator first, InputIterator last);
617
619
620
621 int size(void) const;
623
625
626
627 T& operator [](int i);
629 const T& operator [](int i) const;
631
633
634
637 const_iterator begin(void) const;
641 const_iterator end(void) const;
645 const_reverse_iterator rbegin(void) const;
649 const_reverse_iterator rend(void) const;
651
653
654
657 };
658
659
660 template<class> class ArgArray;
661
665 template<class T>
667 operator +(const ArgArray<T>& x, const ArgArray<T>& y);
668
672 template<class T>
674 operator +(const ArgArray<T>& x, const T& y);
675
679 template<class T>
681 operator +(const T& x, const ArgArray<T>& y);
682
694 template<class T>
695 class ArgArray : public ArgArrayBase<T> {
696 protected:
697 using ArgArrayBase<T>::a;
698 public:
699 using ArgArrayBase<T>::size;
701
702
703 ArgArray(void);
705 explicit ArgArray(int n);
707 ArgArray(int n, const T* e);
711 ArgArray(const std::vector<T>& a);
713 ArgArray(std::initializer_list<T> a);
715 template<class InputIterator>
716 ArgArray(InputIterator first, InputIterator last);
718
720
722 slice(int start, int inc=1, int n=-1);
724
726
728 operator <<(const T& x);
731 operator <<(const ArgArray<T>& x);
733
734 friend typename ArrayTraits<ArgArray<T>>::ArgsType
736 friend typename ArrayTraits<ArgArray<T>>::ArgsType
737 operator + <>(const ArgArray<T>& x, const T& y);
738 friend
740 operator + <>(const T& x, const ArgArray<T>& y);
741
743 ArgArray& operator =(const ArgArray&) = default;
744 };
745
746 template<class> class VarArgArray;
747
751 template<class Var>
754
758 template<class Var>
760 operator +(const VarArgArray<Var>& x, const Var& y);
761
765 template<class Var>
767 operator +(const Var& x, const VarArgArray<Var>& y);
768
780 template<class Var>
781 class VarArgArray : public ArgArrayBase<Var> {
782 protected:
783 using ArgArrayBase<Var>::a;
784 using ArgArrayBase<Var>::n;
785 public:
786 using ArgArrayBase<Var>::size;
788
789
792 explicit VarArgArray(int n);
798 VarArgArray(const std::vector<Var>& a);
800 VarArgArray(std::initializer_list<Var> a);
802 template<class InputIterator>
803 VarArgArray(InputIterator first, InputIterator last);
805
807
809 slice(int start, int inc=1, int n=-1);
811
813
815 operator <<(const Var& x);
820
822 bool assigned(void) const;
823
827 operator + <>(const VarArgArray<Var>& x, const Var& y);
828 friend
830 operator + <>(const Var& x, const VarArgArray<Var>& y);
831
834 };
835
836
843 template<class Var>
851 template<class Var>
859 template<class Var>
867 template<class Var>
869
870
875 template<class Char, class Traits, class Var>
876 std::basic_ostream<Char,Traits>&
877 operator <<(std::basic_ostream<Char,Traits>& os,
878 const VarArray<Var>& x);
879
884 template<class Char, class Traits, class View>
885 std::basic_ostream<Char,Traits>&
886 operator <<(std::basic_ostream<Char,Traits>& os, const ViewArray<View>& x);
887
892 template<class Char, class Traits, class T>
893 std::basic_ostream<Char,Traits>&
894 operator <<(std::basic_ostream<Char,Traits>& os, const ArgArrayBase<T>& x);
895
896
897 /*
898 * Implementation
899 *
900 */
901
902 /*
903 * Variable arrays
904 *
905 * These arrays are allocated in the space.
906 *
907 */
908
909 template<class Var>
910 forceinline
911 VarArray<Var>::VarArray(void) : n(0), x(nullptr) {}
912
913 template<class Var>
914 forceinline
916 : n(n0) {
917 // Allocate from space
918 x = (n>0) ? home.alloc<Var>(n) : nullptr;
919 }
920
921 template<class Var>
922 forceinline
924 n = a.n; x = a.x;
925 }
926
927 template<class Var>
928 inline const VarArray<Var>&
930 n = a.n; x = a.x;
931 return *this;
932 }
933
934 template<class Var>
935 forceinline int
937 return n;
938 }
939
940 template<class Var>
941 forceinline Var&
943 assert((i >= 0) && (i < size()));
944 return x[i];
945 }
946
947 template<class Var>
948 forceinline const Var&
950 assert((i >= 0) && (i < size()));
951 return x[i];
952 }
953
954 template<class Var>
956 VarArray<Var>::slice(int start, int inc, int maxN) {
957 assert(n==0 || start < n);
958 if (n==0 || maxN<0)
959 maxN = n;
960 int s;
961 if (inc == 0)
962 s = n-start;
963 else if (inc > 0)
964 s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
965 else
966 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
967 typename ArrayTraits<VarArgArray<Var>>::ArgsType r(std::min(maxN,s));
968 for (int i=0; i<r.size(); i++, start+=inc)
969 r[i] = x[start];
970 return r;
971 }
972
973 template<class Var>
974 forceinline typename VarArray<Var>::iterator
976 return x;
977 }
978
979 template<class Var>
980 forceinline typename VarArray<Var>::const_iterator
982 return x;
983 }
984
985 template<class Var>
986 forceinline typename VarArray<Var>::iterator
988 return x+n;
989 }
990
991 template<class Var>
992 forceinline typename VarArray<Var>::const_iterator
993 VarArray<Var>::end(void) const {
994 return x+n;
995 }
996
997 template<class Var>
998 forceinline typename VarArray<Var>::reverse_iterator
1000 return reverse_iterator(x+n);
1001 }
1002
1003 template<class Var>
1004 forceinline typename VarArray<Var>::const_reverse_iterator
1006 return const_reverse_iterator(x+n);
1007 }
1008
1009 template<class Var>
1010 forceinline typename VarArray<Var>::reverse_iterator
1012 return reverse_iterator(x);
1013 }
1014
1015 template<class Var>
1016 forceinline typename VarArray<Var>::const_reverse_iterator
1018 return const_reverse_iterator(x);
1019 }
1020
1021 template<class Var>
1022 forceinline void
1024 n = a.n;
1025 if (n > 0) {
1026 x = home.alloc<Var>(n);
1027 for (int i=0; i<n; i++)
1028 x[i].update(home, a.x[i]);
1029 } else {
1030 x = nullptr;
1031 }
1032 }
1033
1034 template<class Var>
1035 forceinline bool
1037 for (int i=0; i<n; i++)
1038 if (!x[i].assigned())
1039 return false;
1040 return true;
1041 }
1042
1043
1044 template<class Var>
1047 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1048 for (int i=0; i<x.size(); i++)
1049 r[i] = x[i];
1050 for (int i=0; i<y.size(); i++)
1051 r[x.size()+i] = y[i];
1052 return r;
1053 }
1054
1055 template<class Var>
1056 typename ArrayTraits<VarArray<Var>>::ArgsType
1058 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1059 for (int i=0; i<x.size(); i++)
1060 r[i] = x[i];
1061 for (int i=0; i<y.size(); i++)
1062 r[x.size()+i] = y[i];
1063 return r;
1064 }
1065
1066 template<class Var>
1067 typename ArrayTraits<VarArray<Var>>::ArgsType
1069 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1070 for (int i=0; i<x.size(); i++)
1071 r[i] = x[i];
1072 for (int i=0; i<y.size(); i++)
1073 r[x.size()+i] = y[i];
1074 return r;
1075 }
1076
1077 template<class Var>
1078 typename ArrayTraits<VarArray<Var>>::ArgsType
1079 operator +(const VarArray<Var>& x, const Var& y) {
1080 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+1);
1081 for (int i=0; i<x.size(); i++)
1082 r[i] = x[i];
1083 r[x.size()] = y;
1084 return r;
1085 }
1086
1087 template<class Var>
1088 typename ArrayTraits<VarArray<Var>>::ArgsType
1089 operator +(const Var& x, const VarArray<Var>& y) {
1090 typename ArrayTraits<VarArray<Var>>::ArgsType r(y.size()+1);
1091 r[0] = x;
1092 for (int i=0; i<y.size(); i++)
1093 r[1+i] = y[i];
1094 return r;
1095 }
1096
1097 /*
1098 * View arrays
1099 *
1100 */
1101
1102 template<class View>
1103 forceinline
1104 ViewArray<View>::ViewArray(void) : n(0), x(nullptr) {}
1105
1106 template<class View>
1107 forceinline
1109 : n(n0) {
1110 x = (n>0) ? home.alloc<View>(n) : nullptr;
1111 }
1112 template<class View>
1113 forceinline
1115 : n(n0) {
1116 x = (n>0) ? r.alloc<View>(n) : nullptr;
1117 }
1118
1119 template<class View>
1121 : n(a.size()) {
1122 if (n>0) {
1123 x = home.alloc<View>(n);
1124 for (int i=0; i<n; i++)
1125 x[i] = a[i];
1126 } else {
1127 x = nullptr;
1128 }
1129 }
1130 template<class View>
1132 : n(a.size()) {
1133 if (n>0) {
1134 x = r.alloc<View>(n);
1135 for (int i=0; i<n; i++)
1136 x[i] = a[i];
1137 } else {
1138 x = nullptr;
1139 }
1140 }
1141
1142 template<class View>
1143 forceinline
1145 : n(a.n), x(a.x) {}
1146
1147 template<class View>
1148 forceinline const ViewArray<View>&
1150 n = a.n; x = a.x;
1151 return *this;
1152 }
1153
1154 template<class View>
1155 forceinline int
1157 return n;
1158 }
1159
1160 template<class View>
1161 forceinline void
1163 n = n0;
1164 }
1165
1166 template<class View>
1167 forceinline View&
1169 assert((i >= 0) && (i < size()));
1170 return x[i];
1171 }
1172
1173 template<class View>
1174 forceinline const View&
1176 assert((i >= 0) && (i < size()));
1177 return x[i];
1178 }
1179
1180 template<class View>
1181 forceinline typename ViewArray<View>::iterator
1183 return x;
1184 }
1185
1186 template<class View>
1187 forceinline typename ViewArray<View>::const_iterator
1189 return x;
1190 }
1191
1192 template<class View>
1193 forceinline typename ViewArray<View>::iterator
1195 return x+n;
1196 }
1197
1198 template<class View>
1199 forceinline typename ViewArray<View>::const_iterator
1201 return x+n;
1202 }
1203
1204 template<class View>
1205 forceinline typename ViewArray<View>::reverse_iterator
1207 return reverse_iterator(x+n);
1208 }
1209
1210 template<class View>
1211 forceinline typename ViewArray<View>::const_reverse_iterator
1213 return const_reverse_iterator(x+n);
1214 }
1215
1216 template<class View>
1217 forceinline typename ViewArray<View>::reverse_iterator
1219 return reverse_iterator(x);
1220 }
1221
1222 template<class View>
1223 forceinline typename ViewArray<View>::const_reverse_iterator
1225 return const_reverse_iterator(x);
1226 }
1227
1228 template<class View>
1229 forceinline void
1231 x[i]=x[0]; x++; n--;
1232 }
1233
1234 template<class View>
1235 forceinline void
1237 n--; x[i]=x[n];
1238 }
1239
1240 template<class View>
1241 forceinline void
1243 assert(i>=0);
1244 x += i; n -= i;
1245 }
1246
1247 template<class View>
1248 forceinline void
1250 assert(i<n);
1251 n = i+1;
1252 }
1253
1254 template<class View>
1255 forceinline void
1257 // Move x[0] to x[i]
1258 x[i].cancel(home,p,pc);
1259 x[i]=x[0]; x++; n--;
1260 }
1261
1262 template<class View>
1263 forceinline void
1265 // Move x[n-1] to x[i]
1266 x[i].cancel(home,p,pc);
1267 n--; x[i]=x[n];
1268 }
1269
1270 template<class View>
1271 void
1273 // Drop elements from 0..i-1
1274 assert(i>=0);
1275 for (int j=0; j<i; j++)
1276 x[j].cancel(home,p,pc);
1277 x += i; n -= i;
1278 }
1279
1280 template<class View>
1281 void
1283 // Drop elements from i+1..n-1
1284 assert(i<n);
1285 for (int j=i+1; j<n; j++)
1286 x[j].cancel(home,p,pc);
1287 n = i+1;
1288 }
1289
1290 template<class View>
1291 forceinline void
1293 // Move x[0] to x[i]
1294 x[i].cancel(home,a);
1295 x[i]=x[0]; x++; n--;
1296 }
1297
1298 template<class View>
1299 forceinline void
1301 // Move x[n-1] to x[i]
1302 x[i].cancel(home,a);
1303 n--; x[i]=x[n];
1304 }
1305
1306 template<class View>
1307 void
1309 // Drop elements from 0..i-1
1310 assert(i>=0);
1311 for (int j=0; j<i; j++)
1312 x[j].cancel(home,a);
1313 x += i; n -= i;
1314 }
1315
1316 template<class View>
1317 void
1319 // Drop elements from i+1..n-1
1320 assert(i<n);
1321 for (int j=i+1; j<n; j++)
1322 x[j].cancel(home,a);
1323 n = i+1;
1324 }
1325
1326 template<class View>
1327 void
1329 n = y.n;
1330 if (n > 0) {
1331 x = home.alloc<View>(n);
1332 for (int i=0; i<n; i++)
1333 x[i].update(home, y.x[i]);
1334 } else {
1335 x = nullptr;
1336 }
1337 }
1338
1339 template<class View>
1340 void
1342 bool schedule) {
1343 for (int i=0; i<n; i++)
1344 x[i].subscribe(home,p,pc,schedule);
1345 }
1346
1347 template<class View>
1348 void
1350 for (int i=0; i<n; i++)
1351 x[i].cancel(home,p,pc);
1352 }
1353
1354 template<class View>
1355 void
1357 for (int i=0; i<n; i++)
1358 x[i].subscribe(home,a);
1359 }
1360
1361 template<class View>
1362 void
1364 for (int i=0; i<n; i++)
1365 x[i].cancel(home,a);
1366 }
1367
1368 template<class View>
1369 void
1371 for (int i=0; i<n; i++)
1372 x[i].reschedule(home,p,pc);
1373 }
1374
1375 template<class View>
1376 forceinline bool
1378 for (int i=0; i<n; i++)
1379 if (!x[i].assigned())
1380 return false;
1381 return true;
1382 }
1383
1384 template<class View>
1385 bool
1387 if (n < 2)
1388 return false;
1389 Region r;
1390 View* y = r.alloc<View>(n);
1391 int j=0;
1392 for (int i=0; i<n; i++)
1393 if (!x[i].assigned())
1394 y[j++] = x[i];
1395 if (j < 2)
1396 return false;
1398 for (int i=1; i<j; i++)
1399 if (y[i-1] == y[i])
1400 return true;
1401 return false;
1402 }
1403
1404 template<class View>
1405 bool
1406 ViewArray<View>::same(const View& y) const {
1407 if (y.assigned())
1408 return false;
1409 for (int i=0; i<n; i++)
1410 if (x[i] == y)
1411 return true;
1412 return false;
1413 }
1414
1415 template<class View>
1416 void
1418 if (n < 2)
1419 return;
1420 Region r;
1422 for (int i=0; i<n; i++) {
1423 o[i].x = x[i]; o[i].i = i;
1424 }
1426 // Assign bucket numbers
1427 int* bkt = r.alloc<int>(n);
1428 int b = 0;
1429 bkt[o[0].i] = b;
1430 for (int i=1; i<n; i++) {
1431 if (o[i-1].x != o[i].x)
1432 b++;
1433 bkt[o[i].i] = b;
1434 }
1435 // Eliminate duplicate elements
1436 Support::BitSet<Region> seen(r,static_cast<unsigned int>(b+1));
1437 int j=0;
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]));
1441 } else {
1442 x[j]=x[i];
1443 }
1444 assert(j == b+1);
1445 n = j;
1446 }
1447
1448
1449 /*
1450 * Sharing for view arrays
1451 *
1452 */
1453 template<class ViewX, class ViewY>
1454 bool
1456 if ((x.size() == 0) || (y.size() == 0))
1457 return false;
1458 Region r;
1459 void** px = r.alloc<void*>(x.size());
1460 int j=0;
1461 for (int i=0; i<x.size(); i++)
1462 if (!x[i].assigned() && x[i].varimp())
1463 px[j++] = x[i].varimp();
1464 if (j == 0)
1465 return false;
1466 void** py = r.alloc<void*>(y.size());
1467 int k=0;
1468 for (int i=0; i<y.size(); i++)
1469 if (!y[i].assigned() && y[i].varimp())
1470 py[k++] = y[i].varimp();
1471 if (k == 0)
1472 return false;
1473 return Kernel::duplicates(px,j,py,k);
1474 }
1475
1476 template<class ViewX, class ViewY>
1477 bool
1479 if (y.assigned() || !y.varimp())
1480 return false;
1481 for (int i=0; i<x.size(); i++)
1482 if (!x[i].assigned() && x[i].varimp() && (x[i].varimp() == y.varimp()))
1483 return true;
1484 return false;
1485 }
1486
1487 template<class ViewX, class ViewY>
1488 forceinline bool
1490 return shared(y,x);
1491 }
1492
1493 template<class View>
1494 bool
1496 if (x.size() < 2)
1497 return false;
1498 Region r;
1499 void** px = r.alloc<void*>(x.size());
1500 int j=0;
1501 for (int i=0; i<x.size(); i++)
1502 if (!x[i].assigned() && x[i].varimp())
1503 px[j++] = x[i].varimp();
1504 return (j > 2) && Kernel::duplicates(px,j);
1505 }
1506
1507
1508
1509 /*
1510 * Argument arrays: base class
1511 *
1512 */
1513
1514 template<class T>
1515 forceinline T*
1517 return (n > onstack_size) ?
1518 heap.alloc<T>(static_cast<unsigned int>(n)) : &onstack[0];
1519 }
1520
1521 template<class T>
1522 forceinline void
1524 if (n+i >= capacity) {
1525 assert(n+i >= onstack_size);
1526 int newCapacity = (3*capacity)/2;
1527 if (newCapacity <= n+i)
1528 newCapacity = n+i;
1529 T* newA = allocate(newCapacity);
1530 heap.copy<T>(newA,a,n);
1531 if (capacity > onstack_size)
1532 heap.free(a,capacity);
1533 capacity = newCapacity;
1534 a = newA;
1535 }
1536 }
1537
1538 template<class T>
1539 forceinline
1542
1543 template<class T>
1544 forceinline
1547
1548 template<class T>
1549 inline
1551 : n(aa.n), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1552 heap.copy<T>(a,aa.a,n);
1553 }
1554
1555 template<class T>
1556 inline
1557 ArgArrayBase<T>::ArgArrayBase(const std::vector<T>& aa)
1558 : n(static_cast<int>(aa.size())),
1560 if (n > 0)
1561 heap.copy<T>(a,aa.data(),n);
1562 }
1563
1564 template<class T>
1565 inline
1566 ArgArrayBase<T>::ArgArrayBase(std::initializer_list<T> aa)
1567 : n(static_cast<int>(aa.size())),
1569 int i=0;
1570 for (const T& x : aa)
1571 a[i++]=x;
1572 }
1573
1574 template<class T>
1575 forceinline
1577 if (capacity > onstack_size)
1578 heap.free(a,capacity);
1579 }
1580
1581 template<class T>
1582 forceinline const ArgArrayBase<T>&
1584 if (&aa != this) {
1585 if (capacity > onstack_size)
1586 heap.free(a,capacity);
1587 n = aa.n;
1589 a = allocate(aa.n);
1590 heap.copy<T>(a,aa.a,n);
1591 }
1592 return *this;
1593 }
1594
1595 template<class T>
1596 forceinline int
1598 return n;
1599 }
1600
1601 template<class T>
1602 forceinline T&
1604 assert((i>=0) && (i < n));
1605 return a[i];
1606 }
1607
1608 template<class T>
1609 forceinline const T&
1611 assert((i>=0) && (i < n));
1612 return a[i];
1613 }
1614
1615 template<class T>
1616 forceinline typename ArgArrayBase<T>::iterator
1618 return a;
1619 }
1620
1621 template<class T>
1622 forceinline typename ArgArrayBase<T>::const_iterator
1624 return a;
1625 }
1626
1627 template<class T>
1628 forceinline typename ArgArrayBase<T>::iterator
1630 return a+n;
1631 }
1632
1633 template<class T>
1634 forceinline typename ArgArrayBase<T>::const_iterator
1636 return a+n;
1637 }
1638
1639 template<class T>
1640 forceinline typename ArgArrayBase<T>::reverse_iterator
1642 return reverse_iterator(a+n);
1643 }
1644
1645 template<class T>
1646 forceinline typename ArgArrayBase<T>::const_reverse_iterator
1648 return const_reverse_iterator(a+n);
1649 }
1650
1651 template<class T>
1652 forceinline typename ArgArrayBase<T>::reverse_iterator
1654 return reverse_iterator(a);
1655 }
1656
1657 template<class T>
1658 forceinline typename ArgArrayBase<T>::const_reverse_iterator
1660 return const_reverse_iterator(a);
1661 }
1662
1663 template<class T> template<class A>
1664 A
1665 ArgArrayBase<T>::slice(int start, int inc, int maxN) {
1666 assert(n==0 || start < n);
1667 if (n==0 || maxN<0)
1668 maxN = n;
1669 int s;
1670 if (inc == 0)
1671 s = n-start;
1672 else if (inc > 0)
1673 s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
1674 else
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]);
1679 return r;
1680 }
1681
1682 template<class T> template<class A>
1683 inline A&
1685 resize(1);
1686 new (&a[n++]) T(x);
1687 return static_cast<A&>(*this);
1688 }
1689
1690 template<class T>
1691 template<class InputIterator>
1692 inline
1693 ArgArrayBase<T>::ArgArrayBase(InputIterator first, InputIterator last)
1694 : n(0), capacity(onstack_size), a(allocate(0)) {
1695 while (first != last) {
1696 (void) append<ArgArrayBase<T>>(*first);
1697 ++first;
1698 }
1699 }
1700
1701
1702 template<class T> template<class A>
1703 inline A&
1705 resize(x.size());
1706 for (int i=0; i<x.size(); i++)
1707 new (&a[n++]) T(x[i]);
1708 return static_cast<A&>(*this);
1709 }
1710
1711 template<class T> template<class A>
1712 inline A
1714 A r(n+x.n);
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]);
1719 return r;
1720 }
1721
1722 template<class T> template<class A>
1723 inline A
1724 ArgArrayBase<T>::concat(const T& x) const {
1725 A r(n+1);
1726 for (int i=0; i<n; i++)
1727 new (&r[i]) T(a[i]);
1728 new (&r[n]) T(x);
1729 return r;
1730 }
1731
1732
1733 /*
1734 * Argument arrays
1735 *
1736 */
1737
1738 template<class T>
1739 forceinline
1741
1742 template<class T>
1743 forceinline
1746
1747 template<class T>
1748 ArgArray<T>::ArgArray(int n, const T* a0)
1749 : ArgArrayBase<T>(n) {
1750 for (int i=0; i<n; i++)
1751 a[i] = a0[i];
1752 }
1753
1754 template<class T>
1755 forceinline
1758
1759 template<class T>
1760 forceinline
1761 ArgArray<T>::ArgArray(const std::vector<T>& aa)
1762 : ArgArrayBase<T>(aa) {}
1763
1764 template<class T>
1765 forceinline
1766 ArgArray<T>::ArgArray(std::initializer_list<T> aa)
1767 : ArgArrayBase<T>(aa) {}
1768
1769 template<class T>
1770 template<class InputIterator>
1771 forceinline
1772 ArgArray<T>::ArgArray(InputIterator first, InputIterator last)
1773 : ArgArrayBase<T>(first,last) {}
1774
1775 template<class T>
1776 forceinline typename ArrayTraits<ArgArray<T>>::ArgsType
1777 ArgArray<T>::slice(int start, int inc, int maxN) {
1780 (start,inc,maxN);
1781 }
1782
1783 template<class T>
1785 ArgArray<T>::operator <<(const T& x) {
1786 return
1788 <typename ArrayTraits<ArgArray<T>>::ArgsType>(x);
1789 }
1790
1791 template<class T>
1794 return
1796 <typename ArrayTraits<ArgArray<T>>::ArgsType>(x);
1797 }
1798
1799 template<class T>
1801 operator +(const ArgArray<T>& x, const ArgArray<T>& y) {
1802 return x.template concat
1803 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1804 }
1805
1806 template<class T>
1808 operator +(const ArgArray<T>& x, const T& y) {
1809 return x.template concat
1810 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1811 }
1812
1813 template<class T>
1815 operator +(const T& x, const ArgArray<T>& y) {
1816 ArgArray<T> xa(1);
1817 xa[0] = x;
1818 return xa.template concat
1819 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1820 }
1821
1822 /*
1823 * Argument arrays for variables
1824 *
1825 */
1826
1827 template<class Var>
1828 forceinline
1830
1831 template<class Var>
1832 forceinline
1834
1835 template<class Var>
1836 forceinline
1839
1840 template<class Var>
1841 forceinline
1842 VarArgArray<Var>::VarArgArray(const std::vector<Var>& aa)
1843 : ArgArrayBase<Var>(aa) {}
1844
1845 template<class Var>
1846 forceinline
1847 VarArgArray<Var>::VarArgArray(std::initializer_list<Var> aa)
1848 : ArgArrayBase<Var>(aa) {}
1849
1850 template<class Var>
1851 template<class InputIterator>
1852 forceinline
1853 VarArgArray<Var>::VarArgArray(InputIterator first, InputIterator last)
1854 : ArgArrayBase<Var>(first,last) {}
1855
1856 template<class Var>
1857 inline
1859 : ArgArrayBase<Var>(x.size()) {
1860 for (int i=0; i<x.size(); i++)
1861 a[i]=x[i];
1862 }
1863
1864 template<class Var>
1865 forceinline typename ArrayTraits<VarArgArray<Var>>::ArgsType
1866 VarArgArray<Var>::slice(int start, int inc, int maxN) {
1869 (start,inc,maxN);
1870 }
1871
1872 template<class Var>
1879
1880 template<class Var>
1887
1888 template<class Var>
1891 return x.template concat
1893 }
1894
1895 template<class Var>
1897 operator +(const VarArgArray<Var>& x, const Var& y) {
1898 return x.template concat
1900 }
1901
1902 template<class Var>
1904 operator +(const Var& x, const VarArgArray<Var>& y) {
1905 VarArgArray<Var> xa(1);
1906 xa[0] = x;
1907 return xa.template concat
1909 }
1910
1911 template<class Var>
1912 forceinline bool
1914 for (int i=0; i<n; i++)
1915 if (!a[i].assigned())
1916 return false;
1917 return true;
1918 }
1919
1920
1921 /*
1922 * Checking for multiple occurrences of the same variable
1923 *
1924 */
1925 template<class Var>
1926 bool
1928 if ((x.size() == 0) || (y.size() == 0))
1929 return false;
1930 Region r;
1931 void** px = r.alloc<void*>(x.size());
1932 int j=0;
1933 for (int i=0; i<x.size(); i++)
1934 if (!x[i].assigned())
1935 px[j++] = x[i].varimp();
1936 if (j == 0)
1937 return false;
1938 void** py = r.alloc<void*>(y.size());
1939 int k=0;
1940 for (int i=0; i<y.size(); i++)
1941 if (!y[i].assigned())
1942 py[k++] = y[i].varimp();
1943 if (k == 0)
1944 return false;
1945 return Kernel::duplicates(px,j,py,k);
1946 }
1947
1948 template<class Var>
1949 bool
1951 if (y.assigned())
1952 return false;
1953 for (int i=0; i<x.size(); i++)
1954 if (x[i].varimp() == y.varimp())
1955 return true;
1956 return false;
1957 }
1958
1959 template<class Var>
1960 forceinline bool
1962 return same(y,x);
1963 }
1964
1965 template<class Var>
1966 bool
1968 if (x.size() < 2)
1969 return false;
1970 Region r;
1971 void** px = r.alloc<void*>(x.size());
1972 int j=0;
1973 for (int i=0; i<x.size(); i++)
1974 if (!x[i].assigned())
1975 px[j++] = x[i].varimp();
1976 return (j > 1) && Kernel::duplicates(px,j);
1977 }
1978
1979
1980
1981 /*
1982 * Interdependent code
1983 *
1984 */
1985
1986 template<class Var>
1987 inline
1989 : n(a.size()) {
1990 if (n>0) {
1991 x = home.alloc<Var>(n);
1992 for (int i=0; i<n; i++)
1993 x[i] = a[i];
1994 } else {
1995 x = nullptr;
1996 }
1997 }
1998
1999
2000 /*
2001 * Printing of arrays
2002 *
2003 */
2004 template<class Char, class Traits, class Var>
2005 std::basic_ostream<Char,Traits>&
2006 operator <<(std::basic_ostream<Char,Traits>& os,
2007 const VarArray<Var>& x) {
2008 std::basic_ostringstream<Char,Traits> s;
2009 s.copyfmt(os); s.width(0);
2010 s << '{';
2011 if (x.size() > 0) {
2012 s << x[0];
2013 for (int i=1; i<x.size(); i++)
2014 s << ", " << x[i];
2015 }
2016 s << '}';
2017 return os << s.str();
2018 }
2019
2020 template<class Char, class Traits, class View>
2021 std::basic_ostream<Char,Traits>&
2022 operator <<(std::basic_ostream<Char,Traits>& os,
2023 const ViewArray<View>& x) {
2024 std::basic_ostringstream<Char,Traits> s;
2025 s.copyfmt(os); s.width(0);
2026 s << '{';
2027 if (x.size() > 0) {
2028 s << x[0];
2029 for (int i=1; i<x.size(); i++)
2030 s << ", " << x[i];
2031 }
2032 s << '}';
2033 return os << s.str();
2034 }
2035
2036 template<class Char, class Traits, class T>
2037 std::basic_ostream<Char,Traits>&
2038 operator <<(std::basic_ostream<Char,Traits>& os,
2039 const ArgArrayBase<T>& x) {
2040 std::basic_ostringstream<Char,Traits> s;
2041 s.copyfmt(os); s.width(0);
2042 s << '{';
2043 if (x.size() > 0) {
2044 s << x[0];
2045 for (int i=1; i<x.size(); i++)
2046 s << ", " << x[i];
2047 }
2048 s << '}';
2049 return os << s.str();
2050 }
2051
2052}
2053
2054// STATISTICS: kernel-other
Base-class for advisors.
Definition core.hpp:1301
Base-class for argument arrays.
Definition array.hpp:541
const T & const_reference
Type of a constant reference to the value type.
Definition array.hpp:584
T * allocate(int n)
Allocate memory for n elements.
Definition array.hpp:1516
static const int onstack_size
How many elements are possible inside array.
Definition array.hpp:550
const ArgArrayBase< T > & operator=(const ArgArrayBase< T > &a)
Initialize from view array a (copy elements).
Definition array.hpp:1583
T onstack[onstack_size]
In-array storage for elements.
Definition array.hpp:552
const T * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:588
T value_type
Type of the view stored in this array.
Definition array.hpp:580
T * a
Element array.
Definition array.hpp:548
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1641
void resize(int i)
Resize to hold at least i additional elements.
Definition array.hpp:1523
~ArgArrayBase(void)
Destructor.
Definition array.hpp:1576
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:594
A concat(const ArgArrayBase< T > &x) const
Return this array concatenated with x.
Definition array.hpp:1713
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1653
T * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:590
A slice(int start, int inc=1, int n=-1)
Definition array.hpp:1665
T & operator[](int i)
Return element at position i.
Definition array.hpp:1603
T * pointer
Type of a pointer to the value type.
Definition array.hpp:586
int capacity
Allocated size of the array.
Definition array.hpp:546
int n
Number of elements.
Definition array.hpp:544
A & append(const T &x)
Insert a new element x at the end of the array (increase size by 1).
Definition array.hpp:1684
T & reference
Type of a reference to the value type.
Definition array.hpp:582
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1629
const T * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:592
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:1617
ArgArrayBase(void)
Allocate empty array.
Definition array.hpp:1540
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1597
std::reverse_iterator< const T * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
Definition array.hpp:596
Argument array for non-primitive types.
Definition array.hpp:695
ArgArray(InputIterator first, InputIterator last)
Initialize from InputIterator first and last.
Definition array.hpp:1772
ArgArray(const ArgArray< T > &a)
Initialize from argument array a (copy elements).
Definition array.hpp:1756
ArrayTraits< ArgArray< T > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1777
ArgArray(int n)
Allocate array with n elements.
Definition array.hpp:1744
ArgArray(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1766
ArgArray(int n, const T *e)
Allocate array with n elements and initialize with elements from array e.
Definition array.hpp:1748
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).
Definition array.hpp:1801
ArgArray(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1761
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).
Definition array.hpp:1785
Traits of arrays in Gecode.
Definition array.hpp:94
Occurrence information for a view.
Definition array.hpp:50
bool operator<(const ViewOcc &y) const
Sorting order.
Definition array.hpp:62
View x
The view.
Definition array.hpp:53
int i
The original index in the array.
Definition array.hpp:55
Base-class for propagators.
Definition core.hpp:1073
Handle to region.
Definition region.hpp:55
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition region.hpp:386
Computation spaces.
Definition core.hpp:1775
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2901
bool get(unsigned int i) const
Access value at bit i.
void set(unsigned int i)
Set bit i.
Simple bitsets.
Definition bitset.hpp:45
Argument array for variables.
Definition array.hpp:781
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Test whether array x together with array y contains at least one variable being the same.
Definition array.hpp:1927
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1866
VarArgArray & operator=(const VarArgArray &)=default
Assignment operator.
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1913
ArrayTraits< VarArgArray< Var > >::ArgsType & operator<<(const Var &x)
Insert a new element x at the end of the array (increase size by 1).
Definition array.hpp:1874
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).
Definition array.hpp:1890
bool same(Var x, VarArgArray< Var > y)
Test whether array y contains variable x.
Definition array.hpp:1961
bool same(VarArgArray< Var > x, Var y)
Test whether array x contains variable y.
Definition array.hpp:1950
VarArgArray(void)
Allocate empty array.
Definition array.hpp:1829
Variable arrays
Definition array.hpp:112
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1036
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:999
const Var & const_reference
Type of a constant reference to the value type.
Definition array.hpp:126
const VarArray< Var > & operator=(const VarArray< Var > &a)
Initialize from variable array a (share elements).
Definition array.hpp:929
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Definition array.hpp:956
int n
Number of variables (size).
Definition array.hpp:115
VarArray(void)
Default constructor (array of size 0).
Definition array.hpp:911
std::reverse_iterator< Var * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:136
int size(void) const
Return size of array (number of elements).
Definition array.hpp:936
Var value_type
Type of the variable stored in this array.
Definition array.hpp:122
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Definition array.hpp:1023
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:975
const Var * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:134
Var * pointer
Type of a pointer to the value type.
Definition array.hpp:128
Var & reference
Type of a reference to the value type.
Definition array.hpp:124
std::reverse_iterator< const Var * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
Definition array.hpp:138
Var & operator[](int i)
Return variable at position i.
Definition array.hpp:942
Var * x
Array of variables.
Definition array.hpp:117
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:987
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1011
const Var * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:130
Var * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:132
Base class for variables.
Definition var.hpp:40
View arrays.
Definition array.hpp:255
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition array.hpp:1328
const View & const_reference
Type of a constant reference to the value type.
Definition array.hpp:269
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Test whether array x together with array y contains shared views.
Definition array.hpp:1455
View * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:275
View & reference
Type of a reference to the value type.
Definition array.hpp:267
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition array.hpp:1370
View value_type
Type of the view stored in this array.
Definition array.hpp:265
View & operator[](int i)
Return view at position i.
Definition array.hpp:1168
const View * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:277
void drop_fst(int i)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1242
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1218
bool shared(ViewArray< ViewX > x, ViewY y)
Test whether array x contains a view shared with y.
Definition array.hpp:1478
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:279
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1206
const ViewArray< View > & operator=(const ViewArray< View > &a)
Initialize from view array a (share elements).
Definition array.hpp:1149
const View * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:273
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:1182
std::reverse_iterator< const View * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
Definition array.hpp:281
ViewArray(Region &r, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements).
Definition array.hpp:325
void unique(void)
Remove all duplicate views from array (changes element order).
Definition array.hpp:1417
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
Definition array.hpp:1349
void drop_lst(int i)
Drop views from positions i+1 to size()-1 from array.
Definition array.hpp:1249
void move_lst(int i)
Move view from position size()-1 to position i (truncate array by one).
Definition array.hpp:1236
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition array.hpp:1341
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1377
ViewArray(void)
Default constructor (array of size 0).
Definition array.hpp:1104
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1194
bool same(void) const
Test whether array has multiple occurrence of the same view.
Definition array.hpp:1386
ViewArray(Space &home, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements).
Definition array.hpp:307
void move_fst(int i)
Move view from position 0 to position i (shift elements to the left).
Definition array.hpp:1230
bool shared(ViewX x, ViewArray< ViewY > y)
Test whether array y contains a view shared with x.
Definition array.hpp:1489
View * pointer
Type of a pointer to the value type.
Definition array.hpp:271
bool shared(ViewArray< View > x)
Test whether array x contains shared views.
Definition array.hpp:1495
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1156
Heap heap
The single global heap.
#define GECODE_KERNEL_EXPORT
Definition kernel.hh:70
Kernel functionality
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.
Definition sort.hpp:130
Gecode toplevel namespace
FloatVal operator+(const FloatVal &x)
Definition val.hpp:181
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition val-sel.hpp:39
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1927
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1455
int PropCond
Type for propagation conditions.
Definition core.hpp:77