ldsb.hpp
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 namespace Gecode {
00039
00042 template<class A>
00043 SymmetryHandle
00044 rows_interchange(const Matrix<A>& m) {
00045 typename Matrix<A>::ArgsType xs;
00046 for (int r = 0 ; r < m.height() ; r++)
00047 xs << m.row(r);
00048 return VariableSequenceSymmetry(xs, m.width());
00049 }
00050
00053 template<class A>
00054 SymmetryHandle
00055 columns_interchange(const Matrix<A>& m) {
00056 typename Matrix<A>::ArgsType xs;
00057 for (int c = 0 ; c < m.width() ; c++)
00058 xs << m.col(c);
00059 return VariableSequenceSymmetry(xs, m.height());
00060 }
00061
00064 template<class A>
00065 SymmetryHandle
00066 rows_reflect(const Matrix<A>& m) {
00067 int nrows = m.height();
00068 int ncols = m.width();
00069
00070 int length = (nrows/2) * ncols;
00071 typename Matrix<A>::ArgsType xs(length * 2);
00072 for (int i = 0 ; i < length ; i++) {
00073
00074 int r1 = i/ncols;
00075 int c1 = i%ncols;
00076
00077 int r2 = nrows - r1 - 1;
00078
00079 int c2 = c1;
00080 xs[i] = m(c1,r1);
00081 xs[length+i] = m(c2,r2);
00082 }
00083 return VariableSequenceSymmetry(xs, length);
00084 }
00085
00088 template<class A>
00089 SymmetryHandle columns_reflect(const Matrix<A>& m) {
00090 int nrows = m.height();
00091 int ncols = m.width();
00092
00093 int length = (ncols/2) * nrows;
00094 typename Matrix<A>::ArgsType xs(length * 2);
00095 for (int i = 0 ; i < length ; i++) {
00096
00097 int r1 = i/ncols;
00098 int c1 = i%ncols;
00099
00100 int c2 = ncols - c1 - 1;
00101
00102 int r2 = r1;
00103 xs[i] = m(c1,r1);
00104 xs[length+i] = m(c2,r2);
00105 }
00106 return VariableSequenceSymmetry(xs, length);
00107 }
00108
00111 template<class A>
00112 SymmetryHandle diagonal_reflect(const Matrix<A>& m) {
00113 int nrows = m.height();
00114 int ncols = m.width();
00115
00116 typename Matrix<A>::ArgsType a1;
00117 typename Matrix<A>::ArgsType a2;
00118
00119 for (int i = 0 ; i < nrows ; i++) {
00120 for (int j = i+1 ; j < ncols ; j++) {
00121 a1 << m(j,i);
00122 a2 << m(i,j);
00123 }
00124 }
00125
00126 typename Matrix<A>::ArgsType aboth;
00127 aboth << a1;
00128 aboth << a2;
00129 return VariableSequenceSymmetry(aboth, a1.size());
00130 }
00131 }
00132
00133