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/int/ldsb.hh>
00035 #include <gecode/int/branch.hh>
00036
00037 namespace Gecode { namespace Int { namespace LDSB {
00039 template <>
00040 ArgArray<Literal>
00041 VariableSymmetryImp<IntView>
00042 ::symmetric(Literal l, const ViewArray<IntView>& x) const {
00043 (void) x;
00044 if (indices.valid(l._variable) && indices.get(l._variable)) {
00045 int n = 0;
00046 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00047 n++;
00048 ArgArray<Literal> lits(n);
00049 int j = 0;
00050 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00051 lits[j++] = Literal(i.val(), l._value);
00052 return lits;
00053 } else {
00054 return ArgArray<Literal>(0);
00055 }
00056 }
00058 template <>
00059 ArgArray<Literal>
00060 VariableSymmetryImp<BoolView>
00061 ::symmetric(Literal l, const ViewArray<BoolView>& 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 return lits;
00072 } else {
00073 return ArgArray<Literal>(0);
00074 }
00075 }
00076
00078 template <>
00079 ArgArray<Literal>
00080 ValueSymmetryImp<IntView>
00081 ::symmetric(Literal l, const ViewArray<IntView>& 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 return lits;
00092 } else {
00093 return ArgArray<Literal>(0);
00094 }
00095 }
00097 template <>
00098 ArgArray<Literal>
00099 ValueSymmetryImp<BoolView>
00100 ::symmetric(Literal l, const ViewArray<BoolView>& x) const {
00101 (void) x;
00102 if (values.valid(l._value) && values.get(l._value)) {
00103 int n = 0;
00104 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00105 n++;
00106 ArgArray<Literal> lits(n);
00107 int j = 0;
00108 for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00109 lits[j++] = Literal(l._variable, i.val());
00110 return lits;
00111 } else {
00112 return ArgArray<Literal>(0);
00113 }
00114 }
00115
00117 template <>
00118 ArgArray<Literal>
00119 ValueSequenceSymmetryImp<Int::IntView>
00120 ::symmetric(Literal l, const ViewArray<IntView>& x) const {
00121 (void) x;
00122 Support::DynamicStack<Literal, Heap> s(heap);
00123 std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
00124 if (location.first == -1) return dynamicStackToArgArray(s);
00125 unsigned int seqNum = location.first;
00126 unsigned int seqPos = location.second;
00127 if (! dead_sequences.get(seqNum)) {
00128 for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00129 if (seq == seqNum) continue;
00130 if (dead_sequences.get(seq)) continue;
00131 s.push(Literal(l._variable, getVal(seq,seqPos)));
00132 }
00133 }
00134 return dynamicStackToArgArray(s);
00135 }
00137 template <>
00138 ArgArray<Literal>
00139 ValueSequenceSymmetryImp<BoolView>
00140 ::symmetric(Literal l, const ViewArray<BoolView>& x) const {
00141 (void) x;
00142 Support::DynamicStack<Literal, Heap> s(heap);
00143 std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
00144 if (location.first == -1) return dynamicStackToArgArray(s);
00145 unsigned int seqNum = location.first;
00146 unsigned int seqPos = location.second;
00147 if (! dead_sequences.get(seqNum)) {
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 }
00154 return dynamicStackToArgArray(s);
00155 }
00156
00157 }}}
00158
00159