Generated on Sat Feb 7 2015 02:01:30 for Gecode by doxygen 1.8.9.1
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  * Last modified:
14  * $Date: 2010-08-31 16:19:34 +0200 (Tue, 31 Aug 2010) $ by $Author: schulte $
15  * $Revision: 11366 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 
43 #include <gecode/set.hh>
44 
45 namespace Gecode {
46 
48  : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home)) {}
49 
50  SetVar::SetVar(Space& home,int lbMin,int lbMax,int ubMin,int ubMax,
51  unsigned int minCard, unsigned int maxCard)
52  : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home,lbMin,lbMax,
53  ubMin,ubMax,
54  minCard,maxCard)) {
55  Set::Limits::check(lbMin,"SetVar::SetVar");
56  Set::Limits::check(lbMax,"SetVar::SetVar");
57  Set::Limits::check(ubMin,"SetVar::SetVar");
58  Set::Limits::check(ubMax,"SetVar::SetVar");
59  Set::Limits::check(maxCard,"SetVar::SetVar");
60  if (minCard > maxCard || minCard > lubSize() || maxCard < glbSize() ||
61  lbMin < ubMin || lbMax > ubMax)
62  throw Set::VariableEmptyDomain("SetVar::SetVar");
63  }
64 
65  SetVar::SetVar(Space& home, const IntSet& glb,int ubMin,int ubMax,
66  unsigned int minCard, unsigned int maxCard)
67  : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home,glb,ubMin,ubMax,
68  minCard,maxCard)) {
69  Set::Limits::check(glb,"SetVar::SetVar");
70  Set::Limits::check(ubMin,"SetVar::SetVar");
71  Set::Limits::check(ubMax,"SetVar::SetVar");
72  Set::Limits::check(maxCard,"SetVar::SetVar");
73  if (minCard > maxCard || minCard > lubSize() || maxCard < glbSize() ||
74  glb.min() < ubMin || glb.max() > ubMax)
75  throw Set::VariableEmptyDomain("SetVar::SetVar");
76  }
77 
78  SetVar::SetVar(Space& home,int lbMin,int lbMax,const IntSet& lub,
79  unsigned int minCard, unsigned int maxCard)
80  : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home,lbMin,lbMax,lub,
81  minCard,maxCard)) {
82  Set::Limits::check(lbMin,"SetVar::SetVar");
83  Set::Limits::check(lbMax,"SetVar::SetVar");
84  Set::Limits::check(lub,"SetVar::SetVar");
85  Set::Limits::check(maxCard,"SetVar::SetVar");
86  Iter::Ranges::Singleton glbr(lbMin,lbMax);
87  IntSetRanges lubr(lub);
88  if (minCard > maxCard || minCard > lubSize() || maxCard < glbSize() ||
89  !Iter::Ranges::subset(glbr,lubr))
90  throw Set::VariableEmptyDomain("SetVar::SetVar");
91  }
92 
94  const IntSet& glb, const IntSet& lub,
95  unsigned int minCard, unsigned int maxCard)
96  : VarImpVar<Set::SetVarImp>(new (home) Set::SetVarImp(home,glb,lub,minCard,
97  maxCard)) {
98  Set::Limits::check(glb,"SetVar::SetVar");
99  Set::Limits::check(lub,"SetVar::SetVar");
100  Set::Limits::check(maxCard,"SetVar::SetVar");
101  IntSetRanges glbr(glb);
102  IntSetRanges lubr(lub);
103  if (minCard > maxCard || minCard > lubSize() || maxCard < glbSize() ||
104  !Iter::Ranges::subset(glbr,lubr))
105  throw Set::VariableEmptyDomain("SetVar::SetVar");
106  }
107 
108 }
109 
110 // STATISTICS: set-var
111 
Variables as interfaces to variable implementations.
Definition: var.hpp:51
void check(int n, const char *l)
Check whether integer n is in range, otherwise throw overflow exception with information l...
Definition: limits.hpp:41
Range iterator for singleton range.
Range iterator for integer sets.
Definition: int.hh:271
unsigned int lubSize(void) const
Return number of elements in the least upper bound.
Definition: set.hpp:70
Finite integer set variable implementation.
Definition: var-imp.hpp:434
Computation spaces.
Definition: core.hpp:1362
unsigned int glbSize(void) const
Return number of elements in the greatest lower bound.
Definition: set.hpp:67
Exception: Variable created with empty domain
Definition: exception.hpp:63
Integer sets.
Definition: int.hh:171
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Gecode toplevel namespace
SetVar(void)
Default constructor.
Definition: set.hpp:50
int max(int i) const
Return maximum of range at position i.
Definition: int-set-1.hpp:121
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:115