| 263 | |
| 264 | template<class T, template<class> class E> |
| 265 | void |
| 266 | PBS<T,E>::build(T* s, SEBs& sebs, const Search::Options& o) { |
| 267 | // Check whether all sebs do either best solution search or not |
| 268 | bool best; |
| 269 | { |
| 270 | int b = 0; |
| 271 | for (int i=0; i<sebs.size(); i++) |
| 272 | b += sebs[i]->best() ? 1 : 0; |
| 273 | if ((b > 0) && (b < sebs.size())) |
| 274 | throw Search::MixedBest("PBS::PBS"); |
| 275 | best = (b == sebs.size()); |
| 276 | } |
| 277 | |
| 278 | Search::Options opt(o.expand()); |
| 279 | Search::Statistics stat; |
| 280 | |
| 281 | if (s->status(stat) == SS_FAILED) { |
| 282 | stat.fail++; |
| 283 | if (!opt.clone) |
| 284 | delete s; |
| 285 | e = Search::Seq::dead(opt,stat); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | // Check whether a clone must be used |
| 290 | T* master = opt.clone ? |
| 291 | dynamic_cast<T*>(s->clone()) : s; |
| 292 | opt.clone = false; |
| 293 | |
| 294 | // Always execute master function |
| 295 | (void) master->master(0); |
| 296 | |
| 297 | #ifdef GECODE_HAS_THREADS |
| 298 | if (opt.threads > 1.0) |
| 299 | e = Search::pbspar<T,E>(master,sebs,stat,opt,best); |
| 300 | else |
| 301 | #endif |
| 302 | e = Search::pbsseq<T,E>(master,sebs,stat,opt,best); |
| 303 | } |
| 304 | |
| 305 | template<class T, template<class> class E> |
| 306 | inline |