this repo has no description
at develop 4.2 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2008 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#ifndef GECODE_INT_SUPPORT_VALUES_HH 35#define GECODE_INT_SUPPORT_VALUES_HH 36 37#include <gecode/int.hh> 38 39namespace Gecode { namespace Int { 40 41 /** 42 * \brief %Support value iterator and recorder 43 * 44 * Requires \code #include <gecode/int/support-values.hh> \endcode 45 * \ingroup FuncIntProp 46 */ 47 template<class View, class A> 48 class SupportValues { 49 private: 50 /// Memory allocator 51 A& a; 52 /// Range and position information 53 class RangePos { 54 public: 55 int min; ///< Minimum of range 56 unsigned int pos; ///< Starting position of range 57 }; 58 /// Value iterator for unsupported values 59 class Unsupported { 60 private: 61 /// Current range 62 RangePos* rp; 63 /// Current position 64 unsigned int p; 65 /// Access to other information 66 SupportValues& sv; 67 /// Find next unsupported value 68 void find(void); 69 public: 70 /// \name Constructors and initialization 71 //@{ 72 /// Initialize with values from \a sv 73 Unsupported(SupportValues& sv0); 74 //@} 75 76 /// \name Iteration control 77 //@{ 78 /// Test whether iterator is still at a value or done 79 bool operator ()(void) const; 80 /// Move iterator to next value (if possible) 81 void operator ++(void); 82 //@} 83 84 /// \name Value access 85 //@{ 86 /// Return current value 87 int val(void) const; 88 //@} 89 }; 90 91 /// The view 92 View x; 93 /// Bit set 94 Gecode::Support::BitSetBase bs; 95 /// Start of range and position information 96 RangePos* rp_fst; 97 /// End of range and position information 98 RangePos* rp_lst; 99 /// Current range 100 RangePos* rp; 101 /// Current value 102 int v; 103 /// Current maximum of range 104 int max; 105 106 /// Mark \a n as supported and return whether value can be supported 107 bool _support(int n); 108 public: 109 /// Initialize for view \a x 110 SupportValues(A& a, View x); 111 /// Destructor 112 ~SupportValues(void); 113 114 /// \name Iteration control 115 //@{ 116 /// Reset iterator 117 void reset(void); 118 /// Test whether iterator is still at a value or done 119 bool operator ()(void) const; 120 /// Move iterator to next value (if possible) 121 void operator ++(void); 122 //@} 123 124 /// \name Value access 125 //@{ 126 /// Return current value 127 int val(void) const; 128 //@} 129 130 /// \name Support control 131 //@{ 132 /// Mark current (iterator) value as supported 133 void support(void); 134 /// Mark \a n as supported if possible 135 bool support(int n); 136 /// Mark \a n as supported if possible 137 bool support(long long int n); 138 /// Remove all unsupported values 139 ModEvent tell(Space& home); 140 //@} 141 }; 142 143}} 144 145#include <gecode/int/support-values.hpp> 146 147#endif 148 149// STATISTICS: int-prop 150