Generated on Thu Mar 22 10:39:34 2012 for Gecode by doxygen 1.6.3

branch.cpp

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: 2010-03-11 22:16:29 +0100 (Thu, 11 Mar 2010) $ by $Author: schulte $
00011  *     $Revision: 10418 $
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/branch.hh>
00039 
00040 namespace Gecode {
00041 
00042   void
00043   assign(Home home, const IntVarArgs& x, IntAssign vals,
00044          const ValBranchOptions& o_vals) {
00045     using namespace Int;
00046     if (home.failed()) return;
00047     ViewArray<IntView> xv(home,x);
00048     ViewSelNone<IntView> v(home,VarBranchOptions::def);
00049     switch (vals) {
00050     case INT_ASSIGN_MIN:
00051       {
00052         Branch::AssignValMin<IntView> a(home,o_vals);
00053         ViewValBrancher
00054           <ViewSelNone<IntView>,Branch::AssignValMin<IntView> >
00055           ::post(home,xv,v,a);
00056       }
00057       break;
00058     case INT_ASSIGN_MED:
00059       {
00060         Branch::AssignValMed<IntView> a(home,o_vals);
00061         ViewValBrancher
00062           <ViewSelNone<IntView>,Branch::AssignValMed<IntView> >
00063           ::post(home,xv,v,a);
00064       }
00065       break;
00066     case INT_ASSIGN_MAX:
00067       {
00068         Branch::AssignValMin<MinusView> a(home,o_vals);
00069         ViewValBrancher
00070           <ViewSelNone<IntView>,Branch::AssignValMin<MinusView> >
00071           ::post(home,xv,v,a);
00072       }
00073       break;
00074     case INT_ASSIGN_RND:
00075       {
00076         Branch::AssignValRnd<IntView> a(home,o_vals);
00077         ViewValBrancher
00078           <ViewSelNone<IntView>,Branch::AssignValRnd<IntView> >
00079           ::post(home,xv,v,a);
00080       }
00081       break;
00082     default:
00083       throw UnknownBranching("Int::assign");
00084     }
00085   }
00086 
00087   void
00088   assign(Home home, const BoolVarArgs& x, IntAssign vals,
00089          const ValBranchOptions& o_vals) {
00090     using namespace Int;
00091     if (home.failed()) return;
00092     ViewArray<BoolView> xv(home,x);
00093     ViewSelNone<BoolView> v(home,VarBranchOptions::def);
00094     switch (vals) {
00095     case INT_ASSIGN_MIN:
00096     case INT_ASSIGN_MED: {
00097         Branch::AssignValZero<BoolView> a(home,o_vals);
00098         ViewValBrancher
00099           <ViewSelNone<BoolView>,Branch::AssignValZero<BoolView> >
00100           ::post(home,xv,v,a);
00101       }
00102       break;
00103     case INT_ASSIGN_MAX: {
00104         Branch::AssignValZero<NegBoolView> a(home,o_vals);
00105         ViewValBrancher
00106           <ViewSelNone<BoolView>,Branch::AssignValZero<NegBoolView> >
00107           ::post(home,xv,v,a);
00108       }
00109       break;
00110     case INT_ASSIGN_RND: {
00111         Branch::AssignValRnd<BoolView> a(home,o_vals);
00112         ViewValBrancher
00113           <ViewSelNone<BoolView>,Branch::AssignValRnd<BoolView> >
00114           ::post(home,xv,v,a);
00115       }
00116       break;
00117     default:
00118       throw UnknownBranching("Int::assign");
00119     }
00120   }
00121 
00122   void
00123   branch(Home home, IntVar x, IntValBranch vals,
00124          const ValBranchOptions& o_vals) {
00125     IntVarArgs xv(1); xv[0]=x;
00126     branch(home, xv, INT_VAR_NONE, vals, VarBranchOptions::def, o_vals);
00127   }
00128   
00129   void
00130   branch(Home home, BoolVar x, IntValBranch vals,
00131          const ValBranchOptions& o_vals) {
00132     BoolVarArgs xv(1); xv[0]=x;
00133     branch(home, xv, INT_VAR_NONE, vals, VarBranchOptions::def, o_vals);
00134   }
00135   
00136   void
00137   assign(Home home, IntVar x, IntAssign vals,
00138          const ValBranchOptions& o_vals) {
00139     IntVarArgs xv(1); xv[0]=x;
00140     assign(home, xv, vals, o_vals);
00141   }
00142   
00143   void
00144   assign(Home home, BoolVar x, IntAssign vals,
00145          const ValBranchOptions& o_vals) {
00146     BoolVarArgs xv(1); xv[0]=x;
00147     assign(home, xv, vals, o_vals);
00148   }
00149   
00150 }
00151 
00152 // STATISTICS: int-post