Generated on Wed Sep 3 2014 02:16:45 for Gecode by doxygen 1.8.7
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: 2013-10-30 15:42:34 +0100 (Wed, 30 Oct 2013) $ by $Author: schulte $
11  * $Revision: 14037 $
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  unsigned long int i = stop->m_stat.restart;
48  if (n != NULL) {
49  NoGoods& ng = e->nogoods();
50  ng.ng(0);
51  master->constrain(*n);
52  master->master(i,n,ng);
53  stop->m_stat.nogood += ng.ng();
54  stop->update(e->statistics());
55  if (master->status(stop->m_stat) == SS_FAILED) {
56  delete master;
57  master = NULL;
58  e->reset(NULL);
59  } else {
60  Space* slave = master;
61  master = master->clone(shared);
62  slave->slave(i,n);
63  e->reset(slave);
64  }
65  return n;
66  } else if (e->stopped() && stop->enginestopped()) {
67  NoGoods& ng = e->nogoods();
68  ng.ng(0);
69  master->master(i,NULL,ng);
70  stop->m_stat.nogood += ng.ng();
71  long unsigned int nl = (*co)();
72  stop->limit(e->statistics(),nl);
73  if (master->status(stop->m_stat) == SS_FAILED)
74  return NULL;
75  Space* slave = master;
76  master = master->clone(shared);
77  slave->slave(i,n);
78  e->reset(slave);
79  } else {
80  return NULL;
81  }
82  }
84  return NULL;
85  }
86 
88  RBS::statistics(void) const {
89  return stop->metastatistics()+e->statistics();
90  }
91 
92  bool
93  RBS::stopped(void) const {
94  /*
95  * What might happen during parallel search is that the
96  * engine has been stopped but the meta engine has not, so
97  * the meta engine does not perform a restart. However the
98  * invocation of next will do so and no restart will be
99  * missed.
100  */
101  return e->stopped();
102  }
103 
104  void
106  }
107 
108  NoGoods RBS::eng;
109 
110  NoGoods&
111  RBS::nogoods(void) {
112  return eng;
113  }
114 
115  RBS::~RBS(void) {
116  // Deleting e also deletes stop
117  delete e;
118  delete master;
119  delete co;
120  }
121 
122 }}}
123 
124 // STATISTICS: search-other
unsigned long int ng(void) const
Return number of no-goods posted.
Definition: core.hpp:2643
Search engine statistics
Definition: search.hh:136
Space * clone(bool share=true, CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:2777
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 nogood
Number of no-goods posted.
Definition: search.hh:147
Computation spaces.
Definition: core.hpp:1325
virtual void reset(Space *s)
Reset engine to restart at space s.
Definition: rbs.cpp:105
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
virtual void constrain(const Space &best)
Constrain function for best solution search.
Definition: core.cpp:644
virtual NoGoods & nogoods(void)
Return no-goods.
Definition: rbs.cpp:111
virtual void reset(Space *s)=0
Reset engine to restart at space s.
virtual NoGoods & nogoods(void)=0
Return no-goods.
virtual Space * next(void)
Return next solution (NULL, if none exists or search has been stopped)
Definition: rbs.cpp:44
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
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
Definition: core.cpp:251
virtual Search::Statistics statistics(void) const
Return statistics.
Definition: rbs.cpp:88
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.
virtual bool stopped(void) const
Check whether engine has been stopped.
Definition: rbs.cpp:93
virtual void slave(unsigned long int i, const Space *s)
Slave configuration function for restart meta search engine.
Definition: core.cpp:653
Space is failed
Definition: core.hpp:1264
virtual void master(unsigned long int i, const Space *s, NoGoods &ng)
Master configuration function for restart meta search engine.
Definition: core.cpp:648
virtual ~RBS(void)
Destructor.
Definition: rbs.cpp:115
#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
virtual bool stopped(void) const =0
Check whether engine has been stopped.