Generated on Tue Apr 18 10:22:08 2017 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  *  Last modified:
00010  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00011  *     $Revision: 14967 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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     // Length of each sequence in the symmetry.
00070     int length = (nrows/2) * ncols;
00071     typename Matrix<A>::ArgsType xs(length * 2);
00072     for (int i = 0 ; i < length ; i++) {
00073       // Break position i into its coordinates
00074       int r1 = i/ncols;
00075       int c1 = i%ncols;
00076       // r2 is the row symmetric with r1
00077       int r2 = nrows - r1 - 1;
00078       // The column remains the same
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     // Length of each sequence in the symmetry.
00093     int length = (ncols/2) * nrows;
00094     typename Matrix<A>::ArgsType xs(length * 2);
00095     for (int i = 0 ; i < length ; i++) {
00096       // Break position i into its coordinates
00097       int r1 = i/ncols;
00098       int c1 = i%ncols;
00099       // c2 is the column symmetric with c1
00100       int c2 = ncols - c1 - 1;
00101       // The row remains the same
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 // STATISTICS: minimodel-any