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]);
209 mm.release(ssd.data().sm);
220 Space::findtracerecorder(
void) {
221 for (
Actor** a=d_fst; a<d_cur; a++) {
225 std::swap(*d_fst,*a);
234 assert(pc.p.bid_sc & sc_trace);
235 TraceRecorder* tr = findtracerecorder();
236 if ((tr != NULL) && (tr->events() &
TE_POST)) {
238 unsigned int n = ssd.data().gpi.pid() -
pi.pid;
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);
296 p->unlink(); pl.head(
p);
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);
359 p->unlink(); pl.head(
p);
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);
440 p->unlink(); pl.head(
p);
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());
513 ssd.data().gpi.fail(
p->gpi());
524 switch (top->
propagate(*
this,top_med_o)) {
541 if (
failed() || (b_status == Brancher::cast(&bl))) {
544 Brancher* b = Brancher::cast(bl.next());
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);
558 Brancher* b = Brancher::cast(bl.next());
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;
573 Brancher* b_cur = Brancher::cast(bl.next());
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) {
593 tr->
filter()(b->group())) {
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()))
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);
721 p->next(&pl); pl.prev(
p);
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) {
760 if (
c->d_fst != &Actor::sentinel)
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++) {
778 *(
c->d_cur++) = Actor::cast(
static_cast<ActorLink*
>
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();
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;
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();
849 if (mi.
last() != NULL)
871 if (ssd.data().gpi.unshare()) {
875 = ssd.data().gpi.allocate(
p.gpi().pid,
p.gpi().gid);
879 p.gpi_disabled = gpi;
885 LocalObject::fwdcopy(
Space& home) {
936 if (g.
in(ps.propagator().group()))
937 ps.propagator().group(*
this);
946 if (ps.propagator().id() == pid) {
947 ps.propagator().group(*
this);
961 if (
in(ps.propagator().group()))
984 if (
in(ps.propagator().group()))
985 ps.propagator().disable(home);
1004 if (
in(ps.propagator().group()))
1005 ps.propagator().enable(home);
1014 if (g.
in(bs.brancher().group()))
1015 bs.brancher().group(*
this);
1024 if (bs.brancher().id() == bid) {
1025 bs.brancher().group(*
this);
1039 if (
in(bs.brancher().group()))
Double-linked list for actors.
ActorLink * next(void) const
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.
BrancherGroup(unsigned int gid)
Initialize with group id gid.
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 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.
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.
Class to set group information when a post function is executed.
@ 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.
PropagatorGroup(unsigned int gid)
Initialize with group id gid.
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 void reschedule(Space &home)=0
Schedule function.
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Advise function.
PropagatorGroup group(void) const
Return group propagator belongs to.
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::@055132133326276162005044145100211202071356247106::@275070317317120154232063063134255170030071110047 p
Data only available during propagation or branching.
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@155123175027073262103111264343315000271204104107 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)
unsigned int n_sub
Number of subscriptions.
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)
#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::FloatVal b(9, 12)
Gecode::FloatVal a(-8, 5)
Gecode::IntArgs i({1, 2, 3, 4})
#define GECODE_NEVER
Assert that this command is never executed.
#define GECODE_ASSUME(p)
Assert certain property.