this repo has no description
at develop 6.0 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Linnea Ingmar <linnea.ingmar@hotmail.com> 5 * Mikael Lagerkvist <lagerkvist@gecode.org> 6 * Christian Schulte <schulte@gecode.org> 7 * 8 * Copyright: 9 * Linnea Ingmar, 2017 10 * Mikael Lagerkvist, 2007 11 * Christian Schulte, 2017 12 * 13 * This file is part of Gecode, the generic constraint 14 * development environment: 15 * http://www.gecode.org 16 * 17 * Permission is hereby granted, free of charge, to any person obtaining 18 * a copy of this software and associated documentation files (the 19 * "Software"), to deal in the Software without restriction, including 20 * without limitation the rights to use, copy, modify, merge, publish, 21 * distribute, sublicense, and/or sell copies of the Software, and to 22 * permit persons to whom the Software is furnished to do so, subject to 23 * the following conditions: 24 * 25 * The above copyright notice and this permission notice shall be 26 * included in all copies or substantial portions of the Software. 27 * 28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 * 36 */ 37 38#include <gecode/int/extensional.hh> 39 40namespace Gecode { 41 42 void 43 extensional(Home home, const IntVarArgs& x, const TupleSet& t, bool pos, 44 IntPropLevel) { 45 using namespace Int; 46 if (!t.finalized()) 47 throw NotYetFinalized("Int::extensional"); 48 if (t.arity() != x.size()) 49 throw ArgumentSizeMismatch("Int::extensional"); 50 GECODE_POST; 51 52 ViewArray<IntView> xv(home,x); 53 if (pos) 54 GECODE_ES_FAIL((Extensional::postposcompact<IntView>(home,xv,t))); 55 else 56 GECODE_ES_FAIL((Extensional::postnegcompact<IntView>(home,xv,t))); 57 } 58 59 void 60 extensional(Home home, const IntVarArgs& x, const TupleSet& t, bool pos, 61 Reify r, 62 IntPropLevel) { 63 using namespace Int; 64 if (!t.finalized()) 65 throw NotYetFinalized("Int::extensional"); 66 if (t.arity() != x.size()) 67 throw ArgumentSizeMismatch("Int::extensional"); 68 GECODE_POST; 69 70 ViewArray<IntView> xv(home,x); 71 if (pos) { 72 switch (r.mode()) { 73 case RM_EQV: 74 GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_EQV> 75 (home,xv,t,r.var()))); 76 break; 77 case RM_IMP: 78 GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_IMP> 79 (home,xv,t,r.var()))); 80 break; 81 case RM_PMI: 82 GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_PMI> 83 (home,xv,t,r.var()))); 84 break; 85 default: throw UnknownReifyMode("Int::extensional"); 86 } 87 } else { 88 NegBoolView n(r.var()); 89 switch (r.mode()) { 90 case RM_EQV: 91 GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_EQV> 92 (home,xv,t,n))); 93 break; 94 case RM_IMP: 95 GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_PMI> 96 (home,xv,t,n))); 97 break; 98 case RM_PMI: 99 GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_IMP> 100 (home,xv,t,n))); 101 break; 102 default: throw UnknownReifyMode("Int::extensional"); 103 } 104 } 105 } 106 107 void 108 extensional(Home home, const BoolVarArgs& x, const TupleSet& t, bool pos, 109 IntPropLevel) { 110 using namespace Int; 111 if (!t.finalized()) 112 throw NotYetFinalized("Int::extensional"); 113 if (t.arity() != x.size()) 114 throw ArgumentSizeMismatch("Int::extensional"); 115 if ((t.min() < 0) || (t.max() > 1)) 116 throw NotZeroOne("Int::extensional"); 117 GECODE_POST; 118 119 ViewArray<BoolView> xv(home,x); 120 if (pos) 121 GECODE_ES_FAIL((Extensional::postposcompact<BoolView>(home,xv,t))); 122 else 123 GECODE_ES_FAIL((Extensional::postnegcompact<BoolView>(home,xv,t))); 124 } 125 126 void 127 extensional(Home home, const BoolVarArgs& x, const TupleSet& t, bool pos, 128 Reify r, 129 IntPropLevel) { 130 using namespace Int; 131 if (!t.finalized()) 132 throw NotYetFinalized("Int::extensional"); 133 if (t.arity() != x.size()) 134 throw ArgumentSizeMismatch("Int::extensional"); 135 if ((t.min() < 0) || (t.max() > 1)) 136 throw NotZeroOne("Int::extensional"); 137 GECODE_POST; 138 139 ViewArray<BoolView> xv(home,x); 140 if (pos) { 141 switch (r.mode()) { 142 case RM_EQV: 143 GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_EQV> 144 (home,xv,t,r.var()))); 145 break; 146 case RM_IMP: 147 GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_IMP> 148 (home,xv,t,r.var()))); 149 break; 150 case RM_PMI: 151 GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_PMI> 152 (home,xv,t,r.var()))); 153 break; 154 default: throw UnknownReifyMode("Int::extensional"); 155 } 156 } else { 157 NegBoolView n(r.var()); 158 switch (r.mode()) { 159 case RM_EQV: 160 GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_EQV> 161 (home,xv,t,n))); 162 break; 163 case RM_IMP: 164 GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_PMI> 165 (home,xv,t,n))); 166 break; 167 case RM_PMI: 168 GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_IMP> 169 (home,xv,t,n))); 170 break; 171 default: throw UnknownReifyMode("Int::extensional"); 172 } 173 } 174 } 175 176} 177 178// STATISTICS: int-post