Generated on Tue Apr 18 10:21:35 2017 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, 2012
00008  *
00009  *  Last modified:
00010  *     $Date: 2017-04-01 20:27:10 +0200 (Sat, 01 Apr 2017) $ by $Author: schulte $
00011  *     $Revision: 15623 $
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   branch(Home home, const IntVarArgs& x,
00044          IntVarBranch vars, IntValBranch vals,
00045          IntBranchFilter bf,
00046          IntVarValPrint vvp) {
00047     using namespace Int;
00048     if (home.failed()) return;
00049     vars.expand(home,x);
00050     ViewArray<IntView> xv(home,x);
00051     ViewSel<IntView>* vs[1] = {
00052       Branch::viewsel(home,vars)
00053     };
00054     switch (vals.select()) {
00055     case IntValBranch::SEL_VALUES_MIN:
00056       Branch::postviewvaluesbrancher<1,true>(home,xv,vs,bf,vvp);
00057       break;
00058     case IntValBranch::SEL_VALUES_MAX:
00059       Branch::postviewvaluesbrancher<1,false>(home,xv,vs,bf,vvp);
00060       break;
00061     default:
00062       postviewvalbrancher<IntView,1,int,2>
00063         (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00064       break;
00065     }
00066   }
00067 
00068   void
00069   branch(Home home, const IntVarArgs& x,
00070          TieBreak<IntVarBranch> vars, IntValBranch vals,
00071          IntBranchFilter bf,
00072          IntVarValPrint vvp) {
00073     using namespace Int;
00074     if (home.failed()) return;
00075     vars.a.expand(home,x);
00076     if ((vars.a.select() == IntVarBranch::SEL_NONE) ||
00077         (vars.a.select() == IntVarBranch::SEL_RND))
00078       vars.b = INT_VAR_NONE();
00079     vars.b.expand(home,x);
00080     if ((vars.b.select() == IntVarBranch::SEL_NONE) ||
00081         (vars.b.select() == IntVarBranch::SEL_RND))
00082       vars.c = INT_VAR_NONE();
00083     vars.c.expand(home,x);
00084     if ((vars.c.select() == IntVarBranch::SEL_NONE) ||
00085         (vars.c.select() == IntVarBranch::SEL_RND))
00086       vars.d = INT_VAR_NONE();
00087     vars.d.expand(home,x);
00088     if (vars.b.select() == IntVarBranch::SEL_NONE) {
00089       branch(home,x,vars.a,vals,bf,vvp);
00090     } else {
00091       ViewArray<IntView> xv(home,x);
00092       if (vars.c.select() == IntVarBranch::SEL_NONE) {
00093         ViewSel<IntView>* vs[2] = {
00094           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00095         };
00096         switch (vals.select()) {
00097         case IntValBranch::SEL_VALUES_MIN:
00098           Branch::postviewvaluesbrancher<2,true>(home,xv,vs,bf,vvp);
00099           break;
00100         case IntValBranch::SEL_VALUES_MAX:
00101           Branch::postviewvaluesbrancher<2,false>(home,xv,vs,bf,vvp);
00102           break;
00103         default:
00104           postviewvalbrancher<IntView,2,int,2>
00105             (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00106         }
00107       } else if (vars.d.select() == IntVarBranch::SEL_NONE) {
00108         ViewSel<IntView>* vs[3] = {
00109           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00110           Branch::viewsel(home,vars.c)
00111         };
00112         switch (vals.select()) {
00113         case IntValBranch::SEL_VALUES_MIN:
00114           Branch::postviewvaluesbrancher<3,true>(home,xv,vs,bf,vvp);
00115           break;
00116         case IntValBranch::SEL_VALUES_MAX:
00117           Branch::postviewvaluesbrancher<3,false>(home,xv,vs,bf,vvp);
00118           break;
00119         default:
00120           postviewvalbrancher<IntView,3,int,2>
00121             (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00122         }
00123       } else {
00124         ViewSel<IntView>* vs[4] = {
00125           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00126           Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00127         };
00128         switch (vals.select()) {
00129         case IntValBranch::SEL_VALUES_MIN:
00130           Branch::postviewvaluesbrancher<4,true>(home,xv,vs,bf,vvp);
00131           break;
00132         case IntValBranch::SEL_VALUES_MAX:
00133           Branch::postviewvaluesbrancher<4,false>(home,xv,vs,bf,vvp);
00134           break;
00135         default:
00136           postviewvalbrancher<IntView,4,int,2>
00137             (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00138         }
00139       }
00140     }
00141   }
00142 
00143   void
00144   branch(Home home, IntVar x, IntValBranch vals, IntVarValPrint vvp) {
00145     IntVarArgs xv(1); xv[0]=x;
00146     branch(home, xv, INT_VAR_NONE(), vals, nullptr, vvp);
00147   }
00148 
00149   void
00150   assign(Home home, const IntVarArgs& x, IntAssign ia,
00151          IntBranchFilter bf,
00152          IntVarValPrint vvp) {
00153     using namespace Int;
00154     if (home.failed()) return;
00155     ViewArray<IntView> xv(home,x);
00156     ViewSel<IntView>* vs[1] = {
00157       new (home) ViewSelNone<IntView>(home,INT_VAR_NONE())
00158     };
00159     postviewvalbrancher<IntView,1,int,1>
00160       (home,xv,vs,Branch::valselcommit(home,ia),bf,vvp);
00161   }
00162 
00163   void
00164   assign(Home home, IntVar x, IntAssign ia, IntVarValPrint vvp) {
00165     IntVarArgs xv(1); xv[0]=x;
00166     assign(home, xv, ia, nullptr, vvp);
00167   }
00168 
00169 
00170   void
00171   branch(Home home, const BoolVarArgs& x,
00172          BoolVarBranch vars, BoolValBranch vals,
00173          BoolBranchFilter bf,
00174          BoolVarValPrint vvp) {
00175     using namespace Int;
00176     if (home.failed()) return;
00177     vars.expand(home,x);
00178     ViewArray<BoolView> xv(home,x);
00179     ViewSel<BoolView>* vs[1] = {
00180       Branch::viewsel(home,vars)
00181     };
00182     postviewvalbrancher<BoolView,1,int,2>
00183       (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00184   }
00185 
00186   void
00187   branch(Home home, const BoolVarArgs& x,
00188          TieBreak<BoolVarBranch> vars, BoolValBranch vals,
00189          BoolBranchFilter bf,
00190          BoolVarValPrint vvp) {
00191     using namespace Int;
00192     if (home.failed()) return;
00193     vars.a.expand(home,x);
00194     if ((vars.a.select() == BoolVarBranch::SEL_NONE) ||
00195         (vars.a.select() == BoolVarBranch::SEL_RND))
00196       vars.b = BOOL_VAR_NONE();
00197     vars.b.expand(home,x);
00198     if ((vars.b.select() == BoolVarBranch::SEL_NONE) ||
00199         (vars.b.select() == BoolVarBranch::SEL_RND))
00200       vars.c = BOOL_VAR_NONE();
00201     vars.c.expand(home,x);
00202     if ((vars.c.select() == BoolVarBranch::SEL_NONE) ||
00203         (vars.c.select() == BoolVarBranch::SEL_RND))
00204       vars.d = BOOL_VAR_NONE();
00205     vars.d.expand(home,x);
00206     if (vars.b.select() == BoolVarBranch::SEL_NONE) {
00207       branch(home,x,vars.a,vals,bf,vvp);
00208     } else {
00209       ViewArray<BoolView> xv(home,x);
00210       ValSelCommitBase<BoolView,int>*
00211         vsc = Branch::valselcommit(home,vals);
00212       if (vars.c.select() == BoolVarBranch::SEL_NONE) {
00213         ViewSel<BoolView>* vs[2] = {
00214           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00215         };
00216         postviewvalbrancher<BoolView,2,int,2>(home,xv,vs,vsc,bf,vvp);
00217       } else if (vars.d.select() == BoolVarBranch::SEL_NONE) {
00218         ViewSel<BoolView>* vs[3] = {
00219           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00220           Branch::viewsel(home,vars.c)
00221         };
00222         postviewvalbrancher<BoolView,3,int,2>(home,xv,vs,vsc,bf,vvp);
00223       } else {
00224         ViewSel<BoolView>* vs[4] = {
00225           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00226           Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00227         };
00228         postviewvalbrancher<BoolView,4,int,2>(home,xv,vs,vsc,bf,vvp);
00229       }
00230     }
00231   }
00232 
00233   void
00234   branch(Home home, BoolVar x, BoolValBranch vals, BoolVarValPrint vvp) {
00235     BoolVarArgs xv(1); xv[0]=x;
00236     branch(home, xv, BOOL_VAR_NONE(), vals, nullptr, vvp);
00237   }
00238 
00239   void
00240   assign(Home home, const BoolVarArgs& x, BoolAssign ba,
00241          BoolBranchFilter bf,
00242          BoolVarValPrint vvp) {
00243     using namespace Int;
00244     if (home.failed()) return;
00245     ViewArray<BoolView> xv(home,x);
00246     ViewSel<BoolView>* vs[1] = {
00247       new (home) ViewSelNone<BoolView>(home,BOOL_VAR_NONE())
00248     };
00249     postviewvalbrancher<BoolView,1,int,1>
00250       (home,xv,vs,Branch::valselcommit(home,ba),bf,vvp);
00251   }
00252 
00253   void
00254   assign(Home home, BoolVar x, BoolAssign ba, BoolVarValPrint vvp) {
00255     BoolVarArgs xv(1); xv[0]=x;
00256     assign(home, xv, ba, nullptr, vvp);
00257   }
00258 
00259 }
00260 
00261 // STATISTICS: int-post