sym-imp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <gecode/set/ldsb.hh>
00035
00036 namespace Gecode { namespace Set { namespace LDSB {
00037
00038
00040 bool
00041 equalLUB(const Set::SetView& x, const Set::SetView& y) {
00042 unsigned int n = x.lubSize();
00043 if (n != y.lubSize()) return false;
00044 for (unsigned int i = 0 ; i < n ; i++)
00045 if (x.lubMinN(i) != y.lubMinN(i))
00046 return false;
00047 return true;
00048 }
00049 }}}
00050
00051
00052
00053 namespace Gecode { namespace Int { namespace LDSB {
00054 template <>
00055 ArgArray<Literal>
00056 VariableSymmetryImp<Set::SetView>
00057 ::symmetric(Literal l, const ViewArray<Set::SetView>& x) const {
00058 (void) x;
00059 if (indices.valid(l._variable) && indices.get(l._variable)) {
00060 int n = 0;
00061 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00062 n++;
00063 ArgArray<Literal> lits(n);
00064 int j = 0;
00065 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i) {
00066 lits[j++] = Literal(i.val(), l._value);
00067 }
00068 return lits;
00069 } else {
00070 return ArgArray<Literal>(0);
00071 }
00072 }
00073
00074 template <>
00075 ArgArray<Literal>
00076 ValueSymmetryImp<Set::SetView>
00077 ::symmetric(Literal l, const ViewArray<Set::SetView>& x) const {
00078 (void) x;
00079 if (values.valid(l._value) && values.get(l._value)) {
00080 int n = 0;
00081 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00082 n++;
00083 ArgArray<Literal> lits(n);
00084 int j = 0;
00085 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i) {
00086 lits[j++] = Literal(l._variable, i.val());
00087 }
00088 return lits;
00089 } else {
00090 return ArgArray<Literal>(0);
00091 }
00092 }
00093
00094 template <>
00095 ArgArray<Literal>
00096 VariableSequenceSymmetryImp<Set::SetView>
00097 ::symmetric(Literal l, const ViewArray<Set::SetView>& x) const {
00098 Support::DynamicStack<Literal, Heap> s(heap);
00099 if (l._variable < (int)lookup_size) {
00100 int posIt = lookup[l._variable];
00101 if (posIt == -1) {
00102 return dynamicStackToArgArray(s);
00103 }
00104 unsigned int seqNum = posIt / seq_size;
00105 unsigned int seqPos = posIt % seq_size;
00106 for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00107 if (seq == seqNum) {
00108 continue;
00109 }
00110 if (x[getVal(seq, seqPos)].assigned()) {
00111 continue;
00112 }
00113 bool active = true;
00114 const unsigned int *firstSeq = &indices[seqNum*seq_size];
00115 const unsigned int *secondSeq = &indices[seq*seq_size];
00116 for (unsigned int i = 0 ; i < seq_size ; i++) {
00117 const Set::SetView& xv = x[firstSeq[i]];
00118 const Set::SetView& yv = x[secondSeq[i]];
00119 if ((!xv.assigned() && !yv.assigned())
00120 || (xv.assigned() && yv.assigned() && Set::LDSB::equalLUB(xv, yv))) {
00121 continue;
00122 } else {
00123 active = false;
00124 break;
00125 }
00126 }
00127
00128 if (active) {
00129 s.push(Literal(secondSeq[seqPos], l._value));
00130 }
00131 }
00132 }
00133 return dynamicStackToArgArray(s);
00134 }
00135
00136 template <>
00137 ArgArray<Literal>
00138 ValueSequenceSymmetryImp<Set::SetView>
00139 ::symmetric(Literal l, const ViewArray<Set::SetView>& x) const {
00140 (void) x;
00141 Support::DynamicStack<Literal, Heap> s(heap);
00142 std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
00143 if (location.first == -1) return dynamicStackToArgArray(s);
00144 unsigned int seqNum = location.first;
00145 unsigned int seqPos = location.second;
00146 for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00147 if (seq == seqNum) continue;
00148 if (dead_sequences.get(seq)) continue;
00149 s.push(Literal(l._variable, getVal(seq,seqPos)));
00150 }
00151 return dynamicStackToArgArray(s);
00152 }
00153 }}}
00154
00155