Generated on Sat Feb 7 2015 02:01:29 for Gecode by doxygen 1.8.9.1
rbs.cpp
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: 2015-01-05 07:32:41 +0100 (Mon, 05 Jan 2015) $ by $Author: tack $
11  * $Revision: 14336 $
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 
40 
41 namespace Gecode { namespace Search { namespace Meta {
42 
43  Space*
44  RBS::next(void) {
45  while (true) {
46  Space* n = e->next();
47  // The number of the restart has been incremented in the stop object
48  unsigned long int i = stop->m_stat.restart;
49  if (n != NULL) {
50  sslr++;
51  // The engine found a solution
52  NoGoods& ng = e->nogoods();
53  // Reset number of no-goods found
54  ng.ng(0);
55  CRI cri(i,sslr,e->statistics().fail,n,ng);
56  bool restart = master->master(cri);
57  stop->m_stat.nogood += ng.ng();
58  if (master->status(stop->m_stat) == SS_FAILED) {
59  stop->update(e->statistics());
60  delete master;
61  master = NULL;
62  e->reset(NULL);
63  } else if (restart) {
64  stop->update(e->statistics());
65  Space* slave = master;
67  complete = slave->slave(cri);
68  e->reset(slave);
69  sslr = 0;
70  stop->m_stat.restart++;
71  }
72  delete last;
73  last = n->clone();
74  return n;
75  } else if ( (!complete && !e->stopped()) ||
76  (e->stopped() && stop->enginestopped()) ) {
77  // The engine must perform a true restart
78  sslr = 0;
79  NoGoods& ng = e->nogoods();
80  ng.ng(0);
81  CRI cri(i,sslr,e->statistics().fail,last,ng);
82  (void) master->master(cri);
83  stop->m_stat.nogood += ng.ng();
84  long unsigned int nl = ++(*co);
85  stop->limit(e->statistics(),nl);
86  if (master->status(stop->m_stat) == SS_FAILED)
87  return NULL;
88  Space* slave = master;
90  complete = slave->slave(cri);
91  e->reset(slave);
92  } else {
93  return NULL;
94  }
95  }
97  return NULL;
98  }
99 
101  RBS::statistics(void) const {
102  return stop->metastatistics()+e->statistics();
103  }
104 
105  bool
106  RBS::stopped(void) const {
107  /*
108  * What might happen during parallel search is that the
109  * engine has been stopped but the meta engine has not, so
110  * the meta engine does not perform a restart. However the
111  * invocation of next will do so and no restart will be
112  * missed.
113  */
114  return e->stopped();
115  }
116 
117  void
119  }
120 
121  NoGoods&
122  RBS::nogoods(void) {
123  return NoGoods::eng;
124  }
125 
126  RBS::~RBS(void) {
127  // Deleting e also deletes stop
128  delete e;
129  delete master;
130  delete last;
131  delete co;
132  }
133 
134 }}}
135 
136 // STATISTICS: search-other
unsigned long int ng(void) const
Return number of no-goods posted.
Definition: core.hpp:2686
Search engine statistics
Definition: search.hh:136
Cutoff * co
The cutoff object.
Definition: rbs.hh:56
virtual bool master(const CRI &cri)
Master configuration function for restart meta search engine.
Definition: core.cpp:649
Space * clone(bool share=true, CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:2854
void limit(const Search::Statistics &s, unsigned long int l)
Set current limit for the engine to l fails.
Definition: stop.hpp:135
unsigned long int fail
Number of failed nodes in search tree.
Definition: search.hh:139
unsigned long int nogood
Number of no-goods posted.
Definition: search.hh:147
Current restart information during search.
Definition: core.hpp:1265
Computation spaces.
Definition: core.hpp:1362
virtual void reset(Space *s)
Reset engine to restart at space s.
Definition: rbs.cpp:118
unsigned long int sslr
How many solutions since the last restart.
Definition: rbs.hh:62
MetaStop * stop
The stop control object.
Definition: rbs.hh:58
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
virtual NoGoods & nogoods(void)
Return no-goods.
Definition: rbs.cpp:122
virtual void reset(Space *s)=0
Reset engine to restart at space s.
virtual NoGoods & nogoods(void)=0
Return no-goods.
virtual bool slave(const CRI &cri)
Slave configuration function for restart meta search engine.
Definition: core.cpp:658
virtual Space * next(void)
Return next solution (NULL, if none exists or search has been stopped)
Definition: rbs.cpp:44
Space * last
The last solution space (possibly NULL)
Definition: rbs.hh:54
No-goods recorded from restarts.
Definition: core.hpp:1240
virtual Space * next(void)=0
Return next solution (NULL, if none exists or search has been stopped)
void update(const Search::Statistics &s)
Update statistics.
Definition: stop.hpp:142
Space * master
The master space to restart from.
Definition: rbs.hh:52
Engine * e
The actual engine.
Definition: rbs.hh:50
static NoGoods eng
Empty no-goods.
Definition: core.hpp:1258
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
Definition: core.cpp:252
virtual Search::Statistics statistics(void) const
Return statistics.
Definition: rbs.cpp:101
Statistics metastatistics(void) const
Return statistics for the meta engine.
Definition: stop.hpp:157
unsigned long int restart
Number of restarts.
Definition: search.hh:145
virtual Statistics statistics(void) const =0
Return statistics.
Gecode toplevel namespace
virtual bool stopped(void) const
Check whether engine has been stopped.
Definition: rbs.cpp:106
Space is failed
Definition: core.hpp:1301
virtual ~RBS(void)
Destructor.
Definition: rbs.cpp:126
bool complete
Whether search for the next solution will be complete.
Definition: rbs.hh:64
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
bool enginestopped(void) const
Return whether the engine has been stopped.
Definition: stop.hpp:152
bool shared
Whether the slave can be shared with the master.
Definition: rbs.hh:60
virtual bool stopped(void) const =0
Check whether engine has been stopped.