Generated on for Gecode by doxygen 1.18.0
core.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 * Guido Tack <tack@gecode.dev>
6 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
7 *
8 * Contributing authors:
9 * Filip Konvicka <filip.konvicka@logis.cz>
10 * Kris Coester <kris.coester@sap.com>
11 * Alexander Shepil <alexander.shepil@sap.com>
12 * Samuel Gagnon <samuel.gagnon92@gmail.com>
13 *
14 * Copyright:
15 * Christian Schulte, 2002
16 * Guido Tack, 2003
17 * Mikael Zayenz Lagerkvist, 2006, 2026
18 * Kris Coester, 2024
19 * Alexander Shepil, 2024
20 * LOGIS, s.r.o., 2009
21 * Samuel Gagnon, 2018
22 *
23 * Bugfixes provided by:
24 * Alexander Samoilov <alexander_samoilov@yahoo.com>
25 *
26 * This file is part of Gecode, the generic constraint
27 * development environment:
28 * http://www.gecode.dev
29 *
30 * Permission is hereby granted, free of charge, to any person obtaining
31 * a copy of this software and associated documentation files (the
32 * "Software"), to deal in the Software without restriction, including
33 * without limitation the rights to use, copy, modify, merge, publish,
34 * distribute, sublicense, and/or sell copies of the Software, and to
35 * permit persons to whom the Software is furnished to do so, subject to
36 * the following conditions:
37 *
38 * The above copyright notice and this permission notice shall be
39 * included in all copies or substantial portions of the Software.
40 *
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
42 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
44 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
45 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
46 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
47 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 *
49 */
50
51#include <atomic>
52#include <iostream>
53
54namespace Gecode {
55
56 class Space;
57
66
67 typedef int ModEvent;
68
75
77 typedef int PropCond;
83
94 typedef int ModEventDelta;
95
96}
97
99
100namespace Gecode {
101
104 public:
106 static const int idx_c = -1;
108 static const int idx_d = -1;
112 static const int free_bits = 0;
114 static const int med_fst = 0;
116 static const int med_lst = 0;
118 static const int med_mask = 0;
122 static bool med_update(ModEventDelta& med, ModEvent me);
123 };
124
125 forceinline ModEvent
129 forceinline bool
133
134
135 /*
136 * These are the classes of interest
137 *
138 */
139 class ActorLink;
140 class Actor;
141 class Propagator;
143 class LocalObject;
144 class Advisor;
145 class AFC;
146 class Choice;
147 class Brancher;
148 class Group;
149 class PropagatorGroup;
150 class BrancherGroup;
151 class PostInfo;
152 class ViewTraceInfo;
153 class PropagateTraceInfo;
154 class CommitTraceInfo;
155 class PostTraceInfo;
156 class TraceRecorder;
157 class TraceFilter;
158 class Tracer;
159
160 template<class A> class Council;
161 template<class A> class Advisors;
162 template<class VIC> class VarImp;
163
164
165 /*
166 * Variable implementations
167 *
168 */
169
177 class VarImpBase {};
178
192
199 template<class VarImp>
201 public:
203 VarImpDisposer(void);
205 virtual void dispose(Space& home, VarImpBase* x);
206 };
207
209 class Delta {
210 template<class VIC> friend class VarImp;
211 private:
213 ModEvent me;
214 };
215
223 template<class VIC>
224 class VarImp : public VarImpBase {
225 friend class Space;
226 friend class Propagator;
227 template<class VarImp> friend class VarImpDisposer;
229 private:
230 union {
238 ActorLink** base;
247 VarImp<VIC>* fwd;
248 } b;
249
251 static const int idx_c = VIC::idx_c;
253 static const int idx_d = VIC::idx_d;
255 static const int free_bits = VIC::free_bits;
257 unsigned int entries;
259 unsigned int free_and_bits;
261 static const Gecode::PropCond pc_max = VIC::pc_max;
262#ifdef GECODE_HAS_CBS
264 const unsigned var_id;
265#endif
266
267 union {
278 unsigned int idx[pc_max+1];
281 } u;
282
284 ActorLink** actor(PropCond pc);
286 ActorLink** actorNonZero(PropCond pc);
288 unsigned int& idx(PropCond pc);
290 unsigned int idx(PropCond pc) const;
291
298 void update(VarImp* x, ActorLink**& sub);
305 static void update(Space& home, ActorLink**& sub);
307 static void recover(Space& home, ActorLink**& sub);
308
310 void enter(Space& home, Propagator* p, PropCond pc);
312 void enter(Space& home, ActorLink* a);
314 void resize(Space& home);
316 void remove(Space& home, Propagator* p, PropCond pc);
318 void remove(Space& home, ActorLink* a);
319
320
321 protected:
323 void cancel(Space& home);
329 bool advise(Space& home, ModEvent me, Delta& d);
330 private:
332 void _fail(Space& home);
333 protected:
336#ifdef GECODE_HAS_VAR_DISPOSE
338 static VarImp<VIC>* vars_d(Space& home);
340 static void vars_d(Space& home, VarImp<VIC>* x);
341#endif
342
343 public:
345 VarImp(Space& home);
347 VarImp(void);
348
349#ifdef GECODE_HAS_CBS
351 unsigned int id(void) const;
352#endif
353
355
356
368 void subscribe(Space& home, Propagator& p, PropCond pc,
369 bool assigned, ModEvent me, bool schedule);
371 void cancel(Space& home, Propagator& p, PropCond pc);
380 void subscribe(Space& home, Advisor& a, bool assigned, bool fail);
382 void cancel(Space& home, Advisor& a, bool fail);
383
390 unsigned int degree(void) const;
397 double afc(void) const;
399
401
402
403 VarImp(Space& home, VarImp& x);
405 bool copied(void) const;
407 VarImp* forward(void) const;
409 VarImp* next(void) const;
411
413
414
421 static void schedule(Space& home, Propagator& p, ModEvent me,
422 bool force = false);
430 static void reschedule(Space& home, Propagator& p, PropCond pc,
431 bool assigned, ModEvent me);
433 static ModEvent me(const ModEventDelta& med);
439
441
442
443 static ModEvent modevent(const Delta& d);
445
447
448
449 unsigned int bits(void) const;
451 unsigned int& bits(void);
453
454 protected:
456 void schedule(Space& home, PropCond pc1, PropCond pc2, ModEvent me);
457
458 public:
460
461
462 static void* operator new(size_t,Space&);
464 static void operator delete(void*,Space&);
466 static void operator delete(void*);
468 };
469
470
488
493 class PropCost {
494 friend class Space;
495 public:
515
517 public:
519 enum Mod {
522 };
523 private:
525 static PropCost cost(Mod m, ActualCost lo, ActualCost hi, unsigned int n);
528 public:
530 static PropCost record(void);
532 static PropCost crazy(PropCost::Mod m, unsigned int n);
534 static PropCost crazy(PropCost::Mod m, int n);
536 static PropCost cubic(PropCost::Mod m, unsigned int n);
538 static PropCost cubic(PropCost::Mod m, int n);
540 static PropCost quadratic(PropCost::Mod m, unsigned int n);
542 static PropCost quadratic(PropCost::Mod m, int n);
544 static PropCost linear(PropCost::Mod m, unsigned int n);
546 static PropCost linear(PropCost::Mod m, int n);
550 static PropCost binary(PropCost::Mod m);
552 static PropCost unary(PropCost::Mod m);
553 };
554
555
569 AP_DISPOSE = (1 << 0),
575 AP_WEAKLY = (1 << 1),
580 AP_VIEW_TRACE = (1 << 2),
585 AP_TRACE = (1 << 3)
586 };
587
588
596 class ActorLink {
597 friend class Actor;
598 friend class Propagator;
599 friend class Advisor;
600 friend class Brancher;
601 friend class LocalObject;
602 friend class Space;
603 template<class VIC> friend class VarImp;
604 private:
605 ActorLink* _next; ActorLink* _prev;
606 public:
608
609 ActorLink* prev(void) const; void prev(ActorLink*);
610 ActorLink* next(void) const; void next(ActorLink*);
611 ActorLink** next_ref(void);
613
615 void init(void);
617 void unlink(void);
619 void head(ActorLink* al);
621 void tail(ActorLink* al);
623 bool empty(void) const;
625 template<class T> static ActorLink* cast(T* a);
627 template<class T> static const ActorLink* cast(const T* a);
628 };
629
630
636 friend class ActorLink;
637 friend class Space;
638 friend class Propagator;
639 friend class Advisor;
640 friend class Brancher;
641 friend class LocalObject;
642 template<class VIC> friend class VarImp;
643 template<class A> friend class Council;
644 private:
646 static Actor* cast(ActorLink* al);
648 static const Actor* cast(const ActorLink* al);
650 GECODE_KERNEL_EXPORT static Actor* sentinel;
651 public:
653 virtual Actor* copy(Space& home) = 0;
654
656
657
659 virtual size_t dispose(Space& home);
661 static void* operator new(size_t s, Space& home);
663 static void operator delete(void* p, Space& home);
665 public:
669 static void* operator new(size_t s);
671 static void operator delete(void* p);
672 };
673
674 class Home;
675
680 class Group {
681 friend class Home;
682 friend class Propagator;
683 friend class Brancher;
684 friend class ViewTraceInfo;
685 friend class PropagateTraceInfo;
686 friend class CommitTraceInfo;
687 friend class PostTraceInfo;
688 protected:
690 static const unsigned int GROUPID_ALL = 0U;
692 static const unsigned int GROUPID_DEF = 1U;
694 static const unsigned int GROUPID_MAX = UINT_MAX >> 2;
696 unsigned int gid;
699 static unsigned int next;
704 Group(unsigned int gid0);
705 public:
707
708
710 Group(void);
712 Group(const Group& g);
714 Group& operator =(const Group& g);
716 unsigned int id(void) const;
718 bool in(Group a) const;
720 bool in(void) const;
722
724 static Group all;
727 static Group def;
728 };
729
734 class PropagatorGroup : public Group {
735 friend class Propagator;
736 friend class ViewTraceInfo;
737 friend class PropagateTraceInfo;
738 friend class PostTraceInfo;
739 protected:
741 PropagatorGroup(unsigned int gid);
742 public:
744
745
746 PropagatorGroup(void);
752 Home operator ()(Space& home);
754
756
768 PropagatorGroup& move(Space& home, unsigned int id);
770
772
773 bool operator ==(PropagatorGroup g) const;
775 bool operator !=(PropagatorGroup g) const;
778 unsigned int size(Space& home) const;
781 void kill(Space& home);
784 void disable(Space& home);
792 void enable(Space& home, bool s=true);
794
800 };
801
806 class BrancherGroup : public Group {
807 friend class Brancher;
808 protected:
810 BrancherGroup(unsigned int gid);
811 public:
813
814
815 BrancherGroup(void);
821 Home operator ()(Space& home);
823
825
829 BrancherGroup& move(Space& home, Brancher& b);
837 BrancherGroup& move(Space& home, unsigned int id);
839
841
842 bool operator ==(BrancherGroup g) const;
844 bool operator !=(BrancherGroup g) const;
847 unsigned int size(Space& home) const;
850 void kill(Space& home);
852
858 };
859
863 class Home {
864 friend class PostInfo;
865 protected:
874 public:
876
877
878 Home(Space& s, Propagator* p=nullptr,
882 Home(const Home& h);
884 Home& operator =(const Home& h);
886 operator Space&(void);
888
890
897 Propagator* propagator(void) const;
901 BrancherGroup branchergroup(void) const;
903
905
906 bool failed(void) const;
908 void fail(void);
910 void notice(Actor& a, ActorProperty p, bool duplicate=false);
912 };
913
918 friend class Space;
919 friend class PostInfo;
920 public:
922 enum What {
928 POST = 2,
931 };
932 protected:
936 void propagator(Propagator& p);
938 void brancher(Brancher& b);
940 void post(PropagatorGroup g);
942 void other(void);
943 public:
945 What what(void) const;
947 const Propagator& propagator(void) const;
949 const Brancher& brancher(void) const;
951 PropagatorGroup post(void) const;
952 };
953
957 class PostInfo {
958 friend class Space;
959 protected:
965 unsigned int pid;
967 bool nested;
968 public:
970 PostInfo(Home home);
972 ~PostInfo(void);
973 };
974
979 friend class Space;
980 public:
988 protected:
990 unsigned int i;
994 const Propagator* p;
999 const Propagator* p, Status s);
1000 public:
1002 unsigned int id(void) const;
1004 PropagatorGroup group(void) const;
1006 const Propagator* propagator(void) const;
1008 Status status(void) const;
1009 };
1010
1015 friend class Space;
1016 protected:
1018 const Brancher& b;
1020 const Choice& c;
1022 unsigned int a;
1024 CommitTraceInfo(const Brancher& b, const Choice& c, unsigned int a);
1025 public:
1027 unsigned int id(void) const;
1029 BrancherGroup group(void) const;
1031 const Brancher& brancher(void) const;
1033 const Choice& choice(void) const;
1035 unsigned int alternative(void) const;
1036 };
1037
1042 friend class Space;
1043 friend class PostInfo;
1044 public:
1051 protected:
1057 unsigned int n;
1059 PostTraceInfo(PropagatorGroup g, Status s, unsigned int n);
1060 public:
1062 Status status(void) const;
1064 PropagatorGroup group(void) const;
1066 unsigned int propagators(void) const;
1067 };
1068
1074 friend class ActorLink;
1075 friend class Space;
1076 template<class VIC> friend class VarImp;
1077 friend class Advisor;
1078 template<class A> friend class Council;
1080 friend class PropagatorGroup;
1081 private:
1082 union {
1084 ModEventDelta med;
1086 size_t size;
1088 Gecode::ActorLink* advisors;
1089 } u;
1096 void* gpi_disabled;
1098 static Propagator* cast(ActorLink* al);
1100 static const Propagator* cast(const ActorLink* al);
1102 bool local_info(void) const;
1104 void disable(Space& home);
1106 void enable(Space& home);
1107 protected:
1109 Propagator(Home home);
1111 Propagator(Space& home, Propagator& p);
1113 Propagator* fwd(void) const;
1115 Kernel::GPI::Info& gpi(void);
1116
1117 public:
1119
1120
1128 virtual void reschedule(Space& home) = 0;
1152 virtual ExecStatus propagate(Space& home, const ModEventDelta& med) = 0;
1154 virtual PropCost cost(const Space& home, const ModEventDelta& med) const = 0;
1162 ModEventDelta modeventdelta(void) const;
1199 virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
1202 virtual void advise(Space& home, Advisor& a);
1204
1206
1207 double afc(void) const;
1209#ifdef GECODE_HAS_CBS
1211
1212
1219 typedef std::function<void(unsigned int prop_id, unsigned int var_id,
1220 int val, double dens)> SendMarginal;
1221 virtual void solndistrib(Space& home, SendMarginal send) const;
1230 typedef std::function<bool(unsigned int var_id)> InDecision;
1231 virtual void domainsizesum(InDecision in, unsigned int& size,
1232 unsigned int& size_b) const;
1234#endif
1236
1237
1238 unsigned int id(void) const;
1240 PropagatorGroup group(void) const;
1242 void group(PropagatorGroup g);
1244 bool disabled(void) const;
1246 };
1247
1248
1256 template<class A>
1257 class Council {
1258 friend class Advisor;
1259 friend class Advisors<A>;
1260 private:
1262 mutable ActorLink* advisors;
1263 public:
1265 Council(void);
1267 Council(Space& home);
1269 bool empty(void) const;
1271 void update(Space& home, Council<A>& c);
1273 void dispose(Space& home);
1274 };
1275
1276
1281 template<class A>
1282 class Advisors {
1283 private:
1285 ActorLink* a;
1286 public:
1288 Advisors(const Council<A>& c);
1290 bool operator ()(void) const;
1292 void operator ++(void);
1294 A& advisor(void) const;
1295 };
1296
1297
1308 class Advisor : private ActorLink {
1309 template<class VIC> friend class VarImp;
1310 template<class A> friend class Council;
1311 template<class A> friend class Advisors;
1313 private:
1315 bool disposed(void) const;
1317 static Advisor* cast(ActorLink* al);
1319 static const Advisor* cast(const ActorLink* al);
1321 static ActorLink* link(Advisor& a);
1322 protected:
1324 Propagator& propagator(void) const;
1325 public:
1327 template<class A>
1328 Advisor(Space& home, Propagator& p, Council<A>& c);
1330 Advisor(Space& home, Advisor& a);
1332 const ViewTraceInfo& operator ()(const Space& home) const;
1333
1335
1336
1337 template<class A>
1338 void dispose(Space& home, Council<A>& c);
1340 static void* operator new(size_t s, Space& home);
1342 static void operator delete(void* p, Space& home);
1344 private:
1345#ifndef __GNUC__
1347 static void operator delete(void* p);
1348#endif
1350 static void* operator new(size_t s);
1351 };
1352
1353
1359 private:
1361 void* nl;
1362 public:
1369
1370 NGL(void);
1372 NGL(Space& home);
1374 NGL(Space& home, NGL& ngl);
1376 virtual void subscribe(Space& home, Propagator& p) = 0;
1378 virtual void cancel(Space& home, Propagator& p) = 0;
1380 virtual void reschedule(Space& home, Propagator& p) = 0;
1382 virtual NGL::Status status(const Space& home) const = 0;
1384 virtual ExecStatus prune(Space& home) = 0;
1386 virtual NGL* copy(Space& home) = 0;
1389 virtual bool notice(void) const;
1391 virtual size_t dispose(Space& home);
1393
1394
1395 bool leaf(void) const;
1397 NGL* next(void) const;
1399 void leaf(bool l);
1401 void next(NGL* n);
1403 NGL* add(NGL* n, bool l);
1405
1407
1408 static void* operator new(size_t s, Space& home);
1410 static void operator delete(void* s, Space& home);
1412 static void operator delete(void* p);
1414 public:
1418 static void* operator new(size_t s);
1419 };
1420
1431 friend class Space;
1432 private:
1433 unsigned int bid;
1434 unsigned int alt;
1435
1437 unsigned int id(void) const;
1438 protected:
1440 Choice(const Brancher& b, const unsigned int a);
1441 public:
1443 unsigned int alternatives(void) const;
1445 GECODE_KERNEL_EXPORT virtual ~Choice(void);
1448 virtual void archive(Archive& e) const;
1449 };
1450
1461 friend class ActorLink;
1462 friend class Space;
1463 friend class Choice;
1464 private:
1466 unsigned int bid;
1468 unsigned int gid;
1470 static Brancher* cast(ActorLink* al);
1472 static const Brancher* cast(const ActorLink* al);
1473 protected:
1475 Brancher(Home home);
1477 Brancher(Space& home, Brancher& b);
1478 public:
1480
1481
1489 virtual bool status(const Space& home) const = 0;
1497 virtual const Choice* choice(Space& home) = 0;
1499 virtual const Choice* choice(const Space& home, Archive& e) = 0;
1506 virtual ExecStatus commit(Space& home, const Choice& c,
1507 unsigned int a) = 0;
1522 virtual NGL* ngl(Space& home, const Choice& c, unsigned int a) const;
1531 virtual void print(const Space& home, const Choice& c, unsigned int a,
1532 std::ostream& o) const;
1534
1536
1537 unsigned int id(void) const;
1539 BrancherGroup group(void) const;
1541 void group(BrancherGroup g);
1543 };
1544
1551 class LocalObject : public Actor {
1552 friend class ActorLink;
1553 friend class Space;
1554 friend class LocalHandle;
1555 protected:
1557 LocalObject(Home home);
1559 LocalObject(Space& home, LocalObject& l);
1561 static LocalObject* cast(ActorLink* al);
1563 static const LocalObject* cast(const ActorLink* al);
1564 private:
1566 GECODE_KERNEL_EXPORT void fwdcopy(Space& home);
1567 public:
1569 LocalObject* fwd(Space& home);
1570 };
1571
1577 private:
1579 LocalObject* o;
1580 protected:
1582 LocalHandle(void);
1586 LocalHandle(const LocalHandle& lh);
1587 public:
1591 void update(Space& home, LocalHandle& lh);
1593 ~LocalHandle(void);
1594 protected:
1596 LocalObject* object(void) const;
1598 void object(LocalObject* n);
1599 };
1600
1601
1607 protected:
1609 std::atomic<unsigned long int> n;
1610 public:
1612 NoGoods(void);
1614 NoGoods(const NoGoods& ng);
1616 NoGoods& operator =(const NoGoods& ng);
1619 virtual void post(Space& home) const;
1621 unsigned long int ng(void) const;
1623 void ng(unsigned long int n);
1625 virtual ~NoGoods(void);
1628 static NoGoods eng;
1629 };
1630
1636 public:
1644
1657 protected:
1659 const Type t;
1661
1662
1663 const unsigned long int r;
1667 const unsigned long long int s;
1669 const unsigned long long int f;
1671 const Space* l;
1673 const NoGoods& ng;
1675
1677
1678 const unsigned int a;
1680 public:
1682
1683
1684 MetaInfo(unsigned long int r,
1686 unsigned long long int s,
1687 unsigned long long int f,
1688 const Space* l,
1689 NoGoods& ng);
1691 MetaInfo(unsigned int a);
1693
1694 Type type(void) const;
1696
1697
1698 unsigned long int restart(void) const;
1700 RestartReason reason(void) const;
1702 unsigned long long int solution(void) const;
1704 unsigned long long int fail(void) const;
1706 const Space* last(void) const;
1708 const NoGoods& nogoods(void) const;
1710
1712
1713 unsigned int asset(void) const;
1715 };
1716
1726
1732 public:
1734 unsigned long long int propagate;
1736 StatusStatistics(void);
1738 void reset(void);
1743 };
1744
1750 public:
1752 CloneStatistics(void);
1754 void reset(void);
1759 };
1760
1766 public:
1768 CommitStatistics(void);
1770 void reset(void);
1775 };
1776
1777
1778
1783 friend class Actor;
1784 friend class Propagator;
1785 friend class PropagatorGroup;
1786 friend class Propagators;
1787 friend class Brancher;
1788 friend class BrancherGroup;
1789 friend class Branchers;
1790 friend class Advisor;
1791 template <class A> friend class Council;
1792 template<class VIC> friend class VarImp;
1793 template<class VarImp> friend class VarImpDisposer;
1794 friend class LocalObject;
1795 friend class Region;
1796 friend class AFC;
1797 friend class PostInfo;
1799 void trace(Home home, TraceFilter tf, int te, Tracer& t);
1800 private:
1802 GECODE_KERNEL_EXPORT void* local_info(unsigned int gid);
1807#ifdef GECODE_HAS_CBS
1809 unsigned int var_id_counter;
1810#endif
1812 bool no_gpi;
1814 ActorLink pl;
1816 ActorLink bl;
1822 ActorLink* b_status;
1834 ActorLink* b_commit;
1836 Brancher* brancher(unsigned int id);
1837
1839 void kill(Brancher& b);
1841 void kill(Propagator& p);
1842
1845 void kill_brancher(unsigned int id);
1846
1848 static const unsigned reserved_bid = 0U;
1849
1851 static const unsigned int sc_bits = 2;
1853 static const unsigned int sc_fast = 0;
1855 static const unsigned int sc_disabled = 1;
1857 static const unsigned int sc_trace = 2;
1858
1859 union {
1861 struct {
1874 ActorLink* active;
1876 ActorLink queue[PropCost::AC_MAX+1];
1883 unsigned int bid_sc;
1885 unsigned int n_sub;
1887 ViewTraceInfo vti;
1888 } p;
1890 struct {
1894 VarImpBase* vars_noidx;
1896 LocalObject* local;
1898 Space* source;
1899 } c;
1900 } pc;
1902 void enqueue(Propagator* p);
1907#ifdef GECODE_HAS_VAR_DISPOSE
1909 GECODE_KERNEL_EXPORT static VarImpDisposerBase* vd[AllVarConf::idx_d];
1911 VarImpBase* _vars_d[AllVarConf::idx_d];
1913 template<class VIC> VarImpBase* vars_d(void) const;
1915 template<class VIC> void vars_d(VarImpBase* x);
1916#endif
1918 void update(ActorLink** sub);
1920
1922 void recover_noidx(void);
1923
1925 void recover(Space& source);
1926
1928 bool is_partial_clone(void) const;
1929
1931 Actor** d_fst;
1933 Actor** d_cur;
1935 Actor** d_lst;
1936
1938 GECODE_KERNEL_EXPORT static StatusStatistics unused_status;
1940 GECODE_KERNEL_EXPORT static CloneStatistics unused_clone;
1942 GECODE_KERNEL_EXPORT static CommitStatistics unused_commit;
1943
1957 GECODE_KERNEL_EXPORT Space* _clone(void);
1958
1992 void _commit(const Choice& c, unsigned int a);
1993
2025 void _trycommit(const Choice& c, unsigned int a);
2026
2029 TraceRecorder* findtracerecorder(void);
2032 void post(const PostInfo& pi);
2033
2041 void ap_notice_dispose(Actor* a, bool d);
2049 void ap_ignore_dispose(Actor* a, bool d);
2050 public:
2065 class NoGPI {
2066 private:
2068 Space& home;
2070 bool previous;
2071 NoGPI(const NoGPI&) = delete;
2072 NoGPI& operator =(const NoGPI&) = delete;
2073 public:
2075 explicit NoGPI(Space& home);
2077 ~NoGPI(void);
2078 };
2079
2087 class UseGPI {
2088 private:
2090 Space& home;
2092 bool previous;
2093 UseGPI(const UseGPI&) = delete;
2094 UseGPI& operator =(const UseGPI&) = delete;
2095 public:
2097 explicit UseGPI(Space& home);
2099 ~UseGPI(void);
2100 };
2101
2107 Space(void);
2122 Space& operator =(const Space& s) = default;
2128 virtual ~Space(void);
2139 virtual Space* copy(void) = 0;
2150 GECODE_KERNEL_EXPORT virtual void constrain(const Space& best);
2175 virtual bool master(const MetaInfo& mi);
2202 virtual bool slave(const MetaInfo& mi);
2203
2204 /*
2205 * Member functions for search engines
2206 *
2207 */
2208
2223 SpaceStatus status(void);
2224
2257 const Choice* choice(void);
2258
2269 const Choice* choice(Archive& e) const;
2270
2287 Space* clone(void) const;
2289 Space* clone(CloneStatistics& stat) const;
2290
2326 void commit(const Choice& c, unsigned int a);
2328 void commit(const Choice& c, unsigned int a,
2329 CommitStatistics& stat);
2363 void trycommit(const Choice& c, unsigned int a);
2365 void trycommit(const Choice& c, unsigned int a,
2366 CommitStatistics& stat);
2386 NGL* ngl(const Choice& c, unsigned int a);
2387
2403 void print(const Choice& c, unsigned int a, std::ostream& o) const;
2404
2414 void notice(Actor& a, ActorProperty p, bool duplicate=false);
2423 void ignore(Actor& a, ActorProperty p, bool duplicate=false);
2424
2425
2474
2485 template<class A>
2497 template<class A>
2510 template<class A>
2512
2520 void fail(void);
2529 bool failed(void) const;
2534 bool stable(void) const;
2535
2537
2538
2539 Home operator ()(Propagator& p);
2541 Home operator ()(PropagatorGroup pg);
2543 Home operator ()(BrancherGroup bg);
2545
2551
2557 template<class T>
2558 T* alloc(long unsigned int n);
2565 template<class T>
2566 T* alloc(long int n);
2573 template<class T>
2574 T* alloc(unsigned int n);
2581 template<class T>
2582 T* alloc(int n);
2592 template<class T>
2593 void free(T* b, long unsigned int n);
2603 template<class T>
2604 void free(T* b, long int n);
2614 template<class T>
2615 void free(T* b, unsigned int n);
2625 template<class T>
2626 void free(T* b, int n);
2638 template<class T>
2639 T* realloc(T* b, long unsigned int n, long unsigned int m);
2651 template<class T>
2652 T* realloc(T* b, long int n, long int m);
2664 template<class T>
2665 T* realloc(T* b, unsigned int n, unsigned int m);
2677 template<class T>
2678 T* realloc(T* b, int n, int m);
2686 template<class T>
2687 T** realloc(T** b, long unsigned int n, long unsigned int m);
2695 template<class T>
2696 T** realloc(T** b, long int n, long int m);
2704 template<class T>
2705 T** realloc(T** b, unsigned int n, unsigned int m);
2713 template<class T>
2714 T** realloc(T** b, int n, int m);
2716 void* ralloc(size_t s);
2718 void rfree(void* p, size_t s);
2720 void* rrealloc(void* b, size_t n, size_t m);
2722 template<size_t> void* fl_alloc(void);
2728 template<size_t> void fl_dispose(FreeList* f, FreeList* l);
2730
2732
2735 template<class T>
2736 T& construct(void);
2742 template<class T, typename A1>
2743 T& construct(A1 const& a1);
2749 template<class T, typename A1, typename A2>
2750 T& construct(A1 const& a1, A2 const& a2);
2756 template<class T, typename A1, typename A2, typename A3>
2757 T& construct(A1 const& a1, A2 const& a2, A3 const& a3);
2763 template<class T, typename A1, typename A2, typename A3, typename A4>
2764 T& construct(A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4);
2770 template<class T, typename A1, typename A2, typename A3, typename A4, typename A5>
2771 T& construct(A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5);
2773
2775
2776
2777 void afc_decay(double d);
2779 double afc_decay(void) const;
2783
2784 protected:
2791 private:
2793 Space& home;
2795 ActorLink* q;
2797 ActorLink* c;
2799 ActorLink* e;
2800 public:
2802 Propagators(Space& home);
2804 bool operator ()(void) const;
2806 void operator ++(void);
2808 Propagator& propagator(void) const;
2809 };
2810
2816 private:
2818 Space& home;
2820 ActorLink* q;
2822 ActorLink* c;
2824 ActorLink* e;
2825 public:
2829 bool operator ()(void) const;
2831 void operator ++(void);
2833 Propagator& propagator(void) const;
2834 };
2835
2841 private:
2843 ActorLink* c;
2845 ActorLink* e;
2846 public:
2848 IdlePropagators(Space& home);
2850 bool operator ()(void) const;
2852 void operator ++(void);
2854 Propagator& propagator(void) const;
2855 };
2856
2862 private:
2864 ActorLink* c;
2866 ActorLink* e;
2867 public:
2869 Branchers(Space& home);
2871 bool operator ()(void) const;
2873 void operator ++(void);
2875 Brancher& brancher(void) const;
2876 };
2877 };
2878
2881 private:
2886 public:
2888 Propagators(const Space& home, PropagatorGroup g);
2890 bool operator ()(void) const;
2892 void operator ++(void);
2894 const Propagator& propagator(void) const;
2895 };
2896
2899 private:
2903 BrancherGroup g;
2904 public:
2906 Branchers(const Space& home, BrancherGroup g);
2908 bool operator ()(void) const;
2910 void operator ++(void);
2912 const Brancher& brancher(void) const;
2913 };
2914
2915
2916
2917
2918 /*
2919 * Memory management
2920 *
2921 */
2922
2923 // Space allocation: general space heaps and free lists
2924 forceinline void*
2925 Space::ralloc(size_t s) {
2926 return mm.alloc(ssd.data().sm,s);
2927 }
2928 forceinline void
2929 Space::rfree(void* p, size_t s) {
2930 return mm.reuse(p,s);
2931 }
2932 forceinline void*
2933 Space::rrealloc(void* _b, size_t n, size_t m) {
2934 char* b = static_cast<char*>(_b);
2935 if (n < m) {
2936 char* p = static_cast<char*>(ralloc(m));
2937 memcpy(p,b,n);
2938 rfree(b,n);
2939 return p;
2940 } else {
2941 rfree(b+m,m-n);
2942 return b;
2943 }
2944 }
2945
2946 template<size_t s>
2947 forceinline void*
2949 return mm.template fl_alloc<s>(ssd.data().sm);
2950 }
2951 template<size_t s>
2952 forceinline void
2954 mm.template fl_dispose<s>(f,l);
2955 }
2956
2957 /*
2958 * Typed allocation routines
2959 *
2960 */
2961 template<class T>
2962 forceinline T*
2963 Space::alloc(long unsigned int n) {
2964 T* p = static_cast<T*>(ralloc(sizeof(T)*n));
2965 for (long unsigned int i=0; i<n; i++)
2966 (void) new (p+i) T();
2967 return p;
2968 }
2969 template<class T>
2970 forceinline T*
2971 Space::alloc(long int n) {
2972 assert(n >= 0);
2973 return alloc<T>(static_cast<long unsigned int>(n));
2974 }
2975 template<class T>
2976 forceinline T*
2977 Space::alloc(unsigned int n) {
2978 return alloc<T>(static_cast<long unsigned int>(n));
2979 }
2980 template<class T>
2981 forceinline T*
2983 assert(n >= 0);
2984 return alloc<T>(static_cast<long unsigned int>(n));
2985 }
2986
2987 template<class T>
2988 forceinline void
2989 Space::free(T* b, long unsigned int n) {
2990 for (long unsigned int i=0; i<n; i++)
2991 b[i].~T();
2992 rfree(b,n*sizeof(T));
2993 }
2994 template<class T>
2995 forceinline void
2996 Space::free(T* b, long int n) {
2997 assert(n >= 0);
2998 free<T>(b,static_cast<long unsigned int>(n));
2999 }
3000 template<class T>
3001 forceinline void
3002 Space::free(T* b, unsigned int n) {
3003 free<T>(b,static_cast<long unsigned int>(n));
3004 }
3005 template<class T>
3006 forceinline void
3007 Space::free(T* b, int n) {
3008 assert(n >= 0);
3009 free<T>(b,static_cast<long unsigned int>(n));
3010 }
3011
3012 template<class T>
3013 forceinline T*
3014 Space::realloc(T* b, long unsigned int n, long unsigned int m) {
3015 if (n < m) {
3016 T* p = static_cast<T*>(ralloc(sizeof(T)*m));
3017 for (long unsigned int i=0; i<n; i++)
3018 (void) new (p+i) T(b[i]);
3019 for (long unsigned int i=n; i<m; i++)
3020 (void) new (p+i) T();
3021 free<T>(b,n);
3022 return p;
3023 } else {
3024 free<T>(b+m,m-n);
3025 return b;
3026 }
3027 }
3028 template<class T>
3029 forceinline T*
3030 Space::realloc(T* b, long int n, long int m) {
3031 assert((n >= 0) && (m >= 0));
3032 return realloc<T>(b,static_cast<long unsigned int>(n),
3033 static_cast<long unsigned int>(m));
3034 }
3035 template<class T>
3036 forceinline T*
3037 Space::realloc(T* b, unsigned int n, unsigned int m) {
3038 return realloc<T>(b,static_cast<long unsigned int>(n),
3039 static_cast<long unsigned int>(m));
3040 }
3041 template<class T>
3042 forceinline T*
3043 Space::realloc(T* b, int n, int m) {
3044 assert((n >= 0) && (m >= 0));
3045 return realloc<T>(b,static_cast<long unsigned int>(n),
3046 static_cast<long unsigned int>(m));
3047 }
3048
3049#define GECODE_KERNEL_REALLOC(T) \
3050 template<> \
3051 forceinline T* \
3052 Space::realloc<T>(T* b, long unsigned int n, long unsigned int m) { \
3053 return static_cast<T*>(rrealloc(b,n*sizeof(T),m*sizeof(T))); \
3054 } \
3055 template<> \
3056 forceinline T* \
3057 Space::realloc<T>(T* b, long int n, long int m) { \
3058 assert((n >= 0) && (m >= 0)); \
3059 return realloc<T>(b,static_cast<long unsigned int>(n), \
3060 static_cast<long unsigned int>(m)); \
3061 } \
3062 template<> \
3063 forceinline T* \
3064 Space::realloc<T>(T* b, unsigned int n, unsigned int m) { \
3065 return realloc<T>(b,static_cast<long unsigned int>(n), \
3066 static_cast<long unsigned int>(m)); \
3067 } \
3068 template<> \
3069 forceinline T* \
3070 Space::realloc<T>(T* b, int n, int m) { \
3071 assert((n >= 0) && (m >= 0)); \
3072 return realloc<T>(b,static_cast<long unsigned int>(n), \
3073 static_cast<long unsigned int>(m)); \
3074 }
3075
3077 GECODE_KERNEL_REALLOC(signed char)
3078 GECODE_KERNEL_REALLOC(unsigned char)
3079 GECODE_KERNEL_REALLOC(signed short int)
3080 GECODE_KERNEL_REALLOC(unsigned short int)
3081 GECODE_KERNEL_REALLOC(signed int)
3082 GECODE_KERNEL_REALLOC(unsigned int)
3083 GECODE_KERNEL_REALLOC(signed long int)
3084 GECODE_KERNEL_REALLOC(unsigned long int)
3086 GECODE_KERNEL_REALLOC(double)
3087
3088#undef GECODE_KERNEL_REALLOC
3089
3090 template<class T>
3091 forceinline T**
3092 Space::realloc(T** b, long unsigned int n, long unsigned int m) {
3093 return static_cast<T**>(rrealloc(b,n*sizeof(T),m*sizeof(T*)));
3094 }
3095 template<class T>
3096 forceinline T**
3097 Space::realloc(T** b, long int n, long int m) {
3098 assert((n >= 0) && (m >= 0));
3099 return realloc<T*>(b,static_cast<long unsigned int>(n),
3100 static_cast<long unsigned int>(m));
3101 }
3102 template<class T>
3103 forceinline T**
3104 Space::realloc(T** b, unsigned int n, unsigned int m) {
3105 return realloc<T*>(b,static_cast<long unsigned int>(n),
3106 static_cast<long unsigned int>(m));
3107 }
3108 template<class T>
3109 forceinline T**
3110 Space::realloc(T** b, int n, int m) {
3111 assert((n >= 0) && (m >= 0));
3112 return realloc<T*>(b,static_cast<long unsigned int>(n),
3113 static_cast<long unsigned int>(m));
3114 }
3115
3116
3117#ifdef GECODE_HAS_VAR_DISPOSE
3118 template<class VIC>
3119 forceinline VarImpBase*
3120 Space::vars_d(void) const {
3121 return _vars_d[VIC::idx_d];
3122 }
3123 template<class VIC>
3124 forceinline void
3125 Space::vars_d(VarImpBase* x) {
3126 _vars_d[VIC::idx_d] = x;
3127 }
3128#endif
3129
3130 forceinline bool
3131 Space::is_partial_clone(void) const {
3132 return d_fst == &Actor::sentinel;
3133 }
3134
3135 // Space allocated entities: Actors, variable implementations, and advisors
3136 forceinline void
3137 Actor::operator delete(void*) {}
3138 forceinline void
3139 Actor::operator delete(void*, Space&) {}
3140 forceinline void*
3141 Actor::operator new(size_t s, Space& home) {
3142 return home.ralloc(s);
3143 }
3144
3145 template<class VIC>
3146 forceinline void
3147 VarImp<VIC>::operator delete(void*) {}
3148 template<class VIC>
3149 forceinline void
3150 VarImp<VIC>::operator delete(void*, Space&) {}
3151 template<class VIC>
3152 forceinline void*
3153 VarImp<VIC>::operator new(size_t s, Space& home) {
3154 return home.ralloc(s);
3155 }
3156
3157#ifndef __GNUC__
3158 forceinline void
3159 Advisor::operator delete(void*) {}
3160#endif
3161 forceinline void
3162 Advisor::operator delete(void*, Space&) {}
3163 forceinline void*
3164 Advisor::operator new(size_t s, Space& home) {
3165 return home.ralloc(s);
3166 }
3167
3168 forceinline void
3169 NGL::operator delete(void*) {}
3170 forceinline void
3171 NGL::operator delete(void*, Space&) {}
3172 forceinline void*
3173 NGL::operator new(size_t s, Space& home) {
3174 return home.ralloc(s);
3175 }
3176
3177
3178 /*
3179 * No-goods
3180 *
3181 */
3182 forceinline
3184 : n(0) {}
3185 forceinline
3187 : n(ng0.ng()) {}
3188 forceinline NoGoods&
3190 ng(ng0.ng());
3191 return *this;
3192 }
3193 forceinline unsigned long int
3194 NoGoods::ng(void) const {
3195 return n.load(std::memory_order_acquire);
3196 }
3197 forceinline void
3198 NoGoods::ng(unsigned long int n0) {
3199 n.store(n0, std::memory_order_release);
3200 }
3201 forceinline
3203
3204
3205 /*
3206 * Information from meta search engines
3207 */
3208 forceinline
3209 MetaInfo::MetaInfo(unsigned long int r0,
3210 RestartReason rr0,
3211 unsigned long long int s0,
3212 unsigned long long int f0,
3213 const Space* l0,
3214 NoGoods& ng0)
3215 : t(RESTART), r(r0), rr(rr0), s(s0), f(f0), l(l0), ng(ng0), a(0) {}
3216
3217 forceinline
3218 MetaInfo::MetaInfo(unsigned int a0)
3219 : t(PORTFOLIO), r(0), rr(RR_NO), s(0), f(0), l(nullptr), ng(NoGoods::eng), a(a0) {}
3220
3221 forceinline MetaInfo::Type
3222 MetaInfo::type(void) const {
3223 return t;
3224 }
3225 forceinline unsigned long int
3226 MetaInfo::restart(void) const {
3227 assert(type() == RESTART);
3228 return r;
3229 }
3230 forceinline MetaInfo::RestartReason
3231 MetaInfo::reason(void) const {
3232 return rr;
3233 }
3234 forceinline unsigned long long int
3236 assert(type() == RESTART);
3237 return s;
3238 }
3239 forceinline unsigned long long int
3240 MetaInfo::fail(void) const {
3241 assert(type() == RESTART);
3242 return f;
3243 }
3244 forceinline const Space*
3245 MetaInfo::last(void) const {
3246 assert(type() == RESTART);
3247 return l;
3248 }
3249 forceinline const NoGoods&
3250 MetaInfo::nogoods(void) const {
3251 assert(type() == RESTART);
3252 return ng;
3253 }
3254 forceinline unsigned int
3255 MetaInfo::asset(void) const {
3256 assert(type() == PORTFOLIO);
3257 return a;
3258 }
3259
3260
3261
3262 /*
3263 * ActorLink
3264 *
3265 */
3266 forceinline ActorLink*
3267 ActorLink::prev(void) const {
3268 return _prev;
3269 }
3270
3271 forceinline ActorLink*
3272 ActorLink::next(void) const {
3273 return _next;
3274 }
3275
3276 forceinline ActorLink**
3278 return &_next;
3279 }
3280
3281 forceinline void
3283 _prev = al;
3284 }
3285
3286 forceinline void
3288 _next = al;
3289 }
3290
3291 forceinline void
3293 ActorLink* p = _prev; ActorLink* n = _next;
3294 p->_next = n; n->_prev = p;
3295 }
3296
3297 forceinline void
3299 _next = this; _prev =this;
3300 }
3301
3302 forceinline void
3304 // Inserts al at head of link-chain (that is, after this)
3305 ActorLink* n = _next;
3306 this->_next = a; a->_prev = this;
3307 a->_next = n; n->_prev = a;
3308 }
3309
3310 forceinline void
3312 // Inserts al at tail of link-chain (that is, before this)
3313 ActorLink* p = _prev;
3314 a->_next = this; this->_prev = a;
3315 p->_next = a; a->_prev = p;
3316 }
3317
3318 forceinline bool
3319 ActorLink::empty(void) const {
3320 return _next == this;
3321 }
3322
3323 template<class T>
3324 forceinline ActorLink*
3326 // Turning al into a reference is for gcc, assume is for MSVC
3327 GECODE_NOT_NULL(a);
3328 ActorLink& t = *a;
3329 return static_cast<ActorLink*>(&t);
3330 }
3331
3332 template<class T>
3333 forceinline const ActorLink*
3334 ActorLink::cast(const T* a) {
3335 // Turning al into a reference is for gcc, assume is for MSVC
3336 GECODE_NOT_NULL(a);
3337 const ActorLink& t = *a;
3338 return static_cast<const ActorLink*>(&t);
3339 }
3340
3341
3342 /*
3343 * Actor
3344 *
3345 */
3346 forceinline Actor*
3347 Actor::cast(ActorLink* al) {
3348 // Turning al into a reference is for gcc, assume is for MSVC
3349 GECODE_NOT_NULL(al);
3350 ActorLink& t = *al;
3351 return static_cast<Actor*>(&t);
3352 }
3353
3354 forceinline const Actor*
3355 Actor::cast(const ActorLink* al) {
3356 // Turning al into a reference is for gcc, assume is for MSVC
3357 GECODE_NOT_NULL(al);
3358 const ActorLink& t = *al;
3359 return static_cast<const Actor*>(&t);
3360 }
3361
3362 forceinline void
3363 Home::notice(Actor& a, ActorProperty p, bool duplicate) {
3364 s.notice(a,p,duplicate);
3365 }
3366
3367 forceinline SpaceStatus
3369 StatusStatistics stat;
3370 return status(stat);
3371 }
3372
3373 forceinline Space*
3374 Space::clone(void) const {
3375 CloneStatistics stat;
3376 return clone(stat);
3377 }
3378
3379 forceinline Space*
3381 // Clone is only const for search engines. During cloning, several data
3382 // structures are updated (e.g. forwarding pointers), so we have to
3383 // cast away the constness.
3384 return const_cast<Space*>(this)->_clone();
3385 }
3386
3387 forceinline void
3388 Space::commit(const Choice& c, unsigned int a) {
3389 CommitStatistics stat;
3390 commit(c,a,stat);
3391 }
3392
3393 forceinline void
3394 Space::commit(const Choice& c, unsigned int a, CommitStatistics&) {
3395 _commit(c,a);
3396 }
3397
3398 forceinline void
3399 Space::trycommit(const Choice& c, unsigned int a) {
3400 CommitStatistics stat;
3401 trycommit(c,a,stat);
3402 }
3403
3404 forceinline void
3405 Space::trycommit(const Choice& c, unsigned int a, CommitStatistics&) {
3406 _trycommit(c,a);
3407 }
3408
3409 forceinline double
3410 Space::afc_decay(void) const {
3411 return ssd.data().gpi.decay();
3412 }
3413
3414 forceinline void
3416 ssd.data().gpi.decay(d);
3417 }
3418
3419 forceinline size_t
3421 return sizeof(*this);
3422 }
3423
3424
3425 /*
3426 * Home for posting actors
3427 *
3428 */
3429 forceinline
3432 : s(s0), p(p0), pg(pg0), bg(bg0) {}
3433 forceinline
3435 : s(h.s), p(h.p), pg(h.pg), bg(h.bg) {}
3436 forceinline Home&
3438 s=h.s; p=h.p; pg=h.pg; bg=h.bg;
3439 return *this;
3440 }
3441 forceinline
3442 Home::operator Space&(void) {
3443 return s;
3444 }
3445 forceinline Home
3447 return Home(s,&p);
3448 }
3449 forceinline Home
3453 forceinline Home
3457 forceinline Home
3459 return Home(*this,&p);
3460 }
3461 forceinline Home
3463 return Home(*this,nullptr,pg,BrancherGroup::def);
3464 }
3465 forceinline Home
3467 return Home(*this,nullptr,PropagatorGroup::def,bg);
3468 }
3469 forceinline Propagator*
3470 Home::propagator(void) const {
3471 return p;
3472 }
3473 forceinline PropagatorGroup
3475 return pg;
3476 }
3477 forceinline BrancherGroup
3479 return bg;
3480 }
3481
3482 /*
3483 * View trace information
3484 *
3485 */
3486 forceinline void
3488 who = reinterpret_cast<Support::uptrint_t>(&p) | PROPAGATOR;
3489 }
3490 forceinline void
3492 who = reinterpret_cast<Support::uptrint_t>(&b) | BRANCHER;
3493 }
3494 forceinline void
3496 who = (static_cast<Support::uptrint_t>(g.id()) << 2) | POST;
3497 }
3498 forceinline void
3500 who = OTHER;
3501 }
3502 forceinline ViewTraceInfo::What
3504 return static_cast<What>(who & 0b11);
3505 }
3506 forceinline const Propagator&
3508 assert(what() == PROPAGATOR);
3509 // Because PROPAGATOR == 0
3510 return *reinterpret_cast<Propagator*>(who);
3511 }
3512 forceinline const Brancher&
3514 assert(what() == BRANCHER);
3515 return *reinterpret_cast<Brancher*>
3516 (who & ~static_cast<Support::uptrint_t>(0b11));
3517 }
3518 forceinline PropagatorGroup
3520 assert(what() == POST);
3521 return PropagatorGroup(static_cast<unsigned int>(who >> 2));
3522 }
3523
3524 /*
3525 * Post information
3526 */
3527 forceinline
3529 : h(home), pg(home.propagatorgroup()),
3530 pid(h.ssd.data().gpi.pid()),
3531 nested(h.pc.p.vti.what() != ViewTraceInfo::OTHER) {
3532 h.pc.p.vti.post(pg);
3533 }
3534
3535 forceinline
3537 if (!nested) {
3538 if (h.pc.p.bid_sc & Space::sc_trace)
3539 h.post(*this);
3540 h.pc.p.vti.other();
3541 }
3542 }
3543
3544
3545 /*
3546 * Propagate trace information
3547 *
3548 */
3549 forceinline
3551 const Propagator* p0, Status s0)
3552 : i(i0), g(g0), p(p0), s(s0) {}
3553 forceinline unsigned int
3555 return i;
3556 }
3557 forceinline PropagatorGroup
3559 return g;
3560 }
3561 forceinline const Propagator*
3563 return p;
3564 }
3565 forceinline PropagateTraceInfo::Status
3567 return s;
3568 }
3569
3570
3571 /*
3572 * Commit trace information
3573 *
3574 */
3575 forceinline
3577 unsigned int a0)
3578 : b(b0), c(c0), a(a0) {}
3579 forceinline unsigned int
3581 return b.id();
3582 }
3583 forceinline BrancherGroup
3585 return b.group();
3586 }
3587 forceinline const Brancher&
3589 return b;
3590 }
3591 forceinline const Choice&
3593 return c;
3594 }
3595 forceinline unsigned int
3597 return a;
3598 }
3599
3600
3601 /*
3602 * Post trace information
3603 *
3604 */
3605 forceinline
3607 : g(g0), s(s0), n(n0) {}
3608 forceinline PropagatorGroup
3610 return g;
3611 }
3612 forceinline PostTraceInfo::Status
3614 return s;
3615 }
3616 forceinline unsigned int
3618 return n;
3619 }
3620
3621
3622 forceinline
3623 Space::NoGPI::NoGPI(Space& h) : home(h), previous(h.no_gpi) {
3624 home.no_gpi = true;
3625 }
3626
3627 forceinline
3629 home.no_gpi = previous;
3630 }
3631
3632
3633 forceinline
3634 Space::UseGPI::UseGPI(Space& h) : home(h), previous(h.no_gpi) {
3635 home.no_gpi = false;
3636 }
3637
3638 forceinline
3640 home.no_gpi = previous;
3641 }
3642
3643
3644 /*
3645 * Propagator
3646 *
3647 */
3648 forceinline Propagator*
3649 Propagator::cast(ActorLink* al) {
3650 // Turning al into a reference is for gcc, assume is for MSVC
3651 GECODE_NOT_NULL(al);
3652 ActorLink& t = *al;
3653 return static_cast<Propagator*>(&t);
3654 }
3655
3656 forceinline const Propagator*
3657 Propagator::cast(const ActorLink* al) {
3658 // Turning al into a reference is for gcc, assume is for MSVC
3659 GECODE_NOT_NULL(al);
3660 const ActorLink& t = *al;
3661 return static_cast<const Propagator*>(&t);
3662 }
3663
3664 forceinline Propagator*
3665 Propagator::fwd(void) const {
3666 return static_cast<Propagator*>(prev());
3667 }
3668
3669 forceinline bool
3670 Propagator::local_info(void) const {
3671 return (reinterpret_cast<Support::uptrint_t>(gpi_disabled) & 0b10) != 0;
3672 }
3673
3674 forceinline bool
3676 return Support::marked(gpi_disabled);
3677 }
3678
3679 forceinline void
3680 Propagator::disable(Space& home) {
3681 home.pc.p.bid_sc |= Space::sc_disabled;
3682 gpi_disabled = Support::fmark(gpi_disabled);
3683 }
3684
3685 forceinline void
3686 Propagator::enable(Space& home) {
3687 (void) home;
3688 gpi_disabled = Support::funmark(gpi_disabled);
3689 }
3690
3691 forceinline Kernel::GPI::Info&
3693 return *static_cast<Kernel::GPI::Info*>(Support::funmark<2>(gpi_disabled));
3694 }
3695
3696 forceinline
3698 : gpi_disabled((home.propagator() != nullptr) ?
3699 // Inherit propagator information
3700 home.propagator()->gpi_disabled :
3701 static_cast<Space&>(home).no_gpi ?
3702 static_cast<Space&>(home).local_info
3703 (home.propagatorgroup().gid) :
3704 // New propagator information
3705 static_cast<Space&>(home).ssd.data().gpi.allocate
3706 (home.propagatorgroup().gid)) {
3707 u.advisors = nullptr;
3708 assert((u.med == 0) && (u.size == 0));
3709 static_cast<Space&>(home).pl.head(this);
3710 }
3711
3712 forceinline
3714 : gpi_disabled(p.gpi_disabled) {
3715 if (p.local_info()) {
3716 Kernel::GPI::Info* i = home.alloc<Kernel::GPI::Info>(1);
3717 *i = p.gpi();
3718 gpi_disabled = Support::ptrjoin(i, p.disabled() ? 0b11 : 0b10);
3719 }
3720 u.advisors = nullptr;
3721 assert((u.med == 0) && (u.size == 0));
3722 // Set forwarding pointer
3723 p.prev(this);
3724 }
3725
3726 forceinline ModEventDelta
3728 return u.med;
3729 }
3730
3731 forceinline double
3732 Propagator::afc(void) const {
3733 return const_cast<Propagator&>(*this).gpi().afc;
3734 }
3735
3736#ifdef GECODE_HAS_CBS
3737 forceinline void
3738 Propagator::solndistrib(Space&, SendMarginal) const {}
3739
3740 forceinline void
3741 Propagator::domainsizesum(InDecision, unsigned int& size,
3742 unsigned int& size_b) const {
3743 size = 0;
3744 size_b = 0;
3745 }
3746#endif
3747
3748 forceinline unsigned int
3749 Propagator::id(void) const {
3750 return const_cast<Propagator&>(*this).gpi().pid;
3751 }
3752
3753 forceinline PropagatorGroup
3754 Propagator::group(void) const {
3755 return PropagatorGroup(const_cast<Propagator&>(*this).gpi().gid);
3756 }
3757
3758 forceinline void
3760 gpi().gid = g.id();
3761 }
3762
3763 forceinline ExecStatus
3765 p.u.size = s;
3766 return ES_SUBSUMED_;
3767 }
3768
3769 forceinline ExecStatus
3771 p.u.size = p.dispose(*this);
3772 return ES_SUBSUMED_;
3773 }
3774
3775 forceinline ExecStatus
3777 p.u.med = med;
3778 assert(p.u.med != 0);
3779 return ES_PARTIAL_;
3780 }
3781
3782 forceinline ExecStatus
3784 p.u.med = AllVarConf::med_combine(p.u.med,med);
3785 assert(p.u.med != 0);
3786 return ES_PARTIAL_;
3787 }
3788
3789
3790
3791 /*
3792 * Brancher
3793 *
3794 */
3795 forceinline Brancher*
3796 Brancher::cast(ActorLink* al) {
3797 // Turning al into a reference is for gcc, assume is for MSVC
3798 GECODE_NOT_NULL(al);
3799 ActorLink& t = *al;
3800 return static_cast<Brancher*>(&t);
3801 }
3802
3803 forceinline const Brancher*
3804 Brancher::cast(const ActorLink* al) {
3805 // Turning al into a reference is for gcc, assume is for MSVC
3806 GECODE_NOT_NULL(al);
3807 const ActorLink& t = *al;
3808 return static_cast<const Brancher*>(&t);
3809 }
3810
3811 forceinline
3813 gid(_home.branchergroup().gid) {
3814 Space& home = static_cast<Space&>(_home);
3815 bid = home.pc.p.bid_sc >> Space::sc_bits;
3816 home.pc.p.bid_sc += (1 << Space::sc_bits);
3817 if ((home.pc.p.bid_sc >> Space::sc_bits) == 0U)
3818 throw TooManyBranchers("Brancher::Brancher");
3819 // If no brancher available, make it the first one
3820 if (home.b_status == &static_cast<Space&>(home).bl) {
3821 home.b_status = this;
3822 if (home.b_commit == &static_cast<Space&>(home).bl)
3823 home.b_commit = this;
3824 }
3825 home.bl.tail(this);
3826 }
3827
3828 forceinline
3830 : bid(b.bid), gid(b.gid) {
3831 // Set forwarding pointer
3832 b.prev(this);
3833 }
3834
3835 forceinline unsigned int
3836 Brancher::id(void) const {
3837 return bid;
3838 }
3839
3840 forceinline BrancherGroup
3841 Brancher::group(void) const {
3842 return BrancherGroup(gid);
3843 }
3844
3845 forceinline void
3847 gid = g.id();
3848 }
3849
3850
3851 forceinline void
3852 Space::kill(Brancher& b) {
3853 assert(!failed());
3854 // Make sure that neither b_status nor b_commit does not point to b!
3855 if (b_commit == &b)
3856 b_commit = b.next();
3857 if (b_status == &b)
3858 b_status = b.next();
3859 b.unlink();
3860 rfree(&b,b.dispose(*this));
3861 }
3862
3863 forceinline void
3864 Space::kill(Propagator& p) {
3865 assert(!failed());
3866 p.unlink();
3867 rfree(&p,p.dispose(*this));
3868 // Is the space already stable?
3869 if (pc.p.active < &pc.p.queue[0])
3870 return;
3871 // Enforce that empty queues are ignored
3872 do {
3873 assert(pc.p.active >= &pc.p.queue[0]);
3874 // First propagator or link back to queue?
3875 if (pc.p.active != pc.p.active->next())
3876 return; // A propagator is left in the queue
3877 } while (--pc.p.active >= &pc.p.queue[0]);
3878 // The space is stable now
3879 assert(pc.p.active < &pc.p.queue[0]);
3880 }
3881
3882 forceinline Brancher*
3883 Space::brancher(unsigned int id) {
3884 /*
3885 * Due to weakly monotonic propagators the following scenario might
3886 * occur: a brancher has been committed with all its available
3887 * choices. Then, propagation determines less information
3888 * than before and the brancher now will create new choices.
3889 * Later, during recomputation, all of these choices
3890 * can be used together, possibly interleaved with
3891 * choices for other branchers. That means all branchers
3892 * must be scanned to find the matching brancher for the choice.
3893 *
3894 * b_commit tries to optimize scanning as it is most likely that
3895 * recomputation does not generate new choices during recomputation
3896 * and hence b_commit is moved from newer to older branchers.
3897 */
3898 ActorLink* b_old = b_commit;
3899 // Try whether we are lucky
3900 while (b_commit != &bl)
3901 if (id != Brancher::cast(b_commit)->id())
3902 b_commit = b_commit->next();
3903 else
3904 return Brancher::cast(b_commit);
3905 if (b_commit == &bl) {
3906 // We did not find the brancher, start at the beginning
3907 b_commit = bl.next();
3908 while (b_commit != b_old)
3909 if (id != Brancher::cast(b_commit)->id())
3910 b_commit = b_commit->next();
3911 else
3912 return Brancher::cast(b_commit);
3913 }
3914 return nullptr;
3915 }
3916
3917
3918 /*
3919 * Local objects
3920 *
3921 */
3922
3923 forceinline LocalObject*
3925 // Turning al into a reference is for gcc, assume is for MSVC
3926 GECODE_NOT_NULL(al);
3927 ActorLink& t = *al;
3928 return static_cast<LocalObject*>(&t);
3929 }
3930
3931 forceinline const LocalObject*
3933 // Turning al into a reference is for gcc, assume is for MSVC
3934 GECODE_NOT_NULL(al);
3935 const ActorLink& t = *al;
3936 return static_cast<const LocalObject*>(&t);
3937 }
3938
3939 forceinline
3941 (void) home;
3942 ActorLink::cast(this)->prev(nullptr);
3943 }
3944
3945 forceinline
3949
3950 forceinline LocalObject*
3952 if (prev() == nullptr)
3953 fwdcopy(home);
3954 return LocalObject::cast(prev());
3955 }
3956
3957 forceinline
3958 LocalHandle::LocalHandle(void) : o(nullptr) {}
3959 forceinline
3961 forceinline
3963 forceinline LocalHandle&
3965 o = lh.o;
3966 return *this;
3967 }
3968 forceinline
3970 forceinline LocalObject*
3971 LocalHandle::object(void) const { return o; }
3972 forceinline void
3974 forceinline void
3976 object(lh.object()->fwd(home));
3977 }
3978
3979
3980 /*
3981 * Choices
3982 *
3983 */
3984 forceinline
3985 Choice::Choice(const Brancher& b, const unsigned int a)
3986 : bid(b.id()), alt(a) {}
3987
3988 forceinline unsigned int
3990 return alt;
3991 }
3992
3993 forceinline unsigned int
3994 Choice::id(void) const {
3995 return bid;
3996 }
3997
3998 forceinline
4000
4001
4002
4003 /*
4004 * No-good literal
4005 *
4006 */
4007 forceinline bool
4008 NGL::leaf(void) const {
4009 return Support::marked(nl);
4010 }
4011 forceinline NGL*
4012 NGL::next(void) const {
4013 return static_cast<NGL*>(Support::funmark(nl));
4014 }
4015 forceinline void
4016 NGL::leaf(bool l) {
4017 nl = l ? Support::fmark(nl) : Support::funmark(nl);
4018 }
4019 forceinline void
4021 nl = Support::marked(nl) ? Support::mark(n) : n;
4022 }
4023 forceinline NGL*
4024 NGL::add(NGL* n, bool l) {
4025 nl = Support::marked(nl) ? Support::mark(n) : n;
4026 n->leaf(l);
4027 return n;
4028 }
4029
4030 forceinline
4032 : nl(nullptr) {}
4033 forceinline
4035 : nl(nullptr) {}
4036 forceinline
4038 : nl(nullptr) {}
4039 forceinline size_t
4041 return sizeof(*this);
4042 }
4043
4044 /*
4045 * Advisor
4046 *
4047 */
4048 template<class A>
4049 forceinline
4051 // Store propagator and forwarding in prev()
4052 ActorLink::prev(&p);
4053 // Link to next advisor in next()
4054 ActorLink::next(c.advisors); c.advisors = static_cast<A*>(this);
4055 }
4056
4057 forceinline
4059
4060 forceinline bool
4061 Advisor::disposed(void) const {
4062 return prev() == nullptr;
4063 }
4064
4065 forceinline Advisor*
4066 Advisor::cast(ActorLink* al) {
4067 return static_cast<Advisor*>(al);
4068 }
4069
4070 forceinline const Advisor*
4071 Advisor::cast(const ActorLink* al) {
4072 return static_cast<const Advisor*>(al);
4073 }
4074
4075 forceinline ActorLink*
4076 Advisor::link(Advisor& a) {
4077 return static_cast<ActorLink*>(&a);
4078 }
4079
4080 forceinline Propagator&
4082 assert(!disposed());
4083 return *Propagator::cast(ActorLink::prev());
4084 }
4085
4086 template<class A>
4087 forceinline void
4089 assert(!disposed());
4090 ActorLink::prev(nullptr);
4091 // Shorten chains of disposed advisors by one, if possible
4092 Advisor* n = Advisor::cast(next());
4093 if ((n != nullptr) && n->disposed())
4094 next(n->next());
4095 }
4096
4097 forceinline const ViewTraceInfo&
4098 Advisor::operator ()(const Space& home) const {
4099 return home.pc.p.vti;
4100 }
4101
4102 template<class A>
4103 forceinline ExecStatus
4105 a.dispose(*this,c);
4106 return ES_FIX;
4107 }
4108
4109 template<class A>
4110 forceinline ExecStatus
4112 a.dispose(*this,c);
4113 return ES_NOFIX;
4114 }
4115
4116 template<class A>
4117 forceinline ExecStatus
4119 a.dispose(*this,c);
4120 return ES_NOFIX_FORCE;
4121 }
4122
4123
4124
4125 /*
4126 * Advisor council
4127 *
4128 */
4129 template<class A>
4130 forceinline
4132
4133 template<class A>
4134 forceinline
4136 : advisors(nullptr) {}
4137
4138 template<class A>
4139 forceinline bool
4140 Council<A>::empty(void) const {
4141 ActorLink* a = advisors;
4142 while ((a != nullptr) && static_cast<A*>(a)->disposed())
4143 a = a->next();
4144 advisors = a;
4145 return a == nullptr;
4146 }
4147
4148 template<class A>
4149 forceinline void
4151 // Skip all disposed advisors
4152 {
4153 ActorLink* a = c.advisors;
4154 while ((a != nullptr) && static_cast<A*>(a)->disposed())
4155 a = a->next();
4156 c.advisors = a;
4157 }
4158 // Are there any advisors to be cloned?
4159 if (c.advisors != nullptr) {
4160 // The propagator in from-space
4161 Propagator* p_f = &static_cast<A*>(c.advisors)->propagator();
4162 // The propagator in to-space
4163 Propagator* p_t = Propagator::cast(p_f->prev());
4164 // Advisors in from-space
4165 ActorLink** a_f = &c.advisors;
4166 // Advisors in to-space
4167 A* a_t = nullptr;
4168 // Enter advisor link early so failed clone recovery can restore links.
4169 assert(p_f->u.advisors == nullptr);
4170 p_f->u.advisors = c.advisors;
4171 try {
4172 while (*a_f != nullptr) {
4173 if (static_cast<A*>(*a_f)->disposed()) {
4174 *a_f = (*a_f)->next();
4175 } else {
4176 // Run specific copying part
4177 A* a = new (home) A(home,*static_cast<A*>(*a_f));
4178 // Set propagator pointer
4179 a->prev(p_t);
4180 // Set forwarding pointer
4181 (*a_f)->prev(a);
4182 // Link
4183 a->next(a_t);
4184 a_t = a;
4185 advisors = a_t;
4186 a_f = (*a_f)->next_ref();
4187 }
4188 }
4189 } catch (...) {
4190 dispose(home);
4191 advisors = nullptr;
4192 for (ActorLink* a = c.advisors; a != nullptr; a = a->next())
4193 if (!static_cast<A*>(a)->disposed())
4194 a->prev(p_f);
4195 p_f->u.advisors = nullptr;
4196 throw;
4197 }
4198 advisors = a_t;
4199 } else {
4200 advisors = nullptr;
4201 }
4202 }
4203
4204 template<class A>
4205 forceinline void
4207 ActorLink* a = advisors;
4208 while (a != nullptr) {
4209 if (!static_cast<A*>(a)->disposed())
4210 static_cast<A*>(a)->dispose(home,*this);
4211 a = a->next();
4212 }
4213 }
4214
4215
4216
4217 /*
4218 * Advisor iterator
4219 *
4220 */
4221 template<class A>
4222 forceinline
4224 : a(c.advisors) {
4225 while ((a != nullptr) && static_cast<A*>(a)->disposed())
4226 a = a->next();
4227 }
4228
4229 template<class A>
4230 forceinline bool
4232 return a != nullptr;
4233 }
4234
4235 template<class A>
4236 forceinline void
4238 do {
4239 a = a->next();
4240 } while ((a != nullptr) && static_cast<A*>(a)->disposed());
4241 }
4242
4243 template<class A>
4244 forceinline A&
4246 return *static_cast<A*>(a);
4247 }
4248
4249
4250
4251 /*
4252 * Space
4253 *
4254 */
4255 forceinline void
4256 Space::enqueue(Propagator* p) {
4257 ActorLink::cast(p)->unlink();
4258 ActorLink* c = &pc.p.queue[p->cost(*this,p->u.med).ac];
4259 c->tail(ActorLink::cast(p));
4260 if (c > pc.p.active)
4261 pc.p.active = c;
4262 }
4263
4264 forceinline void
4266 pc.p.active = &pc.p.queue[PropCost::AC_MAX+1]+1;
4267 /*
4268 * Now active points beyond the last queue. This is essential as
4269 * enqueuing a propagator in a failed space keeps the space
4270 * failed.
4271 */
4272 }
4273 forceinline void
4275 s.fail();
4276 }
4277
4278 forceinline bool
4279 Space::failed(void) const {
4280 return pc.p.active > &pc.p.queue[PropCost::AC_MAX+1];
4281 }
4282 forceinline bool
4283 Home::failed(void) const {
4284 return s.failed();
4285 }
4286
4287 forceinline bool
4288 Space::stable(void) const {
4289 return ((pc.p.active < &pc.p.queue[0]) ||
4290 (pc.p.active > &pc.p.queue[PropCost::AC_MAX+1]));
4291 }
4292
4293 forceinline void
4295 if (p & AP_DISPOSE) {
4296 ap_notice_dispose(&a,d);
4297 }
4298 if (p & AP_VIEW_TRACE) {
4299 pc.p.bid_sc |= sc_trace;
4300 }
4301 if (p & AP_TRACE) {
4302 pc.p.bid_sc |= sc_trace;
4303 }
4304 // Currently unused
4305 if (p & AP_WEAKLY) {
4306 // Nothing to do
4307 }
4308 }
4309
4310 forceinline void
4312 // Check whether array has already been discarded as space
4313 // deletion is already in progress
4314 if ((p & AP_DISPOSE) && (d_fst != nullptr))
4315 ap_ignore_dispose(&a,d);
4316 if (p & AP_VIEW_TRACE) {
4317 // Nothing to do
4318 }
4319 if (p & AP_TRACE) {
4320 // Nothing to do
4321 }
4322 // Currently unused
4323 if (p & AP_WEAKLY) {
4324 // Nothing to do
4325 }
4326 }
4327
4328
4329
4330 /*
4331 * Variable implementation
4332 *
4333 */
4334 template<class VIC>
4335 forceinline ActorLink**
4336 VarImp<VIC>::actor(PropCond pc) {
4337 assert((pc >= 0) && (pc < pc_max+2));
4338 return (pc == 0) ? b.base : b.base+u.idx[pc-1];
4339 }
4340
4341 template<class VIC>
4342 forceinline ActorLink**
4343 VarImp<VIC>::actorNonZero(PropCond pc) {
4344 assert((pc > 0) && (pc < pc_max+2));
4345 return b.base+u.idx[pc-1];
4346 }
4347
4348 template<class VIC>
4349 forceinline unsigned int&
4350 VarImp<VIC>::idx(PropCond pc) {
4351 assert((pc > 0) && (pc < pc_max+2));
4352 return u.idx[pc-1];
4353 }
4354
4355 template<class VIC>
4356 forceinline unsigned int
4357 VarImp<VIC>::idx(PropCond pc) const {
4358 assert((pc > 0) && (pc < pc_max+2));
4359 return u.idx[pc-1];
4360 }
4361
4362 template<class VIC>
4363 forceinline
4365#ifdef GECODE_HAS_CBS
4366 : var_id(++home.var_id_counter)
4367#endif
4368 {
4369#ifndef GECODE_HAS_CBS
4370 (void) home;
4371#endif
4372 b.base = nullptr; entries = 0;
4373 for (PropCond pc=1; pc<pc_max+2; pc++)
4374 idx(pc) = 0;
4375 free_and_bits = 0;
4376 }
4377
4378 template<class VIC>
4379 forceinline
4381#ifdef GECODE_HAS_CBS
4382 : var_id(0)
4383#endif
4384 {
4385 b.base = nullptr; entries = 0;
4386 for (PropCond pc=1; pc<pc_max+2; pc++)
4387 idx(pc) = 0;
4388 free_and_bits = 0;
4389 }
4390
4391#ifdef GECODE_HAS_CBS
4392 template<class VIC>
4393 forceinline unsigned int
4394 VarImp<VIC>::id(void) const {
4395 return var_id;
4396 }
4397#endif
4398
4399 template<class VIC>
4400 forceinline unsigned int
4402 assert(!copied());
4403 return entries;
4404 }
4405
4406 template<class VIC>
4407 forceinline double
4408 VarImp<VIC>::afc(void) const {
4409 double d = 0.0;
4410 // Count the afc of each propagator
4411 {
4412 ActorLink** a = const_cast<VarImp<VIC>*>(this)->actor(0);
4413 ActorLink** e = const_cast<VarImp<VIC>*>(this)->actorNonZero(pc_max+1);
4414 while (a < e) {
4415 d += Propagator::cast(*a)->afc(); a++;
4416 }
4417 }
4418 // Count the afc of each advisor's propagator
4419 {
4420 ActorLink** a = const_cast<VarImp<VIC>*>(this)->actorNonZero(pc_max+1);
4421 ActorLink** e = const_cast<VarImp<VIC>*>(this)->b.base+entries;
4422 while (a < e) {
4423 d += Advisor::cast(static_cast<ActorLink*>(Support::funmark(*a)))
4424 ->propagator().afc();
4425 a++;
4426 }
4427 }
4428 return d;
4429 }
4430
4431 template<class VIC>
4432 forceinline ModEvent
4434 return d.me;
4435 }
4436
4437 template<class VIC>
4438 forceinline unsigned int
4439 VarImp<VIC>::bits(void) const {
4440 return free_and_bits;
4441 }
4442
4443 template<class VIC>
4444 forceinline unsigned int&
4446 return free_and_bits;
4447 }
4448
4449#ifdef GECODE_HAS_VAR_DISPOSE
4450 template<class VIC>
4451 forceinline VarImp<VIC>*
4452 VarImp<VIC>::vars_d(Space& home) {
4453 return static_cast<VarImp<VIC>*>(home.vars_d<VIC>());
4454 }
4455
4456 template<class VIC>
4457 forceinline void
4458 VarImp<VIC>::vars_d(Space& home, VarImp<VIC>* x) {
4459 home.vars_d<VIC>(x);
4460 }
4461#endif
4462
4463 template<class VIC>
4464 forceinline bool
4466 return Support::marked(b.fwd);
4467 }
4468
4469 template<class VIC>
4470 forceinline VarImp<VIC>*
4472 assert(copied());
4473 return static_cast<VarImp<VIC>*>(Support::unmark(b.fwd));
4474 }
4475
4476 template<class VIC>
4477 forceinline VarImp<VIC>*
4478 VarImp<VIC>::next(void) const {
4479 assert(copied());
4480 return u.next;
4481 }
4482
4483 template<class VIC>
4484 forceinline
4486#ifdef GECODE_HAS_CBS
4487 : var_id(x.var_id)
4488#endif
4489 {
4490 VarImpBase** reg;
4491 free_and_bits = x.free_and_bits & ((1 << free_bits) - 1);
4492 if (x.b.base == nullptr) {
4493 // Variable implementation needs no index structure
4494 reg = &home.pc.c.vars_noidx;
4495 assert(x.degree() == 0);
4496 } else {
4497 reg = &home.pc.c.vars_u[idx_c];
4498 }
4499 // Save subscriptions in copy
4500 b.base = x.b.base;
4501 entries = x.entries;
4502 for (PropCond pc=1; pc<pc_max+2; pc++)
4503 idx(pc) = x.idx(pc);
4504
4505 // Set forwarding pointer
4506 x.b.fwd = static_cast<VarImp<VIC>*>(Support::mark(this));
4507 // Register original
4508 x.u.next = static_cast<VarImp<VIC>*>(*reg); *reg = &x;
4509 }
4510
4511 template<class VIC>
4512 forceinline ModEvent
4514 return static_cast<ModEvent>((med & VIC::med_mask) >> VIC::med_fst);
4515 }
4516
4517 template<class VIC>
4518 forceinline ModEventDelta
4520 return static_cast<ModEventDelta>(me << VIC::med_fst);
4521 }
4522
4523 template<class VIC>
4524 forceinline ModEvent
4526 return VIC::me_combine(me1,me2);
4527 }
4528
4529 template<class VIC>
4530 forceinline void
4532 bool force) {
4533 if (VIC::med_update(p.u.med,me) || force)
4534 home.enqueue(&p);
4535 }
4536
4537 template<class VIC>
4538 forceinline void
4540 if (b.base == nullptr)
4541 return;
4542 ActorLink** begin = actor(pc1);
4543 ActorLink** end = actorNonZero(pc2+1);
4544 while (end > begin) {
4545 end--;
4546 schedule(home,*Propagator::cast(*end),me);
4547 }
4548 }
4549
4550 template<class VIC>
4551 forceinline void
4552 VarImp<VIC>::resize(Space& home) {
4553 if (b.base == nullptr) {
4554 assert((free_and_bits >> free_bits) == 0);
4555 // Create fresh dependency array with four entries
4556 free_and_bits += 4 << free_bits;
4557 b.base = home.alloc<ActorLink*>(4);
4558 for (int i=0; i<pc_max+1; i++)
4559 u.idx[i] = 0;
4560 } else {
4561 // Resize dependency array
4562 unsigned int n = degree();
4563 // Find out whether the area is most likely in the special area
4564 // reserved for subscriptions. If yes, just resize mildly otherwise
4565 // more aggressively
4566 ActorLink** s = static_cast<ActorLink**>(home.mm.subscriptions());
4567 unsigned int m =
4568 ((s <= b.base) && (b.base < s+home.pc.p.n_sub)) ?
4569 (n+4) : ((n+1)*3>>1);
4570 ActorLink** prop = home.alloc<ActorLink*>(m);
4571 free_and_bits += (m-n) << free_bits;
4572 // Copy entries
4573 Heap::copy<ActorLink*>(prop, b.base, n);
4574 home.free<ActorLink*>(b.base,n);
4575 b.base = prop;
4576 }
4577 }
4578
4579 template<class VIC>
4580 forceinline void
4581 VarImp<VIC>::enter(Space& home, Propagator* p, PropCond pc) {
4582 assert(pc <= pc_max);
4583 // Count one new subscription
4584 home.pc.p.n_sub += 1;
4585 if ((free_and_bits >> free_bits) == 0)
4586 resize(home);
4587 free_and_bits -= 1 << free_bits;
4588
4589 // Enter subscription
4590 b.base[entries] = *actorNonZero(pc_max+1);
4591 entries++;
4592 for (PropCond j = pc_max; j > pc; j--) {
4593 *actorNonZero(j+1) = *actorNonZero(j);
4594 idx(j+1)++;
4595 }
4596 *actorNonZero(pc+1) = *actor(pc);
4597 idx(pc+1)++;
4598 *actor(pc) = ActorLink::cast(p);
4599
4600#ifdef GECODE_AUDIT
4601 ActorLink** f = actor(pc);
4602 while (f < (pc == pc_max+1 ? b.base+entries : actorNonZero(pc+1)))
4603 if (*f == p)
4604 goto found;
4605 else
4606 f++;
4608 found: ;
4609#endif
4610 }
4611
4612 template<class VIC>
4613 forceinline void
4614 VarImp<VIC>::enter(Space& home, ActorLink* a) {
4615 // Note that a might be a marked pointer
4616 // Count one new subscription
4617 home.pc.p.n_sub += 1;
4618 if ((free_and_bits >> free_bits) == 0)
4619 resize(home);
4620 free_and_bits -= 1 << free_bits;
4621
4622 // Enter subscription
4623 b.base[entries++] = *actorNonZero(pc_max+1);
4624 *actorNonZero(pc_max+1) = a;
4625 }
4626
4627 template<class VIC>
4628 forceinline void
4630 bool assigned, ModEvent me, bool schedule) {
4631 if (assigned) {
4632 // Do not subscribe, just schedule the propagator
4633 if (schedule)
4635 } else {
4636 enter(home,&p,pc);
4637 // Schedule propagator
4638 if (schedule && (pc != PC_GEN_ASSIGNED))
4639 VarImp<VIC>::schedule(home,p,me);
4640 }
4641 }
4642
4643 template<class VIC>
4644 forceinline void
4645 VarImp<VIC>::subscribe(Space& home, Advisor& a, bool assigned, bool fail) {
4646 if (!assigned) {
4647 ActorLink* ma = static_cast<ActorLink*>
4648 (Support::ptrjoin(Advisor::link(a),fail ? 1 : 0));
4649 enter(home,ma);
4650 }
4651 }
4652
4653 template<class VIC>
4654 forceinline void
4656 bool assigned, ModEvent me) {
4657 if (assigned)
4659 else if (pc != PC_GEN_ASSIGNED)
4660 VarImp<VIC>::schedule(home,p,me);
4661 }
4662
4663 template<class VIC>
4664 void
4665 VarImp<VIC>::remove(Space& home, Propagator* p, PropCond pc) {
4666 assert(pc <= pc_max);
4667 ActorLink* a = ActorLink::cast(p);
4668 // Find actor in dependency array
4669 ActorLink** f = actor(pc);
4670#ifdef GECODE_AUDIT
4671 while (f < actorNonZero(pc+1))
4672 if (*f == a)
4673 goto found;
4674 else
4675 f++;
4677 found: ;
4678#else
4679 while (*f != a) f++;
4680#endif
4681 // Remove actor
4682 *f = *(actorNonZero(pc+1)-1);
4683 for (PropCond j = pc+1; j< pc_max+1; j++) {
4684 *(actorNonZero(j)-1) = *(actorNonZero(j+1)-1);
4685 idx(j)--;
4686 }
4687 *(actorNonZero(pc_max+1)-1) = b.base[entries-1];
4688 idx(pc_max+1)--;
4689 entries--;
4690 free_and_bits += 1 << free_bits;
4691 home.pc.p.n_sub -= 1;
4692 }
4693
4694 template<class VIC>
4695 forceinline void
4697 if ((b.base != nullptr) && !home.is_partial_clone())
4698 remove(home,&p,pc);
4699 }
4700
4701 template<class VIC>
4702 void
4703 VarImp<VIC>::remove(Space& home, ActorLink* a) {
4704 // Note that a might be a marked pointer
4705 // Find actor in dependency array
4706 ActorLink** f = actorNonZero(pc_max+1);
4707#ifdef GECODE_AUDIT
4708 while (f < b.base+entries)
4709 if (*f == a)
4710 goto found;
4711 else
4712 f++;
4714 found: ;
4715#else
4716 while (*f != a) f++;
4717#endif
4718 // Remove actor
4719 *f = b.base[--entries];
4720 free_and_bits += 1 << free_bits;
4721 home.pc.p.n_sub -= 1;
4722 }
4723
4724 template<class VIC>
4725 forceinline void
4727 if ((b.base != nullptr) && !home.is_partial_clone()) {
4728 ActorLink* ma = static_cast<ActorLink*>
4729 (Support::ptrjoin(Advisor::link(a),fail ? 1 : 0));
4730 remove(home,ma);
4731 }
4732 }
4733
4734 template<class VIC>
4735 forceinline void
4737 unsigned int n_sub = degree();
4738 home.pc.p.n_sub -= n_sub;
4739 unsigned int n = (free_and_bits >> free_bits) + n_sub;
4740 home.free<ActorLink*>(b.base,n);
4741 // Must be nullptr such that cloning works
4742 b.base = nullptr;
4743 // Must be 0 such that degree works
4744 entries = 0;
4745 // Must be nullptr such that afc works
4746 for (PropCond pc=1; pc<pc_max+2; pc++)
4747 idx(pc) = 0;
4748 free_and_bits &= (1 << free_bits) - 1;
4749 }
4750
4751 template<class VIC>
4752 forceinline bool
4754 /*
4755 * An advisor that is executed might remove itself due to subsumption.
4756 * As entries are removed from front to back, the advisors must
4757 * be iterated in forward direction.
4758 */
4759 ActorLink** la = actorNonZero(pc_max+1);
4760 ActorLink** le = b.base+entries;
4761 if (la == le)
4762 return true;
4763 d.me = me;
4764 // An advisor that is run, might be removed during execution.
4765 // As removal is done from the back the advisors have to be executed
4766 // in inverse order.
4767 do {
4768 Advisor* a = Advisor::cast
4769 (static_cast<ActorLink*>(Support::funmark(*la)));
4770 assert(!a->disposed());
4771 Propagator& p = a->propagator();
4772 switch (p.advise(home,*a,d)) {
4773 case ES_FIX:
4774 break;
4775 case ES_FAILED:
4776 return false;
4777 case ES_NOFIX:
4778 schedule(home,p,me);
4779 break;
4780 case ES_NOFIX_FORCE:
4781 schedule(home,p,me,true);
4782 break;
4783 case ES_SUBSUMED_:
4784 default:
4786 }
4787 } while (++la < le);
4788 return true;
4789 }
4790
4791 template<class VIC>
4792 void
4793 VarImp<VIC>::_fail(Space& home) {
4794 /*
4795 * An advisor that is executed might remove itself due to subsumption.
4796 * As entries are removed from front to back, the advisors must
4797 * be iterated in forward direction.
4798 */
4799 ActorLink** la = actorNonZero(pc_max+1);
4800 ActorLink** le = b.base+entries;
4801 if (la == le)
4802 return;
4803 // An advisor that is run, might be removed during execution.
4804 // As removal is done from the back the advisors have to be executed
4805 // in inverse order.
4806 do {
4807 if (Support::marked(*la)) {
4808 Advisor* a = Advisor::cast(static_cast<ActorLink*>
4809 (Support::unmark(*la)));
4810 assert(!a->disposed());
4811 Propagator& p = a->propagator();
4812 p.advise(home,*a);
4813 }
4814 } while (++la < le);
4815 }
4816
4817 template<class VIC>
4818 ModEvent
4820 _fail(home);
4821 return ME_GEN_FAILED;
4822 }
4823
4824 // Clang incorrectly reports an error on the access to u.idx[1] for BoolVarImp,
4825 // even though the access is guarded by pc_max > 0 which implies that the size is sufficient.
4826#pragma clang diagnostic push
4827#pragma clang diagnostic ignored "-Warray-bounds"
4828
4829 template<class VIC>
4830 forceinline void
4831 VarImp<VIC>::update(VarImp<VIC>* x, ActorLink**& sub) {
4832 // this refers to the variable to be updated (clone)
4833 // x refers to the original
4834 // Recover from copy
4835 x->b.base = b.base;
4836 x->u.idx[0] = u.idx[0];
4837 if (pc_max > 0 && sizeof(ActorLink**) > sizeof(unsigned int))
4838 x->u.idx[1] = u.idx[1];
4839
4840 unsigned int np =
4841 static_cast<unsigned int>(x->actorNonZero(pc_max+1) - x->actor(0));
4842 unsigned int na =
4843 static_cast<unsigned int >(x->b.base + x->entries -
4844 x->actorNonZero(pc_max+1));
4845 unsigned int n = na + np;
4846 assert(n == x->degree());
4847
4848 ActorLink** f = x->b.base;
4849 ActorLink** t = sub;
4850
4851 sub += n;
4852 b.base = t;
4853 // Process propagator subscriptions
4854 while (np >= 4) {
4855 ActorLink* p3 = f[3]->prev();
4856 ActorLink* p0 = f[0]->prev();
4857 ActorLink* p1 = f[1]->prev();
4858 ActorLink* p2 = f[2]->prev();
4859 t[0] = p0; t[1] = p1; t[2] = p2; t[3] = p3;
4860 np -= 4; t += 4; f += 4;
4861 }
4862 if (np >= 2) {
4863 ActorLink* p0 = f[0]->prev();
4864 ActorLink* p1 = f[1]->prev();
4865 t[0] = p0; t[1] = p1;
4866 np -= 2; t += 2; f += 2;
4867 }
4868 if (np > 0) {
4869 ActorLink* p0 = f[0]->prev();
4870 t[0] = p0;
4871 t += 1; f += 1;
4872 }
4873 // Process advisor subscriptions
4874 while (na >= 4) {
4875 ptrdiff_t m0, m1, m2, m3;
4876 ActorLink* p3 =
4877 static_cast<ActorLink*>(Support::ptrsplit(f[3],m3))->prev();
4878 ActorLink* p0 =
4879 static_cast<ActorLink*>(Support::ptrsplit(f[0],m0))->prev();
4880 ActorLink* p1 =
4881 static_cast<ActorLink*>(Support::ptrsplit(f[1],m1))->prev();
4882 ActorLink* p2 =
4883 static_cast<ActorLink*>(Support::ptrsplit(f[2],m2))->prev();
4884 t[0] = static_cast<ActorLink*>(Support::ptrjoin(p0,m0));
4885 t[1] = static_cast<ActorLink*>(Support::ptrjoin(p1,m1));
4886 t[2] = static_cast<ActorLink*>(Support::ptrjoin(p2,m2));
4887 t[3] = static_cast<ActorLink*>(Support::ptrjoin(p3,m3));
4888 na -= 4; t += 4; f += 4;
4889 }
4890 if (na >= 2) {
4891 ptrdiff_t m0, m1;
4892 ActorLink* p0 =
4893 static_cast<ActorLink*>(Support::ptrsplit(f[0],m0))->prev();
4894 ActorLink* p1 =
4895 static_cast<ActorLink*>(Support::ptrsplit(f[1],m1))->prev();
4896 t[0] = static_cast<ActorLink*>(Support::ptrjoin(p0,m0));
4897 t[1] = static_cast<ActorLink*>(Support::ptrjoin(p1,m1));
4898 na -= 2; t += 2; f += 2;
4899 }
4900 if (na > 0) {
4901 ptrdiff_t m0;
4902 ActorLink* p0 =
4903 static_cast<ActorLink*>(Support::ptrsplit(f[0],m0))->prev();
4904 t[0] = static_cast<ActorLink*>(Support::ptrjoin(p0,m0));
4905 }
4906 }
4907#pragma clang diagnostic pop
4908
4909 template<class VIC>
4910 forceinline void
4911 VarImp<VIC>::update(Space& home, ActorLink**& sub) {
4912 VarImp<VIC>* x = static_cast<VarImp<VIC>*>(home.pc.c.vars_u[idx_c]);
4913 while (x != nullptr) {
4914 VarImp<VIC>* n = x->next(); x->forward()->update(x,sub); x = n;
4915 }
4916 }
4917
4918 template<class VIC>
4919 forceinline void
4920 VarImp<VIC>::recover(Space& home, ActorLink**&) {
4921 VarImp<VIC>* x = static_cast<VarImp<VIC>*>(home.pc.c.vars_u[idx_c]);
4922 while (x != nullptr) {
4923 if (x->copied()) {
4924 VarImp<VIC>* n = x->next();
4925 VarImp<VIC>* copy = x->forward();
4926 x->b.base = copy->b.base;
4927 x->u.idx[0] = copy->u.idx[0];
4928 if (pc_max > 0 && sizeof(ActorLink**) > sizeof(unsigned int))
4929 x->u.idx[1] = copy->u.idx[1];
4930 x = n;
4931 } else {
4932 break;
4933 }
4934 }
4935 }
4936
4937
4938
4939 /*
4940 * Variable disposer
4941 *
4942 */
4943 template<class VarImp>
4945#ifdef GECODE_HAS_VAR_DISPOSE
4946 Space::vd[VarImp::idx_d] = this;
4947#endif
4948 }
4949
4950 template<class VarImp>
4951 void
4953 VarImp* x = static_cast<VarImp*>(_x);
4954 do {
4955 x->dispose(home); x = static_cast<VarImp*>(x->next_d());
4956 } while (x != nullptr);
4957 }
4958
4959 /*
4960 * Statistics
4961 */
4962
4963 forceinline void
4965 propagate = 0;
4966 }
4967 forceinline
4971 forceinline StatusStatistics&
4973 propagate += s.propagate;
4974 return *this;
4975 }
4976 forceinline StatusStatistics
4978 StatusStatistics t(s);
4979 return t += *this;
4980 }
4981
4982 forceinline void
4984
4985 forceinline
4989 forceinline CloneStatistics
4992 return s;
4993 }
4994 forceinline CloneStatistics&
4996 return *this;
4997 }
4998
4999 forceinline void
5001
5002 forceinline
5006 forceinline CommitStatistics
5009 return s;
5010 }
5011 forceinline CommitStatistics&
5013 return *this;
5014 }
5015
5016 /*
5017 * Cost computation
5018 *
5019 */
5020
5021 forceinline
5022 PropCost::PropCost(PropCost::ActualCost ac0) : ac(ac0) {}
5023
5024 forceinline PropCost
5025 PropCost::cost(PropCost::Mod m,
5027 unsigned int n) {
5028 if (n < 2)
5029 return (m == LO) ? AC_UNARY_LO : AC_UNARY_HI;
5030 else if (n == 2)
5031 return (m == LO) ? AC_BINARY_LO : AC_BINARY_HI;
5032 else if (n == 3)
5033 return (m == LO) ? AC_TERNARY_LO : AC_TERNARY_HI;
5034 else
5035 return (m == LO) ? lo : hi;
5036 }
5037
5038 forceinline PropCost
5040 return AC_RECORD;
5041 }
5042 forceinline PropCost
5043 PropCost::crazy(PropCost::Mod m, unsigned int n) {
5044 return cost(m,AC_CRAZY_LO,AC_CRAZY_HI,n);
5045 }
5046 forceinline PropCost
5048 assert(n >= 0);
5049 return crazy(m,static_cast<unsigned int>(n));
5050 }
5051 forceinline PropCost
5052 PropCost::cubic(PropCost::Mod m, unsigned int n) {
5053 return cost(m,AC_CUBIC_LO,AC_CUBIC_HI,n);
5054 }
5055 forceinline PropCost
5057 assert(n >= 0);
5058 return cubic(m,static_cast<unsigned int>(n));
5059 }
5060 forceinline PropCost
5062 return cost(m,AC_QUADRATIC_LO,AC_QUADRATIC_HI,n);
5063 }
5064 forceinline PropCost
5066 assert(n >= 0);
5067 return quadratic(m,static_cast<unsigned int>(n));
5068 }
5069 forceinline PropCost
5070 PropCost::linear(PropCost::Mod m, unsigned int n) {
5071 return cost(m,AC_LINEAR_LO,AC_LINEAR_HI,n);
5072 }
5073 forceinline PropCost
5075 assert(n >= 0);
5076 return linear(m,static_cast<unsigned int>(n));
5077 }
5078 forceinline PropCost
5080 return (m == LO) ? AC_TERNARY_LO : AC_TERNARY_HI;
5081 }
5082 forceinline PropCost
5084 return (m == LO) ? AC_BINARY_LO : AC_BINARY_HI;
5085 }
5086 forceinline PropCost
5088 return (m == LO) ? AC_UNARY_LO : AC_UNARY_HI;
5089 }
5090
5091 /*
5092 * Iterators for propagators and branchers of a space
5093 *
5094 */
5095 forceinline
5097 : home(home0), q(home.pc.p.active) {
5098 while (q >= &home.pc.p.queue[0]) {
5099 if (q->next() != q) {
5100 c = q->next(); e = q; q--;
5101 return;
5102 }
5103 q--;
5104 }
5105 q = nullptr;
5106 if (!home.pl.empty()) {
5107 c = home.pl.next();
5108 e = &home.pl;
5109 } else {
5110 c = e = nullptr;
5111 }
5112 }
5113 forceinline bool
5115 return c != nullptr;
5116 }
5117 forceinline void
5119 c = c->next();
5120 if (c == e) {
5121 if (q == nullptr) {
5122 c = nullptr;
5123 } else {
5124 while (q >= &home.pc.p.queue[0]) {
5125 if (q->next() != q) {
5126 c = q->next(); e = q; q--;
5127 return;
5128 }
5129 q--;
5130 }
5131 q = nullptr;
5132 if (!home.pl.empty()) {
5133 c = home.pl.next();
5134 e = &home.pl;
5135 } else {
5136 c = nullptr;
5137 }
5138 }
5139 }
5140 }
5141 forceinline Propagator&
5143 return *Propagator::cast(c);
5144 }
5145
5146
5147 forceinline
5149 : home(home0), q(home.pc.p.active) {
5150 while (q >= &home.pc.p.queue[0]) {
5151 if (q->next() != q) {
5152 c = q->next(); e = q; q--;
5153 return;
5154 }
5155 q--;
5156 }
5157 q = c = e = nullptr;
5158 }
5159 forceinline bool
5161 return c != nullptr;
5162 }
5163 forceinline void
5165 c = c->next();
5166 if (c == e) {
5167 if (q == nullptr) {
5168 c = nullptr;
5169 } else {
5170 while (q >= &home.pc.p.queue[0]) {
5171 if (q->next() != q) {
5172 c = q->next(); e = q; q--;
5173 return;
5174 }
5175 q--;
5176 }
5177 q = c = e = nullptr;
5178 }
5179 }
5180 }
5181 forceinline Propagator&
5183 return *Propagator::cast(c);
5184 }
5185
5186
5187 forceinline
5189 c = home.pl.next();
5190 e = &home.pl;
5191 }
5192 forceinline bool
5194 return c != e;
5195 }
5196 forceinline void
5198 c = c->next();
5199 }
5200 forceinline Propagator&
5202 return *Propagator::cast(c);
5203 }
5204
5205
5206 forceinline
5208 : c(home.bl.next()), e(&home.bl) {}
5209 forceinline bool
5211 return c != e;
5212 }
5213 forceinline void
5215 c = c->next();
5216 }
5217 forceinline Brancher&
5219 return *Brancher::cast(c);
5220 }
5221
5222
5223 /*
5224 * Groups of actors
5225 */
5226 forceinline
5227 Group::Group(unsigned int gid0) : gid(gid0) {}
5228
5229 forceinline bool
5230 Group::in(Group actor) const {
5231 return (gid == GROUPID_ALL) || (gid == actor.gid);
5232 }
5233
5234 forceinline bool
5235 Group::in(void) const {
5236 return (gid != GROUPID_ALL) && (gid != GROUPID_DEF);
5237 }
5238
5239 forceinline
5240 Group::Group(const Group& g) : gid(g.gid) {}
5241
5242 forceinline Group&
5244 gid=g.gid; return *this;
5245 }
5246
5247 forceinline unsigned int
5248 Group::id(void) const {
5249 return gid;
5250 }
5251
5252
5253 forceinline
5255
5256 forceinline
5259
5260 forceinline
5263
5264 forceinline PropagatorGroup&
5266 return static_cast<PropagatorGroup&>(Group::operator =(g));
5267 }
5268
5269 forceinline Home
5271 return Home(home,nullptr,*this,BrancherGroup::def);
5272 }
5273
5274 forceinline bool
5276 return id() == g.id();
5277 }
5278 forceinline bool
5280 return id() != g.id();
5281 }
5282
5283 forceinline PropagatorGroup&
5285 if (id() != GROUPID_ALL)
5286 p.group(*this);
5287 return *this;
5288 }
5289
5290
5291 forceinline
5293
5294 forceinline
5296 : Group(gid) {}
5297
5298 forceinline
5301
5302 forceinline BrancherGroup&
5304 return static_cast<BrancherGroup&>(Group::operator =(g));
5305 }
5306
5307 forceinline Home
5309 return Home(home,nullptr,PropagatorGroup::def,*this);
5310 }
5311
5312 forceinline bool
5314 return id() == g.id();
5315 }
5316 forceinline bool
5318 return id() != g.id();
5319 }
5320
5321 forceinline BrancherGroup&
5323 if (id() != GROUPID_ALL)
5324 p.group(*this);
5325 return *this;
5326 }
5327
5328
5329 /*
5330 * Iterators for propagators and branchers in a group
5331 *
5332 */
5333 forceinline
5335 : ps(const_cast<Space&>(home)), g(g0) {
5336 while (ps() && !g.in(ps.propagator().group()))
5337 ++ps;
5338 }
5339 forceinline bool
5341 return ps();
5342 }
5343 forceinline void
5345 do
5346 ++ps;
5347 while (ps() && !g.in(ps.propagator().group()));
5348 }
5349 forceinline const Propagator&
5351 return ps.propagator();
5352 }
5353
5354 forceinline
5356 : bs(const_cast<Space&>(home)), g(g0) {
5357 while (bs() && !g.in(bs.brancher().group()))
5358 ++bs;
5359 }
5360 forceinline bool
5362 return bs();
5363 }
5364 forceinline void
5366 do
5367 ++bs;
5368 while (bs() && !g.in(bs.brancher().group()));
5369 }
5370 forceinline const Brancher&
5372 return bs.brancher();
5373 }
5374
5375
5376 /*
5377 * Space construction support
5378 *
5379 */
5380 template<class T>
5381 forceinline T&
5383 return alloc<T>(1);
5384 }
5385 template<class T, typename A1>
5386 forceinline T&
5387 Space::construct(A1 const& a1) {
5388 T& t = *static_cast<T*>(ralloc(sizeof(T)));
5389 new (&t) T(a1);
5390 return t;
5391 }
5392 template<class T, typename A1, typename A2>
5393 forceinline T&
5394 Space::construct(A1 const& a1, A2 const& a2) {
5395 T& t = *static_cast<T*>(ralloc(sizeof(T)));
5396 new (&t) T(a1,a2);
5397 return t;
5398 }
5399 template<class T, typename A1, typename A2, typename A3>
5400 forceinline T&
5401 Space::construct(A1 const& a1, A2 const& a2, A3 const& a3) {
5402 T& t = *static_cast<T*>(ralloc(sizeof(T)));
5403 new (&t) T(a1,a2,a3);
5404 return t;
5405 }
5406 template<class T, typename A1, typename A2, typename A3, typename A4>
5407 forceinline T&
5408 Space::construct(A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) {
5409 T& t = *static_cast<T*>(ralloc(sizeof(T)));
5410 new (&t) T(a1,a2,a3,a4);
5411 return t;
5412 }
5413 template<class T, typename A1, typename A2, typename A3, typename A4, typename A5>
5414 forceinline T&
5415 Space::construct(A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) {
5416 T& t = *static_cast<T*>(ralloc(sizeof(T)));
5417 new (&t) T(a1,a2,a3,a4,a5);
5418 return t;
5419 }
5420
5421}
5422
5423// STATISTICS: kernel-core
Class for AFC (accumulated failure count) management.
Definition afc.hpp:40
Base-class for both propagators and branchers.
Definition core.hpp:635
friend class Space
Definition core.hpp:637
friend class LocalObject
Definition core.hpp:641
virtual ~Actor(void)
To avoid warnings.
friend class ActorLink
Definition core.hpp:636
friend class VarImp
Definition core.hpp:642
friend class Advisor
Definition core.hpp:639
friend class Propagator
Definition core.hpp:638
friend class Brancher
Definition core.hpp:640
virtual Actor * copy(Space &home)=0
Create copy.
friend class Council
Definition core.hpp:643
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3420
Base-class for advisors.
Definition core.hpp:1308
friend class SubscribedPropagators
Definition core.hpp:1312
Propagator & propagator(void) const
Return the advisor's propagator.
Definition core.hpp:4081
Advisor(Space &home, Propagator &p, Council< A > &c)
Constructor for creation.
Definition core.hpp:4050
friend class VarImp
Definition core.hpp:1309
void dispose(Space &home, Council< A > &c)
Dispose the advisor.
Definition core.hpp:4088
friend class Advisors
Definition core.hpp:1311
friend class Council
Definition core.hpp:1310
const ViewTraceInfo & operator()(const Space &home) const
Provide access to view trace information.
Definition core.hpp:4098
Class to iterate over advisors of a council.
Definition core.hpp:1282
Advisors(const Council< A > &c)
Initialize.
Definition core.hpp:4223
bool operator()(void) const
Test whether there advisors left.
Definition core.hpp:4231
void operator++(void)
Move iterator to next advisor.
Definition core.hpp:4237
A & advisor(void) const
Return advisor.
Definition core.hpp:4245
static const int idx_c
Index for cloning.
Definition var-type.hpp:467
static ModEventDelta med_combine(ModEventDelta med1, ModEventDelta med2)
Combine modification event delta med1 with med2.
Definition var-type.hpp:897
Archive representation
Definition archive.hpp:42
Group of branchers.
Definition core.hpp:806
unsigned int size(Space &home) const
Return number of branchers in a group.
static BrancherGroup def
Group of branchers not in any user-defined group.
Definition core.hpp:857
static BrancherGroup all
Group of all branchers.
Definition core.hpp:854
BrancherGroup & operator=(const BrancherGroup &g)
Assignment operator.
Definition core.hpp:5303
BrancherGroup & move(Space &home, BrancherGroup g)
Move branchers from group g to this group.
BrancherGroup(unsigned int gid)
Initialize with group id gid.
Definition core.hpp:5295
BrancherGroup & move(Space &home, unsigned int id)
Move brancher with id id to this group.
friend class Brancher
Definition core.hpp:807
Home operator()(Space &home)
To augment a space argument.
Definition core.hpp:5308
bool operator!=(BrancherGroup g) const
Test whether this group is different from group g.
Definition core.hpp:5317
void kill(Space &home)
Kill all branchers in a group.
bool operator==(BrancherGroup g) const
Test whether this group is equal to group g.
Definition core.hpp:5313
BrancherGroup(void)
Constructor.
Definition core.hpp:5292
Base-class for branchers.
Definition core.hpp:1460
virtual NGL * ngl(Space &home, const Choice &c, unsigned int a) const
Create no-good literal for choice c and alternative a.
virtual const Choice * choice(Space &home)=0
Return choice.
friend class Space
Definition core.hpp:1462
virtual ExecStatus commit(Space &home, const Choice &c, unsigned int a)=0
Commit for choice c and alternative a.
friend class ActorLink
Definition core.hpp:1461
unsigned int id(void) const
Return brancher id.
Definition core.hpp:3836
virtual void print(const Space &home, const Choice &c, unsigned int a, std::ostream &o) const
Print branch for choice c and alternative a.
virtual const Choice * choice(const Space &home, Archive &e)=0
Return choice from e.
BrancherGroup group(void) const
Return group brancher belongs to.
Definition core.hpp:3841
virtual bool status(const Space &home) const =0
Check status of brancher, return true if alternatives left.
Brancher(Home home)
Constructor for creation.
Definition core.hpp:3812
friend class Choice
Definition core.hpp:1463
void operator++(void)
Move iterator to next brancher.
Definition core.hpp:5365
const Brancher & brancher(void) const
Return propagator.
Definition core.hpp:5371
bool operator()(void) const
Test whether there are branchers left.
Definition core.hpp:5361
Branchers(const Space &home, BrancherGroup g)
Initialize.
Definition core.hpp:5355
Choice for performing commit
Definition core.hpp:1430
Choice(const Brancher &b, const unsigned int a)
Initialize for particular brancher b and alternatives a.
Definition core.hpp:3985
friend class Space
Definition core.hpp:1431
virtual void archive(Archive &e) const
Archive into e.
virtual ~Choice(void)
Destructor.
Definition core.hpp:3999
unsigned int alternatives(void) const
Return number of alternatives.
Definition core.hpp:3989
Statistics for execution of clone
Definition core.hpp:1749
CloneStatistics operator+(const CloneStatistics &s)
Return sum with s.
Definition core.hpp:4990
void reset(void)
Reset information.
Definition core.hpp:4983
CloneStatistics & operator+=(const CloneStatistics &s)
Increment by statistics s.
Definition core.hpp:4995
CloneStatistics(void)
Initialize.
Definition core.hpp:4986
Statistics for execution of commit
Definition core.hpp:1765
CommitStatistics & operator+=(const CommitStatistics &s)
Increment by statistics s.
Definition core.hpp:5012
void reset(void)
Reset information.
Definition core.hpp:5000
CommitStatistics operator+(const CommitStatistics &s)
Return sum with s.
Definition core.hpp:5007
CommitStatistics(void)
Initialize.
Definition core.hpp:5003
Commit trace information.
Definition core.hpp:1014
BrancherGroup group(void) const
Return brancher group.
Definition core.hpp:3584
friend class Space
Definition core.hpp:1015
unsigned int alternative(void) const
Return alternative.
Definition core.hpp:3596
const Brancher & b
Brancher.
Definition core.hpp:1018
CommitTraceInfo(const Brancher &b, const Choice &c, unsigned int a)
Initialize.
Definition core.hpp:3576
unsigned int id(void) const
Return brancher identifier.
Definition core.hpp:3580
unsigned int a
Alternative.
Definition core.hpp:1022
const Choice & c
Choice.
Definition core.hpp:1020
const Choice & choice(void) const
Return choice.
Definition core.hpp:3592
const Brancher & brancher(void) const
Return brancher.
Definition core.hpp:3588
Council of advisors
Definition core.hpp:1257
bool empty(void) const
Test whether council has advisor left.
Definition core.hpp:4140
void update(Space &home, Council< A > &c)
Update during cloning (copies all advisors).
Definition core.hpp:4150
void dispose(Space &home)
Dispose council.
Definition core.hpp:4206
friend class Advisor
Definition core.hpp:1258
Council(void)
Default constructor.
Definition core.hpp:4131
Generic domain change information to be supplied to advisors.
Definition core.hpp:209
friend class VarImp
Definition core.hpp:210
Base-class for freelist-managed objects.
Definition manager.hpp:100
Group baseclass for controlling actors.
Definition core.hpp:680
static Group all
Group of all actors.
Definition core.hpp:724
static Group def
Group of actors not in any user-defined group.
Definition core.hpp:727
static const unsigned int GROUPID_ALL
Fake id for group of all actors.
Definition core.hpp:690
Group(void)
Constructor.
bool in(void) const
Check whether this is a real group (and not just default).
Definition core.hpp:5235
friend class CommitTraceInfo
Definition core.hpp:686
static Support::Mutex m
Mutex for protection.
Definition core.hpp:702
friend class PostTraceInfo
Definition core.hpp:687
static const unsigned int GROUPID_MAX
The maximal group number.
Definition core.hpp:694
Group & operator=(const Group &g)
Assignment operator.
Definition core.hpp:5243
unsigned int id(void) const
Return a unique id for the group.
Definition core.hpp:5248
static const unsigned int GROUPID_DEF
Pre-defined default group id.
Definition core.hpp:692
unsigned int gid
The group id.
Definition core.hpp:696
bool in(Group a) const
Check whether actor group a is included in this group.
Definition core.hpp:5230
friend class Propagator
Definition core.hpp:682
friend class Brancher
Definition core.hpp:683
static unsigned int next
Next group id.
Definition core.hpp:699
friend class PropagateTraceInfo
Definition core.hpp:685
Group(unsigned int gid0)
Construct with predefined group id gid0.
Definition core.hpp:5227
friend class Home
Definition core.hpp:681
friend class ViewTraceInfo
Definition core.hpp:684
Base class for heap allocated objects.
Definition heap.hpp:344
static T * copy(T *d, const T *s, long unsigned int n)
Copy n objects starting at s to d.
Definition heap.hpp:593
Home class for posting propagators
Definition core.hpp:863
PropagatorGroup pg
A propagator group.
Definition core.hpp:871
BrancherGroup branchergroup(void) const
Return brancher group.
Definition core.hpp:3478
Home(Space &s, Propagator *p=nullptr, PropagatorGroup pg=PropagatorGroup::def, BrancherGroup bg=BrancherGroup::def)
Initialize the home with space s and propagator p and group g.
Definition core.hpp:3430
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition core.hpp:3363
Propagator * p
A propagator (possibly) that is currently being rewritten.
Definition core.hpp:869
Space & s
The space where the propagator is to be posted.
Definition core.hpp:867
void fail(void)
Mark space as failed.
Definition core.hpp:4274
BrancherGroup bg
A brancher group.
Definition core.hpp:873
Propagator * propagator(void) const
Return propagator (or nullptr) for currently rewritten propagator.
Definition core.hpp:3470
PropagatorGroup propagatorgroup(void) const
Return propagator group.
Definition core.hpp:3474
friend class PostInfo
Definition core.hpp:864
Home operator()(Propagator &p)
Return a home extended by propagator to be rewritten.
Definition core.hpp:3446
bool failed(void) const
Check whether corresponding space is failed.
Definition core.hpp:4283
Home & operator=(const Home &h)
Assignment operator.
Definition core.hpp:3437
Class for storing propagator information.
Definition gpi.hpp:42
unsigned int gid
Group identifier.
Definition gpi.hpp:47
Manage memory for space.
Definition manager.hpp:122
void * subscriptions(void) const
Get the memory area for subscriptions.
Definition manager.hpp:299
Class to store data shared among several spaces.
Handles for local (space-shared) objects.
Definition core.hpp:1576
LocalHandle(void)
Create local handle pointing to nullptr object.
Definition core.hpp:3958
~LocalHandle(void)
Destructor.
Definition core.hpp:3969
void update(Space &home, LocalHandle &lh)
Updating during cloning.
Definition core.hpp:3975
LocalHandle & operator=(const LocalHandle &lh)
Assignment operator.
Definition core.hpp:3964
LocalObject * object(void) const
Access to the local object.
Definition core.hpp:3971
Local (space-shared) object.
Definition core.hpp:1551
static LocalObject * cast(ActorLink *al)
Static cast for a non-null pointer (to give a hint to optimizer).
Definition core.hpp:3924
friend class Space
Definition core.hpp:1553
LocalObject * fwd(Space &home)
Return forwarding pointer.
Definition core.hpp:3951
friend class ActorLink
Definition core.hpp:1552
LocalObject(Home home)
Constructor for creation.
Definition core.hpp:3940
friend class LocalHandle
Definition core.hpp:1554
Information passed by meta search engines.
Definition core.hpp:1635
MetaInfo(unsigned long int r, RestartReason rr, unsigned long long int s, unsigned long long int f, const Space *l, NoGoods &ng)
Constructor for restart-based engine.
Definition core.hpp:3209
const NoGoods & nogoods(void) const
Return no-goods recorded from restart.
Definition core.hpp:3250
const unsigned long long int f
Number of failures since last restart.
Definition core.hpp:1669
Type
Which type of information is provided.
Definition core.hpp:1638
@ PORTFOLIO
Information is provided by a portfolio-based engine.
Definition core.hpp:1642
@ RESTART
Information is provided by a restart-based engine.
Definition core.hpp:1640
unsigned long long int fail(void) const
Return number of failures since last restart.
Definition core.hpp:3240
const RestartReason rr
Reason for restarting.
Definition core.hpp:1665
const Type t
Type of information.
Definition core.hpp:1659
unsigned int asset(void) const
Return number of asset in portfolio.
Definition core.hpp:3255
const Space * l
Last solution found.
Definition core.hpp:1671
unsigned long long int solution(void) const
Return number of solutions since last restart.
Definition core.hpp:3235
unsigned long int restart(void) const
Return number of restarts.
Definition core.hpp:3226
const Space * last(void) const
Return last solution found (possibly nullptr).
Definition core.hpp:3245
const unsigned long int r
Number of restarts.
Definition core.hpp:1663
RestartReason reason(void) const
Return reason for restarting.
Definition core.hpp:3231
const unsigned long long int s
Number of solutions since last restart.
Definition core.hpp:1667
const unsigned int a
Number of asset in portfolio.
Definition core.hpp:1678
RestartReason
Reason for restarting.
Definition core.hpp:1645
@ RR_NO
No reason - used for PORTFOLIO.
Definition core.hpp:1647
@ RR_INIT
Restarting after initialisation.
Definition core.hpp:1649
@ RR_SOL
Restarting after a solution is found.
Definition core.hpp:1651
@ RR_CMPL
Restarting after exhausting search space.
Definition core.hpp:1653
@ RR_LIM
Restarting after reaching restart limit.
Definition core.hpp:1655
const NoGoods & ng
No-goods from restart.
Definition core.hpp:1673
Type type(void) const
Return type of information.
Definition core.hpp:3222
No-good literal recorded during search.
Definition core.hpp:1358
bool leaf(void) const
Test whether literal is a leaf.
Definition core.hpp:4008
virtual ExecStatus prune(Space &home)=0
Propagate the negation of the no-good literal.
virtual void cancel(Space &home, Propagator &p)=0
Cancel propagator p from all views of the no-good literal.
virtual void subscribe(Space &home, Propagator &p)=0
Subscribe propagator p to all views of the no-good literal.
virtual bool notice(void) const
Whether dispose must always be called (returns false).
virtual NGL::Status status(const Space &home) const =0
Test the status of the no-good literal.
NGL(void)
Constructor for creation.
Definition core.hpp:4031
virtual NGL * copy(Space &home)=0
Create copy.
Status
The status of a no-good literal.
Definition core.hpp:1364
@ SUBSUMED
The literal is subsumed.
Definition core.hpp:1366
@ FAILED
The literal is failed.
Definition core.hpp:1365
@ NONE
The literal is neither failed nor subsumed.
Definition core.hpp:1367
virtual void reschedule(Space &home, Propagator &p)=0
Schedule propagator p for all views of the no-good literal.
virtual ~NGL(void)
To avoid warnings.
NGL * next(void) const
Return pointer to next literal.
Definition core.hpp:4012
virtual size_t dispose(Space &home)
Dispose.
Definition core.hpp:4040
NGL * add(NGL *n, bool l)
Add node n and mark it as leaf l and return n.
Definition core.hpp:4024
No-goods recorded from restarts.
Definition core.hpp:1606
static NoGoods eng
Empty no-goods.
Definition core.hpp:1628
virtual ~NoGoods(void)
Destructor.
Definition core.hpp:3202
NoGoods(void)
Initialize.
Definition core.hpp:3183
std::atomic< unsigned long int > n
Number of no-goods.
Definition core.hpp:1609
unsigned long int ng(void) const
Return number of no-goods posted.
Definition core.hpp:3194
virtual void post(Space &home) const
Post no-goods.
NoGoods & operator=(const NoGoods &ng)
Assignment operator.
Definition core.hpp:3189
Configuration class for variable implementations without index structure.
Definition core.hpp:103
static bool med_update(ModEventDelta &med, ModEvent me)
Update modification even delta med by me, return true on change.
Definition core.hpp:130
static const int free_bits
Freely available bits.
Definition core.hpp:112
static const int idx_c
Index for update.
Definition core.hpp:106
static const int med_fst
Start of bits for modification event delta.
Definition core.hpp:114
static const int med_lst
End of bits for modification event delta.
Definition core.hpp:116
static const PropCond pc_max
Maximal propagation condition.
Definition core.hpp:110
static const int idx_d
Index for disposal.
Definition core.hpp:108
static Gecode::ModEvent me_combine(ModEvent me1, ModEvent me2)
Combine modification events me1 and me2.
Definition core.hpp:126
static const int med_mask
Bitmask for modification event delta.
Definition core.hpp:118
Class to set group information when a post function is executed.
Definition core.hpp:957
Space & h
The home space.
Definition core.hpp:961
friend class Space
Definition core.hpp:958
PostInfo(Home home)
Set information.
Definition core.hpp:3528
bool nested
Whether it is used nested.
Definition core.hpp:967
unsigned int pid
Next free propagator id.
Definition core.hpp:965
PropagatorGroup pg
The propagator group.
Definition core.hpp:963
~PostInfo(void)
Reset information.
Definition core.hpp:3536
Post trace information.
Definition core.hpp:1041
unsigned int propagators(void) const
Return number of posted propagators.
Definition core.hpp:3617
friend class Space
Definition core.hpp:1042
PropagatorGroup group(void) const
Return propagator group.
Definition core.hpp:3609
PropagatorGroup g
Propagator group.
Definition core.hpp:1053
Status
Post status.
Definition core.hpp:1046
@ SUBSUMED
Propagator not posted as already subsumed.
Definition core.hpp:1049
@ FAILED
Posting failed.
Definition core.hpp:1048
@ POSTED
Propagator was posted.
Definition core.hpp:1047
Status status(void) const
Return post status.
Definition core.hpp:3613
friend class PostInfo
Definition core.hpp:1043
PostTraceInfo(PropagatorGroup g, Status s, unsigned int n)
Initialize.
Definition core.hpp:3606
Status s
Status.
Definition core.hpp:1055
unsigned int n
Number of posted propagators.
Definition core.hpp:1057
Propagation cost.
Definition core.hpp:493
ActualCost ac
Actual cost.
Definition core.hpp:516
friend class Space
Definition core.hpp:494
static PropCost unary(PropCost::Mod m)
Single variable for modifier pcm.
Definition core.hpp:5087
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition core.hpp:5079
static PropCost record(void)
For recording information (no propagation allowed).
Definition core.hpp:5039
static PropCost crazy(PropCost::Mod m, unsigned int n)
Exponential complexity for modifier m and size measure n.
Definition core.hpp:5043
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition core.hpp:5061
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition core.hpp:5070
static PropCost cubic(PropCost::Mod m, unsigned int n)
Cubic complexity for modifier m and size measure n.
Definition core.hpp:5052
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition core.hpp:5083
Mod
Propagation cost modifier.
Definition core.hpp:519
@ HI
Expensive.
Definition core.hpp:521
ActualCost
The actual cost values that are used.
Definition core.hpp:497
@ AC_TERNARY_LO
Three variables, cheap.
Definition core.hpp:509
@ AC_TERNARY_HI
Three variables, expensive.
Definition core.hpp:507
@ AC_BINARY_LO
Two variables, cheap.
Definition core.hpp:510
@ AC_CUBIC_LO
Cubic complexity, cheap.
Definition core.hpp:501
@ AC_UNARY_HI
Only single variable, expensive.
Definition core.hpp:512
@ AC_RECORD
Reserved for recording information.
Definition core.hpp:498
@ AC_BINARY_HI
Two variables, expensive.
Definition core.hpp:508
@ AC_LINEAR_HI
Linear complexity, expensive.
Definition core.hpp:505
@ AC_CUBIC_HI
Cubic complexity, expensive.
Definition core.hpp:502
@ AC_MAX
Maximal cost value.
Definition core.hpp:513
@ AC_CRAZY_LO
Exponential complexity, cheap.
Definition core.hpp:499
@ AC_LINEAR_LO
Linear complexity, cheap.
Definition core.hpp:506
@ AC_UNARY_LO
Only single variable, cheap.
Definition core.hpp:511
@ AC_QUADRATIC_LO
Quadratic complexity, cheap.
Definition core.hpp:503
@ AC_CRAZY_HI
Exponential complexity, expensive.
Definition core.hpp:500
@ AC_QUADRATIC_HI
Quadratic complexity, expensive.
Definition core.hpp:504
Propagate trace information.
Definition core.hpp:978
unsigned int i
Propagator id.
Definition core.hpp:990
Status
Propagator status.
Definition core.hpp:982
@ SUBSUMED
Propagator is subsumed.
Definition core.hpp:986
@ FIX
Propagator computed fixpoint.
Definition core.hpp:983
@ NOFIX
Propagator did not compute fixpoint.
Definition core.hpp:984
@ FAILED
Propagator failed.
Definition core.hpp:985
PropagateTraceInfo(unsigned int i, PropagatorGroup g, const Propagator *p, Status s)
Initialize.
Definition core.hpp:3550
const Propagator * propagator(void) const
Return pointer to non-subsumed propagator.
Definition core.hpp:3562
unsigned int id(void) const
Return propagator identifier.
Definition core.hpp:3554
Status status(void) const
Return propagator status.
Definition core.hpp:3566
const Propagator * p
Propagator.
Definition core.hpp:994
PropagatorGroup g
Propagator group.
Definition core.hpp:992
PropagatorGroup group(void) const
Return propagator group.
Definition core.hpp:3558
Group of propagators.
Definition core.hpp:734
unsigned int size(Space &home) const
Return number of propagators in a group.
bool operator==(PropagatorGroup g) const
Test whether this group is equal to group g.
Definition core.hpp:5275
static PropagatorGroup def
Group of propagators not in any user-defined group.
Definition core.hpp:799
PropagatorGroup & move(Space &home, PropagatorGroup g)
Move propagators from group g to this group.
friend class PostTraceInfo
Definition core.hpp:738
PropagatorGroup(unsigned int gid)
Initialize with group id gid.
Definition core.hpp:5257
bool operator!=(PropagatorGroup g) const
Test whether this group is different from group g.
Definition core.hpp:5279
PropagatorGroup(void)
Constructor.
Definition core.hpp:5254
PropagatorGroup & operator=(const PropagatorGroup &g)
Assignment operator.
Definition core.hpp:5265
friend class Propagator
Definition core.hpp:735
void disable(Space &home)
Disable all propagators in a group.
PropagatorGroup & move(Space &home, unsigned int id)
Move propagator with id id to this group.
void enable(Space &home, bool s=true)
Enable all propagators in a group.
Home operator()(Space &home)
To augment a space argument.
Definition core.hpp:5270
friend class PropagateTraceInfo
Definition core.hpp:737
void kill(Space &home)
Kill all propagators in a group.
friend class ViewTraceInfo
Definition core.hpp:736
static PropagatorGroup all
Group of all propagators.
Definition core.hpp:796
Base-class for propagators.
Definition core.hpp:1073
virtual void reschedule(Space &home)=0
Schedule function.
friend class SubscribedPropagators
Definition core.hpp:1079
friend class Space
Definition core.hpp:1075
double afc(void) const
Return the accumulated failure count.
Definition core.hpp:3732
virtual PropCost cost(const Space &home, const ModEventDelta &med) const =0
Cost function.
friend class ActorLink
Definition core.hpp:1074
virtual void advise(Space &home, Advisor &a)
Run advisor a to be run on failure in failed space.
Kernel::GPI::Info & gpi(void)
Provide access to propagator information.
Definition core.hpp:3692
unsigned int id(void) const
Return propagator id.
Definition core.hpp:3749
friend class VarImp
Definition core.hpp:1076
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Advise function.
friend class Advisor
Definition core.hpp:1077
PropagatorGroup group(void) const
Return group propagator belongs to.
Definition core.hpp:3754
ModEventDelta modeventdelta(void) const
Return the modification event delta.
Definition core.hpp:3727
Propagator * fwd(void) const
Return forwarding pointer during copying.
Definition core.hpp:3665
friend class PropagatorGroup
Definition core.hpp:1080
friend class Council
Definition core.hpp:1078
bool disabled(void) const
Whether propagator is currently disabled.
Definition core.hpp:3675
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)=0
Propagation function.
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3697
bool operator()(void) const
Test whether there are propagators left.
Definition core.hpp:5340
const Propagator & propagator(void) const
Return propagator.
Definition core.hpp:5350
void operator++(void)
Move iterator to next propagator.
Definition core.hpp:5344
Propagators(const Space &home, PropagatorGroup g)
Initialize.
Definition core.hpp:5334
Class to iterate over branchers of a space.
Definition core.hpp:2861
Brancher & brancher(void) const
Return propagator.
Definition core.hpp:5218
void operator++(void)
Move iterator to next brancher.
Definition core.hpp:5214
Branchers(Space &home)
Initialize.
Definition core.hpp:5207
bool operator()(void) const
Test whether there are branchers left.
Definition core.hpp:5210
void operator++(void)
Move iterator to next propagator.
Definition core.hpp:5197
Propagator & propagator(void) const
Return propagator.
Definition core.hpp:5201
bool operator()(void) const
Test whether there are propagators left.
Definition core.hpp:5193
IdlePropagators(Space &home)
Initialize.
Definition core.hpp:5188
~NoGPI(void)
Restore the previous setting.
Definition core.hpp:3628
Class to iterate over propagators of a space.
Definition core.hpp:2790
bool operator()(void) const
Test whether there are propagators left.
Definition core.hpp:5114
Propagators(Space &home)
Initialize.
Definition core.hpp:5096
void operator++(void)
Move iterator to next propagator.
Definition core.hpp:5118
Propagator & propagator(void) const
Return propagator.
Definition core.hpp:5142
ScheduledPropagators(Space &home)
Initialize.
Definition core.hpp:5148
Propagator & propagator(void) const
Return propagator.
Definition core.hpp:5182
bool operator()(void) const
Test whether there are propagators left.
Definition core.hpp:5160
void operator++(void)
Move iterator to next propagator.
Definition core.hpp:5164
~UseGPI(void)
Restore the previous setting.
Definition core.hpp:3639
Computation spaces.
Definition core.hpp:1782
T * realloc(T *b, long unsigned int n, long unsigned int m)
Reallocate block of n objects starting at b to m objects of type T from the space heap.
Definition core.hpp:3014
friend void trace(Home home, TraceFilter tf, int te, Tracer &t)
Create tracer.
void * ralloc(size_t s)
Allocate memory on space heap.
Definition core.hpp:2925
double afc_decay(void) const
Return AFC decay factor.
Definition core.hpp:3410
void afc_unshare(void)
Unshare AFC information for all propagators.
T & construct(void)
Construction routines.
Definition core.hpp:5382
friend class LocalObject
Definition core.hpp:1794
void * rrealloc(void *b, size_t n, size_t m)
Reallocate memory block starting at b from size n to size s.
Definition core.hpp:2933
friend class VarImpDisposer
Definition core.hpp:1793
void rfree(void *p, size_t s)
Free memory previously allocated with alloc (might be reused later).
Definition core.hpp:2929
void * fl_alloc(void)
Allocate from freelist-managed memory.
Definition core.hpp:2948
friend class AFC
Definition core.hpp:1796
friend class VarImp
Definition core.hpp:1792
friend class Advisor
Definition core.hpp:1790
friend class PostInfo
Definition core.hpp:1797
void afc_decay(double d)
Set AFC decay factor to d
Definition core.hpp:3415
friend class Propagator
Definition core.hpp:1784
void fl_dispose(FreeList *f, FreeList *l)
Return freelist-managed memory to freelist.
Definition core.hpp:2953
friend class PropagatorGroup
Definition core.hpp:1785
friend class Region
Definition core.hpp:1795
friend class Brancher
Definition core.hpp:1787
friend class Council
Definition core.hpp:1791
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2963
friend class BrancherGroup
Definition core.hpp:1788
void free(T *b, long unsigned int n)
Delete n objects allocated from space heap starting at b.
Definition core.hpp:2989
friend class Actor
Definition core.hpp:1783
Home operator()(Propagator &p)
Return a home for this space with the information that p is being rewritten.
Definition core.hpp:3458
SpaceStatus status(void)
Query space status without collecting statistics.
Definition core.hpp:3368
Statistics for execution of status
Definition core.hpp:1731
void reset(void)
Reset information.
Definition core.hpp:4964
StatusStatistics(void)
Initialize.
Definition core.hpp:4968
unsigned long long int propagate
Number of propagator executions.
Definition core.hpp:1734
StatusStatistics operator+(const StatusStatistics &s)
Return sum with s.
Definition core.hpp:4977
StatusStatistics & operator+=(const StatusStatistics &s)
Increment by statistics s.
Definition core.hpp:4972
Iterator over subscribed propagators.
A mutex for mutual exclausion among several threads.
Definition thread.hpp:78
Exception: too many branchers
Definition exception.hpp:93
Trace filters.
Definition filter.hpp:133
Propagator for recording trace information.
Definition recorder.hpp:154
Base-class for variable implementations.
Definition core.hpp:177
Base class for Variable type disposer.
Definition core.hpp:185
virtual void dispose(Space &home, VarImpBase *x)
Dispose list of variable implementations starting at x.
virtual ~VarImpDisposerBase(void)
Destructor (not used).
VarImpDisposer(void)
Constructor (registers disposer with kernel).
Definition core.hpp:4944
virtual void dispose(Space &home, VarImpBase *x)
Dispose list of variable implementations starting at x.
Definition core.hpp:4952
Base-class for variable implementations.
Definition core.hpp:224
void subscribe(Space &home, Propagator &p, PropCond pc, bool assigned, ModEvent me, bool schedule)
Subscribe propagator p with propagation condition pc.
Definition core.hpp:4629
ModEvent fail(Space &home)
Run advisors to be run on failure and returns ME_GEN_FAILED.
Definition core.hpp:4819
void cancel(Space &home)
Cancel all subscriptions when variable implementation is assigned.
Definition core.hpp:4736
bool advise(Space &home, ModEvent me, Delta &d)
Run advisors when variable implementation has been modified with modification event me and domain cha...
Definition core.hpp:4753
VarImp * next(void) const
Return next copied variable.
Definition core.hpp:4478
VarImp(void)
Creation of static instances.
Definition core.hpp:4380
friend class SubscribedPropagators
Definition core.hpp:228
friend class Space
Definition core.hpp:225
double afc(void) const
Return accumulated failure count (plus degree).
Definition core.hpp:4408
unsigned int bits(void) const
Provide access to free bits.
Definition core.hpp:4439
bool copied(void) const
Is variable already copied.
Definition core.hpp:4465
friend class VarImpDisposer
Definition core.hpp:227
static void reschedule(Space &home, Propagator &p, PropCond pc, bool assigned, ModEvent me)
Schedule propagator p.
Definition core.hpp:4655
static void schedule(Space &home, Propagator &p, ModEvent me, bool force=false)
Definition core.hpp:4531
VarImp * forward(void) const
Use forward pointer if variable already copied.
Definition core.hpp:4471
static ModEvent me(const ModEventDelta &med)
Definition core.hpp:4513
static ModEvent me_combine(ModEvent me1, ModEvent me2)
Combine modifications events me1 and me2.
Definition core.hpp:4525
friend class Propagator
Definition core.hpp:226
unsigned int degree(void) const
Return degree (number of subscribed propagators and advisors).
Definition core.hpp:4401
VarImp(Space &home)
Creation.
Definition core.hpp:4364
static ModEventDelta med(ModEvent me)
Definition core.hpp:4519
static ModEvent modevent(const Delta &d)
Return modification event.
Definition core.hpp:4433
View trace information.
Definition core.hpp:917
What what(void) const
Return what is currently executing.
Definition core.hpp:3503
friend class Space
Definition core.hpp:918
const Brancher & brancher(void) const
Return currently executing brancher.
Definition core.hpp:3513
const Propagator & propagator(void) const
Return currently executing propagator.
Definition core.hpp:3507
void brancher(Brancher &b)
Record that brancher b is executing.
Definition core.hpp:3491
void other(void)
Record that nothing is known at this point.
Definition core.hpp:3499
friend class PostInfo
Definition core.hpp:919
What
What is currently executing.
Definition core.hpp:922
@ BRANCHER
A brancher is executing.
Definition core.hpp:926
@ POST
A post function is executing.
Definition core.hpp:928
@ PROPAGATOR
A propagator is currently executing.
Definition core.hpp:924
PropagatorGroup post(void) const
Return propagator group of currently executing post function.
Definition core.hpp:3519
void propagator(Propagator &p)
Record that propagator p is executing.
Definition core.hpp:3487
Support::uptrint_t who
Encoding a tagged pointer or a tagged group id.
Definition core.hpp:934
void post(PropagatorGroup g)
Record that a post function with propagator group g is executing.
Definition core.hpp:3495
#define GECODE_KERNEL_REALLOC(T)
Definition core.hpp:3049
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
ExecStatus ES_NOFIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has not computed partial fixpoint
Definition core.hpp:3783
ExecStatus ES_FIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has computed partial fixpoint
Definition core.hpp:3776
ExecStatus ES_SUBSUMED_DISPOSED(Propagator &p, size_t s)
Propagator p is subsumed
Definition core.hpp:3764
ExecStatus ES_FIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed
Definition core.hpp:4104
ExecStatus ES_NOFIX_DISPOSE_FORCE(Council< A > &c, A &a)
Advisor a must be disposed and its propagator must be forcefully rescheduled
Definition core.hpp:4118
ExecStatus ES_NOFIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed and its propagator must be run
Definition core.hpp:4111
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3770
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition core.hpp:4311
int ModEventDelta
Modification event deltas.
Definition core.hpp:94
bool failed(void) const
Check whether space is failed.
Definition core.hpp:4279
ActorProperty
Actor properties.
Definition core.hpp:560
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition core.hpp:4294
bool stable(void) const
Return if space is stable (at fixpoint or failed).
Definition core.hpp:4288
void fail(void)
Fail space.
Definition core.hpp:4265
@ AP_VIEW_TRACE
Definition core.hpp:580
@ AP_DISPOSE
Actor must always be disposed.
Definition core.hpp:569
@ AP_TRACE
Definition core.hpp:585
@ AP_WEAKLY
Definition core.hpp:575
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
virtual ~Space(void)
Destructor.
Space(void)
Default constructor.
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
virtual bool master(const MetaInfo &mi)
Master configuration function for meta search engines.
virtual void constrain(const Space &best)
Constrain function for best solution search.
Space(Space &s)
Constructor for cloning.
virtual Space * copy(void)=0
Copying member function.
const Choice * choice(Archive &e) const
Create new choice from e.
void print(const Choice &c, unsigned int a, std::ostream &o) const
Print branch for choice c and alternative a.
Space * clone(void) const
Clone space.
Definition core.hpp:3374
const Choice * choice(void)
Create new choice for current brancher.
SpaceStatus status(StatusStatistics &stat)
Query space status.
NGL * ngl(const Choice &c, unsigned int a)
Create no-good literal for choice c and alternative a.
void trycommit(const Choice &c, unsigned int a)
If possible, commit choice c for alternative a.
Definition core.hpp:3399
void commit(const Choice &c, unsigned int a)
Commit choice c for alternative a.
Definition core.hpp:3388
SpaceStatus
Space status
Definition core.hpp:1721
@ SS_BRANCH
Space must be branched (at least one brancher left)
Definition core.hpp:1724
@ SS_SOLVED
Space is solved (no brancher left)
Definition core.hpp:1723
@ SS_FAILED
Space is failed
Definition core.hpp:1722
#define GECODE_KERNEL_EXPORT
Definition kernel.hh:70
void update(VY &y, Space &home, bool shared, VY py)
Update view y from py.
void * ptrjoin(void *p, ptrdiff_t m)
Join unmarked pointer p and m into marked pointer.
void * ptrsplit(void *p, ptrdiff_t &m)
Split possibly marked pointer p into mark m and unmarked pointer.
void * unmark(void *p)
Return unmarked pointer for a marked pointer p.
std::make_unsigned_t< ptrdiff_t > uptrint_t
Unsigned integer for pointer encodings.
Definition int-type.hpp:53
void * fmark(void *p)
Return marked pointer for p (possibly already marked).
void * mark(void *p)
Return marked pointer for unmarked pointer p.
void * funmark(void *p)
Clear the lowest bits bits of a possibly marked pointer p.
bool marked(void *p)
Check whether p is marked.
Gecode toplevel namespace
const PropCond PC_GEN_ASSIGNED
Propagation condition for an assigned variable.
Definition core.hpp:81
const ModEvent ME_GEN_NONE
Generic modification event: no modification.
Definition core.hpp:72
TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
ExecStatus
Definition core.hpp:479
@ ES_OK
Execution is okay.
Definition core.hpp:483
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:484
@ ES_SUBSUMED_
Internal: propagator is subsumed, do not use.
Definition core.hpp:480
@ ES_NOFIX_FORCE
Advisor forces rescheduling of propagator.
Definition core.hpp:485
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:481
@ ES_PARTIAL_
Internal: propagator has computed partial fixpoint, do not use.
Definition core.hpp:486
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:482
const ModEvent ME_GEN_FAILED
Generic modification event: failed variable.
Definition core.hpp:70
void unary(Home home, const IntVarArgs &s, const IntArgs &p, IntPropLevel ipl=IPL_DEF)
Post propagators for scheduling tasks on unary resources.
int PropCond
Type for propagation conditions.
Definition core.hpp:77
const ModEvent ME_GEN_ASSIGNED
Generic modification event: variable is assigned a value.
Definition core.hpp:74
const PropCond PC_GEN_NONE
Propagation condition to be ignored (convenience).
Definition core.hpp:79
int ModEvent
Type for modification events.
Definition core.hpp:67
const int * pi[]
Definition photo.cpp:14262
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56
#define GECODE_NOT_NULL(p)
Assert that a pointer is never nullptr.
Definition macros.hpp:75
#define GECODE_VTABLE_EXPORT
Definition support.hh:76