Generated on Fri Jul 13 2018 06:08:27 for Gecode by doxygen 1.8.14
ldsb.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christopher Mears <chris.mears@monash.edu>
5  *
6  * Copyright:
7  * Christopher Mears, 2012
8  *
9  * Last modified:
10  * $Date: 2017-04-01 20:27:10 +0200 (Sat, 01 Apr 2017) $ by $Author: schulte $
11  * $Revision: 15623 $
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_LDSB_HH__
39 #define __GECODE_INT_LDSB_HH__
40 
41 #include <gecode/int.hh>
42 
47 namespace Gecode { namespace Int { namespace LDSB {
48 
50  class Literal {
51  public:
53  Literal(void);
55  Literal(int _var, int _val);
56 
59  int _variable;
63  int _value;
64 
67  bool operator <(const Literal &rhs) const;
68  };
69 
82  std::pair<int,int>
83  findVar(int *indices, unsigned int n_values, unsigned int seq_size, int index);
84 }}}
85 
86 namespace Gecode {
88  template<>
90  public:
94  };
95 
99  template<>
101  public:
105  };
106 }
107 
108 namespace Gecode { namespace Int { namespace LDSB {
111  public:
113  int nrefs;
115  SymmetryObject(void);
117  virtual ~SymmetryObject(void);
118  };
121  public:
125  int nxs;
129  ~VariableSymmetryObject(void);
130  };
133  public:
138  };
141  public:
145  int nxs;
147  int seq_size;
152  };
155  public:
159  int seq_size;
162  };
163 
165  template<class View>
166  class SymmetryImp {
167  public:
169  virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const = 0;
171  virtual void update(Literal) = 0;
173  virtual SymmetryImp<View>* copy(Space& home, bool share) const = 0;
175  virtual size_t dispose(Space& home) = 0;
177  virtual ~SymmetryImp(void);
179  static void* operator new(size_t s, Space& home);
181  static void operator delete(void*,Space&);
183  static void operator delete(void*);
184  };
186  template <class View>
187  class VariableSymmetryImp : public SymmetryImp<View> {
188  protected:
191  public:
193  VariableSymmetryImp<View>(Space& home, int* vs, unsigned int n);
197  virtual size_t dispose(Space& home);
199  void update(Literal);
201  virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
203  SymmetryImp<View>* copy(Space& home, bool share) const;
204  };
206  template <class View>
207  class ValueSymmetryImp : public SymmetryImp<View>
208  {
209  public:
213  ValueSymmetryImp<View>(Space& home, int* vs, unsigned int n);
217  virtual size_t dispose(Space& home);
219  void update(Literal);
221  virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
223  SymmetryImp<View>* copy(Space& home, bool share) const;
224  };
226  template <class View>
228  {
229  protected:
231  unsigned int *indices;
233  unsigned int n_indices;
235  unsigned int seq_size;
237  unsigned int n_seqs;
238 
240  // e.g. lookup[2] == 10 indicates that the variable with index 2
241  // occurs at position 10 in the "indices" array.
242  // If a variable occurs more than once, only the first occurrence
243  // is recorded.
244  // A value of -1 indicates that the variable does not occur in
245  // "indices".
246  int *lookup;
248  unsigned int lookup_size;
249 
252  int getVal(unsigned int sequence, unsigned int position) const;
253  public:
255  VariableSequenceSymmetryImp<View>(Space& home, int *_indices, unsigned int n, unsigned int seqsize);
259  virtual size_t dispose(Space& home);
261  void update(Literal);
263  virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
265  SymmetryImp<View>* copy(Space& home, bool share) const;
266  };
268  template <class View>
270  {
271  protected:
273  int *values;
275  unsigned int n_values;
277  unsigned int seq_size;
279  unsigned int n_seqs;
284  int getVal(unsigned int sequence, unsigned int position) const;
285  private:
287  public:
289  ValueSequenceSymmetryImp<View>(Space& home, int* _values, unsigned int n, unsigned int seqsize);
293  virtual size_t dispose(Space& home);
295  void update(Literal);
297  virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
299  SymmetryImp<View>* copy(Space& home, bool share) const;
300  };
301 
304  template<class Val>
306  private:
308  const Literal * const _literals;
310  const int _nliterals;
311  public:
314  LDSBChoice(const Brancher& b, unsigned int a, const Pos& p, const Val& n,
315  const Literal* literals, int nliterals);
317  ~LDSBChoice(void);
319  const Literal* literals(void) const;
321  int nliterals(void) const;
323  virtual size_t size(void) const;
325  virtual void archive(Archive& e) const;
326  };
327 
336  template<class View, int n, class Val, unsigned int a,
337  class Filter, class Print>
338  class LDSBBrancher : public ViewValBrancher<View,n,Val,a,Filter,Print> {
339  public:
344  int _nsyms;
345  // Position of variable that last choice was created for
346  int _prevPos;
347  protected:
349  LDSBBrancher(Space& home, bool share, LDSBBrancher& b);
351  LDSBBrancher(Home home,
353  ViewSel<View>* vs[n],
355  SymmetryImp<View>** syms, int nsyms,
358  public:
360  virtual const Choice* choice(Space& home);
362  virtual const Choice* choice(const Space& home, Archive& e);
364  virtual ExecStatus commit(Space& home, const Choice& c, unsigned int b);
366  virtual Actor* copy(Space& home, bool share);
368  virtual size_t dispose(Space& home);
370  static void post(Home home,
372  ViewSel<View>* vs[n],
374  SymmetryImp<View>** syms,
375  int nsyms,
378  };
379 
381  template<class View, int n, class Val, unsigned int a>
382  void postldsbbrancher(Home home,
384  ViewSel<View>* vs[n],
386  SymmetryImp<View>** syms, int nsyms,
389 
391  template<class View>
392  ModEvent prune(Space& home, View x, int v);
393 
394 }}}
395 
398 
399 #endif
400 
401 // STATISTICS: int-branch
402 
SymmetryImp< View > * copy(Space &home, bool share) const
Copy function.
Definition: sym-imp.hpp:357
Int::LDSB::Literal ValueType
Definition: ldsb.hh:103
virtual ExecStatus commit(Space &home, const Choice &c, unsigned int b)
Perform commit for choice c and alternative b.
Definition: brancher.hpp:242
virtual size_t dispose(Space &home)
Disposal.
Definition: sym-imp.hpp:225
VarImpBase ** xs
Array of variables in symmetry.
Definition: ldsb.hh:123
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
unsigned int n_indices
Total number of indices (n_seqs * seq_size)
Definition: ldsb.hh:233
void sequence(Home home, const IntVarArgs &x, const IntSet &s, int q, int l, int u, IntPropLevel)
Post propagator for .
Definition: sequence.cpp:51
IntSet values
Set of symmetric values.
Definition: ldsb.hh:135
A Literal is a pair of variable index and value.
Definition: ldsb.hh:50
unsigned int lookup_size
Size of lookup.
Definition: ldsb.hh:248
IntArgs values
Array of values in symmetry.
Definition: ldsb.hh:157
std::pair< int, int > findVar(int *indices, unsigned int n_values, unsigned int seq_size, int index)
Find the location of an integer in a collection of sequences.
Definition: ldsb.cpp:46
View::VarType Var
The corresponding variable.
SymmetryImp< View > * copy(Space &home, bool share) const
Copy function.
Definition: sym-imp.hpp:286
Implementation of a value symmetry at the modelling level.
Definition: ldsb.hh:132
Implementation of a value sequence symmetry at the modelling level.
Definition: ldsb.hh:154
virtual ~SymmetryImp(void)
Unused destructor.
Definition: sym-imp.hpp:52
std::function< void(const Space &home, const Brancher &b, unsigned int a, Var x, int i, const Val &m, std::ostream &o)> VarValPrint
Function type for printing variable and value selection.
void postldsbbrancher(Home home, ViewArray< View > &x, ViewSel< View > *vs[n], ValSelCommitBase< View, Val > *vsc, SymmetryImp< View > **syms, int nsyms, BranchFilter< typename View::VarType > bf, VarValPrint< typename View::VarType, Val > vvp)
Post LDSB brancher.
Definition: brancher.hpp:285
int ModEvent
Type for modification events.
Definition: core.hpp:142
Implementation of a symmetry at the modelling level.
Definition: ldsb.hh:110
Implementation of a variable sequence symmetry.
Definition: ldsb.hh:227
SymmetryImp< View > * copy(Space &home, bool share) const
Copy function.
Definition: sym-imp.hpp:117
Support::BitSetOffset< Space > values
Symmetric values.
Definition: ldsb.hh:211
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
ViewArray< View > x
Views to branch on.
int * lookup
Map from variable&#39;s index to its sequence and position.
Definition: ldsb.hh:246
int _value
The value of the literal. For int and bool variables, this is the value itself; for set variables...
Definition: ldsb.hh:63
Base-class for variable implementations.
Definition: core.hpp:249
int _variable
Variable index. The ViewArray that the index is meant for is assumed to be known by context...
Definition: ldsb.hh:59
Computation spaces.
Definition: core.hpp:1748
Base-class for both propagators and branchers.
Definition: core.hpp:696
int nxs
Number of variables in symmetry.
Definition: ldsb.hh:145
ArgArray< Int::LDSB::Literal > LiteralArgs
An array of literals.
Definition: ldsb.hh:97
ViewSel< View > * vs[n]
View selection objects.
virtual size_t dispose(Space &home)
Delete brancher and return its size.
Definition: brancher.hpp:277
bool operator<(const Literal &rhs) const
Less than. The ordering is the lexicographical order on the (variable,value) pair.
Definition: brancher.hpp:53
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Choice storing position and value, and symmetric literals to be excluded on the right branch...
Definition: ldsb.hh:305
Base-class for branchers.
Definition: core.hpp:1446
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
unsigned int n_seqs
Number of sequences in symmetry.
Definition: ldsb.hh:279
Argument array for non-primitive types.
Definition: array.hpp:727
virtual size_t dispose(Space &home)
Disposal.
Definition: sym-imp.hpp:326
virtual size_t dispose(Space &home)=0
Disposal.
unsigned int * indices
Array of variable indices.
Definition: ldsb.hh:231
Generic brancher by view and value selection.
Literal(void)
Constructor for an empty literal.
Definition: brancher.hpp:44
ModEvent prune(Space &home, View x, int v)
Exclude value from variable view .
Implementation of a variable symmetry at the modelling level.
Definition: ldsb.hh:120
Implementation of a value symmetry.
Definition: ldsb.hh:207
std::function< bool(const Space &home, Var x, int i)> BranchFilter
Function type for branch filter functions.
virtual SymmetryImp< View > * copy(Space &home, bool share) const =0
Copy function.
int getVal(unsigned int sequence, unsigned int position) const
Get the value in the specified sequence at the specified position. (Both are zero-based.)
Definition: sym-imp.hpp:182
ValSelCommitBase< View, Val > * vsc
Value selection and commit object.
unsigned int size(I &i)
Size of all ranges of range iterator i.
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
unsigned int seq_size
Size of each sequence in symmetry.
Definition: ldsb.hh:235
ArgArray< VarImpBase * > ArgsType
Definition: ldsb.hh:93
SymmetryImp< View > * copy(Space &home, bool share) const
Copy function.
Definition: sym-imp.hpp:172
int nxs
Number of variables in symmetry.
Definition: ldsb.hh:125
Support::BitSet< Space > dead_sequences
Which sequences are dead.
Definition: ldsb.hh:281
virtual size_t dispose(Space &home)
Disposal.
Definition: sym-imp.hpp:156
static void post(Home home, ViewArray< View > &x, ViewSel< View > *vs[n], ValSelCommitBase< View, Val > *vsc, SymmetryImp< View > **syms, int nsyms, BranchFilter< Var > bf, VarValPrint< Var, Val > vvp)
Brancher post function.
Definition: brancher.hpp:122
int seq_size
Size of each sequence in symmetry.
Definition: ldsb.hh:147
Symmetry-breaking brancher with generic view and value selection.
Definition: ldsb.hh:338
Implementation of a variable sequence symmetry at the modelling level.
Definition: ldsb.hh:140
Support::BitSetOffset< Space > indices
Symmetric variable indices.
Definition: ldsb.hh:190
Integer sets.
Definition: int.hh:174
VarImpBase ** xs
Array of variables in symmetry.
Definition: ldsb.hh:143
Position information.
View arrays.
Definition: array.hpp:234
int seq_size
Size of each sequence in symmetry.
Definition: ldsb.hh:159
virtual void update(Literal)=0
Left-branch update.
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
Passing integer arguments.
Definition: int.hh:610
unsigned int seq_size
Size of each sequence in symmetry.
Definition: ldsb.hh:277
double position(const Space &home, IntVar x, int i)
Definition: ldsb.cpp:1277
const int v[7]
Definition: distinct.cpp:263
unsigned int n_values
Total number of values (n_seqs * seq_size)
Definition: ldsb.hh:275
Implementation of a single symmetry.
Definition: ldsb.hh:166
void update(Literal)
Left-branch update.
Definition: sym-imp.hpp:164
Choice for performing commit
Definition: core.hpp:1414
Archive representation
Definition: archive.hpp:45
ExecStatus
Definition: core.hpp:540
Implementation of a variable symmetry.
Definition: ldsb.hh:187
Simple bitsets.
Definition: bitset.hpp:49
void update(Literal)
Left-branch update.
Definition: sym-imp.hpp:108
Implementation of a value sequence symmetry.
Definition: ldsb.hh:269
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
Definition: sym-imp.hpp:235
Post propagator for SetVar x
Definition: set.hh:784
int _nsyms
Number of symmetry implementations.
Definition: ldsb.hh:344
SymmetryImp< View > ** _syms
Array of symmetry implementations.
Definition: ldsb.hh:342
Traits of arrays in Gecode.
Definition: array.hpp:68
LDSBBrancher(Space &home, bool share, LDSBBrancher &b)
Constructor for cloning b.
Definition: brancher.hpp:135
unsigned int n_seqs
Number of sequences in symmetry.
Definition: ldsb.hh:237
void update(Literal)
Search left-branch update.
Definition: sym-imp.hpp:278
Gecode toplevel namespace
#define GECODE_VTABLE_EXPORT
Definition: support.hh:76
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const =0
Compute symmetric literals.
#define GECODE_INT_EXPORT
Definition: int.hh:81
ArgArray< VarImpBase * > StorageType
Definition: ldsb.hh:91
virtual size_t dispose(Space &home)
Disposal.
Definition: sym-imp.hpp:100
int getVal(unsigned int sequence, unsigned int position) const
Get the value in the specified sequence at the specified position. (Both are zero-based.)
Definition: sym-imp.hpp:295
Home class for posting propagators
Definition: core.hpp:922
Choice storing position and value
virtual const Choice * choice(Space &home)
Return choice.
Definition: brancher.hpp:158
int nrefs
Number of references that point to this symmetry object.
Definition: ldsb.hh:113
void update(Literal)
Left-branch update.
Definition: sym-imp.hpp:334
Bitsets with index offset.
virtual Actor * copy(Space &home, bool share)
Perform cloning.
Definition: brancher.hpp:148
int * values
Set of sequences.
Definition: ldsb.hh:273