Generated on Sat Nov 9 2013 19:18:31 for Gecode by doxygen 1.8.4
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