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