1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 /* 3 * Main authors: 4 * Guido Tack <tack@gecode.org> 5 * Christian Schulte <schulte@gecode.org> 6 * Gabor Szokoli <szokoli@gecode.org> 7 * 8 * Copyright: 9 * Guido Tack, 2004 10 * Christian Schulte, 2004 11 * Gabor Szokoli, 2004 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 39 #include <gecode/set.hh> 40 41 namespace Gecode { 42 SetVar(Space & home)43 SetVar::SetVar(Space& home) 44 : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home)) {} 45 SetVar(Space & home,int lbMin,int lbMax,int ubMin,int ubMax,unsigned int minCard,unsigned int maxCard)46 SetVar::SetVar(Space& home,int lbMin,int lbMax,int ubMin,int ubMax, 47 unsigned int minCard, unsigned int maxCard) 48 : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home,lbMin,lbMax, 49 ubMin,ubMax, 50 minCard,maxCard)) { 51 Set::Limits::check(lbMin,"SetVar::SetVar"); 52 Set::Limits::check(lbMax,"SetVar::SetVar"); 53 Set::Limits::check(ubMin,"SetVar::SetVar"); 54 Set::Limits::check(ubMax,"SetVar::SetVar"); 55 Set::Limits::check(maxCard,"SetVar::SetVar"); 56 if (minCard > maxCard || minCard > lubSize() || maxCard < glbSize() || 57 lbMin < ubMin || lbMax > ubMax) 58 throw Set::VariableEmptyDomain("SetVar::SetVar"); 59 } 60 SetVar(Space & home,const IntSet & glb,int ubMin,int ubMax,unsigned int minCard,unsigned int maxCard)61 SetVar::SetVar(Space& home, const IntSet& glb,int ubMin,int ubMax, 62 unsigned int minCard, unsigned int maxCard) 63 : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home,glb,ubMin,ubMax, 64 minCard,maxCard)) { 65 Set::Limits::check(glb,"SetVar::SetVar"); 66 Set::Limits::check(ubMin,"SetVar::SetVar"); 67 Set::Limits::check(ubMax,"SetVar::SetVar"); 68 Set::Limits::check(maxCard,"SetVar::SetVar"); 69 if (minCard > maxCard || minCard > lubSize() || maxCard < glbSize() || 70 glb.min() < ubMin || glb.max() > ubMax) 71 throw Set::VariableEmptyDomain("SetVar::SetVar"); 72 } 73 SetVar(Space & home,int lbMin,int lbMax,const IntSet & lub,unsigned int minCard,unsigned int maxCard)74 SetVar::SetVar(Space& home,int lbMin,int lbMax,const IntSet& lub, 75 unsigned int minCard, unsigned int maxCard) 76 : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home,lbMin,lbMax,lub, 77 minCard,maxCard)) { 78 Set::Limits::check(lbMin,"SetVar::SetVar"); 79 Set::Limits::check(lbMax,"SetVar::SetVar"); 80 Set::Limits::check(lub,"SetVar::SetVar"); 81 Set::Limits::check(maxCard,"SetVar::SetVar"); 82 Iter::Ranges::Singleton glbr(lbMin,lbMax); 83 IntSetRanges lubr(lub); 84 if (minCard > maxCard || minCard > lubSize() || maxCard < glbSize() || 85 !Iter::Ranges::subset(glbr,lubr)) 86 throw Set::VariableEmptyDomain("SetVar::SetVar"); 87 } 88 SetVar(Space & home,const IntSet & glb,const IntSet & lub,unsigned int minCard,unsigned int maxCard)89 SetVar::SetVar(Space& home, 90 const IntSet& glb, const IntSet& lub, 91 unsigned int minCard, unsigned int maxCard) 92 : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home,glb,lub,minCard, 93 maxCard)) { 94 Set::Limits::check(glb,"SetVar::SetVar"); 95 Set::Limits::check(lub,"SetVar::SetVar"); 96 Set::Limits::check(maxCard,"SetVar::SetVar"); 97 IntSetRanges glbr(glb); 98 IntSetRanges lubr(lub); 99 if (minCard > maxCard || minCard > lubSize() || maxCard < glbSize() || 100 !Iter::Ranges::subset(glbr,lubr)) 101 throw Set::VariableEmptyDomain("SetVar::SetVar"); 102 } 103 104 } 105 106 // STATISTICS: set-var 107 108