Generated on Sat Feb 7 2015 02:01:29 for Gecode by doxygen 1.8.9.1
rbs.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2012
8  *
9  * Last modified:
10  * $Date: 2014-10-22 00:54:49 +0200 (Wed, 22 Oct 2014) $ by $Author: tack $
11  * $Revision: 14262 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/search/support.hh>
40 
41 namespace Gecode {
42 
43  namespace Search {
44  GECODE_SEARCH_EXPORT Engine* rbs(Space* s,
45  MetaStop* stop,
46  Engine* e,
47  const Options& o);
48  }
49 
50  template<template<class> class E, class T>
52  RBS<E,T>::RBS(T* s, const Search::Options& m_opt) {
53  if (m_opt.cutoff == NULL)
54  throw Search::UninitializedCutoff("RBS::RBS");
55  Search::Options e_opt(m_opt);
56  e_opt.clone = false;
57  Search::MetaStop* ms = new Search::MetaStop(m_opt.stop);
58  e_opt.stop = ms;
59  Space* master;
60  Space* slave;
61  if (s->status(ms->m_stat) == SS_FAILED) {
62  ms->m_stat.fail++;
63  master = NULL;
64  slave = NULL;
65  } else {
66  if (m_opt.clone)
67  master = s->clone();
68  else
69  master = s;
70  slave = master->clone();
71  CRI cri(0,0,0,NULL,NoGoods::eng);
72  slave->slave(cri);
73  }
74  E<T> engine(dynamic_cast<T*>(slave),e_opt);
75  EngineBase* eb = &engine;
76  Search::Engine* ee = eb->e;
77  eb->e = NULL;
78  e = Search::rbs(master,ms,ee,m_opt);
79  }
80 
81  template<template<class> class E, class T>
82  forceinline T*
84  return dynamic_cast<T*>(e->next());
85  }
86 
87  template<template<class> class E, class T>
89  RBS<E,T>::statistics(void) const {
90  return e->statistics();
91  }
92 
93  template<template<class> class E, class T>
94  forceinline bool
95  RBS<E,T>::stopped(void) const {
96  return e->stopped();
97  }
98 
99 
100  template<template<class> class E, class T>
101  forceinline T*
102  rbs(T* s, const Search::Options& o) {
103  RBS<E,T> r(s,o);
104  return r.next();
105  }
106 
107 }
108 
109 // STATISTICS: search-other
bool stopped(void) const
Check whether engine has been stopped.
Definition: rbs.hpp:95
Search engine implementation interface
Definition: search.hh:445
Search engine statistics
Definition: search.hh:136
Meta-engine performing restart-based search.
Definition: search.hh:236
#define GECODE_SEARCH_EXPORT
Definition: search.hh:63
Search::Engine * e
The actual search engine.
Definition: search.hh:472
Space * clone(bool share=true, CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:2854
Search engine options
Definition: search.hh:204
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition: script.cpp:46
Search::Statistics statistics(void) const
Return statistics.
Definition: rbs.hpp:89
unsigned long int fail
Number of failed nodes in search tree.
Definition: search.hh:139
Current restart information during search.
Definition: core.hpp:1265
Computation spaces.
Definition: core.hpp:1362
Cutoff * cutoff
Cutoff for restart-based search.
Definition: search.hh:219
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Stop-object for meta engine
Definition: search.hh:349
bool clone
Whether engines create a clone when being initialized.
Definition: search.hh:207
virtual bool slave(const CRI &cri)
Slave configuration function for restart meta search engine.
Definition: core.cpp:658
T * next(void)
Return next solution (NULL, if non exists or search has been stopped)
Definition: rbs.hpp:83
Exception: Uninitialized cutoff for restart-based search
Definition: search.hh:120
#define forceinline
Definition: config.hpp:132
static NoGoods eng
Empty no-goods.
Definition: core.hpp:1258
RBS(T *s, const Search::Options &o)
Initialize engine for space s and options o.
Definition: rbs.hpp:52
Base-class for search engines.
Definition: search.hh:468
Stop * stop
Stop object for stopping search.
Definition: search.hh:217
Gecode toplevel namespace
Space is failed
Definition: core.hpp:1301
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition: rbs.hpp:102
Engine * rbs(Space *s, MetaStop *stop, Engine *e, const Options &o)
Definition: rbs.cpp:44