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  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Contributing authors:
00008  *     Gabor Szokoli <szokoli@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Guido Tack, 2004
00012  *     Christian Schulte, 2004
00013  *     Gabor Szokoli, 2004
00014  *
00015  *  Last modified:
00016  *     $Date: 2008-02-16 10:42:26 +0100 (Sat, 16 Feb 2008) $ by $Author: tack $
00017  *     $Revision: 6185 $
00018  *
00019  *  This file is part of Gecode, the generic constraint
00020  *  development environment:
00021  *     http://www.gecode.org
00022  *
00023  *  Permission is hereby granted, free of charge, to any person obtaining
00024  *  a copy of this software and associated documentation files (the
00025  *  "Software"), to deal in the Software without restriction, including
00026  *  without limitation the rights to use, copy, modify, merge, publish,
00027  *  distribute, sublicense, and/or sell copies of the Software, and to
00028  *  permit persons to whom the Software is furnished to do so, subject to
00029  *  the following conditions:
00030  *
00031  *  The above copyright notice and this permission notice shall be
00032  *  included in all copies or substantial portions of the Software.
00033  *
00034  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00035  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00036  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00037  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00038  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00039  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00040  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00041  *
00042  */
00043 
00044 namespace Gecode { namespace Set { namespace Branch {
00045 
00046   forceinline int
00047   ValMin::val(const Space*, SetView x) const {
00048     UnknownRanges<SetView> unknown(x);
00049     return unknown.min();
00050   }
00051   forceinline ModEvent
00052   ValMin::tell(Space* home, unsigned int a, SetView x, int v) {
00053     return (a == 0) ? x.include(home,v) : x.exclude(home,v);
00054   }
00055   inline Support::Symbol
00056   ValMin::type(void) {
00057     return Support::Symbol("Gecode::Set::Branch::ValMin");
00058   }
00059   forceinline void
00060   ValMin::branchingSpec(const Space* home,
00061                         Reflection::VarMap& m, Reflection::BranchingSpec& bs,
00062                         int alt, SetView x, int n) const {
00063     assert(alt <= 2);
00064     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00065     std::stringstream s;
00066     s << n;
00067     (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00068     (*a0)[1] = x.spec(home, m);
00069     bs[0] = a0;
00070     if (alt == 2) {
00071       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00072       (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00073       (*a1)[1] = x.spec(home, m);
00074       bs[1] = a1;
00075     }
00076   }
00077 
00078   forceinline int
00079   ValMax::val(const Space*, SetView x) const {
00080     int maxElem = 0;
00081     UnknownRanges<SetView> unknown(x);
00082     while (unknown()) {
00083       maxElem = unknown.max();
00084       ++unknown;
00085     }
00086     return maxElem;
00087   }
00088   forceinline ModEvent
00089   ValMax::tell(Space* home, unsigned int a, SetView x, int v) {
00090     return (a == 0) ? x.include(home,v) : x.exclude(home,v);
00091   }
00092   inline Support::Symbol
00093   ValMax::type(void) {
00094     return Support::Symbol("Gecode::Set::Branch::ValMax");
00095   }
00096   forceinline void
00097   ValMax::branchingSpec(const Space* home,
00098                         Reflection::VarMap& m, Reflection::BranchingSpec& bs,
00099                         int alt, SetView x, int n) const {
00100     assert(alt <= 2);
00101     Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00102     std::stringstream s;
00103     s << n;
00104     (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00105     (*a0)[1] = x.spec(home, m);
00106     bs[0] = a0;
00107     if (alt == 2) {
00108       Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00109       (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00110       (*a1)[1] = x.spec(home, m);
00111       bs[1] = a1;
00112     }
00113   }
00114 
00115   template <class SelView>
00116   static void
00117   create(Space* home, ViewArray<SetView>& x, SetValBranch vals) {
00118     switch (vals) {
00119     case SET_VAL_MIN:
00120       (void) new (home) ViewValBranching<SetView,int,SelView,ValMin>(home,x);
00121       break;
00122     case SET_VAL_MAX:
00123       (void) new (home) ViewValBranching<SetView,int,SelView,ValMax>(home,x);
00124       break;
00125     default:
00126       throw UnknownBranching("Set::branch");
00127     }
00128   }
00129 
00130 }}}
00131 
00132 // STATISTICS: set-branch