this repo has no description
at develop 2.6 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Gabor Szokoli <szokoli@gecode.org> 5 * Guido Tack <tack@gecode.org> 6 * Christian Schulte <schulte@gecode.org> 7 * 8 * Copyright: 9 * Gabor Szokoli, 2004 10 * Guido Tack, 2004 11 * Christian Schulte, 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#include <gecode/set.hh> 39#include <gecode/set/int.hh> 40 41namespace Gecode { 42 43 void 44 cardinality(Home home, SetVar x, unsigned int i, unsigned int j) { 45 Set::Limits::check(i, "Set::cardinality"); 46 Set::Limits::check(j, "Set::cardinality"); 47 GECODE_POST; 48 Set::SetView _x(x); 49 GECODE_ME_FAIL(_x.cardMin(home, i)); 50 GECODE_ME_FAIL(_x.cardMax(home, j)); 51 } 52 53 void 54 cardinality(Home home, const SetVarArgs& x, unsigned int i, unsigned int j) { 55 Set::Limits::check(i, "Set::cardinality"); 56 Set::Limits::check(j, "Set::cardinality"); 57 GECODE_POST; 58 for (int k=x.size(); k--; ) { 59 Set::SetView _x(x[k]); 60 GECODE_ME_FAIL(_x.cardMin(home, i)); 61 GECODE_ME_FAIL(_x.cardMax(home, j)); 62 } 63 } 64 65 void 66 cardinality(Home home, SetVar s, IntVar x) { 67 GECODE_POST; 68 GECODE_ES_FAIL(Set::Int::Card<Set::SetView>::post(home,s, x)); 69 } 70 71 void 72 cardinality(Home home, SetVar s, IntVar x, Reify r) { 73 IntVar y(home, 0, static_cast<int>(Set::Limits::card)); 74 rel(home, x, IRT_EQ, y, r); 75 cardinality(home, s, y); 76 } 77 78} 79 80// STATISTICS: set-post