ldsb.hpp /usr/include/gecode/minimodel.hh Gecode /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristopherMears<chris.mears@monash.edu> * *Copyright: *ChristopherMears,2012 * *Lastmodified: *$Date:2013-05-2204:21:36+0200(Wed,22May2013)$by$Author:mears$ *$Revision:13653$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ namespaceGecode{ template<classA> SymmetryHandle rows_interchange(constMatrix<A>&m){ typenameMatrix<A>::ArgsTypexs; for(intr=0;r<m.height();r++) xs<<m.row(r); returnVariableSequenceSymmetry(xs,m.width()); } template<classA> SymmetryHandle columns_interchange(constMatrix<A>&m){ typenameMatrix<A>::ArgsTypexs; for(intc=0;c<m.width();c++) xs<<m.col(c); returnVariableSequenceSymmetry(xs,m.height()); } template<classA> SymmetryHandle rows_reflect(constMatrix<A>&m){ intnrows=m.height(); intncols=m.width(); //Lengthofeachsequenceinthesymmetry. intlength=(nrows/2)*ncols; typenameMatrix<A>::ArgsTypexs(length*2); for(inti=0;i<length;i++){ //Breakpositioniintoitscoordinates intr1=i/ncols; intc1=i%ncols; //r2istherowsymmetricwithr1 intr2=nrows-r1-1; //Thecolumnremainsthesame intc2=c1; xs[i]=m(c1,r1); xs[length+i]=m(c2,r2); } returnVariableSequenceSymmetry(xs,length); } template<classA> SymmetryHandlecolumns_reflect(constMatrix<A>&m){ intnrows=m.height(); intncols=m.width(); //Lengthofeachsequenceinthesymmetry. intlength=(ncols/2)*nrows; typenameMatrix<A>::ArgsTypexs(length*2); for(inti=0;i<length;i++){ //Breakpositioniintoitscoordinates intr1=i/ncols; intc1=i%ncols; //c2isthecolumnsymmetricwithc1 intc2=ncols-c1-1; //Therowremainsthesame intr2=r1; xs[i]=m(c1,r1); xs[length+i]=m(c2,r2); } returnVariableSequenceSymmetry(xs,length); } template<classA> SymmetryHandlediagonal_reflect(constMatrix<A>&m){ intnrows=m.height(); intncols=m.width(); typenameMatrix<A>::ArgsTypea1; typenameMatrix<A>::ArgsTypea2; for(inti=0;i<nrows;i++){ for(intj=i+1;j<ncols;j++){ a1<<m(j,i); a2<<m(i,j); } } typenameMatrix<A>::ArgsTypeaboth; aboth<<a1; aboth<<a2; returnVariableSequenceSymmetry(aboth,a1.size()); } } //STATISTICS:minimodel-any