Generated on Mon Aug 25 11:35:33 2008 for Gecode by doxygen 1.5.6

array.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Patrick Pekczynski <pekczynski@ps.uni-sb.de>
00005  *
00006  *  Copyright:
00007  *     Patrick Pekczynski, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-01 15:22:09 +0100 (Fri, 01 Feb 2008) $ by $Author: tack $
00011  *     $Revision: 6042 $
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 #include "gecode/cpltset.hh"
00039 
00040 namespace Gecode {
00041 
00042   namespace CpltSet {
00043     void 
00044     setVariableOrderFromArray(Space* home, const CpltSetVarArray& x) {
00045       int n = x.size();
00046       ViewArray<CpltSetView> view(home, n);
00047       for (int i = n; i--; ) {
00048         view[i] = x[i];
00049       }
00050       variableorder(view);
00051     }
00052   }
00053 
00054   CpltSetVarArray::CpltSetVarArray(Space* home, int n,
00055                                    int lbMin,int lbMax,int ubMin,int ubMax,
00056                                    unsigned int minCard,
00057                                    unsigned int maxCard)
00058     : VarArray<CpltSetVar>(home,n) {    
00059     Set::Limits::check(lbMin,"CpltSetVarArray::CpltSetVarArray");
00060     Set::Limits::check(lbMax,"CpltSetVarArray::CpltSetVarArray");
00061     Set::Limits::check(ubMin,"CpltSetVarArray::CpltSetVarArray");
00062     Set::Limits::check(ubMax,"CpltSetVarArray::CpltSetVarArray");
00063     Set::Limits::check(maxCard,"CpltSetVarArray::CpltSetVarArray");
00064     if (minCard > maxCard)
00065       throw Set::VariableEmptyDomain("CpltSetVarArray::CpltSetVarArray");
00066 
00067     IntSet glb(lbMin, lbMax);
00068     IntSet lub(ubMin, ubMax);      
00069     CpltSet::testConsistency(glb, lub, minCard, maxCard, "CpltSetVarArray");
00070 
00071     for (int i = 0; i < size(); i++)
00072       x[i].init(home,lbMin,lbMax,ubMin,ubMax,minCard,maxCard);    
00073     
00074     CpltSet::setVariableOrderFromArray(home, *this);
00075   }
00076 
00077   CpltSetVarArray::CpltSetVarArray(Space* home, int n,
00078                                    const IntSet& glb,int ubMin,int ubMax,
00079                                    unsigned int minCard,unsigned int maxCard)
00080     : VarArray<CpltSetVar>(home,n) {
00081     Set::Limits::check(glb,"CpltSetVarArray::CpltSetVarArray");
00082     Set::Limits::check(ubMin,"CpltSetVarArray::CpltSetVarArray");
00083     Set::Limits::check(ubMax,"CpltSetVarArray::CpltSetVarArray");
00084     Set::Limits::check(maxCard,"CpltSetVarArray::CpltSetVarArray");
00085     if (minCard > maxCard)
00086       throw Set::VariableEmptyDomain("CpltSetVarArray::CpltSetVarArray");
00087 
00088     IntSet lub(ubMin, ubMax);
00089     CpltSet::testConsistency(glb, lub, minCard, maxCard, "CpltSetVarArray");
00090 
00091     for (int i = 0; i < size(); i++)
00092       x[i].init(home, glb,ubMin,ubMax,minCard,maxCard);
00093 
00094     CpltSet::setVariableOrderFromArray(home, *this);
00095   }
00096 
00097   CpltSetVarArray::CpltSetVarArray(Space* home, int n,
00098                                    int lbMin,int lbMax,const IntSet& lub,
00099                                    unsigned int minCard,unsigned int maxCard)
00100     : VarArray<CpltSetVar>(home,n) {
00101     IntSet glb(lbMin, lbMax);      
00102     CpltSet::testConsistency(glb, lub, minCard, maxCard, "CpltSetVarArray");
00103 
00104     for (int i = 0; i < size(); i++)
00105       x[i].init(home, lbMin, lbMax, lub, minCard, maxCard);
00106   }
00107 
00108   CpltSetVarArray::CpltSetVarArray(Space* home, int n,
00109                                    const IntSet& glb, const IntSet& lub,
00110                                    unsigned int minCard, unsigned int maxCard)
00111     : VarArray<CpltSetVar>(home,n) {
00112     CpltSet::testConsistency(glb, lub, minCard, maxCard, "CpltSetVarArray");
00113 
00114     for (int i = 0; i < size(); i++)
00115       x[i].init(home, glb,lub,minCard,maxCard);
00116     CpltSet::setVariableOrderFromArray(home, *this);
00117   }
00118 
00119 }
00120 
00121 // STATISTICS: cpltset-other