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>
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);
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
186 const_iterator end(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);
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
363 const_iterator end(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>
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
641 const_iterator end(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
747 template<>
748 class ArrayTraits<ArgArray<double>> {
749 public:
751 typedef double ValueType;
753 };
754
755 template<class> class VarArgArray;
756
760 template<class Var>
763
767 template<class Var>
769 operator +(const VarArgArray<Var>& x, const Var& y);
770
774 template<class Var>
776 operator +(const Var& x, const VarArgArray<Var>& y);
777
789 template<class Var>
790 class VarArgArray : public ArgArrayBase<Var> {
791 protected:
792 using ArgArrayBase<Var>::a;
793 using ArgArrayBase<Var>::n;
794 public:
795 using ArgArrayBase<Var>::size;
797
798
801 explicit VarArgArray(int n);
807 VarArgArray(const std::vector<Var>& a);
809 VarArgArray(std::initializer_list<Var> a);
811 template<class InputIterator>
812 VarArgArray(InputIterator first, InputIterator last);
814
816
818 slice(int start, int inc=1, int n=-1);
820
822
824 operator <<(const Var& x);
829
831 bool assigned(void) const;
832
836 operator + <>(const VarArgArray<Var>& x, const Var& y);
837 friend
839 operator + <>(const Var& x, const VarArgArray<Var>& y);
840
843 };
844
845
852 template<class Var>
860 template<class Var>
868 template<class Var>
876 template<class Var>
878
879
884 template<class Char, class Traits, class Var>
885 std::basic_ostream<Char,Traits>&
886 operator <<(std::basic_ostream<Char,Traits>& os,
887 const VarArray<Var>& x);
888
893 template<class Char, class Traits, class View>
894 std::basic_ostream<Char,Traits>&
895 operator <<(std::basic_ostream<Char,Traits>& os, const ViewArray<View>& x);
896
901 template<class Char, class Traits, class T>
902 std::basic_ostream<Char,Traits>&
903 operator <<(std::basic_ostream<Char,Traits>& os, const ArgArrayBase<T>& x);
904
905
906 /*
907 * Implementation
908 *
909 */
910
911 /*
912 * Variable arrays
913 *
914 * These arrays are allocated in the space.
915 *
916 */
917
918 template<class Var>
920 VarArray<Var>::VarArray(void) : n(0), x(nullptr) {}
921
922 template<class Var>
925 : n(n0) {
926 // Allocate from space
927 x = (n>0) ? home.alloc<Var>(n) : nullptr;
928 }
929
930 template<class Var>
933 n = a.n; x = a.x;
934 }
935
936 template<class Var>
937 inline const VarArray<Var>&
939 n = a.n; x = a.x;
940 return *this;
941 }
942
943 template<class Var>
944 forceinline int
946 return n;
947 }
948
949 template<class Var>
952 assert((i >= 0) && (i < size()));
953 return x[i];
954 }
955
956 template<class Var>
957 forceinline const Var&
959 assert((i >= 0) && (i < size()));
960 return x[i];
961 }
962
963 template<class Var>
965 VarArray<Var>::slice(int start, int inc, int maxN) {
966 assert(n==0 || start < n);
967 if (n==0 || maxN<0)
968 maxN = n;
969 int s;
970 if (inc == 0)
971 s = n-start;
972 else if (inc > 0)
973 s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
974 else
975 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
976 typename ArrayTraits<VarArgArray<Var>>::ArgsType r(std::min(maxN,s));
977 for (int i=0; i<r.size(); i++, start+=inc)
978 r[i] = x[start];
979 return r;
980 }
981
982 template<class Var>
985 return x;
986 }
987
988 template<class Var>
991 return x;
992 }
993
994 template<class Var>
997 return x+n;
998 }
999
1000 template<class Var>
1003 return x+n;
1004 }
1005
1006 template<class Var>
1009 return reverse_iterator(x+n);
1010 }
1011
1012 template<class Var>
1015 return const_reverse_iterator(x+n);
1016 }
1017
1018 template<class Var>
1021 return reverse_iterator(x);
1022 }
1023
1024 template<class Var>
1027 return const_reverse_iterator(x);
1028 }
1029
1030 template<class Var>
1031 forceinline void
1033 n = a.n;
1034 if (n > 0) {
1035 x = home.alloc<Var>(n);
1036 for (int i=0; i<n; i++)
1037 x[i].update(home, a.x[i]);
1038 } else {
1039 x = nullptr;
1040 }
1041 }
1042
1043 template<class Var>
1044 forceinline bool
1046 for (int i=0; i<n; i++)
1047 if (!x[i].assigned())
1048 return false;
1049 return true;
1050 }
1051
1052
1053 template<class Var>
1056 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1057 for (int i=0; i<x.size(); i++)
1058 r[i] = x[i];
1059 for (int i=0; i<y.size(); i++)
1060 r[x.size()+i] = y[i];
1061 return r;
1062 }
1063
1064 template<class Var>
1065 typename ArrayTraits<VarArray<Var>>::ArgsType
1067 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1068 for (int i=0; i<x.size(); i++)
1069 r[i] = x[i];
1070 for (int i=0; i<y.size(); i++)
1071 r[x.size()+i] = y[i];
1072 return r;
1073 }
1074
1075 template<class Var>
1076 typename ArrayTraits<VarArray<Var>>::ArgsType
1078 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1079 for (int i=0; i<x.size(); i++)
1080 r[i] = x[i];
1081 for (int i=0; i<y.size(); i++)
1082 r[x.size()+i] = y[i];
1083 return r;
1084 }
1085
1086 template<class Var>
1087 typename ArrayTraits<VarArray<Var>>::ArgsType
1088 operator +(const VarArray<Var>& x, const Var& y) {
1089 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+1);
1090 for (int i=0; i<x.size(); i++)
1091 r[i] = x[i];
1092 r[x.size()] = y;
1093 return r;
1094 }
1095
1096 template<class Var>
1097 typename ArrayTraits<VarArray<Var>>::ArgsType
1098 operator +(const Var& x, const VarArray<Var>& y) {
1099 typename ArrayTraits<VarArray<Var>>::ArgsType r(y.size()+1);
1100 r[0] = x;
1101 for (int i=0; i<y.size(); i++)
1102 r[1+i] = y[i];
1103 return r;
1104 }
1105
1106 /*
1107 * View arrays
1108 *
1109 */
1110
1111 template<class View>
1113 ViewArray<View>::ViewArray(void) : n(0), x(nullptr) {}
1114
1115 template<class View>
1118 : n(n0) {
1119 x = (n>0) ? home.alloc<View>(n) : nullptr;
1120 }
1121 template<class View>
1124 : n(n0) {
1125 x = (n>0) ? r.alloc<View>(n) : nullptr;
1126 }
1127
1128 template<class View>
1130 : n(a.size()) {
1131 if (n>0) {
1132 x = home.alloc<View>(n);
1133 for (int i=0; i<n; i++)
1134 x[i] = a[i];
1135 } else {
1136 x = nullptr;
1137 }
1138 }
1139 template<class View>
1141 : n(a.size()) {
1142 if (n>0) {
1143 x = r.alloc<View>(n);
1144 for (int i=0; i<n; i++)
1145 x[i] = a[i];
1146 } else {
1147 x = nullptr;
1148 }
1149 }
1150
1151 template<class View>
1154 : n(a.n), x(a.x) {}
1155
1156 template<class View>
1159 n = a.n; x = a.x;
1160 return *this;
1161 }
1162
1163 template<class View>
1164 forceinline int
1166 return n;
1167 }
1168
1169 template<class View>
1170 forceinline void
1172 n = n0;
1173 }
1174
1175 template<class View>
1178 assert((i >= 0) && (i < size()));
1179 return x[i];
1180 }
1181
1182 template<class View>
1183 forceinline const View&
1185 assert((i >= 0) && (i < size()));
1186 return x[i];
1187 }
1188
1189 template<class View>
1192 return x;
1193 }
1194
1195 template<class View>
1198 return x;
1199 }
1200
1201 template<class View>
1204 return x+n;
1205 }
1206
1207 template<class View>
1210 return x+n;
1211 }
1212
1213 template<class View>
1216 return reverse_iterator(x+n);
1217 }
1218
1219 template<class View>
1222 return const_reverse_iterator(x+n);
1223 }
1224
1225 template<class View>
1228 return reverse_iterator(x);
1229 }
1230
1231 template<class View>
1234 return const_reverse_iterator(x);
1235 }
1236
1237 template<class View>
1238 forceinline void
1240 x[i]=x[0]; x++; n--;
1241 }
1242
1243 template<class View>
1244 forceinline void
1246 n--; x[i]=x[n];
1247 }
1248
1249 template<class View>
1250 forceinline void
1252 assert(i>=0);
1253 x += i; n -= i;
1254 }
1255
1256 template<class View>
1257 forceinline void
1259 assert(i<n);
1260 n = i+1;
1261 }
1262
1263 template<class View>
1264 forceinline void
1266 // Move x[0] to x[i]
1267 x[i].cancel(home,p,pc);
1268 x[i]=x[0]; x++; n--;
1269 }
1270
1271 template<class View>
1272 forceinline void
1274 // Move x[n-1] to x[i]
1275 x[i].cancel(home,p,pc);
1276 n--; x[i]=x[n];
1277 }
1278
1279 template<class View>
1280 void
1282 // Drop elements from 0..i-1
1283 assert(i>=0);
1284 for (int j=0; j<i; j++)
1285 x[j].cancel(home,p,pc);
1286 x += i; n -= i;
1287 }
1288
1289 template<class View>
1290 void
1292 // Drop elements from i+1..n-1
1293 assert(i<n);
1294 for (int j=i+1; j<n; j++)
1295 x[j].cancel(home,p,pc);
1296 n = i+1;
1297 }
1298
1299 template<class View>
1300 forceinline void
1302 // Move x[0] to x[i]
1303 x[i].cancel(home,a);
1304 x[i]=x[0]; x++; n--;
1305 }
1306
1307 template<class View>
1308 forceinline void
1310 // Move x[n-1] to x[i]
1311 x[i].cancel(home,a);
1312 n--; x[i]=x[n];
1313 }
1314
1315 template<class View>
1316 void
1318 // Drop elements from 0..i-1
1319 assert(i>=0);
1320 for (int j=0; j<i; j++)
1321 x[j].cancel(home,a);
1322 x += i; n -= i;
1323 }
1324
1325 template<class View>
1326 void
1328 // Drop elements from i+1..n-1
1329 assert(i<n);
1330 for (int j=i+1; j<n; j++)
1331 x[j].cancel(home,a);
1332 n = i+1;
1333 }
1334
1335 template<class View>
1336 void
1338 n = y.n;
1339 if (n > 0) {
1340 x = home.alloc<View>(n);
1341 for (int i=0; i<n; i++)
1342 x[i].update(home, y.x[i]);
1343 } else {
1344 x = nullptr;
1345 }
1346 }
1347
1348 template<class View>
1349 void
1351 bool schedule) {
1352 for (int i=0; i<n; i++)
1353 x[i].subscribe(home,p,pc,schedule);
1354 }
1355
1356 template<class View>
1357 void
1359 for (int i=0; i<n; i++)
1360 x[i].cancel(home,p,pc);
1361 }
1362
1363 template<class View>
1364 void
1366 for (int i=0; i<n; i++)
1367 x[i].subscribe(home,a);
1368 }
1369
1370 template<class View>
1371 void
1373 for (int i=0; i<n; i++)
1374 x[i].cancel(home,a);
1375 }
1376
1377 template<class View>
1378 void
1380 for (int i=0; i<n; i++)
1381 x[i].reschedule(home,p,pc);
1382 }
1383
1384 template<class View>
1385 forceinline bool
1387 for (int i=0; i<n; i++)
1388 if (!x[i].assigned())
1389 return false;
1390 return true;
1391 }
1392
1393 template<class View>
1394 bool
1396 if (n < 2)
1397 return false;
1398 Region r;
1399 View* y = r.alloc<View>(n);
1400 int j=0;
1401 for (int i=0; i<n; i++)
1402 if (!x[i].assigned())
1403 y[j++] = x[i];
1404 if (j < 2)
1405 return false;
1407 for (int i=1; i<j; i++)
1408 if (y[i-1] == y[i])
1409 return true;
1410 return false;
1411 }
1412
1413 template<class View>
1414 bool
1415 ViewArray<View>::same(const View& y) const {
1416 if (y.assigned())
1417 return false;
1418 for (int i=0; i<n; i++)
1419 if (x[i] == y)
1420 return true;
1421 return false;
1422 }
1423
1424 template<class View>
1425 void
1427 if (n < 2)
1428 return;
1429 Region r;
1431 for (int i=0; i<n; i++) {
1432 o[i].x = x[i]; o[i].i = i;
1433 }
1435 // Assign bucket numbers
1436 int* bkt = r.alloc<int>(n);
1437 int b = 0;
1438 bkt[o[0].i] = b;
1439 for (int i=1; i<n; i++) {
1440 if (o[i-1].x != o[i].x)
1441 b++;
1442 bkt[o[i].i] = b;
1443 }
1444 // Eliminate duplicate elements
1445 Support::BitSet<Region> seen(r,static_cast<unsigned int>(b+1));
1446 int j=0;
1447 for (int i=0; i<n; i++)
1448 if (!seen.get(static_cast<unsigned int>(bkt[i]))) {
1449 x[j++]=x[i]; seen.set(static_cast<unsigned int>(bkt[i]));
1450 } else {
1451 x[j]=x[i];
1452 }
1453 assert(j == b+1);
1454 n = j;
1455 }
1456
1457
1458 /*
1459 * Sharing for view arrays
1460 *
1461 */
1462 template<class ViewX, class ViewY>
1463 bool
1465 if ((x.size() == 0) || (y.size() == 0))
1466 return false;
1467 Region r;
1468 void** px = r.alloc<void*>(x.size());
1469 int j=0;
1470 for (int i=0; i<x.size(); i++)
1471 if (!x[i].assigned() && x[i].varimp())
1472 px[j++] = x[i].varimp();
1473 if (j == 0)
1474 return false;
1475 void** py = r.alloc<void*>(y.size());
1476 int k=0;
1477 for (int i=0; i<y.size(); i++)
1478 if (!y[i].assigned() && y[i].varimp())
1479 py[k++] = y[i].varimp();
1480 if (k == 0)
1481 return false;
1482 return Kernel::duplicates(px,j,py,k);
1483 }
1484
1485 template<class ViewX, class ViewY>
1486 bool
1488 if (y.assigned() || !y.varimp())
1489 return false;
1490 for (int i=0; i<x.size(); i++)
1491 if (!x[i].assigned() && x[i].varimp() && (x[i].varimp() == y.varimp()))
1492 return true;
1493 return false;
1494 }
1495
1496 template<class ViewX, class ViewY>
1497 forceinline bool
1499 return shared(y,x);
1500 }
1501
1502 template<class View>
1503 bool
1505 if (x.size() < 2)
1506 return false;
1507 Region r;
1508 void** px = r.alloc<void*>(x.size());
1509 int j=0;
1510 for (int i=0; i<x.size(); i++)
1511 if (!x[i].assigned() && x[i].varimp())
1512 px[j++] = x[i].varimp();
1513 return (j > 2) && Kernel::duplicates(px,j);
1514 }
1515
1516
1517
1518 /*
1519 * Argument arrays: base class
1520 *
1521 */
1522
1523 template<class T>
1524 forceinline T*
1526 return (n > onstack_size) ?
1527 heap.alloc<T>(static_cast<unsigned int>(n)) : &onstack[0];
1528 }
1529
1530 template<class T>
1531 forceinline void
1533 if (n+i >= capacity) {
1534 assert(n+i >= onstack_size);
1535 int newCapacity = (3*capacity)/2;
1536 if (newCapacity <= n+i)
1537 newCapacity = n+i;
1538 T* newA = allocate(newCapacity);
1539 heap.copy<T>(newA,a,n);
1540 if (capacity > onstack_size)
1541 heap.free(a,capacity);
1542 capacity = newCapacity;
1543 a = newA;
1544 }
1545 }
1546
1547 template<class T>
1551
1552 template<class T>
1556
1557 template<class T>
1558 inline
1560 : n(aa.n), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1561 heap.copy<T>(a,aa.a,n);
1562 }
1563
1564 template<class T>
1565 inline
1566 ArgArrayBase<T>::ArgArrayBase(const std::vector<T>& aa)
1567 : n(static_cast<int>(aa.size())),
1569 if (n > 0)
1570 heap.copy<T>(a,aa.data(),n);
1571 }
1572
1573 template<class T>
1574 inline
1575 ArgArrayBase<T>::ArgArrayBase(std::initializer_list<T> aa)
1576 : n(static_cast<int>(aa.size())),
1578 int i=0;
1579 for (const T& x : aa)
1580 a[i++]=x;
1581 }
1582
1583 template<class T>
1586 if (capacity > onstack_size)
1587 heap.free(a,capacity);
1588 }
1589
1590 template<class T>
1593 if (&aa != this) {
1594 if (capacity > onstack_size)
1595 heap.free(a,capacity);
1596 n = aa.n;
1598 a = allocate(aa.n);
1599 heap.copy<T>(a,aa.a,n);
1600 }
1601 return *this;
1602 }
1603
1604 template<class T>
1605 forceinline int
1607 return n;
1608 }
1609
1610 template<class T>
1611 forceinline T&
1613 assert((i>=0) && (i < n));
1614 return a[i];
1615 }
1616
1617 template<class T>
1618 forceinline const T&
1620 assert((i>=0) && (i < n));
1621 return a[i];
1622 }
1623
1624 template<class T>
1627 return a;
1628 }
1629
1630 template<class T>
1633 return a;
1634 }
1635
1636 template<class T>
1639 return a+n;
1640 }
1641
1642 template<class T>
1645 return a+n;
1646 }
1647
1648 template<class T>
1651 return reverse_iterator(a+n);
1652 }
1653
1654 template<class T>
1657 return const_reverse_iterator(a+n);
1658 }
1659
1660 template<class T>
1663 return reverse_iterator(a);
1664 }
1665
1666 template<class T>
1669 return const_reverse_iterator(a);
1670 }
1671
1672 template<class T> template<class A>
1673 A
1674 ArgArrayBase<T>::slice(int start, int inc, int maxN) {
1675 assert(n==0 || start < n);
1676 if (n==0 || maxN<0)
1677 maxN = n;
1678 int s;
1679 if (inc == 0)
1680 s = n-start;
1681 else if (inc > 0)
1682 s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
1683 else
1684 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1685 A r(std::min(maxN,s));
1686 for (int i=0; i<r.size(); i++, start+=inc)
1687 new (&r[i]) T(a[start]);
1688 return r;
1689 }
1690
1691 template<class T> template<class A>
1692 inline A&
1694 resize(1);
1695 new (&a[n++]) T(x);
1696 return static_cast<A&>(*this);
1697 }
1698
1699 template<class T>
1700 template<class InputIterator>
1701 inline
1702 ArgArrayBase<T>::ArgArrayBase(InputIterator first, InputIterator last)
1703 : n(0), capacity(onstack_size), a(allocate(0)) {
1704 while (first != last) {
1705 (void) append<ArgArrayBase<T>>(*first);
1706 ++first;
1707 }
1708 }
1709
1710
1711 template<class T> template<class A>
1712 inline A&
1714 resize(x.size());
1715 for (int i=0; i<x.size(); i++)
1716 new (&a[n++]) T(x[i]);
1717 return static_cast<A&>(*this);
1718 }
1719
1720 template<class T> template<class A>
1721 inline A
1723 A r(n+x.n);
1724 for (int i=0; i<n; i++)
1725 new (&r[i]) T(a[i]);
1726 for (int i=0; i<x.n; i++)
1727 new (&r[n+i]) T(x.a[i]);
1728 return r;
1729 }
1730
1731 template<class T> template<class A>
1732 inline A
1733 ArgArrayBase<T>::concat(const T& x) const {
1734 A r(n+1);
1735 for (int i=0; i<n; i++)
1736 new (&r[i]) T(a[i]);
1737 new (&r[n]) T(x);
1738 return r;
1739 }
1740
1741
1742 /*
1743 * Argument arrays
1744 *
1745 */
1746
1747 template<class T>
1750
1751 template<class T>
1755
1756 template<class T>
1757 ArgArray<T>::ArgArray(int n, const T* a0)
1758 : ArgArrayBase<T>(n) {
1759 for (int i=0; i<n; i++)
1760 a[i] = a0[i];
1761 }
1762
1763 template<class T>
1767
1768 template<class T>
1770 ArgArray<T>::ArgArray(const std::vector<T>& aa)
1771 : ArgArrayBase<T>(aa) {}
1772
1773 template<class T>
1775 ArgArray<T>::ArgArray(std::initializer_list<T> aa)
1776 : ArgArrayBase<T>(aa) {}
1777
1778 template<class T>
1779 template<class InputIterator>
1781 ArgArray<T>::ArgArray(InputIterator first, InputIterator last)
1782 : ArgArrayBase<T>(first,last) {}
1783
1784 template<class T>
1786 ArgArray<T>::slice(int start, int inc, int maxN) {
1789 (start,inc,maxN);
1790 }
1791
1792 template<class T>
1799
1800 template<class T>
1807
1808 template<class T>
1810 operator +(const ArgArray<T>& x, const ArgArray<T>& y) {
1811 return x.template concat
1812 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1813 }
1814
1815 template<class T>
1817 operator +(const ArgArray<T>& x, const T& y) {
1818 return x.template concat
1819 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1820 }
1821
1822 template<class T>
1824 operator +(const T& x, const ArgArray<T>& y) {
1825 ArgArray<T> xa(1);
1826 xa[0] = x;
1827 return xa.template concat
1828 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1829 }
1830
1831 /*
1832 * Argument arrays for variables
1833 *
1834 */
1835
1836 template<class Var>
1839
1840 template<class Var>
1843
1844 template<class Var>
1848
1849 template<class Var>
1851 VarArgArray<Var>::VarArgArray(const std::vector<Var>& aa)
1852 : ArgArrayBase<Var>(aa) {}
1853
1854 template<class Var>
1856 VarArgArray<Var>::VarArgArray(std::initializer_list<Var> aa)
1857 : ArgArrayBase<Var>(aa) {}
1858
1859 template<class Var>
1860 template<class InputIterator>
1862 VarArgArray<Var>::VarArgArray(InputIterator first, InputIterator last)
1863 : ArgArrayBase<Var>(first,last) {}
1864
1865 template<class Var>
1866 inline
1868 : ArgArrayBase<Var>(x.size()) {
1869 for (int i=0; i<x.size(); i++)
1870 a[i]=x[i];
1871 }
1872
1873 template<class Var>
1875 VarArgArray<Var>::slice(int start, int inc, int maxN) {
1878 (start,inc,maxN);
1879 }
1880
1881 template<class Var>
1888
1889 template<class Var>
1896
1897 template<class Var>
1900 return x.template concat
1902 }
1903
1904 template<class Var>
1906 operator +(const VarArgArray<Var>& x, const Var& y) {
1907 return x.template concat
1909 }
1910
1911 template<class Var>
1913 operator +(const Var& x, const VarArgArray<Var>& y) {
1914 VarArgArray<Var> xa(1);
1915 xa[0] = x;
1916 return xa.template concat
1918 }
1919
1920 template<class Var>
1921 forceinline bool
1923 for (int i=0; i<n; i++)
1924 if (!a[i].assigned())
1925 return false;
1926 return true;
1927 }
1928
1929
1930 /*
1931 * Checking for multiple occurrences of the same variable
1932 *
1933 */
1934 template<class Var>
1935 bool
1937 if ((x.size() == 0) || (y.size() == 0))
1938 return false;
1939 Region r;
1940 void** px = r.alloc<void*>(x.size());
1941 int j=0;
1942 for (int i=0; i<x.size(); i++)
1943 if (!x[i].assigned())
1944 px[j++] = x[i].varimp();
1945 if (j == 0)
1946 return false;
1947 void** py = r.alloc<void*>(y.size());
1948 int k=0;
1949 for (int i=0; i<y.size(); i++)
1950 if (!y[i].assigned())
1951 py[k++] = y[i].varimp();
1952 if (k == 0)
1953 return false;
1954 return Kernel::duplicates(px,j,py,k);
1955 }
1956
1957 template<class Var>
1958 bool
1960 if (y.assigned())
1961 return false;
1962 for (int i=0; i<x.size(); i++)
1963 if (x[i].varimp() == y.varimp())
1964 return true;
1965 return false;
1966 }
1967
1968 template<class Var>
1969 forceinline bool
1971 return same(y,x);
1972 }
1973
1974 template<class Var>
1975 bool
1977 if (x.size() < 2)
1978 return false;
1979 Region r;
1980 void** px = r.alloc<void*>(x.size());
1981 int j=0;
1982 for (int i=0; i<x.size(); i++)
1983 if (!x[i].assigned())
1984 px[j++] = x[i].varimp();
1985 return (j > 1) && Kernel::duplicates(px,j);
1986 }
1987
1988
1989
1990 /*
1991 * Interdependent code
1992 *
1993 */
1994
1995 template<class Var>
1996 inline
1998 : n(a.size()) {
1999 if (n>0) {
2000 x = home.alloc<Var>(n);
2001 for (int i=0; i<n; i++)
2002 x[i] = a[i];
2003 } else {
2004 x = nullptr;
2005 }
2006 }
2007
2008
2009 /*
2010 * Printing of arrays
2011 *
2012 */
2013 template<class Char, class Traits, class Var>
2014 std::basic_ostream<Char,Traits>&
2015 operator <<(std::basic_ostream<Char,Traits>& os,
2016 const VarArray<Var>& x) {
2017 std::basic_ostringstream<Char,Traits> s;
2018 s.copyfmt(os); s.width(0);
2019 s << '{';
2020 if (x.size() > 0) {
2021 s << x[0];
2022 for (int i=1; i<x.size(); i++)
2023 s << ", " << x[i];
2024 }
2025 s << '}';
2026 return os << s.str();
2027 }
2028
2029 template<class Char, class Traits, class View>
2030 std::basic_ostream<Char,Traits>&
2031 operator <<(std::basic_ostream<Char,Traits>& os,
2032 const ViewArray<View>& x) {
2033 std::basic_ostringstream<Char,Traits> s;
2034 s.copyfmt(os); s.width(0);
2035 s << '{';
2036 if (x.size() > 0) {
2037 s << x[0];
2038 for (int i=1; i<x.size(); i++)
2039 s << ", " << x[i];
2040 }
2041 s << '}';
2042 return os << s.str();
2043 }
2044
2045 template<class Char, class Traits, class T>
2046 std::basic_ostream<Char,Traits>&
2047 operator <<(std::basic_ostream<Char,Traits>& os,
2048 const ArgArrayBase<T>& x) {
2049 std::basic_ostringstream<Char,Traits> s;
2050 s.copyfmt(os); s.width(0);
2051 s << '{';
2052 if (x.size() > 0) {
2053 s << x[0];
2054 for (int i=1; i<x.size(); i++)
2055 s << ", " << x[i];
2056 }
2057 s << '}';
2058 return os << s.str();
2059 }
2060
2061}
2062
2063// STATISTICS: kernel-other
Base-class for advisors.
Definition core.hpp:1308
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:1525
static const int onstack_size
Definition array.hpp:550
const ArgArrayBase< T > & operator=(const ArgArrayBase< T > &a)
Initialize from view array a (copy elements).
Definition array.hpp:1592
int onstack[onstack_size]
Definition array.hpp:552
const T * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:588
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1668
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1656
T value_type
Type of the view stored in this array.
Definition array.hpp:580
ArgArrayBase(int n)
Allocate array with n elements.
Definition array.hpp:1554
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1650
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1644
void resize(int i)
Resize to hold at least i additional elements.
Definition array.hpp:1532
~ArgArrayBase(void)
Destructor.
Definition array.hpp:1585
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:594
ArgArrayBase(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1575
A concat(const ArgArrayBase< T > &x) const
Return this array concatenated with x.
Definition array.hpp:1722
A concat(const T &x) const
Return this array concatenated with x.
Definition array.hpp:1733
A & append(const ArgArrayBase< T > &x)
Append x to the end of the array.
Definition array.hpp:1713
ArgArrayBase(InputIterator first, InputIterator last)
Initialize from InputIterator begin and end.
Definition array.hpp:1702
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1662
T * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:590
ArgArrayBase(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1566
A slice(int start, int inc=1, int n=-1)
Definition array.hpp:1674
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:1632
T & operator[](int i)
Return element at position i.
Definition array.hpp:1612
T * pointer
Type of a pointer to the value type.
Definition array.hpp:586
A & append(const T &x)
Insert a new element x at the end of the array (increase size by 1).
Definition array.hpp:1693
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:1638
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:1626
ArgArrayBase(const ArgArrayBase< T > &a)
Initialize from argument array a (copy elements).
Definition array.hpp:1559
ArgArrayBase(void)
Allocate empty array.
Definition array.hpp:1549
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1606
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:1781
ArgArray(const ArgArray< T > &a)
Initialize from argument array a (copy elements).
Definition array.hpp:1765
ArrayTraits< ArgArray< T > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1786
ArgArray(int n)
Allocate array with n elements.
Definition array.hpp:1753
ArgArray(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1775
ArgArray(int n, const T *e)
Allocate array with n elements and initialize with elements from array e.
Definition array.hpp:1757
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:1810
ArgArray(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1770
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:1794
Traits of arrays in Gecode.
Definition array.hpp:94
FloatValImpType x
Implementation of float value.
Definition float.hh:420
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
Computation spaces.
Definition core.hpp:1787
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2973
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:790
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:1936
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1875
VarArgArray & operator=(const VarArgArray &)=default
Assignment operator.
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1922
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:1883
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:1899
bool same(Var x, VarArgArray< Var > y)
Test whether array y contains variable x.
Definition array.hpp:1970
bool same(VarArgArray< Var > x, Var y)
Test whether array x contains variable y.
Definition array.hpp:1959
VarArgArray(void)
Allocate empty array.
Definition array.hpp:1838
Variable arrays
Definition array.hpp:112
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1045
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1008
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:938
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Definition array.hpp:965
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1026
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:990
VarArray(void)
Default constructor (array of size 0).
Definition array.hpp:920
std::reverse_iterator< Var * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:136
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1002
int size(void) const
Return size of array (number of elements).
Definition array.hpp:945
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:1032
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:984
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
VarArray(Space &home, int m)
Allocate array with m variables.
Definition array.hpp:924
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:951
VarArray(Space &home, const VarArgArray< Var > &)
Initialize from variable argument array a (copy elements).
Definition array.hpp:1997
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:996
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1020
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
VarArray(const VarArray< Var > &a)
Initialize from variable array a (share elements).
Definition array.hpp:932
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1014
Base class for variables.
Definition var.hpp:40
View arrays.
Definition array.hpp:255
void cancel(Space &home, Advisor &a)
Cancel subscription of advisor a.
Definition array.hpp:1372
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition array.hpp:1337
bool same(const View &y) const
Test whether array contains a view being the same as y.
Definition array.hpp:1415
void drop_fst(int i, Space &home, Propagator &p, PropCond pc)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1281
const View & const_reference
Type of a constant reference to the value type.
Definition array.hpp:269
void move_fst(int i, Space &home, Propagator &p, PropCond pc)
Move view from position 0 to position i (shift elements to the left).
Definition array.hpp:1265
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:1197
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Test whether array x together with array y contains shared views.
Definition array.hpp:1464
View * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:275
void subscribe(Space &home, Advisor &a)
Subscribe advisor a to variable.
Definition array.hpp:1365
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:1379
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:1177
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1233
const View * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:277
void drop_lst(int i, Space &home, Propagator &p, PropCond pc)
Drop assigned views from positions i+1 to size()-1 from array.
Definition array.hpp:1291
ViewArray(Space &home, const ViewArray< View > &a)
Initialize from view array a (copy elements).
Definition array.hpp:1129
void drop_fst(int i)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1251
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1227
bool shared(ViewArray< ViewX > x, ViewY y)
Test whether array x contains a view shared with y.
Definition array.hpp:1487
void drop_fst(int i, Space &home, Advisor &a)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1317
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:279
void move_fst(int i, Space &home, Advisor &a)
Move view from position 0 to position i (shift elements to the left).
Definition array.hpp:1301
void move_lst(int i, Space &home, Advisor &a)
Move view from position size()-1 to position i (truncate array by one).
Definition array.hpp:1309
ViewArray(const ViewArray< View > &a)
Initialize from view array a (share elements).
Definition array.hpp:1153
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1215
const ViewArray< View > & operator=(const ViewArray< View > &a)
Initialize from view array a (share elements).
Definition array.hpp:1158
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:1191
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:1426
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
Definition array.hpp:1358
void drop_lst(int i)
Drop views from positions i+1 to size()-1 from array.
Definition array.hpp:1258
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1221
void drop_lst(int i, Space &home, Advisor &a)
Drop assigned views from positions i+1 to size()-1 from array.
Definition array.hpp:1327
void move_lst(int i)
Move view from position size()-1 to position i (truncate array by one).
Definition array.hpp:1245
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1209
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition array.hpp:1350
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1386
ViewArray(void)
Default constructor (array of size 0).
Definition array.hpp:1113
void move_lst(int i, Space &home, Propagator &p, PropCond pc)
Move view from position size()-1 to position i (truncate array by one).
Definition array.hpp:1273
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1203
ViewArray(Region &r, const ViewArray< View > &a)
Initialize from view array a (copy elements).
Definition array.hpp:1140
bool same(void) const
Test whether array has multiple occurrence of the same view.
Definition array.hpp:1395
ViewArray(Region &r, int m)
Allocate array with m views.
Definition array.hpp:1123
ViewArray(Space &home, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements).
Definition array.hpp:307
ViewArray(Space &home, int m)
Allocate array with m views.
Definition array.hpp:1117
void move_fst(int i)
Move view from position 0 to position i (shift elements to the left).
Definition array.hpp:1239
bool shared(ViewX x, ViewArray< ViewY > y)
Test whether array y contains a view shared with x.
Definition array.hpp:1498
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:1504
void size(int n)
Decrease size of array (number of elements).
Definition array.hpp:1171
Heap heap
The single global heap.
Definition heap.cpp:44
#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).
Definition array.cpp:39
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:165
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition val-sel.hpp:39
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1936
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1464
int PropCond
Type for propagation conditions.
Definition core.hpp:77
Gecode::IntArgs i({1, 2, 3, 4})
#define forceinline
Definition config.hpp:144