Go to the documentation of this file.
57 Actor* Actor::sentinel;
98 std::ostream&)
const {
111 #ifdef GECODE_HAS_VAR_DISPOSE
116 #ifdef GECODE_HAS_CBS
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++) {
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());
550 b_status = b_commit = Brancher::cast(&bl);
558 while (
b != b_status) {
560 b = Brancher::cast(
b->next());
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++) {
777 *(
c->d_cur++) = Actor::cast(
static_cast<ActorLink*
>
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);
878 p.gpi_disabled = gpi;
884 LocalObject::fwdcopy(
Space& home) {
885 ActorLink::cast(
this)->prev(copy(home));
886 next(home.pc.
c.local);
887 home.pc.
c.local =
this;
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);
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);
1038 if (in(bs.brancher().group()))
Exception: Commit when no brancher present
@ SS_SOLVED
Space is solved (no brancher left)
@ AC_MAX
Maximal cost value.
void * ptrsplit(void *p, ptrdiff_t &m)
Split possibly marked pointer p into mark m and unmarked pointer.
Exception: Commit with illegal alternative
virtual void dispose(Space &home, VarImpBase *x)
Dispose list of variable implementations starting at x.
void id(CArray t1, int w1, int h1, Array t2, int &w2, int &h2)
Identity symmetry.
ViewTraceInfo vti
View trace information.
Propagator for recording trace information.
Base class for Variable type disposer.
bool stable(void) const
Return if space is stable (at fixpoint or failed)
const Choice * choice(void)
Create new choice for current brancher.
void fail(Info &c)
Increment failure count.
unsigned int size(I &i)
Size of all ranges of range iterator i.
struct Gecode::Space::@61::@63 c
Data available only during copying.
@ TE_COMMIT
Trace commit operations by branchers.
@ POSTED
Propagator was posted.
Class to iterate over branchers of a space.
void * mark(void *p)
Return marked pointer for unmarked pointer p.
virtual ~Actor(void)
To avoid warnings.
@ SS_BRANCH
Space must be branched (at least one brancher left)
static ActorLink * cast(T *a)
Static cast for a non-null pointer (to give a hint to optimizer)
virtual void post(Space &home) const
Post no-goods.
Base-class for both propagators and branchers.
@ __ES_PARTIAL
Internal: propagator has computed partial fixpoint, do not use.
Exception: Operation on not stable space invoked
SharedMemory sm
The shared memory area.
unsigned int pid(void) const
Return next free propagator id.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)=0
Propagation function.
Propagator & propagator(void) const
Return propagator.
A lock as a scoped frontend for a mutex.
Double-linked list for actors.
Exception: unknown brancher
@ __ES_SUBSUMED
Internal: propagator is subsumed, do not use.
Gecode toplevel namespace
Base-class for propagators.
Exception: unknown propagator
No-goods recorded from restarts.
void release(SharedMemory &sm)
Release all allocated heap chunks.
struct Gecode::Space::@61::@62 p
Data only available during propagation or branching.
Node * x
Pointer to corresponding Boolean expression node.
unsigned int id(void) const
Return brancher id.
Generic domain change information to be supplied to advisors.
ActorLink * next(void) const
Base-class for branchers.
Commit trace information.
NGL * ngl(const Choice &c, unsigned int a)
Create no-good literal for choice c and alternative a.
@ SUBSUMED
Propagator not posted as already subsumed.
void init(void)
Initialize links (self-linked)
ModEventDelta med
A set of modification events (used during propagation)
IntRelType swap(IntRelType irt)
Return swapped relation type of irt.
bool in(Group a) const
Check whether actor group a is included in this group.
unsigned int id(void) const
Return a unique id for the group.
Statistics for execution of clone
Exception: too many groups
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Data & data(void) const
Provide access.
int events(void) const
Which events to trace.
virtual void print(const Space &home, const Choice &c, unsigned int a, std::ostream &o) const
Print branch for choice c and alternative a.
Tracer & tracer(void) const
Return tracer.
Group baseclass for controlling actors.
virtual bool status(const Space &home) const =0
Check status of brancher, return true if alternatives left.
#define GECODE_NEVER
Assert that this command is never executed.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
bool failed(void) const
Check whether space is failed.
void fail(void)
Fail space.
Space(void)
Default constructor.
unsigned long int propagate
Number of propagator executions.
ActorLink * prev(void) const
Routines for double-linked list.
virtual NGL * ngl(Space &home, const Choice &c, unsigned int a) const
Create no-good literal for choice c and alternative a.
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Advise function.
@ AC_RECORD
Reserved for recording information.
virtual ~VarImpDisposerBase(void)
Destructor (not used)
static const int idx_c
Index for cloning.
Class to iterate over propagators of a space.
@ ES_FIX
Propagation has computed fixpoint.
void rfree(void *p, size_t s)
Free memory previously allocated with alloc (might be reused later)
Statistics for execution of status
static const int idx_d
Index for dispose.
Class for storing propagator information.
virtual ~Space(void)
Destructor.
static NoGoods eng
Empty no-goods.
Brancher & brancher(void) const
Return propagator.
Base-class for variable implementations.
void print(const Choice &c, unsigned int a, std::ostream &o) const
Print branch for choice c and alternative a.
void * ptrjoin(void *p, ptrdiff_t m)
Join unmarked pointer p and m into marked pointer.
virtual size_t dispose(Space &home)
Delete actor and return its size.
void head(ActorLink *al)
Insert al directly after this.
GPI gpi
The global propagator information.
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
@ TE_POST
Trace propagator posting.
Gecode::FloatVal c(-8, 8)
No-good literal recorded during search.
A mutex for mutual exclausion among several threads.
int n
Number of negative literals for node type.
virtual const Choice * choice(Space &home)=0
Return choice.
Choice for performing commit
@ ES_FAILED
Execution has resulted in failure.
int ModEventDelta
Modification event deltas.
@ ES_NOFIX
Propagation has not computed fixpoint.
const TraceFilter & filter(void) const
Return trace filter.
@ FAILED
Node representing failure.
Gecode::IntArgs i({1, 2, 3, 4})
@ SS_FAILED
Space is failed
Statistics for execution of commit
int p
Number of positive literals for node type.
bool marked(void *p)
Check whether p is marked.
#define GECODE_STATUS_TRACE(q, s)
#define GECODE_ASSUME(p)
Assert certain property.