[gecode-users] More than one Stop object?
Christian Schulte
cschulte at kth.se
Tue Mar 10 08:14:59 CET 2009
Hi Malcolm,
Yes, that is possible: A stop object is nothing but something that inherits
from Search::Stop and implements a virtual stop member function. Building a
class that combines several other stop objects by conjunction or disjunction
is easy.
Below find something that I have taken out off the example support for
Gecode 3.0.0: it combines three stop objects if they are needed.
Cheers
Christian
/**
* \brief Stop object based on nodes, failures, and time
*
*/
class Cutoff : public Search::Stop {
private:
Search::NodeStop* ns; ///< Used node stop object
Search::FailStop* fs; ///< Used fail stop object
Search::TimeStop* ts; ///< Used time stop object
/// Initialize stop object
Cutoff(unsigned int node, unsigned int fail, unsigned int time)
: ns((node > 0) ? new Search::NodeStop(node) : NULL),
fs((fail > 0) ? new Search::FailStop(fail) : NULL),
ts((time > 0) ? new Search::TimeStop(time) : NULL) {}
public:
/// Test whether search must be stopped
virtual bool stop(const Search::Statistics& s) {
return
((ns != NULL) && ns->stop(s)) ||
((fs != NULL) && fs->stop(s)) ||
((ts != NULL) && ts->stop(s));
}
/// Create appropriate stop-object
static Search::Stop*
create(unsigned int node, unsigned int fail, unsigned int time) {
if ((node == 0) && (fail == 0) && (time == 0))
return NULL;
else
return new Cutoff(node,fail,time);
}
/// Destructor
~Cutoff(void) {
delete ns; delete fs; delete ts;
}
};
--
Christian Schulte, www.it.kth.se/~cschulte/
-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Malcolm Ryan
Sent: Tuesday, March 10, 2009 6:21 AM
To: gecode list
Subject: [gecode-users] More than one Stop object?
Can a search have multiple Stop objects, eg for time and memory limits?
Malcolm
_______________________________________________
Gecode users mailing list
users at gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users
More information about the gecode-users
mailing list