Generated on Thu Apr 11 13:59:08 2019 for Gecode by doxygen 1.6.3

extensional-tuple-set.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Linnea Ingmar <linnea.ingmar@hotmail.com>
00005  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00006  *     Christian Schulte <schulte@gecode.org>
00007  *
00008  *  Copyright:
00009  *     Linnea Ingmar, 2017
00010  *     Mikael Lagerkvist, 2007
00011  *     Christian Schulte, 2017
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/int/extensional.hh>
00039 
00040 namespace Gecode {
00041 
00042   void
00043   extensional(Home home, const IntVarArgs& x, const TupleSet& t, bool pos,
00044               IntPropLevel) {
00045     using namespace Int;
00046     if (!t.finalized())
00047       throw NotYetFinalized("Int::extensional");
00048     if (t.arity() != x.size())
00049       throw ArgumentSizeMismatch("Int::extensional");
00050     GECODE_POST;
00051 
00052     ViewArray<IntView> xv(home,x);
00053     if (pos)
00054       GECODE_ES_FAIL((Extensional::postposcompact<IntView>(home,xv,t)));
00055     else
00056       GECODE_ES_FAIL((Extensional::postnegcompact<IntView>(home,xv,t)));
00057   }
00058 
00059   void
00060   extensional(Home home, const IntVarArgs& x, const TupleSet& t, bool pos,
00061               Reify r,
00062               IntPropLevel) {
00063     using namespace Int;
00064     if (!t.finalized())
00065       throw NotYetFinalized("Int::extensional");
00066     if (t.arity() != x.size())
00067       throw ArgumentSizeMismatch("Int::extensional");
00068     GECODE_POST;
00069 
00070     ViewArray<IntView> xv(home,x);
00071     if (pos) {
00072       switch (r.mode()) {
00073       case RM_EQV:
00074         GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_EQV>
00075                         (home,xv,t,r.var())));
00076         break;
00077       case RM_IMP:
00078         GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_IMP>
00079                         (home,xv,t,r.var())));
00080         break;
00081       case RM_PMI:
00082         GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_PMI>
00083                         (home,xv,t,r.var())));
00084         break;
00085       default: throw UnknownReifyMode("Int::extensional");
00086       }
00087     } else {
00088       NegBoolView n(r.var());
00089       switch (r.mode()) {
00090       case RM_EQV:
00091         GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_EQV>
00092                         (home,xv,t,n)));
00093         break;
00094       case RM_IMP:
00095         GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_PMI>
00096                         (home,xv,t,n)));
00097         break;
00098       case RM_PMI:
00099         GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_IMP>
00100                         (home,xv,t,n)));
00101         break;
00102       default: throw UnknownReifyMode("Int::extensional");
00103       }
00104     }
00105   }
00106 
00107   void
00108   extensional(Home home, const BoolVarArgs& x, const TupleSet& t, bool pos,
00109               IntPropLevel) {
00110     using namespace Int;
00111     if (!t.finalized())
00112       throw NotYetFinalized("Int::extensional");
00113     if (t.arity() != x.size())
00114       throw ArgumentSizeMismatch("Int::extensional");
00115     if ((t.min() < 0) || (t.max() > 1))
00116       throw NotZeroOne("Int::extensional");
00117     GECODE_POST;
00118 
00119     ViewArray<BoolView> xv(home,x);
00120     if (pos)
00121       GECODE_ES_FAIL((Extensional::postposcompact<BoolView>(home,xv,t)));
00122     else
00123       GECODE_ES_FAIL((Extensional::postnegcompact<BoolView>(home,xv,t)));
00124   }
00125 
00126   void
00127   extensional(Home home, const BoolVarArgs& x, const TupleSet& t, bool pos,
00128               Reify r,
00129               IntPropLevel) {
00130     using namespace Int;
00131     if (!t.finalized())
00132       throw NotYetFinalized("Int::extensional");
00133     if (t.arity() != x.size())
00134       throw ArgumentSizeMismatch("Int::extensional");
00135     if ((t.min() < 0) || (t.max() > 1))
00136       throw NotZeroOne("Int::extensional");
00137     GECODE_POST;
00138 
00139     ViewArray<BoolView> xv(home,x);
00140     if (pos) {
00141       switch (r.mode()) {
00142       case RM_EQV:
00143         GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_EQV>
00144                         (home,xv,t,r.var())));
00145         break;
00146       case RM_IMP:
00147         GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_IMP>
00148                         (home,xv,t,r.var())));
00149         break;
00150       case RM_PMI:
00151         GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_PMI>
00152                         (home,xv,t,r.var())));
00153         break;
00154       default: throw UnknownReifyMode("Int::extensional");
00155       }
00156     } else {
00157       NegBoolView n(r.var());
00158       switch (r.mode()) {
00159       case RM_EQV:
00160         GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_EQV>
00161                         (home,xv,t,n)));
00162         break;
00163       case RM_IMP:
00164         GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_PMI>
00165                         (home,xv,t,n)));
00166         break;
00167       case RM_PMI:
00168         GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_IMP>
00169                         (home,xv,t,n)));
00170         break;
00171       default: throw UnknownReifyMode("Int::extensional");
00172       }
00173     }
00174   }
00175 
00176 }
00177 
00178 // STATISTICS: int-post