/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2015 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include namespace Gecode { namespace Search { namespace Seq { forceinline PortfolioStop::PortfolioStop(Stop* so0) : so(so0) {} forceinline void PortfolioStop::share(SharedStopInfo* ssi0) { ssi = ssi0; } forceinline Slave::Slave(void) : slave(nullptr), stop(nullptr) {} forceinline void Slave::init(Engine* e, Stop* s) { slave = e; stop = s; } forceinline Space* Slave::next(void) { return slave->next(); } forceinline Statistics Slave::statistics(void) const { return slave->statistics(); } forceinline bool Slave::stopped(void) const { return slave->stopped(); } forceinline void Slave::constrain(const Space& b) { slave->constrain(b); } forceinline Slave::~Slave(void) { delete slave; delete stop; } template forceinline PBS::PBS(Engine** e, Stop** s, unsigned int n, const Statistics& stat0, const Search::Options& opt) : stat(stat0), slice(opt.slice), slaves(heap.alloc(n)), n_slaves(n), cur(0), slave_stop(false) { ssi.done = false; ssi.l = opt.slice; for (unsigned int i=0U; i(s[i])); static_cast(s[i])->share(&ssi); } } template Space* PBS::next(void) { slave_stop = false; unsigned int n_exhausted = 0; while (n_slaves > 0) { if (Space* s = slaves[cur].next()) { // Constrain other slaves if (best) { for (unsigned int i=0U; i bool PBS::stopped(void) const { return slave_stop; } template Statistics PBS::statistics(void) const { Statistics s(stat); for (unsigned int i=0U; i void PBS::constrain(const Space& b) { if (!best) throw NoBest("PBS::constrain"); for (unsigned int i=0U; i PBS::~PBS(void) { for (unsigned int i=0U; i