Generated on Thu Apr 11 13:59:17 2019 for Gecode by doxygen 1.6.3

ldsb.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christopher Mears <chris.mears@monash.edu>
00005  *
00006  *  Copyright:
00007  *     Christopher Mears, 2012
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode {
00035 
00038   template<class A>
00039   SymmetryHandle
00040   rows_interchange(const Matrix<A>& m) {
00041     typename Matrix<A>::ArgsType xs;
00042     for (int r = 0 ; r < m.height() ; r++)
00043       xs << m.row(r);
00044     return VariableSequenceSymmetry(xs, m.width());
00045   }
00046 
00049   template<class A>
00050   SymmetryHandle
00051   columns_interchange(const Matrix<A>& m) {
00052     typename Matrix<A>::ArgsType xs;
00053     for (int c = 0 ; c < m.width() ; c++)
00054       xs << m.col(c);
00055     return VariableSequenceSymmetry(xs, m.height());
00056   }
00057 
00060   template<class A>
00061   SymmetryHandle
00062   rows_reflect(const Matrix<A>& m) {
00063     int nrows = m.height();
00064     int ncols = m.width();
00065     // Length of each sequence in the symmetry.
00066     int length = (nrows/2) * ncols;
00067     typename Matrix<A>::ArgsType xs(length * 2);
00068     for (int i = 0 ; i < length ; i++) {
00069       // Break position i into its coordinates
00070       int r1 = i/ncols;
00071       int c1 = i%ncols;
00072       // r2 is the row symmetric with r1
00073       int r2 = nrows - r1 - 1;
00074       // The column remains the same
00075       int c2 = c1;
00076       xs[i] = m(c1,r1);
00077       xs[length+i] = m(c2,r2);
00078     }
00079     return VariableSequenceSymmetry(xs, length);
00080   }
00081 
00084   template<class A>
00085   SymmetryHandle columns_reflect(const Matrix<A>& m) {
00086     int nrows = m.height();
00087     int ncols = m.width();
00088     // Length of each sequence in the symmetry.
00089     int length = (ncols/2) * nrows;
00090     typename Matrix<A>::ArgsType xs(length * 2);
00091     for (int i = 0 ; i < length ; i++) {
00092       // Break position i into its coordinates
00093       int r1 = i/ncols;
00094       int c1 = i%ncols;
00095       // c2 is the column symmetric with c1
00096       int c2 = ncols - c1 - 1;
00097       // The row remains the same
00098       int r2 = r1;
00099       xs[i] = m(c1,r1);
00100       xs[length+i] = m(c2,r2);
00101     }
00102     return VariableSequenceSymmetry(xs, length);
00103   }
00104 
00107   template<class A>
00108   SymmetryHandle diagonal_reflect(const Matrix<A>& m) {
00109     int nrows = m.height();
00110     int ncols = m.width();
00111 
00112     typename Matrix<A>::ArgsType a1;
00113     typename Matrix<A>::ArgsType a2;
00114 
00115     for (int i = 0 ; i < nrows ; i++) {
00116       for (int j = i+1 ; j < ncols ; j++) {
00117         a1 << m(j,i);
00118         a2 << m(i,j);
00119       }
00120     }
00121 
00122     typename Matrix<A>::ArgsType aboth;
00123     aboth << a1;
00124     aboth << a2;
00125     return VariableSequenceSymmetry(aboth, a1.size());
00126   }
00127 }
00128 
00129 // STATISTICS: minimodel-any