Generated on Sat Feb 7 2015 02:01:24 for Gecode by doxygen 1.8.9.1
sym-imp.cpp
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: 2013-03-07 17:39:13 +0100 (Thu, 07 Mar 2013) $ by $Author: schulte $
11  * $Revision: 13458 $
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 #include <gecode/set/ldsb.hh>
39 
40 namespace Gecode { namespace Set { namespace LDSB {
41  // XXX: implementation of equalValues could be improved?
42 
44  bool
45  equalLUB(const Set::SetView& x, const Set::SetView& y) {
46  unsigned int n = x.lubSize();
47  if (n != y.lubSize()) return false;
48  for (unsigned int i = 0 ; i < n ; i++)
49  if (x.lubMinN(i) != y.lubMinN(i))
50  return false;
51  return true;
52  }
53 }}}
54 
55 // Note carefully that this is in the Gecode::Int::LDSB namespace, not
56 // Gecode::Set::LDSB.
57 namespace Gecode { namespace Int { namespace LDSB {
58  template <>
59  ArgArray<Literal>
62  (void) x;
63  if (indices.valid(l._variable) && indices.get(l._variable)) {
64  int n = 0;
66  n++;
67  ArgArray<Literal> lits(n);
68  int j = 0;
70  lits[j++] = Literal(i.val(), l._value);
71  }
72  return lits;
73  } else {
74  return ArgArray<Literal>(0);
75  }
76  }
77 
78  template <>
82  (void) x;
83  if (values.valid(l._value) && values.get(l._value)) {
84  int n = 0;
86  n++;
87  ArgArray<Literal> lits(n);
88  int j = 0;
90  lits[j++] = Literal(l._variable, i.val());
91  }
92  return lits;
93  } else {
94  return ArgArray<Literal>(0);
95  }
96  }
97 
98  template <>
103  if (l._variable < (int)lookup_size) {
104  int posIt = lookup[l._variable];
105  if (posIt == -1) {
106  return dynamicStackToArgArray(s);
107  }
108  unsigned int seqNum = posIt / seq_size;
109  unsigned int seqPos = posIt % seq_size;
110  for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
111  if (seq == seqNum) {
112  continue;
113  }
114  if (x[getVal(seq, seqPos)].assigned()) {
115  continue;
116  }
117  bool active = true;
118  const unsigned int *firstSeq = &indices[seqNum*seq_size];
119  const unsigned int *secondSeq = &indices[seq*seq_size];
120  for (unsigned int i = 0 ; i < seq_size ; i++) {
121  const Set::SetView& xv = x[firstSeq[i]];
122  const Set::SetView& yv = x[secondSeq[i]];
123  if ((!xv.assigned() && !yv.assigned())
124  || (xv.assigned() && yv.assigned() && Set::LDSB::equalLUB(xv, yv))) {
125  continue;
126  } else {
127  active = false;
128  break;
129  }
130  }
131 
132  if (active) {
133  s.push(Literal(secondSeq[seqPos], l._value));
134  }
135  }
136  }
137  return dynamicStackToArgArray(s);
138  }
139 
140  template <>
144  (void) x;
146  std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
147  if (location.first == -1) return dynamicStackToArgArray(s);
148  unsigned int seqNum = location.first;
149  unsigned int seqPos = location.second;
150  for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
151  if (seq == seqNum) continue;
152  if (dead_sequences.get(seq)) continue;
153  s.push(Literal(l._variable, getVal(seq,seqPos)));
154  }
155  return dynamicStackToArgArray(s);
156  }
157 }}}
158 
159 // STATISTICS: set-branch
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
A Literal is a pair of variable index and value.
Definition: ldsb.hh:50
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
int _value
The value of the literal. For int and bool variables, this is the value itself; for set variables...
Definition: ldsb.hh:63
int _variable
Variable index. The ViewArray that the index is meant for is assumed to be known by context...
Definition: ldsb.hh:59
Heap heap
The single global heap.
Definition: heap.cpp:49
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Argument array for non-primitive types.
Definition: array.hpp:727
int lubMinN(unsigned int n) const
Return n-th smallest element of the least upper bound.
Definition: set.hpp:102
View arrays.
Definition: array.hpp:234
Set view for set variables
Definition: view.hpp:60
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
void values(Home home, const IntVarArgs &x, IntSet y, IntConLevel icl=ICL_DEF)
Post constraint .
Definition: minimodel.hh:1869
Value iterator for values in an offset bitset.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
bool equalLUB(const Set::SetView &x, const Set::SetView &y)
Do two set variables have equal least-upper-bounds?
Definition: sym-imp.cpp:45
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:448
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
Definition: sym-imp.hpp:232
Stack with arbitrary number of elements.
Gecode toplevel namespace
ArgArray< T > dynamicStackToArgArray(const Support::DynamicStack< T, A > &s)
Convert a DynamicStack into an ArgArray
Definition: sym-imp.hpp:43
unsigned int lubSize(void) const
Return the number of elements in the least upper bound.
Definition: set.hpp:70
void push(const T &x)
Push element x on top of stack.
Bitsets with index offset.