/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * Christian Schulte * * Copyright: * Guido Tack, 2005 * Christian Schulte, 2005 * * 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. * */ #ifndef GECODE_TEST_SET_HH #define GECODE_TEST_SET_HH #include #include "test/test.hh" #include "test/int.hh" namespace Test { /// Testing finite sets namespace Set { /** * \defgroup TaskTestSet Testing finite sets * \ingroup TaskTest */ /** * \defgroup TaskTestSetSupport General set test support * \ingroup TaskTestSet */ //@{ /// Value iterator producing subsets of an IntSet class CountableSetValues { private: Gecode::IntSetValues dv; int cur; int i; public: /// Default constructor CountableSetValues(void) {} /// Initialize with set \a d0 and bit-pattern \a cur0 CountableSetValues(const Gecode::IntSet& d0, int cur0) : dv(d0), cur(cur0), i(1) { if (! (i & cur)) operator++(); } /// Initialize with set \a d0 and bit-pattern \a cur0 void init(const Gecode::IntSet& d0, int cur0) { dv = d0; cur = cur0; i = 1; if (! (i & cur)) operator++(); } /// Test if finished bool operator()(void) const { return i<=cur; } /// Move to next value void operator++(void) { do { ++dv; i = i<<1; } while (! (i & cur) && i { private: /// The corresponding value iterator CountableSetValues v; public: /// Default constructor CountableSetRanges(void) {} /// Initialize with set \a d0 and bit-pattern \a cur0 CountableSetRanges(const Gecode::IntSet& d, int cur) : v(d, cur) { Gecode::Iter::Values::ToRanges::init(v); } /// Initialize with set \a d0 and bit-pattern \a cur0 void init(const Gecode::IntSet& d, int cur) { v.init(d, cur); Gecode::Iter::Values::ToRanges::init(v); } }; /// Iterate all subsets of a given set class CountableSet { private: /// The superset Gecode::IntSet d; /// Integer representing the current subset to iterate unsigned int cur; /// Endpoint of iteration unsigned int lubmax; public: /// Initialize with set \a s CountableSet(const Gecode::IntSet& s); /// Default constructor CountableSet(void) {} /// Initialize with set \a s void init(const Gecode::IntSet& s); /// Check if still subsets left bool operator()(void) const { return cur=0) && (i