Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
set.cpp
Go to the documentation of this file.
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
41namespace Gecode {
42
44 : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home)) {}
45
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
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
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
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
Range iterator for integer sets.
Definition int.hh:292
Integer sets.
Definition int.hh:174
int min(int i) const
Return minimum of range at position i.
int max(int i) const
Return maximum of range at position i.
Exception: Variable created with empty domain
Definition exception.hpp:59
Range iterator for singleton range.
SetVar(void)
Default constructor.
Definition set.hpp:46
unsigned int lubSize(void) const
Return number of elements in the least upper bound.
Definition set.hpp:66
unsigned int glbSize(void) const
Return number of elements in the greatest lower bound.
Definition set.hpp:63
Finite integer set variable implementation.
Definition var-imp.hpp:430
Computation spaces.
Definition core.hpp:1742
Variables as interfaces to variable implementations.
Definition var.hpp:47
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
void check(int n, const char *l)
Check whether integer n is in range, otherwise throw overflow exception with information l.
Definition limits.hpp:37
Gecode toplevel namespace