Generated on for Gecode by doxygen 1.17.0
pbs.hh
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2015
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
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#ifndef GECODE_SEARCH_SEQ_PBS_HH
35#define GECODE_SEARCH_SEQ_PBS_HH
36
37#include <gecode/search.hh>
38
39namespace Gecode { namespace Search { namespace Seq {
40
43 public:
45 bool done;
47 unsigned long long int l;
48 };
49
52 private:
54 Stop* so;
56 Stop* po;
58 SharedStopInfo* ssi;
59 public:
61 PortfolioStop(Stop* so, Stop* po=nullptr);
63 void share(SharedStopInfo* ssi);
65 virtual bool stop(const Statistics& s, const Options& o);
66 };
67
69 class Slave {
70 protected:
75 public:
77 Slave(void);
79 Slave(const Slave& s) = default;
81 Slave& operator =(const Slave& s) = default;
83 void init(Engine* s, Stop* so);
85 Space* next(void);
87 Statistics statistics(void) const;
89 bool stopped(void) const;
91 bool limited(void) const;
93 void constrain(const Space& b);
95 void run(void);
97 ~Slave(void);
98 };
99
101 template<bool best>
103 protected:
109 unsigned int slice;
113 unsigned int n_slaves;
115 unsigned int cur;
120 public:
122 PBS(Engine** slaves, Stop** stops, unsigned int n,
123 const Statistics& stat, const Search::Options& opt);
125 virtual Space* next(void);
127 virtual Statistics statistics(void) const;
129 virtual bool stopped(void) const;
131 virtual void constrain(const Space& b);
133 virtual ~PBS(void);
134 };
135
136}}}
137
139
140#endif
141
142// STATISTICS: search-seq
Search engine implementation interface
Definition search.hh:1063
Engine(void)
Construct a meta engine without worker control.
Definition engine.cpp:39
Search engine options
Definition search.hh:848
Slave * slaves
Slaves.
Definition pbs.hh:111
bool incomplete
Whether a slave stopped at a local limit.
Definition pbs.hh:119
SharedStopInfo ssi
Shared slave information.
Definition pbs.hh:107
unsigned int n_slaves
Number of slave engines.
Definition pbs.hh:113
bool slave_stop
Whether a slave has been stopped.
Definition pbs.hh:117
unsigned int slice
Size of a slice.
Definition pbs.hh:109
virtual Space * next(void)
Return next solution (nullptr, if none exists or search has been stopped).
Definition pbs.hpp:105
Statistics stat
Master statistics.
Definition pbs.hh:105
virtual bool stopped(void) const
Check whether engine has been stopped.
Definition pbs.hpp:153
virtual Statistics statistics(void) const
Return statistics.
Definition pbs.hpp:159
unsigned int cur
Current slave to run.
Definition pbs.hh:115
virtual void constrain(const Space &b)
Constrain future solutions to be better than b.
Definition pbs.hpp:168
PBS(Engine **slaves, Stop **stops, unsigned int n, const Statistics &stat, const Search::Options &opt)
Initialize.
Definition pbs.hpp:88
virtual bool stop(const Statistics &s, const Options &o)
Return true if portfolio engine must be stopped.
Definition pbs.cpp:39
void share(SharedStopInfo *ssi)
Initialize shared stop information.
Definition pbs.hpp:43
PortfolioStop(Stop *so, Stop *po=nullptr)
Initialize with slave stop so and portfolio stop po.
Definition pbs.hpp:40
Shared stop information.
Definition pbs.hh:42
unsigned long long int l
The current failure limit, incremented for each slice.
Definition pbs.hh:47
bool done
Whether search stopped because the slice is done.
Definition pbs.hh:45
Runnable slave of a portfolio master.
Definition pbs.hh:69
bool stopped(void) const
Check whether slave has been stopped.
Definition pbs.hpp:64
Space * next(void)
Return next solution.
Definition pbs.hpp:56
Slave & operator=(const Slave &s)=default
Assignment operator.
Engine * slave
The slave engine.
Definition pbs.hh:72
Slave(void)
Default constructor.
Definition pbs.hpp:49
void constrain(const Space &b)
Constrain with better solution b.
Definition pbs.hpp:76
Stop * stop
Stop object.
Definition pbs.hh:74
bool limited(void) const
Check whether slave stopped at a local limit.
Definition pbs.hpp:68
void init(Engine *s, Stop *so)
Initialize with slave s and its stop object so.
Definition pbs.hpp:52
Statistics statistics(void) const
Return statistics of slave.
Definition pbs.hpp:60
Slave(const Slave &s)=default
Copy constructor.
~Slave(void)
Delete slave.
Definition pbs.hpp:80
void run(void)
Perform one run.
Search engine statistics
Definition search.hh:155
Base-class for Stop-object.
Definition search.hh:919
Stop(void)
Default constructor.
Definition stop.hpp:45
Computation spaces.
Definition core.hpp:1787
Search engines
Gecode toplevel namespace
#define GECODE_SEARCH_EXPORT
Definition search.hh:75