00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GC_SEARCHEXT_HH_
00021 #define GC_SEARCHEXT_HH_
00022
00032 #include "gecode/minimodel.hh"
00033 #include "gecode/support/dynamic-array.hh"
00034
00035 namespace Gecode {
00036
00037
00038 template <class Int, class T>
00039 Int
00040 countDFS(T* initialSpace, unsigned int c_d, unsigned int a_d, Search::Statistics* stat, Gecode::Search::Stop* st, Int maxSols) {
00041
00042
00043 Gecode::DFS<T> dfsEngine( initialSpace, c_d, a_d, st);
00044
00045 Int sols = 0;
00046
00047
00048 T* nextSol = dfsEngine.next();
00049
00050 while( nextSol != NULL && sols < maxSols) {
00051
00052 sols++;
00053
00054 delete nextSol;
00055 nextSol = dfsEngine.next();
00056 }
00057 if (stat != NULL)
00058 *stat = dfsEngine.statistics();
00059 return sols;
00060 }
00061 template <class Int, class T>
00062 Int
00063 countDDS(T* initialSpace, unsigned int c_d, unsigned int a_d, Search::Statistics* stat, Gecode::Search::Stop* st, Int maxSols) {
00064
00065 return countDDS<Int,T>(initialSpace, c_d, a_d, stat, st, maxSols);
00066 }
00067
00068
00069 namespace Search {
00070
00071
00072
00073
00074
00084 template<class View, class Val>
00085 class SymmBreaker {
00086 protected:
00088 BoolVarArray cps;
00090 Support::DynamicArray<int> symOf;
00091
00093 virtual
00094 void tellSymm(Space *home,int symmetry, ViewArray<View> &x, int pos, Val val) const {
00095 BoolVar b = reifySymm(home,symmetry,x,pos,val);
00096 post(home,b==1);
00097 }
00098
00100 virtual
00101 BoolVar reifySymm(Space *home,int symmetry, ViewArray<View> &x, int pos, Val val) const=0;
00102
00104 void
00105 updateCps(Space *home, ViewArray<View> &x, int pos, Val val);
00106
00108 void
00109 postImplications(Space *home, ViewArray<View> &x, int pos, Val val) const;
00110
00111 public:
00113 SymmBreaker(Space *home, int sym_num)
00114 : cps(BoolVarArray(home,sym_num,1,1)),
00115 symOf(sym_num)
00116 {
00117
00118 for (int i=0; i< sym_num; i++)
00119 symOf[i] = i;
00120 }
00121
00123
00124
00125
00126 SymmBreaker(Space *home, int sym_num, BoolVarArray &init_cp)
00127 : cps(), symOf(sym_num)
00128 {
00129 assert(sym_num == init_cp.size());
00130
00131 cps.update(home, false, init_cp);
00132
00133 for (int i=0; i< sym_num; i++)
00134 symOf[i] = i;
00135 }
00136
00138 SymmBreaker(Space *home, bool share,const SymmBreaker<View,Val> &symm) {
00139 assert(symm.cps.size()>0);
00140 int newSize = 1;
00141 for (int i=1; i<symm.cps.size(); i++)
00142 if (!symm.cps[i].assigned() || symm.cps[i].val() != false)
00143 newSize++;
00144 cps = BoolVarArray(home, newSize);
00145 symOf = Support::DynamicArray<int>(newSize);
00146 cps[0].update(home,share,(BoolVar&)symm.cps[0]);
00147 symOf[0] = symm.symOf[0];
00148 int cpI = 1;
00149 for (int i=1; i<symm.cps.size(); i++) {
00150 if (!symm.cps[i].assigned() || symm.cps[i].val() != false) {
00151 cps[cpI].update(home,share,(BoolVar&)symm.cps[i]);
00152 symOf[cpI] = symm.symOf[i];
00153 cpI++;
00154 }
00155 }
00156
00157 }
00158
00159 virtual
00160 ~SymmBreaker() {}
00161
00164 virtual bool
00165 status(const Space *home) const {return true;}
00166
00168 void
00169 tell(Space *home, int a, ViewArray<View> &x, int pos, Val val);
00170
00172 virtual
00173 void
00174 print(void) const;
00175 };
00176
00177
00182 template <class View, class Val, class ViewSel, class ValSel, class SymmBreaker>
00183 class SBViewValBranching : public ViewValBranching<View,Val,ViewSel,ValSel> {
00184 protected:
00185 SymmBreaker symmetries;
00186
00187 SBViewValBranching(Space* home, bool share, SBViewValBranching& b);
00188 public:
00190 SBViewValBranching(Space* home, ViewArray<View>& x);
00191
00193 SBViewValBranching(Space* home, ViewArray<View>& x, SymmBreaker &sym);
00194
00196 virtual bool status(const Space* home) const;
00197
00199 virtual ExecStatus commit(Space* home, const BranchingDesc* d,
00200 unsigned int a);
00202 virtual Actor* copy(Space* home, bool share);
00203 };
00204 }
00205 }
00206
00207
00208 #include "symm-break.icc"
00209 #endif