Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.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:
53 View x;
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;
173 typename ArrayTraits<VarArgArray<Var>>::ArgsType
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
205 private:
206 static void* operator new(size_t) throw();
207 static void operator delete(void*,size_t);
208 };
209
213 template<class T>
214 typename ArrayTraits<VarArray<T>>::ArgsType
216
220 template<class T>
221 typename ArrayTraits<VarArray<T>>::ArgsType
223
227 template<class T>
228 typename ArrayTraits<VarArray<T>>::ArgsType
230
234 template<class T>
235 typename ArrayTraits<VarArray<T>>::ArgsType
236 operator +(const VarArray<T>& x, const T& y);
237
241 template<class T>
242 typename ArrayTraits<VarArray<T>>::ArgsType
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
263 typedef View value_type;
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 }
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 }
335
337
338
339 int size(void) const;
341 void size(int n);
343
345
346
347 View& operator [](int i);
349 const View& operator [](int i) const;
351
353
354
361 const_iterator end(void) const;
371
373
374
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);
392
394
395
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>
513 template<class ViewX, class ViewY>
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>
662 typename ArrayTraits<ArgArray<T>>::ArgsType
664
668 template<class T>
669 typename ArrayTraits<ArgArray<T>>::ArgsType
670 operator +(const ArgArray<T>& x, const T& y);
671
675 template<class T>
676 typename ArrayTraits<ArgArray<T>>::ArgsType
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
717 typename ArrayTraits<ArgArray<T>>::ArgsType
718 slice(int start, int inc=1, int n=-1);
720
722
723 typename ArrayTraits<ArgArray<T>>::ArgsType&
724 operator <<(const T& x);
726 typename ArrayTraits<ArgArray<T>>::ArgsType&
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
735 typename ArrayTraits<ArgArray<T>>::ArgsType
736 operator + <>(const T& x, const ArgArray<T>& y);
737 };
738
739 template<class> class VarArgArray;
740
744 template<class Var>
745 typename ArrayTraits<VarArgArray<Var>>::ArgsType
747
751 template<class Var>
752 typename ArrayTraits<VarArgArray<Var>>::ArgsType
754
758 template<class Var>
759 typename ArrayTraits<VarArgArray<Var>>::ArgsType
761
773 template<class Var>
774 class VarArgArray : public ArgArrayBase<Var> {
775 protected:
776 using ArgArrayBase<Var>::a;
777 using ArgArrayBase<Var>::n;
778 public:
779 using ArgArrayBase<Var>::size;
781
782
785 explicit VarArgArray(int n);
791 VarArgArray(const std::vector<Var>& a);
793 VarArgArray(std::initializer_list<Var> a);
795 template<class InputIterator>
796 VarArgArray(InputIterator first, InputIterator last);
798
800
801 typename ArrayTraits<VarArgArray<Var>>::ArgsType
802 slice(int start, int inc=1, int n=-1);
804
806
807 typename ArrayTraits<VarArgArray<Var>>::ArgsType&
808 operator <<(const Var& x);
810 typename ArrayTraits<VarArgArray<Var>>::ArgsType&
813
815 bool assigned(void) const;
816
817 friend typename ArrayTraits<VarArgArray<Var>>::ArgsType
819 friend typename ArrayTraits<VarArgArray<Var>>::ArgsType
821 friend
822 typename ArrayTraits<VarArgArray<Var>>::ArgsType
824 };
825
826
833 template<class Var>
841 template<class Var>
849 template<class Var>
857 template<class Var>
859
860
865 template<class Char, class Traits, class Var>
866 std::basic_ostream<Char,Traits>&
867 operator <<(std::basic_ostream<Char,Traits>& os,
868 const VarArray<Var>& x);
869
874 template<class Char, class Traits, class View>
875 std::basic_ostream<Char,Traits>&
876 operator <<(std::basic_ostream<Char,Traits>& os, const ViewArray<View>& x);
877
882 template<class Char, class Traits, class T>
883 std::basic_ostream<Char,Traits>&
884 operator <<(std::basic_ostream<Char,Traits>& os, const ArgArrayBase<T>& x);
885
886
887 /*
888 * Implementation
889 *
890 */
891
892 /*
893 * Variable arrays
894 *
895 * These arrays are allocated in the space.
896 *
897 */
898
899 template<class Var>
901 VarArray<Var>::VarArray(void) : n(0), x(nullptr) {}
902
903 template<class Var>
906 : n(n0) {
907 // Allocate from space
908 x = (n>0) ? home.alloc<Var>(n) : nullptr;
909 }
910
911 template<class Var>
914 n = a.n; x = a.x;
915 }
916
917 template<class Var>
918 inline const VarArray<Var>&
920 n = a.n; x = a.x;
921 return *this;
922 }
923
924 template<class Var>
925 forceinline int
927 return n;
928 }
929
930 template<class Var>
933 assert((i >= 0) && (i < size()));
934 return x[i];
935 }
936
937 template<class Var>
938 forceinline const Var&
940 assert((i >= 0) && (i < size()));
941 return x[i];
942 }
943
944 template<class Var>
945 typename ArrayTraits<VarArgArray<Var>>::ArgsType
946 VarArray<Var>::slice(int start, int inc, int maxN) {
947 assert(n==0 || start < n);
948 if (n==0 || maxN<0)
949 maxN = n;
950 int s;
951 if (inc == 0)
952 s = n-start;
953 else if (inc > 0)
954 s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
955 else
956 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
957 typename ArrayTraits<VarArgArray<Var>>::ArgsType r(std::min(maxN,s));
958 for (int i=0; i<r.size(); i++, start+=inc)
959 r[i] = x[start];
960 return r;
961 }
962
963 template<class Var>
966 return x;
967 }
968
969 template<class Var>
972 return x;
973 }
974
975 template<class Var>
978 return x+n;
979 }
980
981 template<class Var>
983 VarArray<Var>::end(void) const {
984 return x+n;
985 }
986
987 template<class Var>
990 return reverse_iterator(x+n);
991 }
992
993 template<class Var>
996 return const_reverse_iterator(x+n);
997 }
998
999 template<class Var>
1002 return reverse_iterator(x);
1003 }
1004
1005 template<class Var>
1008 return const_reverse_iterator(x);
1009 }
1010
1011 template<class Var>
1012 forceinline void
1014 n = a.n;
1015 if (n > 0) {
1016 x = home.alloc<Var>(n);
1017 for (int i=0; i<n; i++)
1018 x[i].update(home, a.x[i]);
1019 } else {
1020 x = nullptr;
1021 }
1022 }
1023
1024 template<class Var>
1025 forceinline bool
1027 for (int i=0; i<n; i++)
1028 if (!x[i].assigned())
1029 return false;
1030 return true;
1031 }
1032
1033 template<class Var>
1034 forceinline void*
1035 VarArray<Var>::operator new(size_t) throw() {
1036 return nullptr;
1037 }
1038
1039 template<class Var>
1040 forceinline void
1041 VarArray<Var>::operator delete(void*,size_t) {
1042 }
1043
1044 template<class Var>
1045 typename ArrayTraits<VarArray<Var>>::ArgsType
1047 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1048 for (int i=0; i<x.size(); i++)
1049 r[i] = x[i];
1050 for (int i=0; i<y.size(); i++)
1051 r[x.size()+i] = y[i];
1052 return r;
1053 }
1054
1055 template<class Var>
1056 typename ArrayTraits<VarArray<Var>>::ArgsType
1058 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1059 for (int i=0; i<x.size(); i++)
1060 r[i] = x[i];
1061 for (int i=0; i<y.size(); i++)
1062 r[x.size()+i] = y[i];
1063 return r;
1064 }
1065
1066 template<class Var>
1067 typename ArrayTraits<VarArray<Var>>::ArgsType
1069 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
1070 for (int i=0; i<x.size(); i++)
1071 r[i] = x[i];
1072 for (int i=0; i<y.size(); i++)
1073 r[x.size()+i] = y[i];
1074 return r;
1075 }
1076
1077 template<class Var>
1078 typename ArrayTraits<VarArray<Var>>::ArgsType
1079 operator +(const VarArray<Var>& x, const Var& y) {
1080 typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+1);
1081 for (int i=0; i<x.size(); i++)
1082 r[i] = x[i];
1083 r[x.size()] = y;
1084 return r;
1085 }
1086
1087 template<class Var>
1088 typename ArrayTraits<VarArray<Var>>::ArgsType
1089 operator +(const Var& x, const VarArray<Var>& y) {
1090 typename ArrayTraits<VarArray<Var>>::ArgsType r(y.size()+1);
1091 r[0] = x;
1092 for (int i=0; i<y.size(); i++)
1093 r[1+i] = y[i];
1094 return r;
1095 }
1096
1097 /*
1098 * View arrays
1099 *
1100 */
1101
1102 template<class View>
1104 ViewArray<View>::ViewArray(void) : n(0), x(nullptr) {}
1105
1106 template<class View>
1109 : n(n0) {
1110 x = (n>0) ? home.alloc<View>(n) : nullptr;
1111 }
1112 template<class View>
1115 : n(n0) {
1116 x = (n>0) ? r.alloc<View>(n) : nullptr;
1117 }
1118
1119 template<class View>
1121 : n(a.size()) {
1122 if (n>0) {
1123 x = home.alloc<View>(n);
1124 for (int i=0; i<n; i++)
1125 x[i] = a[i];
1126 } else {
1127 x = nullptr;
1128 }
1129 }
1130 template<class View>
1132 : n(a.size()) {
1133 if (n>0) {
1134 x = r.alloc<View>(n);
1135 for (int i=0; i<n; i++)
1136 x[i] = a[i];
1137 } else {
1138 x = nullptr;
1139 }
1140 }
1141
1142 template<class View>
1146
1147 template<class View>
1150 n = a.n; x = a.x;
1151 return *this;
1152 }
1153
1154 template<class View>
1155 forceinline int
1157 return n;
1158 }
1159
1160 template<class View>
1161 forceinline void
1163 n = n0;
1164 }
1165
1166 template<class View>
1167 forceinline View&
1169 assert((i >= 0) && (i < size()));
1170 return x[i];
1171 }
1172
1173 template<class View>
1174 forceinline const View&
1176 assert((i >= 0) && (i < size()));
1177 return x[i];
1178 }
1179
1180 template<class View>
1183 return x;
1184 }
1185
1186 template<class View>
1189 return x;
1190 }
1191
1192 template<class View>
1195 return x+n;
1196 }
1197
1198 template<class View>
1201 return x+n;
1202 }
1203
1204 template<class View>
1207 return reverse_iterator(x+n);
1208 }
1209
1210 template<class View>
1213 return const_reverse_iterator(x+n);
1214 }
1215
1216 template<class View>
1219 return reverse_iterator(x);
1220 }
1221
1222 template<class View>
1225 return const_reverse_iterator(x);
1226 }
1227
1228 template<class View>
1229 forceinline void
1231 x[i]=x[0]; x++; n--;
1232 }
1233
1234 template<class View>
1235 forceinline void
1237 n--; x[i]=x[n];
1238 }
1239
1240 template<class View>
1241 forceinline void
1243 assert(i>=0);
1244 x += i; n -= i;
1245 }
1246
1247 template<class View>
1248 forceinline void
1250 assert(i<n);
1251 n = i+1;
1252 }
1253
1254 template<class View>
1255 forceinline void
1257 // Move x[0] to x[i]
1258 x[i].cancel(home,p,pc);
1259 x[i]=x[0]; x++; n--;
1260 }
1261
1262 template<class View>
1263 forceinline void
1265 // Move x[n-1] to x[i]
1266 x[i].cancel(home,p,pc);
1267 n--; x[i]=x[n];
1268 }
1269
1270 template<class View>
1271 void
1273 // Drop elements from 0..i-1
1274 assert(i>=0);
1275 for (int j=0; j<i; j++)
1276 x[j].cancel(home,p,pc);
1277 x += i; n -= i;
1278 }
1279
1280 template<class View>
1281 void
1283 // Drop elements from i+1..n-1
1284 assert(i<n);
1285 for (int j=i+1; j<n; j++)
1286 x[j].cancel(home,p,pc);
1287 n = i+1;
1288 }
1289
1290 template<class View>
1291 forceinline void
1293 // Move x[0] to x[i]
1294 x[i].cancel(home,a);
1295 x[i]=x[0]; x++; n--;
1296 }
1297
1298 template<class View>
1299 forceinline void
1301 // Move x[n-1] to x[i]
1302 x[i].cancel(home,a);
1303 n--; x[i]=x[n];
1304 }
1305
1306 template<class View>
1307 void
1309 // Drop elements from 0..i-1
1310 assert(i>=0);
1311 for (int j=0; j<i; j++)
1312 x[j].cancel(home,a);
1313 x += i; n -= i;
1314 }
1315
1316 template<class View>
1317 void
1319 // Drop elements from i+1..n-1
1320 assert(i<n);
1321 for (int j=i+1; j<n; j++)
1322 x[j].cancel(home,a);
1323 n = i+1;
1324 }
1325
1326 template<class View>
1327 void
1329 n = y.n;
1330 if (n > 0) {
1331 x = home.alloc<View>(n);
1332 for (int i=0; i<n; i++)
1333 x[i].update(home, y.x[i]);
1334 } else {
1335 x = nullptr;
1336 }
1337 }
1338
1339 template<class View>
1340 void
1342 bool schedule) {
1343 for (int i=0; i<n; i++)
1344 x[i].subscribe(home,p,pc,schedule);
1345 }
1346
1347 template<class View>
1348 void
1350 for (int i=0; i<n; i++)
1351 x[i].cancel(home,p,pc);
1352 }
1353
1354 template<class View>
1355 void
1357 for (int i=0; i<n; i++)
1358 x[i].subscribe(home,a);
1359 }
1360
1361 template<class View>
1362 void
1364 for (int i=0; i<n; i++)
1365 x[i].cancel(home,a);
1366 }
1367
1368 template<class View>
1369 void
1371 for (int i=0; i<n; i++)
1372 x[i].reschedule(home,p,pc);
1373 }
1374
1375 template<class View>
1376 forceinline bool
1378 for (int i=0; i<n; i++)
1379 if (!x[i].assigned())
1380 return false;
1381 return true;
1382 }
1383
1384 template<class View>
1385 bool
1387 if (n < 2)
1388 return false;
1389 Region r;
1390 View* y = r.alloc<View>(n);
1391 int j=0;
1392 for (int i=0; i<n; i++)
1393 if (!x[i].assigned())
1394 y[j++] = x[i];
1395 if (j < 2)
1396 return false;
1398 for (int i=1; i<j; i++)
1399 if (y[i-1] == y[i])
1400 return true;
1401 return false;
1402 }
1403
1404 template<class View>
1405 bool
1406 ViewArray<View>::same(const View& y) const {
1407 if (y.assigned())
1408 return false;
1409 for (int i=0; i<n; i++)
1410 if (x[i] == y)
1411 return true;
1412 return false;
1413 }
1414
1415 template<class View>
1416 void
1418 if (n < 2)
1419 return;
1420 Region r;
1422 for (int i=0; i<n; i++) {
1423 o[i].x = x[i]; o[i].i = i;
1424 }
1426 // Assign bucket numbers
1427 int* bkt = r.alloc<int>(n);
1428 int b = 0;
1429 bkt[o[0].i] = b;
1430 for (int i=1; i<n; i++) {
1431 if (o[i-1].x != o[i].x)
1432 b++;
1433 bkt[o[i].i] = b;
1434 }
1435 // Eliminate duplicate elements
1436 Support::BitSet<Region> seen(r,static_cast<unsigned int>(b+1));
1437 int j=0;
1438 for (int i=0; i<n; i++)
1439 if (!seen.get(bkt[i])) {
1440 x[j++]=x[i]; seen.set(bkt[i]);
1441 } else {
1442 x[j]=x[i];
1443 }
1444 assert(j == b+1);
1445 n = j;
1446 }
1447
1448 template<class View>
1449 forceinline void*
1450 ViewArray<View>::operator new(size_t) throw() {
1451 return nullptr;
1452 }
1453
1454 template<class View>
1455 forceinline void
1456 ViewArray<View>::operator delete(void*,size_t) {
1457 }
1458
1459
1460 /*
1461 * Sharing for view arrays
1462 *
1463 */
1464 template<class ViewX, class ViewY>
1465 bool
1467 if ((x.size() == 0) || (y.size() == 0))
1468 return false;
1469 Region r;
1470 void** px = r.alloc<void*>(x.size());
1471 int j=0;
1472 for (int i=0; i<x.size(); i++)
1473 if (!x[i].assigned() && x[i].varimp())
1474 px[j++] = x[i].varimp();
1475 if (j == 0)
1476 return false;
1477 void** py = r.alloc<void*>(y.size());
1478 int k=0;
1479 for (int i=0; i<y.size(); i++)
1480 if (!y[i].assigned() && y[i].varimp())
1481 py[k++] = y[i].varimp();
1482 if (k == 0)
1483 return false;
1484 return Kernel::duplicates(px,j,py,k);
1485 }
1486
1487 template<class ViewX, class ViewY>
1488 bool
1490 if (y.assigned() || !y.varimp())
1491 return false;
1492 for (int i=0; i<x.size(); i++)
1493 if (!x[i].assigned() && x[i].varimp() && (x[i].varimp() == y.varimp()))
1494 return true;
1495 return false;
1496 }
1497
1498 template<class ViewX, class ViewY>
1499 forceinline bool
1501 return shared(y,x);
1502 }
1503
1504 template<class View>
1505 bool
1507 if (x.size() < 2)
1508 return false;
1509 Region r;
1510 void** px = r.alloc<void*>(x.size());
1511 int j=0;
1512 for (int i=0; i<x.size(); i++)
1513 if (!x[i].assigned() && x[i].varimp())
1514 px[j++] = x[i].varimp();
1515 return (j > 2) && Kernel::duplicates(px,j);
1516 }
1517
1518
1519
1520 /*
1521 * Argument arrays: base class
1522 *
1523 */
1524
1525 template<class T>
1526 forceinline T*
1528 return (n > onstack_size) ?
1529 heap.alloc<T>(static_cast<unsigned int>(n)) : &onstack[0];
1530 }
1531
1532 template<class T>
1533 forceinline void
1535 if (n+i >= capacity) {
1536 assert(n+i >= onstack_size);
1537 int newCapacity = (3*capacity)/2;
1538 if (newCapacity <= n+i)
1539 newCapacity = n+i;
1540 T* newA = allocate(newCapacity);
1541 heap.copy<T>(newA,a,n);
1542 if (capacity > onstack_size)
1544 capacity = newCapacity;
1545 a = newA;
1546 }
1547 }
1548
1549 template<class T>
1552 : n(0), capacity(onstack_size), a(allocate(0)) {}
1553
1554 template<class T>
1557 : n(n0), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {}
1558
1559 template<class T>
1560 inline
1562 : n(aa.n), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1563 heap.copy<T>(a,aa.a,n);
1564 }
1565
1566 template<class T>
1567 inline
1568 ArgArrayBase<T>::ArgArrayBase(const std::vector<T>& aa)
1569 : n(static_cast<int>(aa.size())),
1570 capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1571 heap.copy<T>(a,&aa[0],n);
1572 }
1573
1574 template<class T>
1575 inline
1576 ArgArrayBase<T>::ArgArrayBase(std::initializer_list<T> aa)
1577 : n(static_cast<int>(aa.size())),
1578 capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
1579 int i=0;
1580 for (const T& x : aa)
1581 a[i++]=x;
1582 }
1583
1584 template<class T>
1587 if (capacity > onstack_size)
1589 }
1590
1591 template<class T>
1594 if (&aa != this) {
1595 if (capacity > onstack_size)
1597 n = aa.n;
1598 capacity = (n < onstack_size ? onstack_size : n);
1599 a = allocate(aa.n);
1600 heap.copy<T>(a,aa.a,n);
1601 }
1602 return *this;
1603 }
1604
1605 template<class T>
1606 forceinline int
1608 return n;
1609 }
1610
1611 template<class T>
1612 forceinline T&
1614 assert((i>=0) && (i < n));
1615 return a[i];
1616 }
1617
1618 template<class T>
1619 forceinline const T&
1621 assert((i>=0) && (i < n));
1622 return a[i];
1623 }
1624
1625 template<class T>
1628 return a;
1629 }
1630
1631 template<class T>
1634 return a;
1635 }
1636
1637 template<class T>
1640 return a+n;
1641 }
1642
1643 template<class T>
1646 return a+n;
1647 }
1648
1649 template<class T>
1652 return reverse_iterator(a+n);
1653 }
1654
1655 template<class T>
1658 return const_reverse_iterator(a+n);
1659 }
1660
1661 template<class T>
1664 return reverse_iterator(a);
1665 }
1666
1667 template<class T>
1670 return const_reverse_iterator(a);
1671 }
1672
1673 template<class T> template<class A>
1674 A
1675 ArgArrayBase<T>::slice(int start, int inc, int maxN) {
1676 assert(n==0 || start < n);
1677 if (n==0 || maxN<0)
1678 maxN = n;
1679 int s;
1680 if (inc == 0)
1681 s = n-start;
1682 else if (inc > 0)
1683 s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
1684 else
1685 s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
1686 A r(std::min(maxN,s));
1687 for (int i=0; i<r.size(); i++, start+=inc)
1688 new (&r[i]) T(a[start]);
1689 return r;
1690 }
1691
1692 template<class T> template<class A>
1693 inline A&
1695 resize(1);
1696 new (&a[n++]) T(x);
1697 return static_cast<A&>(*this);
1698 }
1699
1700 template<class T>
1701 template<class InputIterator>
1702 inline
1703 ArgArrayBase<T>::ArgArrayBase(InputIterator first, InputIterator last)
1704 : n(0), capacity(onstack_size), a(allocate(0)) {
1705 while (first != last) {
1706 (void) append<ArgArrayBase<T>>(*first);
1707 ++first;
1708 }
1709 }
1710
1711
1712 template<class T> template<class A>
1713 inline A&
1715 resize(x.size());
1716 for (int i=0; i<x.size(); i++)
1717 new (&a[n++]) T(x[i]);
1718 return static_cast<A&>(*this);
1719 }
1720
1721 template<class T> template<class A>
1722 inline A
1724 A r(n+x.n);
1725 for (int i=0; i<n; i++)
1726 new (&r[i]) T(a[i]);
1727 for (int i=0; i<x.n; i++)
1728 new (&r[n+i]) T(x.a[i]);
1729 return r;
1730 }
1731
1732 template<class T> template<class A>
1733 inline A
1734 ArgArrayBase<T>::concat(const T& x) const {
1735 A r(n+1);
1736 for (int i=0; i<n; i++)
1737 new (&r[i]) T(a[i]);
1738 new (&r[n]) T(x);
1739 return r;
1740 }
1741
1742
1743 /*
1744 * Argument arrays
1745 *
1746 */
1747
1748 template<class T>
1751
1752 template<class T>
1756
1757 template<class T>
1758 ArgArray<T>::ArgArray(int n, const T* a0)
1759 : ArgArrayBase<T>(n) {
1760 for (int i=0; i<n; i++)
1761 a[i] = a0[i];
1762 }
1763
1764 template<class T>
1768
1769 template<class T>
1771 ArgArray<T>::ArgArray(const std::vector<T>& aa)
1772 : ArgArrayBase<T>(aa) {}
1773
1774 template<class T>
1776 ArgArray<T>::ArgArray(std::initializer_list<T> aa)
1777 : ArgArrayBase<T>(aa) {}
1778
1779 template<class T>
1780 template<class InputIterator>
1782 ArgArray<T>::ArgArray(InputIterator first, InputIterator last)
1783 : ArgArrayBase<T>(first,last) {}
1784
1785 template<class T>
1786 forceinline typename ArrayTraits<ArgArray<T>>::ArgsType
1787 ArgArray<T>::slice(int start, int inc, int maxN) {
1788 return ArgArrayBase<T>::template slice
1789 <typename ArrayTraits<ArgArray<T>>::ArgsType>
1790 (start,inc,maxN);
1791 }
1792
1793 template<class T>
1795 ArgArray<T>::operator <<(const T& x) {
1796 return
1798 <typename ArrayTraits<ArgArray<T>>::ArgsType>(x);
1799 }
1800
1801 template<class T>
1804 return
1806 <typename ArrayTraits<ArgArray<T>>::ArgsType>(x);
1807 }
1808
1809 template<class T>
1810 typename ArrayTraits<ArgArray<T>>::ArgsType
1812 return x.template concat
1813 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1814 }
1815
1816 template<class T>
1817 typename ArrayTraits<ArgArray<T>>::ArgsType
1818 operator +(const ArgArray<T>& x, const T& y) {
1819 return x.template concat
1820 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1821 }
1822
1823 template<class T>
1824 typename ArrayTraits<ArgArray<T>>::ArgsType
1825 operator +(const T& x, const ArgArray<T>& y) {
1826 ArgArray<T> xa(1);
1827 xa[0] = x;
1828 return xa.template concat
1829 <typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
1830 }
1831
1832 /*
1833 * Argument arrays for variables
1834 *
1835 */
1836
1837 template<class Var>
1840
1841 template<class Var>
1844
1845 template<class Var>
1849
1850 template<class Var>
1852 VarArgArray<Var>::VarArgArray(const std::vector<Var>& aa)
1853 : ArgArrayBase<Var>(aa) {}
1854
1855 template<class Var>
1857 VarArgArray<Var>::VarArgArray(std::initializer_list<Var> aa)
1858 : ArgArrayBase<Var>(aa) {}
1859
1860 template<class Var>
1861 template<class InputIterator>
1863 VarArgArray<Var>::VarArgArray(InputIterator first, InputIterator last)
1864 : ArgArrayBase<Var>(first,last) {}
1865
1866 template<class Var>
1867 inline
1869 : ArgArrayBase<Var>(x.size()) {
1870 for (int i=0; i<x.size(); i++)
1871 a[i]=x[i];
1872 }
1873
1874 template<class Var>
1875 forceinline typename ArrayTraits<VarArgArray<Var>>::ArgsType
1876 VarArgArray<Var>::slice(int start, int inc, int maxN) {
1877 return ArgArrayBase<Var>::template slice
1878 <typename ArrayTraits<VarArgArray<Var>>::ArgsType>
1879 (start,inc,maxN);
1880 }
1881
1882 template<class Var>
1885 return
1887 <typename ArrayTraits<VarArgArray<Var>>::ArgsType>(x);
1888 }
1889
1890 template<class Var>
1893 return
1895 <typename ArrayTraits<VarArgArray<Var>>::ArgsType>(x);
1896 }
1897
1898 template<class Var>
1899 typename ArrayTraits<VarArgArray<Var>>::ArgsType
1901 return x.template concat
1902 <typename ArrayTraits<VarArgArray<Var>>::ArgsType>(y);
1903 }
1904
1905 template<class Var>
1906 typename ArrayTraits<VarArgArray<Var>>::ArgsType
1908 return x.template concat
1909 <typename ArrayTraits<VarArgArray<Var>>::ArgsType>(y);
1910 }
1911
1912 template<class Var>
1913 typename ArrayTraits<VarArgArray<Var>>::ArgsType
1915 VarArgArray<Var> xa(1);
1916 xa[0] = x;
1917 return xa.template concat
1918 <typename ArrayTraits<VarArgArray<Var>>::ArgsType>(y);
1919 }
1920
1921 template<class Var>
1922 forceinline bool
1924 for (int i=0; i<n; i++)
1925 if (!a[i].assigned())
1926 return false;
1927 return true;
1928 }
1929
1930
1931 /*
1932 * Checking for multiple occurences of the same variable
1933 *
1934 */
1935 template<class Var>
1936 bool
1938 if ((x.size() == 0) || (y.size() == 0))
1939 return false;
1940 Region r;
1941 void** px = r.alloc<void*>(x.size());
1942 int j=0;
1943 for (int i=0; i<x.size(); i++)
1944 if (!x[i].assigned())
1945 px[j++] = x[i].varimp();
1946 if (j == 0)
1947 return false;
1948 void** py = r.alloc<void*>(y.size());
1949 int k=0;
1950 for (int i=0; i<y.size(); i++)
1951 if (!y[i].assigned())
1952 py[k++] = y[i].varimp();
1953 if (k == 0)
1954 return false;
1955 return Kernel::duplicates(px,j,py,k);
1956 }
1957
1958 template<class Var>
1959 bool
1961 if (y.assigned())
1962 return false;
1963 for (int i=0; i<x.size(); i++)
1964 if (x[i].varimp() == y.varimp())
1965 return true;
1966 return false;
1967 }
1968
1969 template<class Var>
1970 forceinline bool
1972 return same(y,x);
1973 }
1974
1975 template<class Var>
1976 bool
1978 if (x.size() < 2)
1979 return false;
1980 Region r;
1981 void** px = r.alloc<void*>(x.size());
1982 int j=0;
1983 for (int i=0; i<x.size(); i++)
1984 if (!x[i].assigned())
1985 px[j++] = x[i].varimp();
1986 return (j > 1) && Kernel::duplicates(px,j);
1987 }
1988
1989
1990
1991 /*
1992 * Interdependent code
1993 *
1994 */
1995
1996 template<class Var>
1997 inline
1999 : n(a.size()) {
2000 if (n>0) {
2001 x = home.alloc<Var>(n);
2002 for (int i=0; i<n; i++)
2003 x[i] = a[i];
2004 } else {
2005 x = nullptr;
2006 }
2007 }
2008
2009
2010 /*
2011 * Printing of arrays
2012 *
2013 */
2014 template<class Char, class Traits, class Var>
2015 std::basic_ostream<Char,Traits>&
2016 operator <<(std::basic_ostream<Char,Traits>& os,
2017 const VarArray<Var>& x) {
2018 std::basic_ostringstream<Char,Traits> s;
2019 s.copyfmt(os); s.width(0);
2020 s << '{';
2021 if (x.size() > 0) {
2022 s << x[0];
2023 for (int i=1; i<x.size(); i++)
2024 s << ", " << x[i];
2025 }
2026 s << '}';
2027 return os << s.str();
2028 }
2029
2030 template<class Char, class Traits, class View>
2031 std::basic_ostream<Char,Traits>&
2032 operator <<(std::basic_ostream<Char,Traits>& os,
2033 const ViewArray<View>& x) {
2034 std::basic_ostringstream<Char,Traits> s;
2035 s.copyfmt(os); s.width(0);
2036 s << '{';
2037 if (x.size() > 0) {
2038 s << x[0];
2039 for (int i=1; i<x.size(); i++)
2040 s << ", " << x[i];
2041 }
2042 s << '}';
2043 return os << s.str();
2044 }
2045
2046 template<class Char, class Traits, class T>
2047 std::basic_ostream<Char,Traits>&
2048 operator <<(std::basic_ostream<Char,Traits>& os,
2049 const ArgArrayBase<T>& x) {
2050 std::basic_ostringstream<Char,Traits> s;
2051 s.copyfmt(os); s.width(0);
2052 s << '{';
2053 if (x.size() > 0) {
2054 s << x[0];
2055 for (int i=1; i<x.size(); i++)
2056 s << ", " << x[i];
2057 }
2058 s << '}';
2059 return os << s.str();
2060 }
2061
2062}
2063
2064// STATISTICS: kernel-other
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Node * x
Pointer to corresponding Boolean expression node.
Base-class for advisors.
Definition core.hpp:1292
Base-class for argument arrays.
Definition array.hpp:537
T * allocate(int n)
Allocate memory for n elements.
Definition array.hpp:1527
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:590
T * pointer
Type of a pointer to the value type.
Definition array.hpp:582
T value_type
Type of the view stored in this array.
Definition array.hpp:576
static const int onstack_size
How many elements are possible inside array.
Definition array.hpp:546
const T * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:584
const ArgArrayBase< T > & operator=(const ArgArrayBase< T > &a)
Initialize from view array a (copy elements)
Definition array.hpp:1593
T onstack[onstack_size]
In-array storage for elements.
Definition array.hpp:548
const T * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
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:1669
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1657
ArgArrayBase(int n)
Allocate array with n elements.
Definition array.hpp:1556
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
T * a
Element array.
Definition array.hpp:544
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1651
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1645
void resize(int i)
Resize to hold at least i additional elements.
Definition array.hpp:1534
~ArgArrayBase(void)
Destructor.
Definition array.hpp:1586
ArgArrayBase(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1576
A concat(const ArgArrayBase< T > &x) const
Return this array concatenated with x.
Definition array.hpp:1723
A concat(const T &x) const
Return this array concatenated with x.
Definition array.hpp:1734
A & append(const ArgArrayBase< T > &x)
Append x to the end of the array.
Definition array.hpp:1714
ArgArrayBase(InputIterator first, InputIterator last)
Initialize from InputIterator begin and end.
Definition array.hpp:1703
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1663
T & reference
Type of a reference to the value type.
Definition array.hpp:578
ArgArrayBase(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1568
A slice(int start, int inc=1, int n=-1)
Definition array.hpp:1675
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:1633
T & operator[](int i)
Return element at position i.
Definition array.hpp:1613
int capacity
Allocated size of the array.
Definition array.hpp:542
int n
Number of elements.
Definition array.hpp:540
A & append(const T &x)
Insert a new element x at the end of the array (increase size by 1)
Definition array.hpp:1694
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1639
T * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:586
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:1627
ArgArrayBase(const ArgArrayBase< T > &a)
Initialize from argument array a (copy elements)
Definition array.hpp:1561
ArgArrayBase(void)
Allocate empty array.
Definition array.hpp:1551
const T & const_reference
Type of a constant reference to the value type.
Definition array.hpp:580
int size(void) const
Return size of array (number of elements)
Definition array.hpp:1607
Argument array for non-primitive types.
Definition array.hpp:691
ArgArray(InputIterator first, InputIterator last)
Initialize from InputIterator first and last.
Definition array.hpp:1782
ArgArray(const ArgArray< T > &a)
Initialize from argument array a (copy elements)
Definition array.hpp:1766
ArgArray(void)
Allocate empty array.
Definition array.hpp:1750
ArrayTraits< ArgArray< T > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1787
ArgArray(int n)
Allocate array with n elements.
Definition array.hpp:1754
ArgArray(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1776
ArgArray(int n, const T *e)
Allocate array with n elements and initialize with elements from array e.
Definition array.hpp:1758
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:1811
ArgArray(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1771
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:1795
Traits of arrays in Gecode.
Definition array.hpp:94
Boolean integer variables.
Definition int.hh:512
static T * copy(T *d, const T *s, long unsigned int n)
Copy n objects starting at s to d.
Definition heap.hpp:583
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition heap.hpp:457
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition heap.hpp:431
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:1064
Handle to region.
Definition region.hpp:55
Computation spaces.
Definition core.hpp:1742
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2837
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:774
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:1937
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1876
VarArgArray(const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements)
Definition array.hpp:1847
VarArgArray(std::initializer_list< Var > a)
Initialize from initializer list a.
Definition array.hpp:1857
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1923
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:1884
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:1900
bool same(Var x, VarArgArray< Var > y)
Test whether array y contains variable x.
Definition array.hpp:1971
VarArgArray(InputIterator first, InputIterator last)
Initialize from InputIterator first and last.
Definition array.hpp:1863
VarArgArray(const VarArray< Var > &a)
Initialize from variable array a (copy elements)
Definition array.hpp:1868
VarArgArray(int n)
Allocate array with n elements.
Definition array.hpp:1843
bool same(VarArgArray< Var > x, Var y)
Test whether array x contains variable y.
Definition array.hpp:1960
VarArgArray(void)
Allocate empty array.
Definition array.hpp:1839
VarArgArray(const std::vector< Var > &a)
Initialize from vector a.
Definition array.hpp:1852
Variable arrays
Definition array.hpp:112
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1026
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:989
Var value_type
Type of the variable stored in this array.
Definition array.hpp:122
const VarArray< Var > & operator=(const VarArray< Var > &a)
Initialize from variable array a (share elements)
Definition array.hpp:919
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Definition array.hpp:946
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1007
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:971
int n
Number of variables (size)
Definition array.hpp:115
VarArray(void)
Default constructor (array of size 0)
Definition array.hpp:901
const Var & const_reference
Type of a constant reference to the value type.
Definition array.hpp:126
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:983
int size(void) const
Return size of array (number of elements)
Definition array.hpp:926
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
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Definition array.hpp:1013
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:965
Var * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:132
Var & reference
Type of a reference to the value type.
Definition array.hpp:124
VarArray(Space &home, int m)
Allocate array with m variables.
Definition array.hpp:905
Var & operator[](int i)
Return variable at position i.
Definition array.hpp:932
Var * pointer
Type of a pointer to the value type.
Definition array.hpp:128
const Var * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:130
VarArray(Space &home, const VarArgArray< Var > &)
Initialize from variable argument array a (copy elements)
Definition array.hpp:1998
Var * x
Array of variables.
Definition array.hpp:117
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:977
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1001
std::reverse_iterator< Var * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:136
VarArray(const VarArray< Var > &a)
Initialize from variable array a (share elements)
Definition array.hpp:913
const Var * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:134
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:995
bool assigned(void) const
Test whether view is assigned.
Definition var.hpp:111
VarImp * varimp(void) const
Return variable implementation of variable.
Definition var.hpp:96
VarImp * x
Pointer to variable implementation.
Definition var.hpp:50
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:1363
View * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:273
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition array.hpp:1328
bool same(const View &y) const
Test whether array contains a view being the same as y.
Definition array.hpp:1406
void drop_fst(int i, Space &home, Propagator &p, PropCond pc)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1272
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
const View * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:275
View & reference
Type of a reference to the value type.
Definition array.hpp:265
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:1256
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:1188
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Test whether array x together with array y contains shared views.
Definition array.hpp:1466
void subscribe(Space &home, Advisor &a)
Subscribe advisor a to variable.
Definition array.hpp:1356
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition array.hpp:1370
View & operator[](int i)
Return view at position i.
Definition array.hpp:1168
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1224
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:1282
ViewArray(Space &home, const ViewArray< View > &a)
Initialize from view array a (copy elements)
Definition array.hpp:1120
void drop_fst(int i)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1242
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1218
const View & const_reference
Type of a constant reference to the value type.
Definition array.hpp:267
bool shared(ViewArray< ViewX > x, ViewY y)
Test whether array x contains a view shared with y.
Definition array.hpp:1489
void drop_fst(int i, Space &home, Advisor &a)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1308
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:1292
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:1300
ViewArray(const ViewArray< View > &a)
Initialize from view array a (share elements)
Definition array.hpp:1144
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1206
const ViewArray< View > & operator=(const ViewArray< View > &a)
Initialize from view array a (share elements)
Definition array.hpp:1149
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:1182
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:1417
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
Definition array.hpp:1349
const View * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:271
View value_type
Type of the view stored in this array.
Definition array.hpp:263
void drop_lst(int i)
Drop views from positions i+1 to size()-1 from array.
Definition array.hpp:1249
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1212
void drop_lst(int i, Space &home, Advisor &a)
Drop assigned views from positions i+1 to size()-1 from array.
Definition array.hpp:1318
void move_lst(int i)
Move view from position size()-1 to position i (truncate array by one)
Definition array.hpp:1236
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1200
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition array.hpp:1341
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1377
ViewArray(void)
Default constructor (array of size 0)
Definition array.hpp:1104
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:1264
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1194
View * pointer
Type of a pointer to the value type.
Definition array.hpp:269
ViewArray(Region &r, const ViewArray< View > &a)
Initialize from view array a (copy elements)
Definition array.hpp:1131
bool same(void) const
Test whether array has multiple occurence of the same view.
Definition array.hpp:1386
ViewArray(Region &r, int m)
Allocate array with m views.
Definition array.hpp:1114
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:1108
void move_fst(int i)
Move view from position 0 to position i (shift elements to the left)
Definition array.hpp:1230
bool shared(ViewX x, ViewArray< ViewY > y)
Test whether array y contains a view shared with x.
Definition array.hpp:1500
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:277
bool shared(ViewArray< View > x)
Test whether array x contains shared views.
Definition array.hpp:1506
void size(int n)
Decrease size of array (number of elements)
Definition array.hpp:1162
int size(void) const
Return size of array (number of elements)
Definition array.hpp:1156
const int capacity[n_warehouses]
Capacity of a single warehouse.
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
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:767
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition val-sel.hpp:39
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1937
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:767
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1466
int PropCond
Type for propagation conditions.
Definition core.hpp:72
Post propagator for SetVar x
Definition set.hh:767
Gecode::IntArgs i({1, 2, 3, 4})
#define forceinline
Definition config.hpp:187