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  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-07-11 09:39:08 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00011  *     $Revision: 7297 $
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 Int { namespace Branch {
00039 
00040   template<class View>
00041   forceinline int
00042   ValMin<View>::val(const Space*, View x) const {
00043     return x.min();
00044   }
00045   template<class View>
00046   forceinline ModEvent
00047   ValMin<View>::tell(Space* home, unsigned int a, View x, int n) {
00048     return (a == 0) ? x.eq(home,n) : x.gr(home,n);
00049   }
00050   template<class View>
00051   inline Support::Symbol
00052   ValMin<View>::type(void) {
00053     return Support::Symbol("Gecode::Int::Branch::ValMin");
00054   }
00055   template <class View>
00056   forceinline void
00057   ValMin<View>::branchingSpec(const Space* home,
00058                               Reflection::VarMap& m,
00059                               Reflection::BranchingSpec& bs,
00060                               int alt, View x, int n) const {
00061     assert(alt <= 2);
00062     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00063     std::stringstream s;
00064     s << n;
00065     (*a0)[0] = x.spec(home, m);
00066     (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str());
00067     bs[0] = a0;
00068     if (alt == 2) {
00069       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00070       (*a1)[0] = x.spec(home, m);
00071       (*a1)[1] = 
00072         Reflection::Arg::newString((std::string(">")+s.str()).c_str());
00073       bs[1] = a1;
00074     }
00075   }
00076 
00077   template<class View>
00078   forceinline int
00079   ValMed<View>::val(const Space*, View x) const {
00080     return x.med();
00081   }
00082   template<class View>
00083   forceinline ModEvent
00084   ValMed<View>::tell(Space* home, unsigned int a, View x, int n) {
00085     return (a == 0) ? x.eq(home,n) : x.nq(home,n);
00086   }
00087   template<class View>
00088   inline Support::Symbol
00089   ValMed<View>::type(void) {
00090     return Support::Symbol("Gecode::Int::Branch::ValMed");
00091   }
00092   template <class View>
00093   forceinline void
00094   ValMed<View>::branchingSpec(const Space* home,
00095                               Reflection::VarMap& m,
00096                               Reflection::BranchingSpec& bs,
00097                               int alt, View x, int n) const {
00098     assert(alt <= 2);
00099     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00100     std::stringstream s;
00101     s << n;
00102     (*a0)[0] = x.spec(home, m);
00103     (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str());
00104     bs[0] = a0;
00105     if (alt == 2) {
00106       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00107       (*a1)[0] = x.spec(home, m);
00108       (*a1)[1] = 
00109         Reflection::Arg::newString((std::string("!=")+s.str()).c_str());
00110       bs[1] = a1;
00111     }
00112   }
00113 
00114 
00115   template<class View>
00116   forceinline int
00117   ValMax<View>::val(const Space*, View x) const {
00118     return x.max();
00119   }
00120   template<class View>
00121   forceinline ModEvent
00122   ValMax<View>::tell(Space* home, unsigned int a, View x, int n) {
00123     return (a == 0) ? x.eq(home,n) : x.le(home,n);
00124   }
00125   template<class View>
00126   inline Support::Symbol
00127   ValMax<View>::type(void) {
00128     return Support::Symbol("Gecode::Int::Branch::ValMax");
00129   }
00130   template <class View>
00131   forceinline void
00132   ValMax<View>::branchingSpec(const Space* home,
00133                               Reflection::VarMap& m,
00134                               Reflection::BranchingSpec& bs,
00135                               int alt, View x, int n) const {
00136     assert(alt <= 2);
00137     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00138     std::stringstream s;
00139     s << n;
00140     (*a0)[0] = x.spec(home, m);
00141     (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str());
00142     bs[0] = a0;
00143     if (alt == 2) {
00144       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00145       (*a1)[0] = x.spec(home, m);
00146       (*a1)[1] = 
00147         Reflection::Arg::newString((std::string("<")+s.str()).c_str());
00148       bs[1] = a1;
00149     }
00150   }
00151 
00152 
00153   template<class View>
00154   forceinline int
00155   ValSplitMin<View>::val(const Space*, View x) const {
00156     return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2);
00157   }
00158   template<class View>
00159   forceinline ModEvent
00160   ValSplitMin<View>::tell(Space* home, unsigned int a, View x, int n) {
00161     return (a == 0) ? x.lq(home,n) : x.gr(home,n);
00162   }
00163   template<class View>
00164   inline Support::Symbol
00165   ValSplitMin<View>::type(void) {
00166     return Support::Symbol("Gecode::Int::Branch::ValSplitMin");
00167   }
00168   template <class View>
00169   forceinline void
00170   ValSplitMin<View>::branchingSpec(const Space* home,
00171                                    Reflection::VarMap& m,
00172                                    Reflection::BranchingSpec& bs,
00173                                    int alt, View x, int n) const {
00174     assert(alt <= 2);
00175     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00176     std::stringstream s;
00177     s << n;
00178     (*a0)[0] = x.spec(home, m);
00179     (*a0)[1] = 
00180       Reflection::Arg::newString((std::string("<=")+s.str()).c_str());
00181     bs[0] = a0;
00182     if (alt == 2) {
00183       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00184       (*a1)[0] = x.spec(home, m);
00185       (*a1)[1] = 
00186         Reflection::Arg::newString((std::string(">")+s.str()).c_str());
00187       bs[1] = a1;
00188     }
00189   }
00190 
00191 
00192   template<class View>
00193   forceinline int
00194   ValSplitMax<View>::val(const Space*, View x) const {
00195     return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2);
00196   }
00197   template<class View>
00198   forceinline ModEvent
00199   ValSplitMax<View>::tell(Space* home, unsigned int a, View x, int n) {
00200     return (a == 0) ? x.gr(home,n) : x.lq(home,n);
00201   }
00202   template<class View>
00203   inline Support::Symbol
00204   ValSplitMax<View>::type(void) {
00205     return Support::Symbol("Gecode::Int::Branch::ValSplitMax");
00206   }
00207   template <class View>
00208   forceinline void
00209   ValSplitMax<View>::branchingSpec(const Space* home,
00210                                    Reflection::VarMap& m,
00211                                    Reflection::BranchingSpec& bs,
00212                                    int alt, View x, int n) const {
00213     assert(alt <= 2);
00214     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00215     std::stringstream s;
00216     s << n;
00217     (*a0)[0] = x.spec(home, m);
00218     (*a0)[1] = Reflection::Arg::newString((std::string(">")+s.str()).c_str());
00219     bs[0] = a0;
00220     if (alt == 2) {
00221       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00222       (*a1)[0] = x.spec(home, m);
00223       (*a1)[1] = 
00224         Reflection::Arg::newString((std::string("<=")+s.str()).c_str());
00225       bs[1] = a1;
00226     }
00227   }
00228 
00229 
00230   template<template <class,class,class,class> class B, class View,
00231            template <class> class SelView>
00232   void
00233   create(Space* home, ViewArray<View>& x, IntValBranch vals) {
00234     switch (vals) {
00235     case INT_VAL_MIN:
00236       (void) new (home) 
00237         B<View,int,SelView<View>,ValMin<View> >(home,x);
00238       break;
00239     case INT_VAL_MED:
00240       (void) new (home) 
00241         B<View,int,SelView<View>,ValMed<View> >(home,x);
00242       break;
00243     case INT_VAL_MAX:
00244       (void) new (home) 
00245         B<View,int,SelView<View>,ValMax<View> >(home,x);
00246       break;
00247     case INT_VAL_SPLIT_MIN:
00248       (void) new (home)
00249         B<View,int,SelView<View>,ValSplitMin<View> >(home,x);
00250       break;
00251     case INT_VAL_SPLIT_MAX:
00252       (void) new (home)
00253         B<View,int,SelView<View>,ValSplitMax<View> >(home,x);
00254       break;
00255     default:
00256       throw UnknownBranching("Int::branch");
00257     }
00258   }
00259 
00260   inline Support::Symbol
00261   NoValue::type(void) {
00262     return Support::Symbol("Gecode::Int::Branch::NoValue");
00263   }
00264 
00265   template<class View>
00266   forceinline NoValue
00267   ValZeroOne<View>::val(const Space*, View) const {
00268     NoValue n; return n;
00269   }
00270   template<class View>
00271   forceinline ModEvent
00272   ValZeroOne<View>::tell(Space* home, unsigned int a, View x, NoValue) {
00273     return (a == 0) ? x.zero(home) : x.one(home);
00274   }
00275   template<class View>
00276   inline Support::Symbol
00277   ValZeroOne<View>::type(void) {
00278     return Support::Symbol("Gecode::Int::Branch::ValZeroOne");
00279   }
00280   template <class View>
00281   forceinline void
00282   ValZeroOne<View>::branchingSpec(const Space* home,
00283                                   Reflection::VarMap& m,
00284                                   Reflection::BranchingSpec& bs,
00285                                   int alt, View x, NoValue) const {
00286     assert(alt <= 2);
00287     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00288     (*a0)[0] = x.spec(home, m);
00289     (*a0)[1] = Reflection::Arg::newString("= 0");
00290     bs[0] = a0;
00291     if (alt == 2) {
00292       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00293       (*a1)[0] = x.spec(home, m);
00294       (*a1)[1] = Reflection::Arg::newString("= 1");
00295       bs[1] = a1;
00296     }
00297   }
00298 
00299 
00300 
00301   template<class View>
00302   forceinline NoValue
00303   ValOneZero<View>::val(const Space*, View) const {
00304     NoValue n; return n;
00305   }
00306   template<class View>
00307   forceinline ModEvent
00308   ValOneZero<View>::tell(Space* home, unsigned int a, View x, NoValue) {
00309     return (a == 0) ? x.one(home) : x.zero(home);
00310   }
00311   template<class View>
00312   inline Support::Symbol
00313   ValOneZero<View>::type(void) {
00314     return Support::Symbol("Gecode::Int::Branch::ValOneZero");
00315   }
00316   template <class View>
00317   forceinline void
00318   ValOneZero<View>::branchingSpec(const Space* home,
00319                                   Reflection::VarMap& m,
00320                                   Reflection::BranchingSpec& bs,
00321                                   int alt, View x, NoValue) const {
00322     assert(alt <= 2);
00323     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00324     (*a0)[0] = x.spec(home, m);
00325     (*a0)[1] = Reflection::Arg::newString("= 1");
00326     bs[0] = a0;
00327     if (alt == 2) {
00328       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00329       (*a1)[0] = x.spec(home, m);
00330       (*a1)[1] = Reflection::Arg::newString("= 0");
00331       bs[1] = a1;
00332     }
00333   }
00334 
00335 
00336 }}}
00337 
00338 
00339 // STATISTICS: int-branch
00340