Generated on Sat Jan 12 2019 20:58:51 for Gecode by doxygen 1.8.13
support.hh
Go to the documentation of this file.
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 
39 namespace Gecode { namespace Search {
40 
42  forceinline Space*
43  snapshot(Space* s, const Options& o);
44 
46  template<class Worker>
47  class WorkerToEngine : public Engine {
48  protected:
51  public:
53  WorkerToEngine(Space* s, const Options& o);
55  virtual Space* next(void);
57  virtual Search::Statistics statistics(void) const;
59  virtual bool stopped(void) const;
61  virtual void constrain(const Space& b);
63  virtual void reset(Space* s);
65  virtual NoGoods& nogoods(void);
66  };
67 
68 
69 
71  snapshot(Space* s, const Options& o) {
72  return o.clone ? s->clone() : s;
73  }
74 
75 
76  template<class Worker>
78  : w(s,o) {}
79  template<class Worker>
80  Space*
82  return w.next();
83  }
84  template<class Worker>
87  return w.statistics();
88  }
89  template<class Worker>
90  bool
92  return w.stopped();
93  }
94  template<class Worker>
95  void
97  w.reset(s);
98  }
99  template<class Worker>
100  void
102  w.constrain(b);
103  }
104  template<class Worker>
105  NoGoods&
107  return w.nogoods();
108  }
109 
110 }}
111 
112 #endif
113 
114 // STATISTICS: search-other
Search engine implementation interface
Definition: search.hh:899
Search engine statistics
Definition: search.hh:147
Search engine options
Definition: search.hh:746
void reset(unsigned long int d=0)
Reset statistics with root depth d.
Definition: worker.hh:92
virtual bool stopped(void) const
Check whether engine has been stopped.
Definition: support.hh:91
virtual void constrain(const Space &b)
Constrain future solutions to be better than b.
Definition: support.hh:101
#define forceinline
Definition: config.hpp:185
bool stopped(void) const
Check whether engine has been stopped.
Definition: worker.hh:87
Computation spaces.
Definition: core.hpp:1701
virtual Search::Statistics statistics(void) const
Return statistics.
Definition: support.hh:86
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:3181
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
bool clone
Whether engines create a clone when being initialized.
Definition: search.hh:749
virtual NoGoods & nogoods(void)
Return no-goods.
Definition: support.hh:106
Search worker statistics
Definition: worker.hh:44
virtual void reset(Space *s)
Reset engine to restart at space s.
Definition: support.hh:96
No-goods recorded from restarts.
Definition: core.hpp:1547
virtual Space * next(void)
Return next solution (NULL, if none exists or search has been stopped)
Definition: support.hh:81
Gecode toplevel namespace
Virtualize a worker to an engine.
Definition: support.hh:47
WorkerToEngine(Space *s, const Options &o)
Initialization.
Definition: support.hh:77
Space * snapshot(Space *s, const Options &o)
Clone space s dependening on options o.
Definition: support.hh:71
Worker w
The worker to wrap into an engine.
Definition: support.hh:50