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 Region region;
00099 Support::DynamicStack<Literal,Region> s(region);
00100 if (l._variable < (int)lookup_size) {
00101 int posIt = lookup[l._variable];
00102 if (posIt == -1) {
00103 return dynamicStackToArgArray(s);
00104 }
00105 unsigned int seqNum = posIt / seq_size;
00106 unsigned int seqPos = posIt % seq_size;
00107 for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00108 if (seq == seqNum) {
00109 continue;
00110 }
00111 if (x[getVal(seq, seqPos)].assigned()) {
00112 continue;
00113 }
00114 bool active = true;
00115 const unsigned int *firstSeq = &indices[seqNum*seq_size];
00116 const unsigned int *secondSeq = &indices[seq*seq_size];
00117 for (unsigned int i = 0 ; i < seq_size ; i++) {
00118 const Set::SetView& xv = x[firstSeq[i]];
00119 const Set::SetView& yv = x[secondSeq[i]];
00120 if ((!xv.assigned() && !yv.assigned())
00121 || (xv.assigned() && yv.assigned() && Set::LDSB::equalLUB(xv, yv))) {
00122 continue;
00123 } else {
00124 active = false;
00125 break;
00126 }
00127 }
00128
00129 if (active) {
00130 s.push(Literal(secondSeq[seqPos], l._value));
00131 }
00132 }
00133 }
00134 return dynamicStackToArgArray(s);
00135 }
00136
00137 template <>
00138 ArgArray<Literal>
00139 ValueSequenceSymmetryImp<Set::SetView>
00140 ::symmetric(Literal l, const ViewArray<Set::SetView>& x) const {
00141 (void) x;
00142 Region region;
00143 Support::DynamicStack<Literal,Region> s(region);
00144 std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
00145 if (location.first == -1) return dynamicStackToArgArray(s);
00146 unsigned int seqNum = location.first;
00147 unsigned int seqPos = location.second;
00148 for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00149 if (seq == seqNum) continue;
00150 if (dead_sequences.get(seq)) continue;
00151 s.push(Literal(l._variable, getVal(seq,seqPos)));
00152 }
00153 return dynamicStackToArgArray(s);
00154 }
00155 }}}
00156
00157