neg-bool.hpp
Go to the documentation of this file.00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Christian Schulte <schulte@gecode.org> 00005 * 00006 * Contributing authors: 00007 * Samuel Gagnon <samuel.gagnon92@gmail.com> 00008 * 00009 * Copyright: 00010 * Christian Schulte, 2008 00011 * Samuel Gagnon, 2018 00012 * 00013 * This file is part of Gecode, the generic constraint 00014 * development environment: 00015 * http://www.gecode.org 00016 * 00017 * Permission is hereby granted, free of charge, to any person obtaining 00018 * a copy of this software and associated documentation files (the 00019 * "Software"), to deal in the Software without restriction, including 00020 * without limitation the rights to use, copy, modify, merge, publish, 00021 * distribute, sublicense, and/or sell copies of the Software, and to 00022 * permit persons to whom the Software is furnished to do so, subject to 00023 * the following conditions: 00024 * 00025 * The above copyright notice and this permission notice shall be 00026 * included in all copies or substantial portions of the Software. 00027 * 00028 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00029 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00030 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00031 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00032 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00033 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00034 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00035 * 00036 */ 00037 00038 namespace Gecode { namespace Int { 00039 00040 /* 00041 * Negated Boolean views 00042 * 00043 */ 00044 00045 /* 00046 * Constructors and initialization 00047 * 00048 */ 00049 forceinline 00050 NegBoolView::NegBoolView(void) {} 00051 forceinline 00052 NegBoolView::NegBoolView(const BoolView& y) 00053 : DerivedView<BoolView>(y) {} 00054 00055 00056 /* 00057 * Boolean domain tests 00058 * 00059 */ 00060 forceinline BoolStatus 00061 NegBoolView::status(void) const { 00062 return x.status(); 00063 } 00064 forceinline bool 00065 NegBoolView::zero(void) const { 00066 return x.one(); 00067 } 00068 forceinline bool 00069 NegBoolView::one(void) const { 00070 return x.zero(); 00071 } 00072 forceinline bool 00073 NegBoolView::none(void) const { 00074 return x.none(); 00075 } 00076 00077 00078 /* 00079 * Boolean assignment operations 00080 * 00081 */ 00082 forceinline ModEvent 00083 NegBoolView::zero_none(Space& home) { 00084 return x.one_none(home); 00085 } 00086 forceinline ModEvent 00087 NegBoolView::one_none(Space& home) { 00088 return x.zero_none(home); 00089 } 00090 00091 forceinline ModEvent 00092 NegBoolView::zero(Space& home) { 00093 return x.one(home); 00094 } 00095 forceinline ModEvent 00096 NegBoolView::one(Space& home) { 00097 return x.zero(home); 00098 } 00099 00100 00101 /* 00102 * Value access 00103 * 00104 */ 00105 forceinline int 00106 NegBoolView::min(void) const { 00107 return x.max(); 00108 } 00109 forceinline int 00110 NegBoolView::max(void) const { 00111 return x.min(); 00112 } 00113 forceinline int 00114 NegBoolView::val(void) const { 00115 return 1-x.val(); 00116 } 00117 #ifdef GECODE_HAS_CBS 00118 forceinline int 00119 NegBoolView::baseval(int val) const { 00120 return 1-val; 00121 } 00122 #endif 00123 00124 00125 /* 00126 * Delta information for advisors 00127 * 00128 */ 00129 forceinline int 00130 NegBoolView::min(const Delta& d) const { 00131 return x.max(d); 00132 } 00133 forceinline int 00134 NegBoolView::max(const Delta& d) const { 00135 return x.min(d); 00136 } 00137 forceinline unsigned int 00138 NegBoolView::width(const Delta& d) const { 00139 return x.width(d); 00140 } 00141 forceinline bool 00142 NegBoolView::any(const Delta& d) const { 00143 return x.any(d); 00144 } 00145 forceinline bool 00146 NegBoolView::zero(const Delta& d) { 00147 return BoolView::one(d); 00148 } 00149 forceinline bool 00150 NegBoolView::one(const Delta& d) { 00151 return BoolView::zero(d); 00152 } 00153 00154 /* 00155 * View comparison 00156 * 00157 */ 00158 forceinline bool 00159 operator ==(const NegBoolView& x, const NegBoolView& y) { 00160 return x.base() == y.base(); 00161 } 00162 forceinline bool 00163 operator !=(const NegBoolView& x, const NegBoolView& y) { 00164 return !(x == y); 00165 } 00166 00167 00172 template<> 00173 class ViewRanges<NegBoolView> : public Iter::Ranges::Singleton { 00174 public: 00176 00177 00178 ViewRanges(void); 00180 ViewRanges(const NegBoolView& x); 00182 void init(const NegBoolView& x); 00184 }; 00185 00186 forceinline 00187 ViewRanges<NegBoolView>::ViewRanges(void) {} 00188 00189 forceinline 00190 ViewRanges<NegBoolView>::ViewRanges(const NegBoolView& x) 00191 : Iter::Ranges::Singleton(x.min(),x.max()) {} 00192 00193 forceinline void 00194 ViewRanges<NegBoolView>::init(const NegBoolView& x) { 00195 Iter::Ranges::Singleton::init(x.min(),x.max()); 00196 } 00197 00198 }} 00199 00200 // STATISTICS: int-var