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) {
156 unsigned int n =
static_cast<unsigned int>(d_lst - d_fst);
167 Space::ap_ignore_dispose(Actor*
a,
bool duplicate) {
169 assert(d_fst != NULL);
198 (void) (*a)->dispose(*
this);
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;
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) {
759 if (
c->d_fst != &Actor::sentinel)
764 unsigned int n =
static_cast<unsigned int>(d_cur - d_fst);
767 c->d_fst =
c->d_cur =
c->d_lst = NULL;
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*
>
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();
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;
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();
848 if (mi.
last() != NULL)
878 p.gpi_disabled = gpi;
884 LocalObject::fwdcopy(
Space& home) {
935 if (g.
in(ps.propagator().group()))
936 ps.propagator().group(*
this);
945 if (ps.propagator().id() == pid) {
946 ps.propagator().group(*
this);
960 if (
in(ps.propagator().group()))
983 if (
in(ps.propagator().group()))
984 ps.propagator().disable(home);
1003 if (
in(ps.propagator().group()))
1004 ps.propagator().enable(home);
1013 if (g.
in(bs.brancher().group()))
1014 bs.brancher().group(*
this);
1023 if (bs.brancher().id() == bid) {
1024 bs.brancher().group(*
this);
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.
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 Actor * copy(Space &home)=0
Create copy.
static const int idx_d
Index for dispose.
static const int idx_c
Index for cloning.
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.
static BrancherGroup all
Group of all branchers.
BrancherGroup & move(Space &home, BrancherGroup g)
Move branchers from group g to this group.
void kill(Space &home)
Kill all branchers in a group.
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
virtual void archive(Archive &e) const
Archive into e.
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.
static Group all
Group of all actors.
static Group def
Group of actors not in any user-defined group.
static const unsigned int GROUPID_ALL
Fake id for group of all actors.
bool in(void) const
Check whether this is a real group (and not just default)
static Support::Mutex m
Mutex for protection.
static const unsigned int GROUPID_MAX
The maximal group number.
unsigned int id(void) const
Return a unique id for the group.
unsigned int gid
The group id.
bool in(Group a) const
Check whether actor group a is included in this group.
static unsigned int next
Next group id.
Class for storing propagator information.
unsigned int pid(void) const
Return next free propagator id.
void fail(Info &c)
Increment failure count.
bool unshare(void)
Provide access to unshare info and set to true.
Info * allocate(unsigned int p, unsigned int gid)
Allocate info for existing propagator with pid p.
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.
virtual ~NGL(void)
To avoid warnings.
virtual bool notice(void) const
Whether dispose must always be called (returns false)
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.
unsigned int size(Space &home) const
Return number of propagators in a group.
static PropagatorGroup def
Group of propagators not in any user-defined group.
PropagatorGroup & move(Space &home, PropagatorGroup g)
Move propagators from group g to this group.
void disable(Space &home)
Disable all propagators in a group.
void enable(Space &home, bool s=true)
Enable all propagators in a group.
void kill(Space &home)
Kill all propagators in a group.
static PropagatorGroup all
Group of all propagators.
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: Operation on failed space invoked
Exception: Commit with illegal alternative
Exception: Commit when no brancher present
Exception: Copy constructor did not call base class copy constructor
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.
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.
struct Gecode::Space::@61::@63 c
Data available only during copying.
void afc_unshare(void)
Unshare AFC information for all propagators.
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.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
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)
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
#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.
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
virtual void constrain(const Space &best)
Constrain function for best solution search.
virtual bool master(const MetaInfo &mi)
Master configuration function for meta search engines.
virtual Space * copy(void)=0
Copying member function.
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.
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 * mark(void *p)
Return marked pointer for unmarked pointer p.
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.
Post propagator for SetVar x
Gecode::IntArgs i({1, 2, 3, 4})
#define GECODE_NEVER
Assert that this command is never executed.
#define GECODE_ASSUME(p)
Assert certain property.