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

select-val.icc

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-16 10:42:26 +0100 (Sat, 16 Feb 2008) $ by $Author: tack $
00011  *     $Revision: 6185 $
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 namespace Gecode { namespace CpltSet { namespace Branch {
00039 
00040   template <bool exclude>
00041   forceinline int
00042   ValMinUnknown<exclude>::val(const Space*, CpltSetView x) const {
00043     UnknownValues<CpltSetView> unknown(x);
00044     int v = unknown.val();
00045     return v;
00046   }
00047 
00048   template <bool exclude>
00049   forceinline ModEvent
00050   ValMinUnknown<exclude>::tell(Space* home, unsigned int a,
00051                                CpltSetView x, int v) {
00052     return (a == (int) exclude) ? x.include(home,v) : x.exclude(home,v);
00053   }
00054 
00055   template<bool exclude>
00056   inline Support::Symbol
00057   ValMinUnknown<exclude>::type(void) {
00058     return Support::Symbol("CpltSet::Branch::ValMinUnknown");
00059   }
00060 
00061   template<bool exclude>
00062   forceinline void
00063   ValMinUnknown<exclude>::branchingSpec(const Space* home,
00064                                         Reflection::VarMap& m,
00065                                         Reflection::BranchingSpec& bs,
00066                                         int alt, CpltSetView x, int n) const {
00067     assert(alt <= 2);
00068     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00069     std::stringstream s;
00070     s << n;
00071     if (exclude) {
00072       (*a0)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00073     } else {
00074       (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());      
00075     }
00076     (*a0)[1] = x.spec(home, m);
00077     bs[0] = a0;
00078     if (alt == 2) {
00079       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00080       if (exclude) {
00081         (*a1)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00082       } else {
00083         (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());      
00084       }
00085       (*a1)[1] = x.spec(home, m);
00086       bs[1] = a1;
00087     }
00088   }
00089 
00090   template <bool exclude>
00091   forceinline int
00092   ValMaxUnknown<exclude>::val(const Space*, CpltSetView x) const {
00093     int maxElem = 0;
00094     Set::UnknownRanges<CpltSetView> unknown(x);
00095     while (unknown()) {
00096       maxElem = unknown.max();
00097       ++unknown;
00098     }
00099     return maxElem;
00100   }
00101 
00102   template <bool exclude>
00103   forceinline ModEvent
00104   ValMaxUnknown<exclude>::tell(Space* home, unsigned int a,
00105                                CpltSetView x, int v) {
00106     return (a == (int) exclude) ? x.include(home,v) : x.exclude(home,v);
00107   }
00108 
00109   template<bool exclude>
00110   inline Support::Symbol
00111   ValMaxUnknown<exclude>::type(void) {
00112     return Support::Symbol("CpltSet::Branch::ValMaxUnknown");
00113   }
00114 
00115   template<bool exclude>
00116   forceinline void
00117   ValMaxUnknown<exclude>::branchingSpec(const Space* home,
00118                                         Reflection::VarMap& m,
00119                                         Reflection::BranchingSpec& bs,
00120                                         int alt, CpltSetView x, int n) const {
00121     assert(alt <= 2);
00122     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00123     std::stringstream s;
00124     s << n;
00125     if (exclude) {
00126       (*a0)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00127     } else {
00128       (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());      
00129     }
00130     (*a0)[1] = x.spec(home, m);
00131     bs[0] = a0;
00132     if (alt == 2) {
00133       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00134       if (exclude) {
00135         (*a1)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00136       } else {
00137         (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());      
00138       }
00139       (*a1)[1] = x.spec(home, m);
00140       bs[1] = a1;
00141     }
00142   }
00143 
00144   template <class SelView>
00145   static void
00146   create(Space* home, ViewArray<CpltSetView>& x, CpltSetValBranch vals) {
00147     switch (vals) {
00148     case CPLTSET_VAL_MIN_UNKNOWN:
00149       (void) new (home) ViewValBranching<CpltSetView,int,SelView,ValMinUnknown<false> >(home,x);
00150       break;
00151     case CPLTSET_VAL_MIN_UNKNOWN_EX_FIRST:
00152       (void) new (home) ViewValBranching<CpltSetView,int,SelView,ValMinUnknown<true> >(home,x);
00153       break;
00154     case CPLTSET_VAL_MAX_UNKNOWN:
00155       (void) new (home) ViewValBranching<CpltSetView,int,SelView,ValMaxUnknown<false> >(home,x);
00156       break;
00157     case CPLTSET_VAL_MAX_UNKNOWN_EX_FIRST:
00158       (void) new (home) ViewValBranching<CpltSetView,int,SelView,ValMaxUnknown<true> >(home,x);
00159       break;
00160     default:
00161       throw UnknownBranching("CpltSet::branch");
00162     }
00163   }
00164 
00165 }}}
00166 
00167 // STATISTICS: cpltset-branch