Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.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.org>
5 * Guido Tack <tack@gecode.org>
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.org
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 private:
206 static void* operator new(size_t) throw();
207 static void operator delete(void*,size_t);
208 };
209
213 template<class T>
216
220 template<class T>
223
227 template<class T>
230
234 template<class T>
236 operator +(const VarArray<T>& x, const T& y);
237
241 template<class T>
243 operator +(const T& x, const VarArray<T>& y);
244
252 template<class View>
253 class ViewArray {
254 private:
256 int n;
258 View* x;
259 public:
261
262
265 typedef View& reference;
267 typedef const View& const_reference;
269 typedef View* pointer;
271 typedef const View* const_pointer;
273 typedef View* iterator;
275 typedef const View* const_iterator;
277 typedef std::reverse_iterator<View*> reverse_iterator;
279 typedef std::reverse_iterator<const View*> const_reverse_iterator;
281
283
284
287 ViewArray(Space& home, int m);
304 template<class Var>
306 : n(a.size()) {
307 // This may not be in the hpp file (to satisfy the MS compiler)
308 if (n>0) {
309 x = home.alloc<View>(n);
310 for (int i=0; i<n; i++)
311 x[i]=a[i];
312 } else {
313 x = nullptr;
314 }
315 }
316
322 template<class Var>
324 : n(a.size()) {
325 // This may not be in the hpp file (to satisfy the MS compiler)
326 if (n>0) {
327 x = r.alloc<View>(n);
328 for (int i=0; i<n; i++)
329 x[i]=a[i];
330 } else {
331 x = nullptr;
332 }
333 }
334
335
337
338
339 int size(void) const;
341 void size(int n);
343
345
346
349 const View& operator [](int i) const;
351
353
354
361 const_iterator end(void) const;
371
373
374
381 void subscribe(Space& home, Propagator& p, PropCond pc,
382 bool schedule=true);
384 void cancel(Space& home, Propagator& p, PropCond pc);
386 void subscribe(Space& home, Advisor& a);
388 void cancel(Space& home, Advisor& a);
390 void reschedule(Space& home, Propagator& p, PropCond pc);
392
394
395
396 void update(Space& home, ViewArray<View>& a);
398
399
401
402
403 void move_fst(int i);
405 void move_lst(int i);
411 void move_fst(int i, Space& home, Propagator& p, PropCond pc);
417 void move_lst(int i, Space& home, Propagator& p, PropCond pc);
423 void move_fst(int i, Space& home, Advisor& a);
429 void move_lst(int i, Space& home, Advisor& a);
431
433
434
435 void drop_fst(int i);
437 void drop_lst(int i);
443 void drop_fst(int i, Space& home, Propagator& p, PropCond pc);
450 void drop_lst(int i, Space& home, Propagator& p, PropCond pc);
456 void drop_fst(int i, Space& home, Advisor& a);
462 void drop_lst(int i, Space& home, Advisor& a);
464
466 bool assigned(void) const;
467
469
470
475 bool same(void) const;
481 bool same(const View& y) const;
483 void unique(void);
485 private:
486 static void* operator new(size_t) throw();
487 static void operator delete(void*,size_t);
488 };
489
490
497 template<class ViewX, class ViewY>
505 template<class ViewX, class ViewY>
506 bool shared(ViewArray<ViewX> x, ViewY y);
513 template<class ViewX, class ViewY>
514 bool shared(ViewX x, ViewArray<ViewY> y);
521 template<class View>
523
524
536 template<class T>
538 protected:
540 int n;
544 T* a;
546 static const int onstack_size = 16;
550 T* allocate(int n);
552 void resize(int i);
554 template<class A>
555 A concat(const ArgArrayBase<T>& x) const;
557 template<class A>
558 A concat(const T& x) const;
560 template<class A>
561 A& append(const T& x);
563 template<class A>
570 template<class A>
571 A slice(int start, int inc=1, int n=-1);
572 public:
574
575
576 typedef T value_type;
578 typedef T& reference;
580 typedef const T& const_reference;
582 typedef T* pointer;
584 typedef const T* const_pointer;
586 typedef T* iterator;
588 typedef const T* const_iterator;
590 typedef std::reverse_iterator<T*> reverse_iterator;
592 typedef std::reverse_iterator<const T*> const_reverse_iterator;
594
596
597
600 explicit ArgArrayBase(int n);
606 ArgArrayBase(const std::vector<T>& a);
608 ArgArrayBase(std::initializer_list<T> a);
610 template<class InputIterator>
611 ArgArrayBase(InputIterator first, InputIterator last);
613
615
616
617 int size(void) const;
619
621
622
623 T& operator [](int i);
625 const T& operator [](int i) const;
627
629
630
637 const_iterator end(void) const;
647
649
650
653 };
654
655
656 template<class> class ArgArray;
657
661 template<class T>
664
668 template<class T>
670 operator +(const ArgArray<T>& x, const T& y);
671
675 template<class T>
677 operator +(const T& x, const ArgArray<T>& y);
678
690 template<class T>
691 class ArgArray : public ArgArrayBase<T> {
692 protected:
693 using ArgArrayBase<T>::a;
694 public:
695 using ArgArrayBase<T>::size;
697
698
699 ArgArray(void);
701 explicit ArgArray(int n);
703 ArgArray(int n, const T* e);
707 ArgArray(const std::vector<T>& a);
709 ArgArray(std::initializer_list<T> a);
711 template<class InputIterator>
712 ArgArray(InputIterator first, InputIterator last);
714
716
718 slice(int start, int inc=1, int n=-1);
720
722
724 operator <<(const T& x);
727 operator <<(const ArgArray<T>& x);
729
730 friend typename ArrayTraits<ArgArray<T>>::ArgsType
732 friend typename ArrayTraits<ArgArray<T>>::ArgsType
733 operator + <>(const ArgArray<T>& x, const T& y);
734 friend
736 operator + <>(const T& x, const ArgArray<T>& y);
737
739 ArgArray& operator =(const ArgArray&) = default;
740 };
741
742 template<class> class VarArgArray;
743
747 template<class Var>
750
754 template<class Var>
757
761 template<class Var>
764
776 template<class Var>
777 class VarArgArray : public ArgArrayBase<Var> {
778 protected:
779 using ArgArrayBase<Var>::a;
780 using ArgArrayBase<Var>::n;
781 public:
782 using ArgArrayBase<Var>::size;
784
785
788 explicit VarArgArray(int n);
794 VarArgArray(const std::vector<Var>& a);
796 VarArgArray(std::initializer_list<Var> a);
798 template<class InputIterator>
799 VarArgArray(InputIterator first, InputIterator last);
801
803
805 slice(int start, int inc=1, int n=-1);
807
809
811 operator <<(const Var& x);
816
818 bool assigned(void) const;
819
823 operator + <>(const VarArgArray<Var>& x, const Var& y);
824 friend
826 operator + <>(const Var& x, const VarArgArray<Var>& y);
827
830 };
831
832
839 template<class Var>
847 template<class Var>
855 template<class Var>
863 template<class Var>
865
866
871 template<class Char, class Traits, class Var>
872 std::basic_ostream<Char,Traits>&
873 operator <<(std::basic_ostream<Char,Traits>& os,
874 const VarArray<Var>& x);
875
880 template<class Char, class Traits, class View>
881 std::basic_ostream<Char,Traits>&
882 operator <<(std::basic_ostream<Char,Traits>& os, const ViewArray<View>& x);
883
888 template<class Char, class Traits, class T>
889 std::basic_ostream<Char,Traits>&
890 operator <<(std::basic_ostream<Char,Traits>& os, const ArgArrayBase<T>& x);
891
892
893 /*
894 * Implementation
895 *
896 */
897
898 /*
899 * Variable arrays
900 *
901 * These arrays are allocated in the space.
902 *
903 */
904
905 template<class Var>
907 VarArray<Var>::VarArray(void) : n(0), x(nullptr) {}
908
909 template<class Var>
912 : n(n0) {
913 // Allocate from space
914 x = (n>0) ? home.alloc<Var>(n) : nullptr;
915 }
916
917 template<class Var>
920 n = a.n; x = a.x;
921 }
922
923 template<class Var>
924 inline const VarArray<Var>&
926 n = a.n; x = a.x;
927 return *this;
928 }
929
930 template<class Var>
931 forceinline int
933 return n;
934 }
935
936 template<class Var>
939 assert((i >= 0) && (i < size()));
940 return x[i];
941 }
942
943 template<class Var>
944 forceinline const Var&
946 assert((i >= 0) && (i < size()));
947 return x[i];
948 }
949
950 template<class Var>
952 VarArray<Var>::slice(int start, int inc, int maxN) {
953 assert(n==0 || start < n);
954 if (n==0 || maxN<0)
955 maxN = n;
956 int s;
957 if (inc == 0)
958 s = n-start;
959 else if (inc > 0)
960 s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
961 else
962 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
963 typename ArrayTraits<VarArgArray<Var>>::ArgsType r(std::min(maxN,s));
964 for (int i=0; i<r.size(); i++, start+=inc)
965 r[i] = x[start];
966 return r;
967 }
968
969 template<class Var>
972 return x;
973 }
974
975 template<class Var>
978 return x;
979 }
980
981 template<class Var>
984 return x+n;
985 }
986
987 template<class Var>
989 VarArray<Var>::end(void) const {
990 return x+n;
991 }
992
993 template<class Var>
996 return reverse_iterator(x+n);
997 }
998
999 template<class Var>
1002 return const_reverse_iterator(x+n);
1003 }
1004
1005 template<class Var>
1008 return reverse_iterator(x);
1009 }
1010
1011 template<class Var>
1014 return const_reverse_iterator(x);
1015 }
1016
1017 template<class Var>
1018 forceinline void
1020 n = a.n;
1021 if (n > 0) {
1022 x = home.alloc<Var>(n);
1023 for (int i=0; i<n; i++)
1024 x[i].update(home, a.x[i]);
1025 } else {
1026 x = nullptr;
1027 }
1028 }
1029
1030 template<class Var>
1031 forceinline bool
1033 for (int i=0; i<n; i++)
1034 if (!x[i].assigned())
1035 return false;
1036 return true;
1037 }
1038
1039 template<class Var>
1040 forceinline void*
1041 VarArray<Var>::operator new(size_t) throw() {
1042 return nullptr;
1043 }
1044
1045 template<class Var>
1046 forceinline void
1047 VarArray<Var>::operator delete(void*,size_t) {
1048 }
1049
1050 template<class Var>
1051 typename ArrayTraits<VarArray<Var>>::ArgsType
1053 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1054 for (int i=0; i<x.size(); i++)
1055 r[i] = x[i];
1056 for (int i=0; i<y.size(); i++)
1057 r[x.size()+i] = y[i];
1058 return r;
1059 }
1060
1061 template<class Var>
1062 typename ArrayTraits<VarArray<Var>>::ArgsType
1064 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1065 for (int i=0; i<x.size(); i++)
1066 r[i] = x[i];
1067 for (int i=0; i<y.size(); i++)
1068 r[x.size()+i] = y[i];
1069 return r;
1070 }
1071
1072 template<class Var>
1073 typename ArrayTraits<VarArray<Var>>::ArgsType
1075 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1076 for (int i=0; i<x.size(); i++)
1077 r[i] = x[i];
1078 for (int i=0; i<y.size(); i++)
1079 r[x.size()+i] = y[i];
1080 return r;
1081 }
1082
1083 template<class Var>
1084 typename ArrayTraits<VarArray<Var>>::ArgsType
1085 operator +(const VarArray<Var>& x, const Var& y) {
1086 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+1);
1087 for (int i=0; i<x.size(); i++)
1088 r[i] = x[i];
1089 r[x.size()] = y;
1090 return r;
1091 }
1092
1093 template<class Var>
1094 typename ArrayTraits<VarArray<Var>>::ArgsType
1095 operator +(const Var& x, const VarArray<Var>& y) {
1096 typename ArrayTraits<VarArray<Var>>::ArgsType r(y.size()+1);
1097 r[0] = x;
1098 for (int i=0; i<y.size(); i++)
1099 r[1+i] = y[i];
1100 return r;
1101 }
1102
1103 /*
1104 * View arrays
1105 *
1106 */
1107
1108 template<class View>
1110 ViewArray<View>::ViewArray(void) : n(0), x(nullptr) {}
1111
1112 template<class View>
1115 : n(n0) {
1116 x = (n>0) ? home.alloc<View>(n) : nullptr;
1117 }
1118 template<class View>
1121 : n(n0) {
1122 x = (n>0) ? r.alloc<View>(n) : nullptr;
1123 }
1124
1125 template<class View>
1127 : n(a.size()) {
1128 if (n>0) {
1129 x = home.alloc<View>(n);
1130 for (int i=0; i<n; i++)
1131 x[i] = a[i];
1132 } else {
1133 x = nullptr;
1134 }
1135 }
1136 template<class View>
1138 : n(a.size()) {
1139 if (n>0) {
1140 x = r.alloc<View>(n);
1141 for (int i=0; i<n; i++)
1142 x[i] = a[i];
1143 } else {
1144 x = nullptr;
1145 }
1146 }
1147
1148 template<class View>
1151 : n(a.n), x(a.x) {}
1152
1153 template<class View>
1156 n = a.n; x = a.x;
1157 return *this;
1158 }
1159
1160 template<class View>
1161 forceinline int
1163 return n;
1164 }
1165
1166 template<class View>
1167 forceinline void
1169 n = n0;
1170 }
1171
1172 template<class View>
1175 assert((i >= 0) && (i < size()));
1176 return x[i];
1177 }
1178
1179 template<class View>
1180 forceinline const View&
1182 assert((i >= 0) && (i < size()));
1183 return x[i];
1184 }
1185
1186 template<class View>
1189 return x;
1190 }
1191
1192 template<class View>
1195 return x;
1196 }
1197
1198 template<class View>
1201 return x+n;
1202 }
1203
1204 template<class View>
1207 return x+n;
1208 }
1209
1210 template<class View>
1213 return reverse_iterator(x+n);
1214 }
1215
1216 template<class View>
1219 return const_reverse_iterator(x+n);
1220 }
1221
1222 template<class View>
1225 return reverse_iterator(x);
1226 }
1227
1228 template<class View>
1231 return const_reverse_iterator(x);
1232 }
1233
1234 template<class View>
1235 forceinline void
1237 x[i]=x[0]; x++; n--;
1238 }
1239
1240 template<class View>
1241 forceinline void
1243 n--; x[i]=x[n];
1244 }
1245
1246 template<class View>
1247 forceinline void
1249 assert(i>=0);
1250 x += i; n -= i;
1251 }
1252
1253 template<class View>
1254 forceinline void
1256 assert(i<n);
1257 n = i+1;
1258 }
1259
1260 template<class View>
1261 forceinline void
1263 // Move x[0] to x[i]
1264 x[i].cancel(home,p,pc);
1265 x[i]=x[0]; x++; n--;
1266 }
1267
1268 template<class View>
1269 forceinline void
1271 // Move x[n-1] to x[i]
1272 x[i].cancel(home,p,pc);
1273 n--; x[i]=x[n];
1274 }
1275
1276 template<class View>
1277 void
1279 // Drop elements from 0..i-1
1280 assert(i>=0);
1281 for (int j=0; j<i; j++)
1282 x[j].cancel(home,p,pc);
1283 x += i; n -= i;
1284 }
1285
1286 template<class View>
1287 void
1289 // Drop elements from i+1..n-1
1290 assert(i<n);
1291 for (int j=i+1; j<n; j++)
1292 x[j].cancel(home,p,pc);
1293 n = i+1;
1294 }
1295
1296 template<class View>
1297 forceinline void
1299 // Move x[0] to x[i]
1300 x[i].cancel(home,a);
1301 x[i]=x[0]; x++; n--;
1302 }
1303
1304 template<class View>
1305 forceinline void
1307 // Move x[n-1] to x[i]
1308 x[i].cancel(home,a);
1309 n--; x[i]=x[n];
1310 }
1311
1312 template<class View>
1313 void
1315 // Drop elements from 0..i-1
1316 assert(i>=0);
1317 for (int j=0; j<i; j++)
1318 x[j].cancel(home,a);
1319 x += i; n -= i;
1320 }
1321
1322 template<class View>
1323 void
1325 // Drop elements from i+1..n-1
1326 assert(i<n);
1327 for (int j=i+1; j<n; j++)
1328 x[j].cancel(home,a);
1329 n = i+1;
1330 }
1331
1332 template<class View>
1333 void
1335 n = y.n;
1336 if (n > 0) {
1337 x = home.alloc<View>(n);
1338 for (int i=0; i<n; i++)
1339 x[i].update(home, y.x[i]);
1340 } else {
1341 x = nullptr;
1342 }
1343 }
1344
1345 template<class View>
1346 void
1348 bool schedule) {
1349 for (int i=0; i<n; i++)
1350 x[i].subscribe(home,p,pc,schedule);
1351 }
1352
1353 template<class View>
1354 void
1356 for (int i=0; i<n; i++)
1357 x[i].cancel(home,p,pc);
1358 }
1359
1360 template<class View>
1361 void
1363 for (int i=0; i<n; i++)
1364 x[i].subscribe(home,a);
1365 }
1366
1367 template<class View>
1368 void
1370 for (int i=0; i<n; i++)
1371 x[i].cancel(home,a);
1372 }
1373
1374 template<class View>
1375 void
1377 for (int i=0; i<n; i++)
1378 x[i].reschedule(home,p,pc);
1379 }
1380
1381 template<class View>
1382 forceinline bool
1384 for (int i=0; i<n; i++)
1385 if (!x[i].assigned())
1386 return false;
1387 return true;
1388 }
1389
1390 template<class View>
1391 bool
1393 if (n < 2)
1394 return false;
1395 Region r;
1396 View* y = r.alloc<View>(n);
1397 int j=0;
1398 for (int i=0; i<n; i++)
1399 if (!x[i].assigned())
1400 y[j++] = x[i];
1401 if (j < 2)
1402 return false;
1404 for (int i=1; i<j; i++)
1405 if (y[i-1] == y[i])
1406 return true;
1407 return false;
1408 }
1409
1410 template<class View>
1411 bool
1413 if (y.assigned())
1414 return false;
1415 for (int i=0; i<n; i++)
1416 if (x[i] == y)
1417 return true;
1418 return false;
1419 }
1420
1421 template<class View>
1422 void
1424 if (n < 2)
1425 return;
1426 Region r;
1428 for (int i=0; i<n; i++) {
1429 o[i].x = x[i]; o[i].i = i;
1430 }
1432 // Assign bucket numbers
1433 int* bkt = r.alloc<int>(n);
1434 int b = 0;
1435 bkt[o[0].i] = b;
1436 for (int i=1; i<n; i++) {
1437 if (o[i-1].x != o[i].x)
1438 b++;
1439 bkt[o[i].i] = b;
1440 }
1441 // Eliminate duplicate elements
1442 Support::BitSet<Region> seen(r,static_cast<unsigned int>(b+1));
1443 int j=0;
1444 for (int i=0; i<n; i++)
1445 if (!seen.get(bkt[i])) {
1446 x[j++]=x[i]; seen.set(bkt[i]);
1447 } else {
1448 x[j]=x[i];
1449 }
1450 assert(j == b+1);
1451 n = j;
1452 }
1453
1454 template<class View>
1455 forceinline void*
1456 ViewArray<View>::operator new(size_t) throw() {
1457 return nullptr;
1458 }
1459
1460 template<class View>
1461 forceinline void
1462 ViewArray<View>::operator delete(void*,size_t) {
1463 }
1464
1465
1466 /*
1467 * Sharing for view arrays
1468 *
1469 */
1470 template<class ViewX, class ViewY>
1471 bool
1473 if ((x.size() == 0) || (y.size() == 0))
1474 return false;
1475 Region r;
1476 void** px = r.alloc<void*>(x.size());
1477 int j=0;
1478 for (int i=0; i<x.size(); i++)
1479 if (!x[i].assigned() && x[i].varimp())
1480 px[j++] = x[i].varimp();
1481 if (j == 0)
1482 return false;
1483 void** py = r.alloc<void*>(y.size());
1484 int k=0;
1485 for (int i=0; i<y.size(); i++)
1486 if (!y[i].assigned() && y[i].varimp())
1487 py[k++] = y[i].varimp();
1488 if (k == 0)
1489 return false;
1490 return Kernel::duplicates(px,j,py,k);
1491 }
1492
1493 template<class ViewX, class ViewY>
1494 bool
1496 if (y.assigned() || !y.varimp())
1497 return false;
1498 for (int i=0; i<x.size(); i++)
1499 if (!x[i].assigned() && x[i].varimp() && (x[i].varimp() == y.varimp()))
1500 return true;
1501 return false;
1502 }
1503
1504 template<class ViewX, class ViewY>
1505 forceinline bool
1507 return shared(y,x);
1508 }
1509
1510 template<class View>
1511 bool
1513 if (x.size() < 2)
1514 return false;
1515 Region r;
1516 void** px = r.alloc<void*>(x.size());
1517 int j=0;
1518 for (int i=0; i<x.size(); i++)
1519 if (!x[i].assigned() && x[i].varimp())
1520 px[j++] = x[i].varimp();
1521 return (j > 2) && Kernel::duplicates(px,j);
1522 }
1523
1524
1525
1526 /*
1527 * Argument arrays: base class
1528 *
1529 */
1530
1531 template<class T>
1532 forceinline T*
1534 return (n > onstack_size) ?
1535 heap.alloc<T>(static_cast<unsigned int>(n)) : &onstack[0];
1536 }
1537
1538 template<class T>
1539 forceinline void
1541 if (n+i >= capacity) {
1542 assert(n+i >= onstack_size);
1543 int newCapacity = (3*capacity)/2;
1544 if (newCapacity <= n+i)
1545 newCapacity = n+i;
1546 T* newA = allocate(newCapacity);
1547 heap.copy<T>(newA,a,n);
1548 if (capacity > onstack_size)
1549 heap.free(a,capacity);
1550 capacity = newCapacity;
1551 a = newA;
1552 }
1553 }
1554
1555 template<class T>
1559
1560 template<class T>
1564
1565 template<class T>
1566 inline
1568 : n(aa.n), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1569 heap.copy<T>(a,aa.a,n);
1570 }
1571
1572 template<class T>
1573 inline
1574 ArgArrayBase<T>::ArgArrayBase(const std::vector<T>& aa)
1575 : n(static_cast<int>(aa.size())),
1577 heap.copy<T>(a,&aa[0],n);
1578 }
1579
1580 template<class T>
1581 inline
1582 ArgArrayBase<T>::ArgArrayBase(std::initializer_list<T> aa)
1583 : n(static_cast<int>(aa.size())),
1585 int i=0;
1586 for (const T& x : aa)
1587 a[i++]=x;
1588 }
1589
1590 template<class T>
1593 if (capacity > onstack_size)
1594 heap.free(a,capacity);
1595 }
1596
1597 template<class T>
1600 if (&aa != this) {
1601 if (capacity > onstack_size)
1602 heap.free(a,capacity);
1603 n = aa.n;
1605 a = allocate(aa.n);
1606 heap.copy<T>(a,aa.a,n);
1607 }
1608 return *this;
1609 }
1610
1611 template<class T>
1612 forceinline int
1614 return n;
1615 }
1616
1617 template<class T>
1618 forceinline T&
1620 assert((i>=0) && (i < n));
1621 return a[i];
1622 }
1623
1624 template<class T>
1625 forceinline const T&
1627 assert((i>=0) && (i < n));
1628 return a[i];
1629 }
1630
1631 template<class T>
1634 return a;
1635 }
1636
1637 template<class T>
1640 return a;
1641 }
1642
1643 template<class T>
1646 return a+n;
1647 }
1648
1649 template<class T>
1652 return a+n;
1653 }
1654
1655 template<class T>
1658 return reverse_iterator(a+n);
1659 }
1660
1661 template<class T>
1664 return const_reverse_iterator(a+n);
1665 }
1666
1667 template<class T>
1670 return reverse_iterator(a);
1671 }
1672
1673 template<class T>
1676 return const_reverse_iterator(a);
1677 }
1678
1679 template<class T> template<class A>
1680 A
1681 ArgArrayBase<T>::slice(int start, int inc, int maxN) {
1682 assert(n==0 || start < n);
1683 if (n==0 || maxN<0)
1684 maxN = n;
1685 int s;
1686 if (inc == 0)
1687 s = n-start;
1688 else if (inc > 0)
1689 s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
1690 else
1691 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1692 A r(std::min(maxN,s));
1693 for (int i=0; i<r.size(); i++, start+=inc)
1694 new (&r[i]) T(a[start]);
1695 return r;
1696 }
1697
1698 template<class T> template<class A>
1699 inline A&
1701 resize(1);
1702 new (&a[n++]) T(x);
1703 return static_cast<A&>(*this);
1704 }
1705
1706 template<class T>
1707 template<class InputIterator>
1708 inline
1709 ArgArrayBase<T>::ArgArrayBase(InputIterator first, InputIterator last)
1710 : n(0), capacity(onstack_size), a(allocate(0)) {
1711 while (first != last) {
1712 (void) append<ArgArrayBase<T>>(*first);
1713 ++first;
1714 }
1715 }
1716
1717
1718 template<class T> template<class A>
1719 inline A&
1721 resize(x.size());
1722 for (int i=0; i<x.size(); i++)
1723 new (&a[n++]) T(x[i]);
1724 return static_cast<A&>(*this);
1725 }
1726
1727 template<class T> template<class A>
1728 inline A
1730 A r(n+x.n);
1731 for (int i=0; i<n; i++)
1732 new (&r[i]) T(a[i]);
1733 for (int i=0; i<x.n; i++)
1734 new (&r[n+i]) T(x.a[i]);
1735 return r;
1736 }
1737
1738 template<class T> template<class A>
1739 inline A
1740 ArgArrayBase<T>::concat(const T& x) const {
1741 A r(n+1);
1742 for (int i=0; i<n; i++)
1743 new (&r[i]) T(a[i]);
1744 new (&r[n]) T(x);
1745 return r;
1746 }
1747
1748
1749 /*
1750 * Argument arrays
1751 *
1752 */
1753
1754 template<class T>
1757
1758 template<class T>
1762
1763 template<class T>
1764 ArgArray<T>::ArgArray(int n, const T* a0)
1765 : ArgArrayBase<T>(n) {
1766 for (int i=0; i<n; i++)
1767 a[i] = a0[i];
1768 }
1769
1770 template<class T>
1774
1775 template<class T>
1777 ArgArray<T>::ArgArray(const std::vector<T>& aa)
1778 : ArgArrayBase<T>(aa) {}
1779
1780 template<class T>
1782 ArgArray<T>::ArgArray(std::initializer_list<T> aa)
1783 : ArgArrayBase<T>(aa) {}
1784
1785 template<class T>
1786 template<class InputIterator>
1788 ArgArray<T>::ArgArray(InputIterator first, InputIterator last)
1789 : ArgArrayBase<T>(first,last) {}
1790
1791 template<class T>
1793 ArgArray<T>::slice(int start, int inc, int maxN) {
1796 (start,inc,maxN);
1797 }
1798
1799 template<class T>
1806
1807 template<class T>
1814
1815 template<class T>
1818 return x.template concat
1820 }
1821
1822 template<class T>
1824 operator +(const ArgArray<T>& x, const T& y) {
1825 return x.template concat
1827 }
1828
1829 template<class T>
1831 operator +(const T& x, const ArgArray<T>& y) {
1832 ArgArray<T> xa(1);
1833 xa[0] = x;
1834 return xa.template concat
1836 }
1837
1838 /*
1839 * Argument arrays for variables
1840 *
1841 */
1842
1843 template<class Var>
1846
1847 template<class Var>
1850
1851 template<class Var>
1855
1856 template<class Var>
1858 VarArgArray<Var>::VarArgArray(const std::vector<Var>& aa)
1859 : ArgArrayBase<Var>(aa) {}
1860
1861 template<class Var>
1863 VarArgArray<Var>::VarArgArray(std::initializer_list<Var> aa)
1864 : ArgArrayBase<Var>(aa) {}
1865
1866 template<class Var>
1867 template<class InputIterator>
1869 VarArgArray<Var>::VarArgArray(InputIterator first, InputIterator last)
1870 : ArgArrayBase<Var>(first,last) {}
1871
1872 template<class Var>
1873 inline
1875 : ArgArrayBase<Var>(x.size()) {
1876 for (int i=0; i<x.size(); i++)
1877 a[i]=x[i];
1878 }
1879
1880 template<class Var>
1882 VarArgArray<Var>::slice(int start, int inc, int maxN) {
1885 (start,inc,maxN);
1886 }
1887
1888 template<class Var>
1895
1896 template<class Var>
1903
1904 template<class Var>
1907 return x.template concat
1909 }
1910
1911 template<class Var>
1914 return x.template concat
1916 }
1917
1918 template<class Var>
1921 VarArgArray<Var> xa(1);
1922 xa[0] = x;
1923 return xa.template concat
1925 }
1926
1927 template<class Var>
1928 forceinline bool
1930 for (int i=0; i<n; i++)
1931 if (!a[i].assigned())
1932 return false;
1933 return true;
1934 }
1935
1936
1937 /*
1938 * Checking for multiple occurences of the same variable
1939 *
1940 */
1941 template<class Var>
1942 bool
1944 if ((x.size() == 0) || (y.size() == 0))
1945 return false;
1946 Region r;
1947 void** px = r.alloc<void*>(x.size());
1948 int j=0;
1949 for (int i=0; i<x.size(); i++)
1950 if (!x[i].assigned())
1951 px[j++] = x[i].varimp();
1952 if (j == 0)
1953 return false;
1954 void** py = r.alloc<void*>(y.size());
1955 int k=0;
1956 for (int i=0; i<y.size(); i++)
1957 if (!y[i].assigned())
1958 py[k++] = y[i].varimp();
1959 if (k == 0)
1960 return false;
1961 return Kernel::duplicates(px,j,py,k);
1962 }
1963
1964 template<class Var>
1965 bool
1967 if (y.assigned())
1968 return false;
1969 for (int i=0; i<x.size(); i++)
1970 if (x[i].varimp() == y.varimp())
1971 return true;
1972 return false;
1973 }
1974
1975 template<class Var>
1976 forceinline bool
1978 return same(y,x);
1979 }
1980
1981 template<class Var>
1982 bool
1984 if (x.size() < 2)
1985 return false;
1986 Region r;
1987 void** px = r.alloc<void*>(x.size());
1988 int j=0;
1989 for (int i=0; i<x.size(); i++)
1990 if (!x[i].assigned())
1991 px[j++] = x[i].varimp();
1992 return (j > 1) && Kernel::duplicates(px,j);
1993 }
1994
1995
1996
1997 /*
1998 * Interdependent code
1999 *
2000 */
2001
2002 template<class Var>
2003 inline
2005 : n(a.size()) {
2006 if (n>0) {
2007 x = home.alloc<Var>(n);
2008 for (int i=0; i<n; i++)
2009 x[i] = a[i];
2010 } else {
2011 x = nullptr;
2012 }
2013 }
2014
2015
2016 /*
2017 * Printing of arrays
2018 *
2019 */
2020 template<class Char, class Traits, class Var>
2021 std::basic_ostream<Char,Traits>&
2022 operator <<(std::basic_ostream<Char,Traits>& os,
2023 const VarArray<Var>& 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 View>
2037 std::basic_ostream<Char,Traits>&
2038 operator <<(std::basic_ostream<Char,Traits>& os,
2039 const ViewArray<View>& 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 template<class Char, class Traits, class T>
2053 std::basic_ostream<Char,Traits>&
2054 operator <<(std::basic_ostream<Char,Traits>& os,
2055 const ArgArrayBase<T>& x) {
2056 std::basic_ostringstream<Char,Traits> s;
2057 s.copyfmt(os); s.width(0);
2058 s << '{';
2059 if (x.size() > 0) {
2060 s << x[0];
2061 for (int i=1; i<x.size(); i++)
2062 s << ", " << x[i];
2063 }
2064 s << '}';
2065 return os << s.str();
2066 }
2067
2068}
2069
2070// STATISTICS: kernel-other
Base-class for advisors.
Definition core.hpp:1294
Base-class for argument arrays.
Definition array.hpp:537
const T & const_reference
Type of a constant reference to the value type.
Definition array.hpp:580
T * allocate(int n)
Allocate memory for n elements.
Definition array.hpp:1533
static const int onstack_size
Definition array.hpp:546
const ArgArrayBase< T > & operator=(const ArgArrayBase< T > &a)
Initialize from view array a (copy elements)
Definition array.hpp:1599
int onstack[onstack_size]
Definition array.hpp:548
const T * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:584
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1675
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1663
T value_type
Type of the view stored in this array.
Definition array.hpp:576
ArgArrayBase(int n)
Allocate array with n elements.
Definition array.hpp:1562
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1657
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1651
void resize(int i)
Resize to hold at least i additional elements.
Definition array.hpp:1540
~ArgArrayBase(void)
Destructor.
Definition array.hpp:1592
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:590
ArgArrayBase(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1582
A concat(const ArgArrayBase< T > &x) const
Return this array concatenated with x.
Definition array.hpp:1729
A concat(const T &x) const
Return this array concatenated with x.
Definition array.hpp:1740
A & append(const ArgArrayBase< T > &x)
Append x to the end of the array.
Definition array.hpp:1720
ArgArrayBase(InputIterator first, InputIterator last)
Initialize from InputIterator begin and end.
Definition array.hpp:1709
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1669
T * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:586
ArgArrayBase(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1574
A slice(int start, int inc=1, int n=-1)
Definition array.hpp:1681
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:1639
T & operator[](int i)
Return element at position i.
Definition array.hpp:1619
T * pointer
Type of a pointer to the value type.
Definition array.hpp:582
A & append(const T &x)
Insert a new element x at the end of the array (increase size by 1)
Definition array.hpp:1700
T & reference
Type of a reference to the value type.
Definition array.hpp:578
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1645
const T * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:588
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:1633
ArgArrayBase(const ArgArrayBase< T > &a)
Initialize from argument array a (copy elements)
Definition array.hpp:1567
ArgArrayBase(void)
Allocate empty array.
Definition array.hpp:1557
int size(void) const
Return size of array (number of elements)
Definition array.hpp:1613
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:592
Argument array for non-primitive types.
Definition array.hpp:691
ArgArray(InputIterator first, InputIterator last)
Initialize from InputIterator first and last.
Definition array.hpp:1788
ArgArray(const ArgArray< T > &a)
Initialize from argument array a (copy elements)
Definition array.hpp:1772
ArrayTraits< ArgArray< T > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1793
ArgArray(int n)
Allocate array with n elements.
Definition array.hpp:1760
ArgArray(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1782
ArgArray(int n, const T *e)
Allocate array with n elements and initialize with elements from array e.
Definition array.hpp:1764
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:1817
ArgArray(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1777
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:1801
Traits of arrays in Gecode.
Definition array.hpp:94
FloatValImpType x
Implementation of float value.
Definition float.hh:425
Occurence 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:1066
Handle to region.
Definition region.hpp:55
Computation spaces.
Definition core.hpp:1744
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2841
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:777
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:1943
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1882
VarArgArray & operator=(const VarArgArray &)=default
Assignment operator.
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1929
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:1890
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:1906
bool same(Var x, VarArgArray< Var > y)
Test whether array y contains variable x.
Definition array.hpp:1977
bool same(VarArgArray< Var > x, Var y)
Test whether array x contains variable y.
Definition array.hpp:1966
VarArgArray(void)
Allocate empty array.
Definition array.hpp:1845
Variable arrays
Definition array.hpp:112
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1032
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:995
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:925
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Definition array.hpp:952
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1013
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:977
VarArray(void)
Default constructor (array of size 0)
Definition array.hpp:907
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:989
int size(void) const
Return size of array (number of elements)
Definition array.hpp:932
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:1019
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:971
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:911
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:938
VarArray(Space &home, const VarArgArray< Var > &)
Initialize from variable argument array a (copy elements)
Definition array.hpp:2004
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:983
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1007
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:919
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1001
Base class for variables.
Definition var.hpp:40
View arrays.
Definition array.hpp:253
void cancel(Space &home, Advisor &a)
Cancel subscription of advisor a.
Definition array.hpp:1369
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition array.hpp:1334
bool same(const View &y) const
Test whether array contains a view being the same as y.
Definition array.hpp:1412
void drop_fst(int i, Space &home, Propagator &p, PropCond pc)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1278
const View & const_reference
Type of a constant reference to the value type.
Definition array.hpp:267
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:1262
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:1194
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Test whether array x together with array y contains shared views.
Definition array.hpp:1472
View * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:273
void subscribe(Space &home, Advisor &a)
Subscribe advisor a to variable.
Definition array.hpp:1362
View & reference
Type of a reference to the value type.
Definition array.hpp:265
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition array.hpp:1376
View value_type
Type of the view stored in this array.
Definition array.hpp:263
View & operator[](int i)
Return view at position i.
Definition array.hpp:1174
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1230
const View * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:275
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:1288
ViewArray(Space &home, const ViewArray< View > &a)
Initialize from view array a (copy elements)
Definition array.hpp:1126
void drop_fst(int i)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1248
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1224
bool shared(ViewArray< ViewX > x, ViewY y)
Test whether array x contains a view shared with y.
Definition array.hpp:1495
void drop_fst(int i, Space &home, Advisor &a)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1314
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:277
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:1298
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:1306
ViewArray(const ViewArray< View > &a)
Initialize from view array a (share elements)
Definition array.hpp:1150
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1212
const ViewArray< View > & operator=(const ViewArray< View > &a)
Initialize from view array a (share elements)
Definition array.hpp:1155
const View * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:271
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:1188
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:279
ViewArray(Region &r, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
Definition array.hpp:323
void unique(void)
Remove all duplicate views from array (changes element order)
Definition array.hpp:1423
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
Definition array.hpp:1355
void drop_lst(int i)
Drop views from positions i+1 to size()-1 from array.
Definition array.hpp:1255
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1218
void drop_lst(int i, Space &home, Advisor &a)
Drop assigned views from positions i+1 to size()-1 from array.
Definition array.hpp:1324
void move_lst(int i)
Move view from position size()-1 to position i (truncate array by one)
Definition array.hpp:1242
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1206
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition array.hpp:1347
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1383
ViewArray(void)
Default constructor (array of size 0)
Definition array.hpp:1110
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:1270
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1200
ViewArray(Region &r, const ViewArray< View > &a)
Initialize from view array a (copy elements)
Definition array.hpp:1137
bool same(void) const
Test whether array has multiple occurence of the same view.
Definition array.hpp:1392
ViewArray(Region &r, int m)
Allocate array with m views.
Definition array.hpp:1120
ViewArray(Space &home, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
Definition array.hpp:305
ViewArray(Space &home, int m)
Allocate array with m views.
Definition array.hpp:1114
void move_fst(int i)
Move view from position 0 to position i (shift elements to the left)
Definition array.hpp:1236
bool shared(ViewX x, ViewArray< ViewY > y)
Test whether array y contains a view shared with x.
Definition array.hpp:1506
View * pointer
Type of a pointer to the value type.
Definition array.hpp:269
bool shared(ViewArray< View > x)
Test whether array x contains shared views.
Definition array.hpp:1512
void size(int n)
Decrease size of array (number of elements)
Definition array.hpp:1168
Heap heap
The single global heap.
Definition heap.cpp:44
void update(const NoOffset &)
Integer-precision integer scale view.
Definition view.hpp:638
#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:164
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:773
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition val-sel.hpp:39
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1943
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1472
int PropCond
Type for propagation conditions.
Definition core.hpp:72
Post propagator for SetVar x
Definition set.hh:773
Gecode::IntArgs i({1, 2, 3, 4})
#define forceinline
Definition config.hpp:194