Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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 * 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
36
37namespace Gecode { namespace Search { namespace Seq {
38
39 bool
40 RestartStop::stop(const Statistics& s, const Options& o) {
41 // Stop if the fail limit for the engine says so
42 if (s.fail > l) {
43 e_stopped = true;
44 m_stat.restart++;
45 return true;
46 }
47 // Stop if the stop object for the meta engine says so
48 if ((m_stop != NULL) && m_stop->stop(m_stat+s,o)) {
49 e_stopped = false;
50 return true;
51 }
52 return false;
53 }
54
55 Space*
56 RBS::next(void) {
57 if (restart) {
58 restart = false;
59 sslr++;
60 NoGoods& ng = e->nogoods();
61 // Reset number of no-goods found
62 ng.ng(0);
63 MetaInfo mi(stop->m_stat.restart,sslr,e->statistics().fail,last,ng);
64 bool r = master->master(mi);
65 stop->m_stat.nogood += ng.ng();
66 if (master->status(stop->m_stat) == SS_FAILED) {
68 delete master;
69 master = NULL;
70 e->reset(NULL);
71 return NULL;
72 } else if (r) {
74 Space* slave = master;
75 master = master->clone();
76 complete = slave->slave(mi);
77 e->reset(slave);
78 sslr = 0;
79 stop->m_stat.restart++;
80 }
81 }
82 while (true) {
83 Space* n = e->next();
84 if (n != NULL) {
85 // The engine found a solution
86 restart = true;
87 delete last;
88 last = n->clone();
89 return n;
90 } else if ( (!complete && !e->stopped()) ||
91 (e->stopped() && stop->enginestopped()) ) {
92 // The engine must perform a true restart
93 // The number of the restart has been incremented in the stop object
94 sslr = 0;
95 NoGoods& ng = e->nogoods();
96 ng.ng(0);
97 MetaInfo mi(stop->m_stat.restart,sslr,e->statistics().fail,last,ng);
98 (void) master->master(mi);
99 stop->m_stat.nogood += ng.ng();
100 long unsigned int nl = ++(*co);
101 stop->limit(e->statistics(),nl);
102 if (master->status(stop->m_stat) == SS_FAILED)
103 return NULL;
104 Space* slave = master;
105 master = master->clone();
106 complete = slave->slave(mi);
107 e->reset(slave);
108 } else {
109 return NULL;
110 }
111 }
113 return NULL;
114 }
115
117 RBS::statistics(void) const {
118 return stop->metastatistics()+e->statistics();
119 }
120
121 void
123 if (!best)
124 throw NoBest("RBS::constrain");
125 if (last != NULL) {
126 last->constrain(b);
127 if (last->status() == SS_FAILED) {
128 delete last;
129 } else {
130 return;
131 }
132 }
133 last = b.clone();
135 e->constrain(b);
136 }
137
138 bool
139 RBS::stopped(void) const {
140 /*
141 * What might happen during parallel search is that the
142 * engine has been stopped but the meta engine has not, so
143 * the meta engine does not perform a restart. However the
144 * invocation of next will do so and no restart will be
145 * missed.
146 */
147 return e->stopped();
148 }
149
150 RBS::~RBS(void) {
151 delete e;
152 delete master;
153 delete last;
154 delete co;
155 delete stop;
156 }
157
158}}}
159
160// STATISTICS: search-seq
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int n
Number of negative literals for node type.
Information passed by meta search engines.
Definition core.hpp:1613
No-goods recorded from restarts.
Definition core.hpp:1588
unsigned long int ng(void) const
Return number of no-goods posted.
Definition core.hpp:3055
virtual void constrain(const Space &b)
Constrain future solutions to be better than b (raises exception)
Definition engine.cpp:39
virtual Statistics statistics(void) const =0
Return statistics.
virtual Space * next(void)=0
Return next solution (NULL, if none exists or search has been stopped)
virtual void reset(Space *s)
Reset engine to restart at space s (does nothing)
Definition engine.cpp:44
virtual bool stopped(void) const =0
Check whether engine has been stopped.
virtual NoGoods & nogoods(void)
Return no-goods (the no-goods are empty)
Definition engine.cpp:48
Exception: Best solution search is not supported
Definition exception.hpp:60
Search engine options
Definition search.hh:746
RestartStop * stop
The stop control object.
Definition rbs.hh:83
virtual Space * next(void)
Return next solution (NULL, if none exists or search has been stopped)
Definition rbs.cpp:56
bool best
Whether the engine performs best solution search.
Definition rbs.hh:93
Space * master
The master space to restart from.
Definition rbs.hh:77
bool restart
Whether a restart must be performed when next is called.
Definition rbs.hh:91
bool complete
Whether search for the next solution will be complete.
Definition rbs.hh:89
Engine * e
The actual engine.
Definition rbs.hh:75
virtual bool stopped(void) const
Check whether engine has been stopped.
Definition rbs.cpp:139
virtual void constrain(const Space &b)
Constrain future solutions to be better than b.
Definition rbs.cpp:122
Space * last
The last solution space (possibly NULL)
Definition rbs.hh:79
unsigned long int sslr
How many solutions since the last restart.
Definition rbs.hh:85
Cutoff * co
The cutoff object.
Definition rbs.hh:81
virtual ~RBS(void)
Destructor.
Definition rbs.cpp:150
virtual Statistics statistics(void) const
Return statistics.
Definition rbs.cpp:117
Statistics metastatistics(void) const
Return statistics for the meta engine.
Definition rbs.hpp:59
void update(const Search::Statistics &s)
Update statistics.
Definition rbs.hpp:49
virtual bool stop(const Statistics &s, const Options &o)
Return true if meta engine must be stopped.
Definition rbs.cpp:40
void limit(const Statistics &s, unsigned long int l)
Set current limit for the engine to l fails.
Definition rbs.hpp:42
bool enginestopped(void) const
Return whether the engine has been stopped.
Definition rbs.hpp:54
Search engine statistics
Definition search.hh:147
unsigned long int restart
Number of restarts.
Definition search.hh:156
unsigned long int fail
Number of failed nodes in search tree.
Definition search.hh:150
unsigned long int nogood
Number of no-goods posted.
Definition search.hh:158
virtual bool stop(const Statistics &s, const Options &o)=0
Stop search, if returns true.
Computation spaces.
Definition core.hpp:1742
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
Definition core.cpp:863
virtual void constrain(const Space &best)
Constrain function for best solution search.
Definition core.cpp:841
virtual bool master(const MetaInfo &mi)
Master configuration function for meta search engines.
Definition core.cpp:845
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
Definition core.cpp:252
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition core.hpp:3224
@ SS_FAILED
Space is failed
Definition core.hpp:1682
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:767
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56