00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GC_THREADINGSYMMBREAKER_HH_
00021 #define GC_THREADINGSYMMBREAKER_HH_
00022
00023
00024 #include <gecode/kernel.hh>
00025 #include <gecode/search.hh>
00026 #include <gecode/int.hh>
00027 #include <biu/LatticeFrame.hh>
00028 #include "cpsp/gecode/GC_Search.hh"
00029 #include "GC_searchExt.hh"
00030
00031 #ifdef DEBUG
00032 #include <iostream>
00033 #endif
00034
00035
00036
00037 namespace cpsp { namespace gecode {
00038
00045 class GC_ThreadingSymmBreaker : public Gecode::Search::SymmBreaker<MyViewType,int> {
00046 public:
00047 typedef biu::IPointVec GlobalShiftVec;
00048 private:
00049 const biu::LatticeFrame *latticeFrame;
00050 const GlobalShiftVec* shiftVec;
00051 public:
00052
00053 GC_ThreadingSymmBreaker(Gecode::Space *home,
00054 const biu::LatticeFrame *latticeFrame_,
00055 const GlobalShiftVec* shiftVec_)
00056 : Gecode::Search::SymmBreaker<MyViewType,int>(home,latticeFrame_->getDescriptor()->getAutomorphisms().size()),
00057 latticeFrame(latticeFrame_), shiftVec(shiftVec_)
00058 {
00059 }
00060
00061 GC_ThreadingSymmBreaker(Gecode::Space *home,
00062 const biu::LatticeFrame *latticeFrame_,
00063 const GlobalShiftVec* shiftVec_,
00064 Gecode::BoolVarArray &init_cp)
00065 : Gecode::Search::SymmBreaker<MyViewType,int>(home,latticeFrame_->getDescriptor()->getAutomorphisms().size(), init_cp),
00066 latticeFrame(latticeFrame_), shiftVec(shiftVec_)
00067 {
00068 }
00069
00070
00071 GC_ThreadingSymmBreaker(Gecode::Space *home, bool share, const GC_ThreadingSymmBreaker &sym)
00072 : Gecode::Search::SymmBreaker<MyViewType,int>(home,share,sym),
00073 latticeFrame(sym.latticeFrame), shiftVec(sym.shiftVec)
00074 {}
00075
00076 virtual ~GC_ThreadingSymmBreaker() {}
00077
00078 virtual GC_ThreadingSymmBreaker* copy(Gecode::Space* home, bool share) {
00079 return new (home) GC_ThreadingSymmBreaker(home, share, *this);
00080 }
00081
00082
00083 protected:
00084
00086 static
00087 int
00088 getSymmetricIndex(int symmetry, int oldInd,
00089 const biu::LatticeFrame *latticeFrame,
00090 const GlobalShiftVec* shiftVec)
00091 {
00092 assertbiu(latticeFrame != NULL && shiftVec != NULL, "parameter == NULL");
00093 assertbiu(latticeFrame->getDescriptor()->getAutomorphisms().size() == shiftVec->size(), "different sizes of automorphisms and shift vectors");
00094 assertbiu(symmetry >= 0 && (biu::AutomorphismVec::size_type)symmetry < latticeFrame->getDescriptor()->getAutomorphisms().size(), "symmetry is no valid index ot automorphism vector");
00095
00096
00097 biu::IntPoint symm_p = latticeFrame->getPoint(oldInd);
00098 symm_p = latticeFrame->getDescriptor()->getAutomorphisms()[symmetry] * symm_p;
00099
00100
00101 return latticeFrame->getIndex(symm_p + shiftVec->at(symmetry));
00102 }
00103
00104
00105
00106 Gecode::BoolVar
00107 reifySymm(Gecode::Space *home,int symmetry, Gecode::ViewArray<MyViewType> &x, int pos, int val) const {
00108
00109 int sym_val = GC_ThreadingSymmBreaker::getSymmetricIndex(symmetry, val,
00110 latticeFrame, shiftVec);
00111
00112 Gecode::BoolVar b((Gecode::Space*)home,0,1);
00113 rel((Gecode::Space*)home,x[pos],Gecode::IRT_EQ,sym_val,b);
00114 return b;
00115 }
00116
00117 public:
00118
00121 static
00122 Gecode::BoolVarArray
00123 initCpByCore(Gecode::Space* home, HCore* hCore, const biu::LatticeFrame *latticeFrame,
00124 const GlobalShiftVec* shiftVec )
00125 {
00126 assertbiu(home != NULL && latticeFrame != NULL && shiftVec != NULL, "parameter == NULL");
00127 assertbiu(latticeFrame->getDescriptor()->getAutomorphisms().size() == shiftVec->size(), "different sizes of automorphisms and shift vectors");
00128
00129 biu::AutomorphismVec::size_type size = latticeFrame->getDescriptor()->getAutomorphisms().size(), sym=0;
00130 Gecode::BoolVarArray cp = Gecode::BoolVarArray(home, size);
00131 int sym_val = 0;
00132
00133 const biu::IndexSet core = hCore->getIndexedHull(latticeFrame, 0);
00134 biu::IndexSet::const_iterator it;
00135
00136 bool isNotBroken = true;
00137 for (sym=0; sym<size; sym++) {
00138 isNotBroken = true;
00139
00140 for (it = core.begin(); isNotBroken == true && it!= core.end(); it++) {
00141 sym_val = GC_ThreadingSymmBreaker::getSymmetricIndex(sym, *it, latticeFrame, shiftVec);
00142 isNotBroken = isNotBroken && (core.find(sym_val) != core.end());
00143 }
00144
00145 cp[sym] = Gecode::BoolVar(home, isNotBroken, isNotBroken);
00146 }
00147 return cp;
00148 }
00149
00152 static
00153 GlobalShiftVec*
00154 generateGlobalShiftVec(HCore* hCore, const biu::LatticeFrame *latticeFrame,
00155 GlobalShiftVec* shiftVec = NULL)
00156 {
00157 assertbiu(hCore != NULL && latticeFrame != NULL, "paramter == NULL");
00158
00159 biu::AutomorphismVec symms = latticeFrame->getDescriptor()->getAutomorphisms();
00160 biu::AutomorphismVec::size_type i=0, size=symms.size();
00161 if (shiftVec == NULL)
00162 shiftVec = new GlobalShiftVec(size, biu::IntPoint(0,0,0));
00163 else
00164 shiftVec->resize(size, biu::IntPoint(0,0,0));
00165
00166
00167 const biu::IntPoint coreFrameMin = hCore->getCoreFrame()->getMinCorner()
00168 + latticeFrame->getCenter() - hCore->getCoreFrame()->getCenter();
00169 const biu::IntPoint coreFrameMax = hCore->getCoreFrame()->getMaxCorner()
00170 + latticeFrame->getCenter() - hCore->getCoreFrame()->getCenter();
00171 biu::IntPoint c1, c2;
00172
00173 for ( i = 0; i < size; i++)
00174 {
00175 c1 = symms[i] * coreFrameMin;
00176 c2 = symms[i] * coreFrameMax;
00177
00178 shiftVec->at(i) = coreFrameMin - biu::IntPoint(
00179 std::min(c1.getX(), c2.getX()),
00180 std::min(c1.getY(), c2.getY()),
00181 std::min(c1.getZ(), c2.getZ()));
00182 }
00183
00184 return shiftVec;
00185 }
00186
00187
00188
00189 bool
00190 status(const Gecode::Space *home) const {
00191
00192
00193
00194 bool allbroken=true;
00195 for(int i=1; i<cps.size(); i++) {
00196 if (cps[i].min()!=cps[i].max() || cps[i].val()==1) {
00197 allbroken=false;
00198 break;
00199 }
00200 }
00201 return !allbroken;
00202 }
00203 };
00204
00205 } }
00206
00207 #endif