Generated on Fri Oct 19 11:24:52 2018 for Gecode by doxygen 1.6.3

array.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *     Gabor Szokoli <szokoli@gecode.org>
00007  *
00008  *  Copyright:
00009  *     Guido Tack, 2004
00010  *     Christian Schulte, 2004
00011  *     Gabor Szokoli, 2004
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 
00039 
00040 #include <gecode/set.hh>
00041 
00042 namespace Gecode {
00043 
00044   SetVarArray::SetVarArray(Space& home, int n)
00045     : VarArray<SetVar>(home,n) {
00046     for (int i = size(); i--; )
00047       x[i] = SetVar(home);
00048   }
00049 
00050   SetVarArray::SetVarArray(Space& home,int n,
00051                            int lbMin,int lbMax,int ubMin,int ubMax,
00052                            unsigned int minCard,
00053                            unsigned int maxCard)
00054     : VarArray<SetVar>(home,n) {
00055     Set::Limits::check(lbMin,"SetVarArray::SetVarArray");
00056     Set::Limits::check(lbMax,"SetVarArray::SetVarArray");
00057     Set::Limits::check(ubMin,"SetVarArray::SetVarArray");
00058     Set::Limits::check(ubMax,"SetVarArray::SetVarArray");
00059     Set::Limits::check(maxCard,"SetVarArray::SetVarArray");
00060     unsigned int glbSize =
00061       (lbMin <= lbMax ? static_cast<unsigned int>(lbMax-lbMin+1) : 0U);
00062     unsigned int lubSize =
00063       (ubMin <= ubMax ? static_cast<unsigned int>(ubMax-ubMin+1) : 0U);
00064     if (minCard > maxCard || minCard > lubSize || maxCard < glbSize ||
00065         lbMin < ubMin || lbMax > ubMax)
00066       throw Set::VariableEmptyDomain("SetVarArray::SetVarArray");
00067     for (int i = size(); i--; )
00068       x[i] = SetVar(home,lbMin,lbMax,ubMin,ubMax,minCard,maxCard);
00069   }
00070 
00071   SetVarArray::SetVarArray(Space& home,int n,
00072                            const IntSet& glb,int ubMin,int ubMax,
00073                            unsigned int minCard,unsigned int maxCard)
00074     : VarArray<SetVar>(home,n) {
00075     Set::Limits::check(glb,"SetVarArray::SetVarArray");
00076     Set::Limits::check(ubMin,"SetVarArray::SetVarArray");
00077     Set::Limits::check(ubMax,"SetVarArray::SetVarArray");
00078     Set::Limits::check(maxCard,"SetVarArray::SetVarArray");
00079     IntSetRanges glbr(glb);
00080     unsigned int glbSize = Iter::Ranges::size(glbr);
00081     unsigned int lubSize =
00082       (ubMin <= ubMax ? static_cast<unsigned int>(ubMax-ubMin+1) : 0U);
00083     if (minCard > maxCard || minCard > lubSize || maxCard < glbSize ||
00084         glb.min() < ubMin || glb.max() > ubMax)
00085       throw Set::VariableEmptyDomain("SetVarArray::SetVarArray");
00086     for (int i = size(); i--; )
00087       x[i] = SetVar(home,glb,ubMin,ubMax,minCard,maxCard);
00088   }
00089 
00090   SetVarArray::SetVarArray(Space& home,int n,
00091                            int lbMin,int lbMax,const IntSet& lub,
00092                            unsigned int minCard,unsigned int maxCard)
00093     : VarArray<SetVar>(home,n) {
00094     Set::Limits::check(lbMin,"SetVarArray::SetVarArray");
00095     Set::Limits::check(lbMax,"SetVarArray::SetVarArray");
00096     Set::Limits::check(lub,"SetVarArray::SetVarArray");
00097     Set::Limits::check(maxCard,"SetVarArray::SetVarArray");
00098     Iter::Ranges::Singleton glbr(lbMin,lbMax);
00099     IntSetRanges lubr(lub);
00100     IntSetRanges lubr_s(lub);
00101     unsigned int glbSize =
00102       (lbMin <= lbMax ? static_cast<unsigned int>(lbMax-lbMin+1) : 0U);
00103     unsigned int lubSize = Iter::Ranges::size(lubr_s);
00104     if (minCard > maxCard || minCard > lubSize || maxCard < glbSize ||
00105         !Iter::Ranges::subset(glbr,lubr))
00106       throw Set::VariableEmptyDomain("SetVarArray::SetVarArray");
00107     for (int i = size(); i--; )
00108       x[i] = SetVar(home,lbMin,lbMax,lub,minCard,maxCard);
00109   }
00110 
00111   SetVarArray::SetVarArray(Space& home,int n,
00112                            const IntSet& glb, const IntSet& lub,
00113                            unsigned int minCard, unsigned int maxCard)
00114     : VarArray<SetVar>(home,n) {
00115     Set::Limits::check(glb,"SetVarArray::SetVarArray");
00116     Set::Limits::check(lub,"SetVarArray::SetVarArray");
00117     Set::Limits::check(maxCard,"SetVarArray::SetVarArray");
00118     IntSetRanges glbr(glb);
00119     IntSetRanges glbr_s(glb);
00120     unsigned int glbSize = Iter::Ranges::size(glbr_s);
00121     IntSetRanges lubr(lub);
00122     IntSetRanges lubr_s(lub);
00123     unsigned int lubSize = Iter::Ranges::size(lubr_s);
00124     if (minCard > maxCard || minCard > lubSize || maxCard < glbSize ||
00125         !Iter::Ranges::subset(glbr,lubr))
00126       throw Set::VariableEmptyDomain("SetVar");
00127     for (int i = size(); i--; )
00128       x[i] = SetVar(home,glb,lub,minCard,maxCard);
00129   }
00130 
00131   SetVarArgs::SetVarArgs(Space& home,int n,
00132                          int lbMin,int lbMax,int ubMin,int ubMax,
00133                          unsigned int minCard,
00134                          unsigned int maxCard)
00135     : VarArgArray<SetVar>(n) {
00136     Set::Limits::check(lbMin,"SetVarArgs::SetVarArgs");
00137     Set::Limits::check(lbMax,"SetVarArgs::SetVarArgs");
00138     Set::Limits::check(ubMin,"SetVarArgs::SetVarArgs");
00139     Set::Limits::check(ubMax,"SetVarArgs::SetVarArgs");
00140     Set::Limits::check(maxCard,"SetVarArgs::SetVarArgs");
00141     unsigned int glbSize =
00142       (lbMin <= lbMax ? static_cast<unsigned int>(lbMax-lbMin+1) : 0U);
00143     unsigned int lubSize =
00144       (ubMin <= ubMax ? static_cast<unsigned int>(ubMax-ubMin+1) : 0U);
00145     if (minCard > maxCard || minCard > lubSize || maxCard < glbSize ||
00146         lbMin < ubMin || lbMax > ubMax)
00147       throw Set::VariableEmptyDomain("SetVarArgs::SetVarArgs");
00148     for (int i = size(); i--; )
00149       a[i] = SetVar(home,lbMin,lbMax,ubMin,ubMax,minCard,maxCard);
00150   }
00151 
00152   SetVarArgs::SetVarArgs(Space& home,int n,
00153                          const IntSet& glb,int ubMin,int ubMax,
00154                          unsigned int minCard,unsigned int maxCard)
00155     : VarArgArray<SetVar>(n) {
00156     Set::Limits::check(glb,"SetVarArgs::SetVarArgs");
00157     Set::Limits::check(ubMin,"SetVarArgs::SetVarArgs");
00158     Set::Limits::check(ubMax,"SetVarArgs::SetVarArgs");
00159     Set::Limits::check(maxCard,"SetVarArgs::SetVarArgs");
00160     IntSetRanges glbr(glb);
00161     unsigned int glbSize = Iter::Ranges::size(glbr);
00162     unsigned int lubSize =
00163       (ubMin <= ubMax ? static_cast<unsigned int>(ubMax-ubMin+1) : 0U);
00164     if (minCard > maxCard || minCard > lubSize || maxCard < glbSize ||
00165         glb.min() < ubMin || glb.max() > ubMax)
00166       throw Set::VariableEmptyDomain("SetVarArgs::SetVarArgs");
00167     for (int i = size(); i--; )
00168       a[i] = SetVar(home,glb,ubMin,ubMax,minCard,maxCard);
00169   }
00170 
00171   SetVarArgs::SetVarArgs(Space& home,int n,
00172                          int lbMin,int lbMax,const IntSet& lub,
00173                          unsigned int minCard,unsigned int maxCard)
00174     : VarArgArray<SetVar>(n) {
00175     Set::Limits::check(lbMin,"SetVarArgs::SetVarArgs");
00176     Set::Limits::check(lbMax,"SetVarArgs::SetVarArgs");
00177     Set::Limits::check(lub,"SetVarArgs::SetVarArgs");
00178     Set::Limits::check(maxCard,"SetVarArgs::SetVarArgs");
00179     Iter::Ranges::Singleton glbr(lbMin,lbMax);
00180     IntSetRanges lubr(lub);
00181     IntSetRanges lubr_s(lub);
00182     unsigned int glbSize =
00183       (lbMin <= lbMax ? static_cast<unsigned int>(lbMax-lbMin+1) : 0U);
00184     unsigned int lubSize = Iter::Ranges::size(lubr_s);
00185     if (minCard > maxCard || minCard > lubSize || maxCard < glbSize ||
00186         !Iter::Ranges::subset(glbr,lubr))
00187       throw Set::VariableEmptyDomain("SetVarArgs::SetVarArgs");
00188     for (int i = size(); i--; )
00189       a[i] = SetVar(home,lbMin,lbMax,lub,minCard,maxCard);
00190   }
00191 
00192   SetVarArgs::SetVarArgs(Space& home,int n,
00193                          const IntSet& glb, const IntSet& lub,
00194                          unsigned int minCard, unsigned int maxCard)
00195     : VarArgArray<SetVar>(n) {
00196     Set::Limits::check(glb,"SetVarArgs::SetVarArgs");
00197     Set::Limits::check(lub,"SetVarArgs::SetVarArgs");
00198     Set::Limits::check(maxCard,"SetVarArgs::SetVarArgs");
00199     IntSetRanges glbr(glb);
00200     IntSetRanges glbr_s(glb);
00201     unsigned int glbSize = Iter::Ranges::size(glbr_s);
00202     IntSetRanges lubr(lub);
00203     IntSetRanges lubr_s(lub);
00204     unsigned int lubSize = Iter::Ranges::size(lubr_s);
00205     if (minCard > maxCard || minCard > lubSize || maxCard < glbSize ||
00206         !Iter::Ranges::subset(glbr,lubr))
00207       throw Set::VariableEmptyDomain("SetVar");
00208     for (int i = size(); i--; )
00209       a[i] = SetVar(home,glb,lub,minCard,maxCard);
00210   }
00211 
00212 }
00213 
00214 // STATISTICS: set-other
00215