this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2008 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34#ifndef GECODE_SEARCH_SUPPORT_HH 35#define GECODE_SEARCH_SUPPORT_HH 36 37#include <gecode/search.hh> 38 39namespace Gecode { namespace Search { 40 41 /// Clone space \a s dependening on options \a o 42 forceinline Space* 43 snapshot(Space* s, const Options& o); 44 45 /// Virtualize a worker to an engine 46 template<class Worker> 47 class WorkerToEngine : public Engine { 48 protected: 49 /// The worker to wrap into an engine 50 Worker w; 51 public: 52 /// Initialization 53 WorkerToEngine(Space* s, const Options& o); 54 /// Return next solution (nullptr, if none exists or search has been stopped) 55 virtual Space* next(void); 56 /// Return statistics 57 virtual Search::Statistics statistics(void) const; 58 /// Check whether engine has been stopped 59 virtual bool stopped(void) const; 60 /// Constrain future solutions to be better than \a b 61 virtual void constrain(const Space& b); 62 /// Reset engine to restart at space \a s 63 virtual void reset(Space* s); 64 /// Return no-goods 65 virtual NoGoods& nogoods(void); 66 }; 67 68 69 70 forceinline Space* 71 snapshot(Space* s, const Options& o) { 72 return o.clone ? s->clone() : s; 73 } 74 75 76 template<class Worker> 77 WorkerToEngine<Worker>::WorkerToEngine(Space* s, const Options& o) 78 : w(s,o) {} 79 template<class Worker> 80 Space* 81 WorkerToEngine<Worker>::next(void) { 82 return w.next(); 83 } 84 template<class Worker> 85 Search::Statistics 86 WorkerToEngine<Worker>::statistics(void) const { 87 return w.statistics(); 88 } 89 template<class Worker> 90 bool 91 WorkerToEngine<Worker>::stopped(void) const { 92 return w.stopped(); 93 } 94 template<class Worker> 95 void 96 WorkerToEngine<Worker>::reset(Space* s) { 97 w.reset(s); 98 } 99 template<class Worker> 100 void 101 WorkerToEngine<Worker>::constrain(const Space& b) { 102 w.constrain(b); 103 } 104 template<class Worker> 105 NoGoods& 106 WorkerToEngine<Worker>::nogoods(void) { 107 return w.nogoods(); 108 } 109 110}} 111 112#endif 113 114// STATISTICS: search-other