Generated on Sat May 25 2013 18:00:38 for Gecode by doxygen 1.8.3.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