57 Actor* Actor::sentinel;
98 std::ostream&)
const {
111#ifdef GECODE_HAS_VAR_DISPOSE
119#ifdef GECODE_HAS_VAR_DISPOSE
126 b_status = b_commit = Brancher::cast(&bl);
128 d_fst = d_cur = d_lst = NULL;
130 pc.p.active = &pc.p.queue[0]-1;
133 pc.p.queue[i].init();
134 pc.p.bid_sc = (reserved_bid+1) << sc_bits;
140 Space::ap_notice_dispose(
Actor*
a,
bool duplicate) {
142 if (duplicate && (d_fst != NULL)) {
143 for (
Actor** f = d_fst; f < d_cur; f++)
147 if (d_cur == d_lst) {
151 d_fst = alloc<Actor*>(4);
156 unsigned int n =
static_cast<unsigned int>(d_lst - d_fst);
158 d_fst = realloc<Actor*>(d_fst,
n,2*
n);
167 Space::ap_ignore_dispose(Actor*
a,
bool duplicate) {
169 assert(d_fst != NULL);
202#ifdef GECODE_HAS_VAR_DISPOSE
205 if (_vars_d[i] != NULL)
206 vd[i]->dispose(*
this, _vars_d[i]);
220 Space::findtracerecorder(
void) {
221 for (
Actor**
a=d_fst;
a<d_cur;
a++) {
225 std::swap(*d_fst,*
a);
233 Space::post(
const PostInfo&
pi) {
234 assert(pc.p.bid_sc & sc_trace);
235 TraceRecorder* tr = findtracerecorder();
236 if ((tr != NULL) && (tr->events() &
TE_POST)) {
246 PostTraceInfo pti(
pi.pg,s,
n);
247 tr->tracer()._post(*
this,pti);
259 if (pc.p.active >= &pc.p.queue[0]) {
261 if ((pc.p.bid_sc & ((1 << sc_bits) - 1)) == 0) {
271 switch (
p->propagate(*
this,med_o)) {
280 assert(pc.p.active >= &pc.p.queue[0]);
283 if (pc.p.active != fst) {
284 p = Propagator::cast(fst);
297 f_stable_or_unstable:
300 assert(pc.p.active >= &pc.p.queue[0]);
303 if (pc.p.active != fst) {
304 p = Propagator::cast(fst);
307 }
while (--pc.p.active >= &pc.p.queue[0]);
308 assert(pc.p.active < &pc.p.queue[0]);
312 goto f_stable_or_unstable;
315 assert(
p->u.med != 0);
322 }
else if ((pc.p.bid_sc & ((1 << sc_bits) - 1)) == sc_disabled) {
328 goto d_put_into_idle;
333 switch (
p->propagate(*
this,med_o)) {
342 assert(pc.p.active >= &pc.p.queue[0]);
345 if (pc.p.active != fst) {
346 p = Propagator::cast(fst);
360 d_stable_or_unstable:
363 assert(pc.p.active >= &pc.p.queue[0]);
366 if (pc.p.active != fst) {
367 p = Propagator::cast(fst);
370 }
while (--pc.p.active >= &pc.p.queue[0]);
371 assert(pc.p.active < &pc.p.queue[0]);
375 goto d_stable_or_unstable;
378 assert(
p->u.med != 0);
388#define GECODE_STATUS_TRACE(q,s) \
389 if ((tr != NULL) && (tr->events() & TE_PROPAGATE) && \
390 (tr->filter()(p->group()))) { \
391 PropagateTraceInfo pti(p->id(),p->group(),q, \
392 PropagateTraceInfo::s); \
393 tr->tracer()._propagate(*this,pti); \
405 goto t_put_into_idle;
406 pc.p.vti.propagator(*
p);
411 switch (
p->propagate(*
this,med_o)) {
422 assert(pc.p.active >= &pc.p.queue[0]);
425 if (pc.p.active != fst) {
426 p = Propagator::cast(fst);
441 t_stable_or_unstable:
444 assert(pc.p.active >= &pc.p.queue[0]);
447 if (pc.p.active != fst) {
448 p = Propagator::cast(fst);
451 }
while (--pc.p.active >= &pc.p.queue[0]);
452 assert(pc.p.active < &pc.p.queue[0]);
457 goto t_stable_or_unstable;
461 assert(
p->u.med != 0);
471#undef GECODE_STATUS_TRACE
499 while (b_status != Brancher::cast(&bl))
500 if (b_status->
status(*
this)) {
505 b_status = Brancher::cast(b_status->next());
524 switch (top->
propagate(*
this,top_med_o)) {
540 if (
failed() || (b_status == Brancher::cast(&bl))) {
544 while (
b != Brancher::cast(&bl)) {
546 b = Brancher::cast(
b->next());
547 rfree(d,d->dispose(*
this));
550 b_status = b_commit = Brancher::cast(&bl);
558 while (
b != b_status) {
560 b = Brancher::cast(
b->next());
562 rfree(d,d->dispose(*
this));
566 return b_status->
choice(*
this);
571 unsigned int id; e >> id;
573 while (b_cur != Brancher::cast(&bl)) {
574 if (
id == b_cur->
id())
575 return b_cur->
choice(*
this,e);
576 b_cur = Brancher::cast(b_cur->next());
582 Space::_commit(
const Choice& c,
unsigned int a) {
583 if (
a >=
c.alternatives())
589 if (pc.p.bid_sc & sc_trace) {
594 tr->
tracer()._commit(*
this,cti);
596 ViewTraceInfo
vti = pc.p.vti;
597 pc.p.vti.brancher(*
b);
608 throw SpaceNoBrancher(
"Space::commit");
613 Space::_trycommit(
const Choice& c,
unsigned int a) {
614 if (
a >=
c.alternatives())
615 throw SpaceIllegalAlternative(
"Space::commit");
620 if (pc.p.bid_sc & sc_trace) {
621 TraceRecorder* tr = findtracerecorder();
622 if ((tr != NULL) && (tr->events() &
TE_COMMIT) &&
623 tr->filter()(
b->group())) {
624 CommitTraceInfo cti(*
b,
c,
a);
625 tr->tracer()._commit(*
this,cti);
627 ViewTraceInfo
vti = pc.p.vti;
628 pc.p.vti.brancher(*
b);
642 if (
a >=
c.alternatives())
648 return b->ngl(*
this,
c,
a);
656 if (
a >=
c.alternatives())
662 b->print(*
this,
c,
a,o);
670 Space::kill_brancher(
unsigned int id) {
674 b != Brancher::cast(&bl);
b = Brancher::cast(
b->next()))
695 mm(ssd.data().sm,s.mm,s.pc.
p.n_sub*sizeof(
Propagator**)),
697 var_id_counter(s.var_id_counter),
699 d_fst(&
Actor::sentinel) {
700#ifdef GECODE_HAS_VAR_DISPOSE
705 pc.c.vars_u[i] = NULL;
706 pc.c.vars_noidx = NULL;
713 Actor*
c = Actor::cast(
a)->copy(*
this);
727 Actor* c = Actor::cast(
a)->copy(*
this);
734 p->next(&bl); bl.prev(
p);
737 if (s.b_status == &s.bl) {
738 b_status = Brancher::cast(&bl);
740 b_status = Brancher::cast(s.b_status->prev());
742 if (s.b_commit == &s.bl) {
743 b_commit = Brancher::cast(&bl);
745 b_commit = Brancher::cast(s.b_commit->prev());
750 Space::_clone(
void) {
752 throw SpaceFailed(
"Space::clone");
754 throw SpaceNotStable(
"Space::clone");
759 if (
c->d_fst != &Actor::sentinel)
760 throw SpaceNotCloned(
"Space::clone");
764 unsigned int n =
static_cast<unsigned int>(d_cur - d_fst);
767 c->d_fst =
c->d_cur =
c->d_lst = NULL;
770 c->d_fst =
c->alloc<Actor*>(
n+1);
772 c->d_lst =
c->d_fst+
n+1;
773 for (Actor** d_fst_iter = d_fst; d_fst_iter != d_cur; d_fst_iter++) {
775 Actor*
a =
static_cast<Actor*
>(Support::ptrsplit(*d_fst_iter,m));
777 *(
c->d_cur++) = Actor::cast(
static_cast<ActorLink*
>
778 (Support::ptrjoin(
a->prev(),m)));
784 VarImp<NoIdxVarImpConf>*
x =
785 static_cast<VarImp<NoIdxVarImpConf>*
>(
c->pc.c.vars_noidx);
787 VarImp<NoIdxVarImpConf>*
n =
x->next();
788 x->b.base = NULL;
x->u.idx[0] = 0;
789 if (
sizeof(ActorLink**) >
sizeof(
unsigned int))
790 *(1+&
x->u.idx[0]) = 0;
794 c->update(
static_cast<ActorLink**
>(
c->mm.subscriptions()));
798 ActorLink* p_a = &pl;
799 ActorLink* c_a = p_a->next();
802 Propagator*
p = Propagator::cast(c_a);
803 if (
p->u.advisors != NULL) {
804 ActorLink*
a =
p->u.advisors;
805 p->u.advisors = NULL;
807 a->prev(
p);
a =
a->next();
810 c_a->prev(p_a); p_a = c_a; c_a = c_a->next();
814 ActorLink* p_a = &bl;
815 ActorLink* c_a = p_a->next();
818 c_a->prev(p_a); p_a = c_a; c_a = c_a->next();
823 for (ActorLink*
l =
c->pc.c.local;
l != NULL;
l =
l->next())
827 c->pc.p.active = &
c->pc.p.queue[0]-1;
828 for (
int i=0;
i<=PropCost::AC_MAX;
i++)
829 c->pc.p.queue[i].init();
831 c->pc.p.n_sub = pc.p.n_sub;
832 c->pc.p.bid_sc = pc.p.bid_sc;
835 c->pc.p.vti.other(); pc.p.vti.other();
847 case MetaInfo::RESTART:
848 if (mi.
last() != NULL)
849 constrain(*mi.
last());
853 case MetaInfo::PORTFOLIO:
855 BrancherGroup::all.kill(*
this);
869 Space::afc_unshare(
void) {
870 if (ssd.data().gpi.unshare()) {
874 = ssd.data().gpi.allocate(
p.gpi().pid,
p.gpi().gid);
876 p.gpi_disabled = Support::mark(gpi);
878 p.gpi_disabled = gpi;
884 LocalObject::fwdcopy(
Space& home) {
885 ActorLink::cast(
this)->prev(copy(home));
896 NGL::notice(
void)
const {
908 Group Group::all(GROUPID_ALL);
909 Group Group::def(GROUPID_DEF);
917 unsigned int Group::next = GROUPID_DEF+1;
926 if (gid == GROUPID_MAX)
933 if ((
id() != GROUPID_ALL) && (
id() != g.
id()))
935 if (g.
in(ps.propagator().group()))
936 ps.propagator().group(*
this);
941 PropagatorGroup::move(
Space& home,
unsigned int pid) {
942 if (
id() == GROUPID_ALL)
945 if (ps.propagator().id() == pid) {
946 ps.propagator().group(*
this);
955 PropagatorGroup::size(
Space& home)
const {
960 if (in(ps.propagator().group()))
966 PropagatorGroup::kill(
Space& home) {
979 PropagatorGroup::disable(
Space& home) {
983 if (in(ps.propagator().group()))
984 ps.propagator().disable(home);
988 PropagatorGroup::enable(
Space& home,
bool s) {
1003 if (in(ps.propagator().group()))
1004 ps.propagator().enable(home);
1011 if ((
id() != GROUPID_ALL) && (
id() != g.
id()))
1013 if (g.
in(bs.brancher().group()))
1014 bs.brancher().group(*
this);
1019 BrancherGroup::move(
Space& home,
unsigned int bid) {
1020 if (
id() == GROUPID_ALL)
1023 if (bs.brancher().id() == bid) {
1024 bs.brancher().group(*
this);
1033 BrancherGroup::size(
Space& home)
const {
1038 if (in(bs.brancher().group()))
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Node * x
Pointer to corresponding Boolean expression node.
Double-linked list for actors.
ActorLink * next(void) const
void init(void)
Initialize links (self-linked)
void head(ActorLink *al)
Insert al directly after this.
ActorLink * prev(void) const
Routines for double-linked list.
static ActorLink * cast(T *a)
Static cast for a non-null pointer (to give a hint to optimizer)
Base-class for both propagators and branchers.
virtual ~Actor(void)
To avoid warnings.
virtual size_t dispose(Space &home)
Delete actor and return its size.
static const int idx_d
Index for dispose.
static const int idx_c
Index for cloning.
Base-class for branchers.
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(Space &home)=0
Return choice.
unsigned int id(void) const
Return brancher id.
virtual bool status(const Space &home) const =0
Check status of brancher, return true if alternatives left.
virtual NGL * ngl(Space &home, const Choice &c, unsigned int a) const
Create no-good literal for choice c and alternative a.
Choice for performing commit
Statistics for execution of clone
Statistics for execution of commit
Commit trace information.
Generic domain change information to be supplied to advisors.
Group baseclass for controlling actors.
unsigned int id(void) const
Return a unique id for the group.
bool in(Group a) const
Check whether actor group a is included in this group.
Class for storing propagator information.
unsigned int pid(void) const
Return next free propagator id.
void fail(Info &c)
Increment failure count.
void release(SharedMemory &sm)
Release all allocated heap chunks.
GPI gpi
The global propagator information.
SharedMemory sm
The shared memory area.
Data & data(void) const
Provide access.
No-good literal recorded during search.
No-goods recorded from restarts.
virtual void post(Space &home) const
Post no-goods.
static NoGoods eng
Empty no-goods.
@ SUBSUMED
Propagator not posted as already subsumed.
@ POSTED
Propagator was posted.
@ AC_RECORD
Reserved for recording information.
@ AC_MAX
Maximal cost value.
Base-class for propagators.
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Advise function.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)=0
Propagation function.
ModEventDelta med
A set of modification events (used during propagation)
Exception: Commit with illegal alternative
Exception: Commit when no brancher present
Exception: Operation on not stable space invoked
Class to iterate over branchers of a space.
Brancher & brancher(void) const
Return propagator.
Class to iterate over propagators of a space.
Propagator & propagator(void) const
Return propagator.
struct Gecode::Space::@61::@63 c
Data available only during copying.
LocalObject * local
Linked list of local objects.
void rfree(void *p, size_t s)
Free memory previously allocated with alloc (might be reused later)
struct Gecode::Space::@61::@62 p
Data only available during propagation or branching.
ViewTraceInfo vti
View trace information.
Statistics for execution of status
unsigned long int propagate
Number of propagator executions.
A lock as a scoped frontend for a mutex.
A mutex for mutual exclausion among several threads.
Exception: too many groups
Propagator for recording trace information.
int events(void) const
Which events to trace.
const TraceFilter & filter(void) const
Return trace filter.
Tracer & tracer(void) const
Return tracer.
Exception: unknown brancher
Exception: unknown propagator
Base-class for variable implementations.
Base class for Variable type disposer.
virtual void dispose(Space &home, VarImpBase *x)
Dispose list of variable implementations starting at x.
virtual ~VarImpDisposerBase(void)
Destructor (not used)
#define GECODE_STATUS_TRACE(q, s)
int ModEventDelta
Modification event deltas.
bool failed(void) const
Check whether space is failed.
bool stable(void) const
Return if space is stable (at fixpoint or failed)
void fail(void)
Fail space.
Space(void)
Default constructor.
virtual ~Space(void)
Destructor.
void print(const Choice &c, unsigned int a, std::ostream &o) const
Print branch for choice c and alternative a.
const Choice * choice(void)
Create new choice for current brancher.
NGL * ngl(const Choice &c, unsigned int a)
Create no-good literal for choice c and alternative a.
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
@ SS_BRANCH
Space must be branched (at least one brancher left)
@ SS_SOLVED
Space is solved (no brancher left)
@ SS_FAILED
Space is failed
@ TE_POST
Trace propagator posting.
@ TE_COMMIT
Trace commit operations by branchers.
bool marked(void *p)
Check whether p is marked.
Gecode toplevel namespace
@ ES_FIX
Propagation has computed fixpoint.
@ __ES_SUBSUMED
Internal: propagator is subsumed, do not use.
@ __ES_PARTIAL
Internal: propagator has computed partial fixpoint, do not use.
@ ES_FAILED
Execution has resulted in failure.
@ ES_NOFIX
Propagation has not computed fixpoint.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i({1, 2, 3, 4})
#define GECODE_NEVER
Assert that this command is never executed.
#define GECODE_ASSUME(p)
Assert certain property.