Generated on Sat Jan 12 2019 20:58:51 for Gecode by doxygen 1.8.13
extensional.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Linnea Ingmar <linnea.ingmar@hotmail.com>
5  * Mikael Lagerkvist <lagerkvist@gecode.org>
6  * Christian Schulte <schulte@gecode.org>
7  *
8  * Copyright:
9  * Linnea Ingmar, 2017
10  * Mikael Lagerkvist, 2007
11  * Christian Schulte, 2004
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #ifndef __GECODE_INT_EXTENSIONAL_HH__
39 #define __GECODE_INT_EXTENSIONAL_HH__
40 
41 #include <gecode/int.hh>
42 
43 #include <gecode/int/rel.hh>
44 
50 namespace Gecode { namespace Int { namespace Extensional {
51 
66  template<class View, class Val, class Degree, class StateIdx>
67  class LayeredGraph : public Propagator {
68  protected:
70  class State {
71  public:
72  Degree i_deg;
73  Degree o_deg;
74  void init(void);
76  };
78  class Edge {
79  public:
80  StateIdx i_state;
81  StateIdx o_state;
82  };
84  class Support {
85  public:
86  Val val;
87  Degree n_edges;
89  };
93  class Layer {
94  public:
95  View x;
96  StateIdx n_states;
97  ValSize size;
100  };
102  class LayerValues {
103  private:
104  const Support* s1;
105  const Support* s2;
106  public:
108  LayerValues(void);
110  LayerValues(const Layer& l);
112  void init(const Layer& l);
114  bool operator ()(void) const;
116  void operator ++(void);
118  int val(void) const;
119  };
121  class Index : public Advisor {
122  public:
124  int i;
126  Index(Space& home, Propagator& p, Council<Index>& c, int i);
128  Index(Space& home, Index& a);
129  };
131  class IndexRange {
132  private:
133  int _fst;
134  int _lst;
135  public:
137  IndexRange(void);
139  void reset(void);
141  void add(int i);
143  void add(const IndexRange& ir);
145  void lshift(int n);
147  bool empty(void) const;
149  int fst(void) const;
151  int lst(void) const;
152  };
156  int n;
160  StateIdx max_states;
162  unsigned int n_states;
164  unsigned int n_edges;
172  State& i_state(int i, StateIdx is);
174  State& i_state(int i, const Edge& e);
176  bool i_dec(int i, const Edge& e);
178  State& o_state(int i, StateIdx os);
180  State& o_state(int i, const Edge& e);
182  bool o_dec(int i, const Edge& e);
184  void audit(void);
186  template<class Var>
188  const VarArgArray<Var>& x, const DFA& dfa);
191  public:
193  template<class Var>
194  LayeredGraph(Home home,
195  const VarArgArray<Var>& x, const DFA& dfa);
197  virtual Actor* copy(Space& home);
199  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
201  virtual void reschedule(Space& home);
203  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
205  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
207  virtual size_t dispose(Space& home);
209  template<class Var>
210  static ExecStatus post(Home home,
211  const VarArgArray<Var>& x, const DFA& dfa);
212  };
213 
215  template<class Var>
216  ExecStatus post_lgp(Home home,
217  const VarArgArray<Var>& x, const DFA& dfa);
218 
219 }}}
220 
222 
223 namespace Gecode { namespace Int { namespace Extensional {
224 
227 
228  /*
229  * Forward declarations
230  */
231  template<unsigned int size> class TinyBitSet;
232 
234  template<class IndexType>
235  class BitSet {
236  template<class> friend class BitSet;
237  template<unsigned int> friend class TinyBitSet;
238  protected:
240  IndexType _limit;
242  IndexType* _index;
244  BitSetData* _bits;
246  void replace_and_decrease(IndexType i, BitSetData w);
247  public:
249  BitSet(Space& home, unsigned int n);
251  template<class OldIndexType>
252  BitSet(Space& home, const BitSet<OldIndexType>& bs);
254  BitSet(Space& home, const TinyBitSet<1U>& tbs);
256  BitSet(Space& home, const TinyBitSet<2U>& tbs);
258  BitSet(Space& home, const TinyBitSet<3U>& tbs);
260  BitSet(Space& home, const TinyBitSet<4U>& tbs);
262  unsigned int limit(void) const;
264  bool empty(void) const;
266  void flush(void);
268  unsigned int width(void) const;
270  void clear_mask(BitSetData* mask) const;
272  void add_to_mask(const BitSetData* b, BitSetData* mask) const;
274  template<bool sparse>
275  void intersect_with_mask(const BitSetData* mask);
277  void intersect_with_masks(const BitSetData* a, const BitSetData* b);
279  bool intersects(const BitSetData* b) const;
281  void nand_with_mask(const BitSetData* b);
283  unsigned long long int ones(void) const;
285  unsigned long long int ones(const BitSetData* b) const;
287  unsigned long long int bits(void) const;
289  unsigned int words(void) const;
291  unsigned int size(void) const;
292  };
293 
294 }}}
295 
297 
298 namespace Gecode { namespace Int { namespace Extensional {
299 
301  template<unsigned int _size>
302  class TinyBitSet {
303  template<unsigned int> friend class TinyBitSet;
304  protected:
306  BitSetData _bits[_size];
307  public:
309  TinyBitSet(Space& home, unsigned int n);
311  template<unsigned int largersize>
312  TinyBitSet(Space& home, const TinyBitSet<largersize>& tbs);
314  template<class IndexType>
315  TinyBitSet(Space& home, const BitSet<IndexType>& bs);
317  int limit(void) const;
319  bool empty(void) const;
321  void flush(void);
323  unsigned int width(void) const;
325  void clear_mask(BitSetData* mask);
327  void add_to_mask(const BitSetData* b, BitSetData* mask) const;
329  template<bool sparse>
330  void intersect_with_mask(const BitSetData* mask);
332  void intersect_with_masks(const BitSetData* a, const BitSetData* b);
334  bool intersects(const BitSetData* b);
336  void nand_with_mask(const BitSetData* b);
338  void nand_with_masks(const BitSetData* a, const BitSetData* b);
340  unsigned long long int ones(void) const;
342  unsigned long long int ones(const BitSetData* b) const;
344  unsigned long long int bits(void) const;
346  unsigned int words(void) const;
348  unsigned int size(void) const;
349  };
350 
351 }}}
352 
354 
355 namespace Gecode { namespace Int { namespace Extensional {
356 
358  typedef TupleSet::Tuple Tuple;
359 
361  template<class View, bool pos>
362  class Compact : public Propagator {
363  protected:
367  class CTAdvisor : public ViewAdvisor<View> {
368  public:
370  protected:
372  const Range* _fst;
374  const Range* _lst;
375  public:
377 
380  const TupleSet& ts, View x0, int i);
382  CTAdvisor(Space& home, CTAdvisor& a);
384  void adjust(void);
387  const Range* fst(void) const;
389  const Range* lst(void) const;
391  void dispose(Space& home, Council<CTAdvisor>& c);
392  };
394 
396  class ValidSupports {
398  protected:
400  const unsigned int n_words;
402  int max;
406  const Range* sr;
408  const Range* lst;
410  int n;
412  const BitSetData* s;
414  void find(void);
415  public:
419  ValidSupports(const TupleSet& ts, int i, View x);
421  void operator ++(void);
423  bool operator ()(void) const;
425  const BitSetData* supports(void) const;
427  int val(void) const;
428  };
430  class LostSupports {
431  protected:
433  const unsigned int n_words;
435  const Range* r;
437  const Range* lst;
439  int l;
441  int h;
443  const BitSetData* s;
444  public:
447  int l, int h);
449  void operator ++(void);
451  bool operator ()(void) const;
453  const BitSetData* supports(void) const;
454  };
456 
458  bool all(void) const;
461  bool atmostone(void) const;
463  protected:
465  const unsigned int n_words;
471  Compact(Space& home, Compact& p);
473  Compact(Home home, const TupleSet& ts);
475  template<class Table>
476  void setup(Space& home, Table& table, ViewArray<View>& x);
478  template<class Table>
479  bool full(const Table& table) const;
481  const Range* range(CTAdvisor& a, int n);
483  const BitSetData* supports(CTAdvisor& a, int n);
484  public:
486  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
488  size_t dispose(Space& home);
489  };
490 
503  template<class View, class Table>
504  class PosCompact : public Compact<View,true> {
505  public:
510 
515  using Compact<View,true>::c;
517 
519 
520  enum StatusType {
522  SINGLE = 0,
523  MULTIPLE = 1,
524  NONE = 2,
525  PROPAGATING = 3
526  };
528  class Status {
529  protected:
531  ptrdiff_t s;
532  public:
536  Status(const Status& s);
538  StatusType type(void) const;
540  bool single(CTAdvisor& a) const;
542  void touched(CTAdvisor& a);
544  void none(void);
546  void propagating(void);
547  };
551  Table table;
553  bool empty(void) const;
555  template<class TableProp>
556  PosCompact(Space& home, TableProp& p);
558  PosCompact(Home home, ViewArray<View>& x, const TupleSet& ts);
559  public:
561  virtual void reschedule(Space& home);
563  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
565  virtual Actor* copy(Space& home);
567  static ExecStatus post(Home home, ViewArray<View>& x, const TupleSet& ts);
569  size_t dispose(Space& home);
571  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
572  };
573 
575  template<class View>
577 
593  template<class View, class Table>
594  class NegCompact : public Compact<View,false> {
595  public:
599 
606 
608  Table table;
610  template<class TableProp>
611  NegCompact(Space& home, TableProp& p);
613  NegCompact(Home home, ViewArray<View>& x, const TupleSet& ts);
614  public:
616  virtual void reschedule(Space& home);
618  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
620  virtual Actor* copy(Space& home);
622  static ExecStatus post(Home home, ViewArray<View>& x, const TupleSet& ts);
624  size_t dispose(Space& home);
626  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
627  };
628 
630  template<class View>
632 
633 
635  template<class View, class Table, class CtrlView, ReifyMode rm>
636  class ReCompact : public Compact<View,false> {
637  public:
641 
647 
649  Table table;
651  CtrlView b;
655  template<class TableProp>
656  ReCompact(Space& home, TableProp& p);
658  ReCompact(Home home, ViewArray<View>& x, const TupleSet& ts, CtrlView b);
659  public:
661  virtual void reschedule(Space& home);
663  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
665  virtual Actor* copy(Space& home);
667  static ExecStatus post(Home home, ViewArray<View>& x, const TupleSet& ts,
668  CtrlView b);
670  size_t dispose(Space& home);
672  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
673  };
674 
676  template<class View, class CtrlView, ReifyMode rm>
678  CtrlView b);
679 
680 }}}
681 
683 
684 #endif
685 
686 // STATISTICS: int-prop
ExecStatus postnegcompact(Home home, ViewArray< View > &x, const TupleSet &ts)
Post function for compact table propagator.
Definition: compact.hpp:955
IndexRange i_ch
Index range with in-degree modifications.
Definition: extensional.hh:166
TupleSet::Range Range
Range type for supports.
Definition: extensional.hh:365
Council of advisors
Definition: core.hpp:154
ptrdiff_t s
A tagged pointer for storing the status.
Definition: extensional.hh:531
NodeType t
Type of node.
Definition: bool-expr.cpp:230
TupleSet ts
The tuple set.
Definition: extensional.hh:467
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
Compact< View, false >::CTAdvisor CTAdvisor
Definition: extensional.hh:640
void audit(void)
Perform consistency check on data structures.
const unsigned int n_words
Number of words.
Definition: extensional.hh:400
Edge defined by in-state and out-state
Definition: extensional.hh:78
Council< Index > c
The advisor council.
Definition: extensional.hh:154
int n
Number of layers (and views)
Definition: extensional.hh:156
Iterator for telling variable domains by scanning support.
Definition: extensional.hh:102
IndexRange a_ch
Index range for any change (for compression)
Definition: extensional.hh:170
CtrlView b
Boolean control view.
Definition: extensional.hh:651
const BitSetData * s
The lost value&#39;s support.
Definition: extensional.hh:443
StateIdx n_states
Number of states used by outgoing edges.
Definition: extensional.hh:96
unsigned int n_states
Total number of states.
Definition: extensional.hh:162
ViewArray< View > y
The views (for rewriting)
Definition: extensional.hh:653
const Range * _fst
First range of support data structure.
Definition: extensional.hh:372
Compact< View, false >::CTAdvisor CTAdvisor
Definition: extensional.hh:598
int * Tuple
Type of a tuple.
Definition: int.hh:2196
Compact< View, true >::LostSupports LostSupports
Definition: extensional.hh:509
StateIdx i_state
Number of in-state.
Definition: extensional.hh:80
Domain consistent positive extensional propagator.
Definition: extensional.hh:504
Base-class for propagators.
Definition: core.hpp:1023
Base-class for advisors.
Definition: core.hpp:1251
Gecode::Support::BitSetData BitSetData
Import type.
Definition: extensional.hh:226
Computation spaces.
Definition: core.hpp:1701
Advisor storing a single view
Definition: advisor.hpp:43
Support information for a value
Definition: extensional.hh:84
bool i_dec(int i, const Edge &e)
Decrement out degree for in state of edge e for layer i.
LayeredGraph(Space &home, LayeredGraph< View, Val, Degree, StateIdx > &p)
Constructor for cloning p.
IndexRange o_ch
Index range with out-degree modifications.
Definition: extensional.hh:168
Base-class for both propagators and branchers.
Definition: core.hpp:627
const unsigned int n_words
Number of words.
Definition: extensional.hh:433
Range iterator for integer views.
Definition: view.hpp:54
Gecode::IntSet d(v, 7)
State & o_state(int i, StateIdx os)
Return out state for layer i and state index os.
ValSize size
Number of supported values.
Definition: extensional.hh:97
Compact< View, false >::ValidSupports ValidSupports
Definition: extensional.hh:638
Compact< View, false >::Range Range
Definition: extensional.hh:639
StateIdx o_state
Number of out-state.
Definition: extensional.hh:81
Deterministic finite automaton (DFA)
Definition: int.hh:2048
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
::Gecode::TupleSet::Tuple Tuple
Import tuple type.
Definition: tuple-set.cpp:44
Council< CTAdvisor > c
The advisor council.
Definition: extensional.hh:469
Gecode::IntArgs i({1, 2, 3, 4})
Range approximation of which positions have changed.
Definition: extensional.hh:131
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1034
Layer for a view in the layered graph
Definition: extensional.hh:93
Degree n_edges
Number of supporting edges.
Definition: extensional.hh:87
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
void range(Home home, const IntVarArgs &x, SetVar y, SetVar z)
Post constraint .
Definition: minimodel.hh:2026
const unsigned int n_words
Number of words in supports.
Definition: extensional.hh:465
Domain consistent reified extensional propagator.
Definition: extensional.hh:636
size_t size
The size of the propagator (used during subsumption)
Definition: core.hpp:1036
Layer * layers
The layers of the graph.
Definition: extensional.hh:158
ExecStatus postposcompact(Home home, ViewArray< View > &x, const TupleSet &ts)
Post function for positive compact table propagator.
Definition: compact.hpp:685
StateIdx max_states
Maximal number of states per layer.
Definition: extensional.hh:160
ExecStatus post_lgp(Home home, const VarArgArray< Var > &x, const DFA &dfa)
Select small types for the layered graph propagator.
View arrays.
Definition: array.hpp:235
IndexType * _index
Indices.
Definition: extensional.hh:242
const Range * r
Range information.
Definition: extensional.hh:435
Traits to for information about integer types.
Definition: int-type.hpp:52
Degree o_deg
The out-degree (number of outgoing edges) Initialize with zeroes.
Definition: extensional.hh:73
State * states
States used by outgoing edges.
Definition: extensional.hh:98
Domain consistent layered graph (regular) propagator.
Definition: extensional.hh:67
Class represeting a set of tuples.
Definition: int.hh:2190
static ExecStatus post(Home home, const VarArgArray< Var > &x, const DFA &dfa)
Post propagator on views x and DFA dfa.
const Range * _lst
Last range of support data structure.
Definition: extensional.hh:374
Generic domain change information to be supplied to advisors.
Definition: core.hpp:203
Advisors for views (by position in array)
Definition: extensional.hh:121
Compact< View, false >::Range Range
Definition: extensional.hh:597
Propagation cost.
Definition: core.hpp:485
ExecStatus
Definition: core.hpp:471
Compact< View, true >::CTAdvisor CTAdvisor
Definition: extensional.hh:508
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Date item for bitsets.
Definition: bitset-base.hpp:65
Advisor for updating current table.
Definition: extensional.hh:367
ViewRanges< View > xr
Range iterator.
Definition: extensional.hh:404
Post propagator for SetVar x
Definition: set.hh:767
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Edge * edges
Supporting edges in layered graph.
Definition: extensional.hh:88
Domain consistent negative extensional propagator.
Definition: extensional.hh:594
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high linear)
State & i_state(int i, StateIdx is)
Return in state for layer i and state index is.
Gecode toplevel namespace
Argument array for variables.
Definition: array.hpp:61
ExecStatus initialize(Space &home, const VarArgArray< Var > &x, const DFA &dfa)
Initialize layered graph.
Base class for compact table propagator.
Definition: extensional.hh:362
States are described by number of incoming and outgoing edges.
Definition: extensional.hh:70
Degree i_deg
The in-degree (number of incoming edges)
Definition: extensional.hh:72
virtual void reschedule(Space &home)
Schedule function.
bool o_dec(int i, const Edge &e)
Decrement in degree for out state of edge e for layer i.
virtual size_t dispose(Space &home)
Delete propagator and return its size.
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Home class for posting propagators
Definition: core.hpp:853
Status status
Propagator status.
Definition: extensional.hh:549
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
Compact< View, true >::ValidSupports ValidSupports
Definition: extensional.hh:506
Compact< View, true >::Range Range
Definition: extensional.hh:507
unsigned int n_edges
Total number of edges.
Definition: extensional.hh:164
ExecStatus postrecompact(Home home, ViewArray< View > &x, const TupleSet &ts, CtrlView b)
Post function for compact table propagator.
Definition: compact.hpp:1192
Range information.
Definition: int.hh:2200
Gecode::Support::IntTypeTraits< Val >::utype ValSize
Type for support size.
Definition: extensional.hh:91
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Give advice to propagator.
const BitSetData * s
The value&#39;s support.
Definition: extensional.hh:412
Compact< View, false >::ValidSupports ValidSupports
Definition: extensional.hh:596
int i
The position of the view in the view array.
Definition: extensional.hh:124