Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
recorder.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2016
8  *
9  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 namespace Gecode {
35 
40  enum TraceEvent {
42 
43  TE_INIT = 1 << 0,
44  TE_PRUNE = 1 << 1,
45  TE_FIX = 1 << 2,
46  TE_FAIL = 1 << 3,
47  TE_DONE = 1 << 4,
48 
49  TE_PROPAGATE = 1 << 5,
51  TE_COMMIT = 1 << 6
52  };
53 
58  template<class View>
59  class ViewTraceRecorder : public Propagator {
60  public:
68  class Slack {
69  template<class ViewForTraceRecorder> friend class ViewTraceRecorder;
70  protected:
72  SlackValue i;
74  SlackValue p;
76  SlackValue c;
77  public:
79  SlackValue initial(void) const;
81  SlackValue previous(void) const;
83  SlackValue current(void) const;
84  };
85  protected:
87  class Idx : public Advisor {
88  protected:
90  int _idx;
91  public:
93  Idx(Space& home, Propagator& p, Council<Idx>& c, int i);
95  Idx(Space& home, Idx& a);
97  int idx(void) const;
98  };
108  int te;
115  public:
118  TraceFilter tf, int te, ViewTracer<View>& t);
120  virtual Propagator* copy(Space& home);
122  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
124  virtual void reschedule(Space& home);
126  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
128  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
130  virtual size_t dispose(Space& home);
132  static ExecStatus post(Home home, ViewArray<View>& x,
133  TraceFilter tf, int te, ViewTracer<View>& t);
135 
136  const typename View::VarType operator [](int i) const;
139  int size(void) const;
141  const Slack& slack(void) const;
143  };
144 
153  class TraceRecorder : public Propagator {
154  public:
158  int te;
163  public:
165  TraceRecorder(Home home, TraceFilter tf, int te, Tracer& t);
167  virtual Propagator* copy(Space& home);
169  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
171  virtual void reschedule(Space& home);
173  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
175  virtual size_t dispose(Space& home);
177  static ExecStatus post(Home home, TraceFilter tf, int te, Tracer& t);
179 
180  const TraceFilter& filter(void) const;
183  int events(void) const;
185  Tracer& tracer(void) const;
187  };
188 
189 
190  /*
191  * Functions for trace support
192  *
193  */
194  template<class View>
195  forceinline const typename View::VarType
197  const typename View::VarType x(n[i].varimp());
198  return x;
199  }
200  template<class View>
201  forceinline int
203  return n.size();
204  }
205  template<class View>
208  return s;
209  }
210 
211 
212  /*
213  * Functions for access to slack
214  *
215  */
216  template<class View>
219  return i;
220  }
221  template<class View>
224  return p;
225  }
226  template<class View>
229  return c;
230  }
231 
232 
233  /*
234  * Advisor for tracer
235  *
236  */
237 
238  template<class View>
241  Council<Idx>& c, int i)
242  : Advisor(home,p,c), _idx(i) {}
243  template<class View>
246  : Advisor(home,a), _idx(a._idx) {
247  }
248  template<class View>
249  forceinline int
251  return _idx;
252  }
253 
254 
255  /*
256  * Posting of tracer propagator
257  *
258  */
259  template<class View>
262  TraceFilter tf0, int te0,
263  ViewTracer<View>& t0)
264  : Propagator(home), o(home,x.size()), n(x), c(home),
265  tf(tf0), te(te0), t(t0) {
266  home.notice(*this, AP_VIEW_TRACE);
267  home.notice(*this, AP_DISPOSE);
268  for (int i=0; i<n.size(); i++) {
269  o[i] = TraceView(home,n[i]);
270  if (!n[i].assigned())
271  n[i].subscribe(home,*new (home) Idx(home,*this,c,i));
272  }
273  View::schedule(home,*this,ME_GEN_ASSIGNED);
274  s.i = TraceView::slack(n[0]);
275  for (int i=1; i<n.size(); i++)
276  s.i += TraceView::slack(n[i]);
277  s.p = s.i;
278  if ((te & TE_INIT) != 0)
279  t._init(home,*this);
280  }
281 
282 
283  template<class View>
287  if ((x.size() > 0) &&
288  (te & (TE_INIT | TE_PRUNE | TE_FIX | TE_FAIL | TE_DONE)))
289  (void) new (home) ViewTraceRecorder(home,x,tf,te,t);
290  return ES_OK;
291  }
292 
293 
294  /*
295  * Propagation for trace recorder
296  *
297  */
298  template<class View>
301  : Propagator(home,p), tf(p.tf), te(p.te), t(p.t), s(p.s) {
302  o.update(home, p.o);
303  n.update(home, p.n);
304  c.update(home, p.c);
305  }
306 
307  template<class View>
308  Propagator*
310  return new (home) ViewTraceRecorder(home, *this);
311  }
312 
313  template<class View>
314  inline size_t
316  home.ignore(*this, AP_VIEW_TRACE);
317  home.ignore(*this, AP_DISPOSE);
318  tf.~TraceFilter();
319  // Cancel remaining advisors
320  for (Advisors<Idx> as(c); as(); ++as)
321  n[as.advisor().idx()].cancel(home,as.advisor());
322  c.dispose(home);
323  (void) Propagator::dispose(home);
324  return sizeof(*this);
325  }
326 
327  template<class View>
328  PropCost
330  return PropCost::record();
331  }
332 
333  template<class View>
334  void
336  View::schedule(home,*this,ME_GEN_ASSIGNED);
337  }
338 
339  template<class View>
340  ExecStatus
342  Idx& a = static_cast<Idx&>(_a);
343  int i = a.idx();
344  if (((te & TE_PRUNE) != 0) && !disabled() && tf(a(home)) ) {
345  TraceDelta td(o[i],n[i],d);
346  t._prune(home,*this,a(home),i,td);
347  }
348  o[i].prune(home,n[i],d);
349  if (n[a.idx()].assigned())
350  a.dispose(home,c);
351  return ES_NOFIX;
352  }
353 
354  template<class View>
355  ExecStatus
357  s.c = TraceView::slack(n[0]);
358  for (int i=1; i<n.size(); i++)
359  s.c += TraceView::slack(n[i]);
360  if (home.failed() && ((te & TE_FAIL) != 0) && !disabled()) {
361  t._fail(home,*this);
362  return ES_FIX;
363  }
364  if ((te & TE_FIX) != 0)
365  t._fix(home,*this);
366  s.p = s.c;
367  if (c.empty()) {
368  if ((te & TE_DONE) != 0)
369  t._done(home,*this);
370  return home.ES_SUBSUMED(*this);
371  }
372  return ES_FIX;
373  }
374 
375 
376 
377  /*
378  * Functions for trace support
379  *
380  */
381  forceinline const TraceFilter&
382  TraceRecorder::filter(void) const {
383  return tf;
384  }
385  forceinline int
386  TraceRecorder::events(void) const {
387  return te;
388  }
390  TraceRecorder::tracer(void) const {
391  return t;
392  }
393 
394 
395  /*
396  * Trace recorder propagator
397  *
398  */
401  Tracer& t0)
402  : Propagator(home), tf(tf0), te(te0), t(t0) {
403  home.notice(*this, AP_DISPOSE);
404  home.notice(*this, AP_TRACE);
405  }
406 
409  if (te & (TE_PROPAGATE | TE_COMMIT))
410  (void) new (home) TraceRecorder(home,tf,te,t);
411  return ES_OK;
412  }
413 
416  : Propagator(home,p), tf(p.tf), te(p.te), t(p.t) {
417  }
418 
419 }
420 
421 // STATISTICS: kernel-trace
SlackValue i
The initial slack value.
Definition: recorder.hpp:72
Council of advisors
Definition: core.hpp:154
Advisor with index information.
Definition: recorder.hpp:87
Tracer that process view trace information.
Definition: tracer.hpp:51
virtual void reschedule(Space &home)
Schedule function.
Definition: recorder.hpp:335
Collection of slack values.
Definition: recorder.hpp:68
Tracer & t
The actual tracer.
Definition: recorder.hpp:160
ViewArray< View > n
Original views (new information)
Definition: recorder.hpp:102
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition: array.hpp:1310
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3490
Actor must always be disposed.
Definition: core.hpp:561
const View::VarType operator[](int i) const
Return variable being traced at position i.
Definition: recorder.hpp:196
const ModEvent ME_GEN_ASSIGNED
Generic modification event: variable is assigned a value.
Definition: core.hpp:69
TraceTraits< View >::SlackValue SlackValue
The corresponding slack value type.
Definition: recorder.hpp:66
Base-class for propagators.
Definition: core.hpp:1023
TraceFilter tf
The trace filter.
Definition: recorder.hpp:156
Base-class for advisors.
Definition: core.hpp:1251
static PropCost record(void)
For recording information (no propagation allowed)
Definition: core.hpp:4692
Class to iterate over advisors of a council.
Definition: core.hpp:155
TraceRecorder(Space &home, TraceRecorder &p)
Constructor for cloning p.
Definition: recorder.hpp:415
#define forceinline
Definition: config.hpp:185
Propagation has computed fixpoint.
Definition: core.hpp:476
Trace init events.
Definition: recorder.hpp:43
static ExecStatus post(Home home, TraceFilter tf, int te, Tracer &t)
Post propagator.
Definition: recorder.hpp:408
Computation spaces.
Definition: core.hpp:1701
Trace commit operations by branchers.
Definition: recorder.hpp:51
const TraceFilter & filter(void) const
Return trace filter.
Definition: recorder.hpp:382
Gecode::IntSet d(v, 7)
TraceTraits< View >::TraceDelta TraceDelta
The corresponding trace delta type.
Definition: recorder.hpp:64
Single _a(2, 3)
Trace prune events.
Definition: recorder.hpp:44
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Tracer & tracer(void) const
Return tracer.
Definition: recorder.hpp:390
Slack s
Slack information.
Definition: recorder.hpp:112
Gecode::IntArgs i({1, 2, 3, 4})
int _idx
Index information.
Definition: recorder.hpp:90
TraceFilter tf
The trace filter.
Definition: recorder.hpp:106
Propagator for recording trace information.
Definition: recorder.hpp:153
bool failed(void) const
Check whether space is failed.
Definition: core.hpp:3971
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1034
static ExecStatus post(Home home, ViewArray< View > &x, TraceFilter tf, int te, ViewTracer< View > &t)
Post recorder propagator.
Definition: recorder.hpp:285
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Give advice to propagator.
Definition: recorder.hpp:341
TraceTraits< View >::TraceView TraceView
The corresponding duplicate view type.
Definition: recorder.hpp:62
Trace filters.
Definition: filter.hpp:133
bool disabled(void) const
Whether propagator is currently disabled.
Definition: core.hpp:3403
SlackValue previous(void) const
Return previous slack value.
Definition: recorder.hpp:223
Traits for tracing.
Definition: traits.hpp:49
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:3176
int te
Which events to trace.
Definition: recorder.hpp:158
ViewTraceRecorder(Space &home, ViewTraceRecorder &p)
Constructor for cloning p.
Definition: recorder.hpp:300
Propagator for recording view trace information.
Definition: recorder.hpp:59
Trace done events.
Definition: recorder.hpp:47
ViewTracer< View > & t
The actual tracer.
Definition: recorder.hpp:110
int size(void) const
Return number of variables being traced.
Definition: recorder.hpp:202
SlackValue c
Current slack value.
Definition: recorder.hpp:76
Generic domain change information to be supplied to advisors.
Definition: core.hpp:203
int te
Which events to trace.
Definition: recorder.hpp:108
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.hpp:4001
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3209
void dispose(Space &home, Council< A > &c)
Dispose the advisor.
Definition: core.hpp:3791
Propagation cost.
Definition: core.hpp:485
virtual Propagator * copy(Space &home)
Copy propagator during cloning.
Definition: recorder.hpp:309
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: recorder.hpp:356
Idx(Space &home, Propagator &p, Council< Idx > &c, int i)
Constructor for creation.
Definition: recorder.hpp:240
ExecStatus
Definition: core.hpp:471
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (record so that propagator runs last)
Definition: recorder.hpp:329
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
Trace fail events.
Definition: recorder.hpp:46
Post propagator for SetVar x
Definition: set.hh:767
Trace propagator executions.
Definition: recorder.hpp:50
Execution is okay.
Definition: core.hpp:475
Tracer.
Definition: tracer.hpp:149
ViewArray< TraceView > o
Duplicate views (old information)
Definition: recorder.hpp:100
Trace fixpoint events.
Definition: recorder.hpp:45
Propagation has not computed fixpoint.
Definition: core.hpp:474
SlackValue current(void) const
Return current slack value.
Definition: recorder.hpp:228
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: recorder.hpp:315
Gecode toplevel namespace
int idx(void) const
Get index of view.
Definition: recorder.hpp:250
int events(void) const
Which events to trace.
Definition: recorder.hpp:386
const Slack & slack(void) const
Provide access to slack information.
Definition: recorder.hpp:207
SlackValue initial(void) const
Return initial slack value.
Definition: recorder.hpp:218
SlackValue p
Slack value at previous event (fixpoint or init)
Definition: recorder.hpp:74
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1138
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Home class for posting propagators
Definition: core.hpp:853
Council< Idx > c
The advisor council.
Definition: recorder.hpp:104
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
TraceEvent
Which events to trace.
Definition: recorder.hpp:40