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

extensional.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Mikael Lagerkvist, 2007
00009  *     Christian Schulte, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-02-28 10:25:14 +0100 (Thu, 28 Feb 2008) $ by $Author: zayenz $
00013  *     $Revision: 6341 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #include "gecode/int/extensional.hh"
00041 
00042 namespace Gecode {
00043 
00044   void
00045   extensional(Space* home, const IntVarArgs& x, DFA dfa, 
00046               IntConLevel, PropKind) {
00047     using namespace Int;
00048     if (x.same())
00049       throw ArgumentSame("Int::extensional");
00050     if (home->failed()) return;
00051     ViewArray<IntView> xv(home,x);
00052     GECODE_ES_FAIL(home,(Extensional::LayeredGraph<IntView>
00053                          ::post(home,xv,dfa)));
00054   }
00055 
00056   void
00057   extensional(Space* home, const BoolVarArgs& x, DFA dfa, 
00058               IntConLevel, PropKind) {
00059     using namespace Int;
00060     if (x.same())
00061       throw ArgumentSame("Int::extensional");
00062     if (home->failed()) return;
00063     ViewArray<BoolView> xv(home,x);
00064     GECODE_ES_FAIL(home,(Extensional::LayeredGraph<BoolView>
00065                          ::post(home,xv,dfa)));
00066   }
00067 
00068   void
00069   extensional(Space* home, const IntVarArgs& x, const TupleSet& t, 
00070               IntConLevel, PropKind pk) {
00071     using namespace Int;
00072     if (!t.finalized())
00073       const_cast<TupleSet&>(t).finalize();
00074     if (t.arity() != x.size())
00075       throw ArgumentSizeMismatch("Int::extensional");
00076     if (home->failed()) return;
00077 
00078     // Construct view array
00079     ViewArray<IntView> xv(home,x);
00080 
00081     // All variables in the correct domain
00082     for (int i = xv.size(); i--; ) {
00083       GECODE_ME_FAIL(home, xv[i].gq(home, t.min()));
00084       GECODE_ME_FAIL(home, xv[i].lq(home, t.max()));
00085     }
00086 
00087     switch (pk) {
00088     case PK_SPEED:
00089       GECODE_ES_FAIL(home,(Extensional::Incremental<IntView>::post(home,xv,t)));
00090       break;
00091     default:
00092       GECODE_ES_FAIL(home,(Extensional::Basic<IntView>::post(home,xv,t)));
00093       break;
00094     }
00095   }
00096 
00097   void
00098   extensional(Space* home, const BoolVarArgs& x, const TupleSet& t, 
00099               IntConLevel, PropKind pk) {
00100     using namespace Int;
00101     if (!t.finalized())
00102       const_cast<TupleSet&>(t).finalize();
00103     if (t.arity() != x.size())
00104       throw ArgumentSizeMismatch("Int::extensional");
00105     if (home->failed()) return;
00106 
00107     // Construct view array
00108     ViewArray<BoolView> xv(home,x);
00109 
00110     // All variables in the correct domain
00111     for (int i = xv.size(); i--; ) {
00112       GECODE_ME_FAIL(home, xv[i].gq(home, t.min()));
00113       GECODE_ME_FAIL(home, xv[i].lq(home, t.max()));
00114     }
00115 
00116     switch (pk) {
00117     case PK_SPEED:
00118       GECODE_ES_FAIL(home,(Extensional::Incremental<BoolView>::post(home,xv,t)));
00119       break;
00120     default:
00121       GECODE_ES_FAIL(home,(Extensional::Basic<BoolView>::post(home,xv,t)));
00122       break;
00123     }
00124   }
00125 
00126   GECODE_REGISTER1(Int::Extensional::LayeredGraph<Int::IntView>);
00127   GECODE_REGISTER1(Int::Extensional::LayeredGraph<Int::BoolView>);
00128 
00129   GECODE_REGISTER1(Int::Extensional::Basic<Int::IntView>);
00130   GECODE_REGISTER1(Int::Extensional::Incremental<Int::IntView>);
00131 
00132   GECODE_REGISTER1(Int::Extensional::Basic<Int::BoolView>);
00133   GECODE_REGISTER1(Int::Extensional::Incremental<Int::BoolView>);
00134 
00135 }
00136 
00137 // STATISTICS: int-post
00138