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)) {
541 if (
failed() || (b_status == Brancher::cast(&bl))) {
545 while (
b != Brancher::cast(&bl)) {
547 b = Brancher::cast(
b->next());
548 rfree(d,d->dispose(*
this));
551 b_status = b_commit = Brancher::cast(&bl);
559 while (
b != b_status) {
561 b = Brancher::cast(
b->next());
563 rfree(d,d->dispose(*
this));
567 return b_status->
choice(*
this);
572 unsigned int id; e >> id;
574 while (b_cur != Brancher::cast(&bl)) {
575 if (
id == b_cur->
id())
576 return b_cur->
choice(*
this,e);
577 b_cur = Brancher::cast(b_cur->next());
583 Space::_commit(
const Choice& c,
unsigned int a) {
584 if (
a >=
c.alternatives())
590 if (pc.p.bid_sc & sc_trace) {
595 tr->
tracer()._commit(*
this,cti);
597 ViewTraceInfo
vti = pc.p.vti;
598 pc.p.vti.brancher(*
b);
609 throw SpaceNoBrancher(
"Space::commit");
614 Space::_trycommit(
const Choice& c,
unsigned int a) {
615 if (
a >=
c.alternatives())
616 throw SpaceIllegalAlternative(
"Space::commit");
621 if (pc.p.bid_sc & sc_trace) {
622 TraceRecorder* tr = findtracerecorder();
623 if ((tr != NULL) && (tr->events() &
TE_COMMIT) &&
624 tr->filter()(
b->group())) {
625 CommitTraceInfo cti(*
b,
c,
a);
626 tr->tracer()._commit(*
this,cti);
628 ViewTraceInfo
vti = pc.p.vti;
629 pc.p.vti.brancher(*
b);
643 if (
a >=
c.alternatives())
649 return b->ngl(*
this,
c,
a);
657 if (
a >=
c.alternatives())
663 b->print(*
this,
c,
a,o);
671 Space::kill_brancher(
unsigned int id) {
675 b != Brancher::cast(&bl);
b = Brancher::cast(
b->next()))
696 mm(ssd.data().sm,s.mm,s.pc.
p.n_sub*sizeof(
Propagator**)),
698 var_id_counter(s.var_id_counter),
700 d_fst(&
Actor::sentinel) {
701#ifdef GECODE_HAS_VAR_DISPOSE
706 pc.c.vars_u[i] = NULL;
707 pc.c.vars_noidx = NULL;
714 Actor*
c = Actor::cast(
a)->copy(*
this);
728 Actor* c = Actor::cast(
a)->copy(*
this);
735 p->next(&bl); bl.prev(
p);
738 if (s.b_status == &s.bl) {
739 b_status = Brancher::cast(&bl);
741 b_status = Brancher::cast(s.b_status->prev());
743 if (s.b_commit == &s.bl) {
744 b_commit = Brancher::cast(&bl);
746 b_commit = Brancher::cast(s.b_commit->prev());
751 Space::_clone(
void) {
753 throw SpaceFailed(
"Space::clone");
755 throw SpaceNotStable(
"Space::clone");
760 if (
c->d_fst != &Actor::sentinel)
761 throw SpaceNotCloned(
"Space::clone");
765 unsigned int n =
static_cast<unsigned int>(d_cur - d_fst);
768 c->d_fst =
c->d_cur =
c->d_lst = NULL;
771 c->d_fst =
c->alloc<Actor*>(
n+1);
773 c->d_lst =
c->d_fst+
n+1;
774 for (Actor** d_fst_iter = d_fst; d_fst_iter != d_cur; d_fst_iter++) {
776 Actor*
a =
static_cast<Actor*
>(Support::ptrsplit(*d_fst_iter,m));
778 *(
c->d_cur++) = Actor::cast(
static_cast<ActorLink*
>
779 (Support::ptrjoin(
a->prev(),m)));
785 VarImp<NoIdxVarImpConf>*
x =
786 static_cast<VarImp<NoIdxVarImpConf>*
>(
c->pc.c.vars_noidx);
788 VarImp<NoIdxVarImpConf>*
n =
x->next();
789 x->b.base = NULL;
x->u.idx[0] = 0;
790 if (
sizeof(ActorLink**) >
sizeof(
unsigned int))
791 *(1+&
x->u.idx[0]) = 0;
795 c->update(
static_cast<ActorLink**
>(
c->mm.subscriptions()));
799 ActorLink* p_a = &pl;
800 ActorLink* c_a = p_a->next();
803 Propagator*
p = Propagator::cast(c_a);
804 if (
p->u.advisors != NULL) {
805 ActorLink*
a =
p->u.advisors;
806 p->u.advisors = NULL;
808 a->prev(
p);
a =
a->next();
811 c_a->prev(p_a); p_a = c_a; c_a = c_a->next();
815 ActorLink* p_a = &bl;
816 ActorLink* c_a = p_a->next();
819 c_a->prev(p_a); p_a = c_a; c_a = c_a->next();
824 for (ActorLink*
l =
c->pc.c.local;
l != NULL;
l =
l->next())
828 c->pc.p.active = &
c->pc.p.queue[0]-1;
829 for (
int i=0;
i<=PropCost::AC_MAX;
i++)
830 c->pc.p.queue[i].init();
832 c->pc.p.n_sub = pc.p.n_sub;
833 c->pc.p.bid_sc = pc.p.bid_sc;
836 c->pc.p.vti.other(); pc.p.vti.other();
848 case MetaInfo::RESTART:
849 if (mi.
last() != NULL)
850 constrain(*mi.
last());
854 case MetaInfo::PORTFOLIO:
856 BrancherGroup::all.kill(*
this);
870 Space::afc_unshare(
void) {
871 if (ssd.data().gpi.unshare()) {
875 = ssd.data().gpi.allocate(
p.gpi().pid,
p.gpi().gid);
877 p.gpi_disabled = Support::mark(gpi);
879 p.gpi_disabled = gpi;
885 LocalObject::fwdcopy(
Space& home) {
886 ActorLink::cast(
this)->prev(copy(home));
897 NGL::notice(
void)
const {
909 Group Group::all(GROUPID_ALL);
910 Group Group::def(GROUPID_DEF);
918 unsigned int Group::next = GROUPID_DEF+1;
927 if (gid == GROUPID_MAX)
934 if ((
id() != GROUPID_ALL) && (
id() != g.
id()))
936 if (g.
in(ps.propagator().group()))
937 ps.propagator().group(*
this);
942 PropagatorGroup::move(
Space& home,
unsigned int pid) {
943 if (
id() == GROUPID_ALL)
946 if (ps.propagator().id() == pid) {
947 ps.propagator().group(*
this);
956 PropagatorGroup::size(
Space& home)
const {
961 if (in(ps.propagator().group()))
967 PropagatorGroup::kill(
Space& home) {
980 PropagatorGroup::disable(
Space& home) {
984 if (in(ps.propagator().group()))
985 ps.propagator().disable(home);
989 PropagatorGroup::enable(
Space& home,
bool s) {
1004 if (in(ps.propagator().group()))
1005 ps.propagator().enable(home);
1012 if ((
id() != GROUPID_ALL) && (
id() != g.
id()))
1014 if (g.
in(bs.brancher().group()))
1015 bs.brancher().group(*
this);
1020 BrancherGroup::move(
Space& home,
unsigned int bid) {
1021 if (
id() == GROUPID_ALL)
1024 if (bs.brancher().id() == bid) {
1025 bs.brancher().group(*
this);
1034 BrancherGroup::size(
Space& home)
const {
1039 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.