Generated on Fri Mar 20 15:55:57 2015 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: 2013-05-02 17:10:16 +0200 (Thu, 02 May 2013) $ by $Author: schulte $
00011  *     $Revision: 13603 $
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/set/branch.hh>
00039 
00040 namespace Gecode {
00041   BrancherHandle
00042   branch(Home home, const SetVarArgs& x,
00043          SetVarBranch vars, SetValBranch vals, 
00044          SetBranchFilter bf, SetVarValPrint vvp) {
00045     using namespace Set;
00046     if (home.failed()) return BrancherHandle();
00047     vars.expand(home,x);
00048     ViewArray<SetView> xv(home,x);
00049     ViewSel<SetView>* vs[1] = { 
00050       Branch::viewsel(home,vars) 
00051     };
00052     return ViewValBrancher<SetView,1,int,2>::post
00053       (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00054   }
00055 
00056   BrancherHandle
00057   branch(Home home, const SetVarArgs& x,
00058          TieBreak<SetVarBranch> vars, SetValBranch vals, 
00059          SetBranchFilter bf, SetVarValPrint vvp) {
00060     using namespace Set;
00061     if (home.failed()) return BrancherHandle();
00062     vars.a.expand(home,x);
00063     if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
00064         (vars.a.select() == SetVarBranch::SEL_RND))
00065       vars.b = SET_VAR_NONE();
00066     vars.b.expand(home,x);
00067     if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
00068         (vars.b.select() == SetVarBranch::SEL_RND))
00069       vars.c = SET_VAR_NONE();
00070     vars.c.expand(home,x);
00071     if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
00072         (vars.c.select() == SetVarBranch::SEL_RND))
00073       vars.d = SET_VAR_NONE();
00074     vars.d.expand(home,x);
00075     if (vars.b.select() == SetVarBranch::SEL_NONE) {
00076       return branch(home,x,vars.a,vals,bf,vvp);
00077     } else {
00078       ViewArray<SetView> xv(home,x);
00079       ValSelCommitBase<SetView,int>* vsc = Branch::valselcommit(home,vals); 
00080       if (vars.c.select() == SetVarBranch::SEL_NONE) {
00081         ViewSel<SetView>* vs[2] = { 
00082           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00083         };
00084         return ViewValBrancher<SetView,2,int,2>::post(home,xv,vs,vsc,bf,vvp);
00085       } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
00086         ViewSel<SetView>* vs[3] = { 
00087           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00088           Branch::viewsel(home,vars.c)
00089         };
00090         return ViewValBrancher<SetView,3,int,2>::post(home,xv,vs,vsc,bf,vvp);
00091       } else {
00092         ViewSel<SetView>* vs[4] = { 
00093           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00094           Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00095         };
00096         return ViewValBrancher<SetView,4,int,2>::post(home,xv,vs,vsc,bf,vvp);
00097       }
00098     }
00099   }
00100 
00101   BrancherHandle
00102   branch(Home home, SetVar x, SetValBranch vals, SetVarValPrint vvp) {
00103     SetVarArgs xv(1); xv[0]=x;
00104     return branch(home, xv, SET_VAR_NONE(), vals, NULL, vvp);
00105   }
00106   
00107   BrancherHandle
00108   assign(Home home, const SetVarArgs& x, SetAssign sa,
00109          SetBranchFilter bf, SetVarValPrint vvp) {
00110     using namespace Set;
00111     if (home.failed()) return BrancherHandle();
00112     ViewArray<SetView> xv(home,x);
00113     ViewSel<SetView>* vs[1] = { 
00114       new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
00115     };
00116     return ViewValBrancher<SetView,1,int,1>::post
00117       (home,xv,vs,Branch::valselcommit(home,sa),bf,vvp);
00118   }
00119 
00120   BrancherHandle
00121   assign(Home home, SetVar x, SetAssign sa, SetVarValPrint vvp) {
00122     SetVarArgs xv(1); xv[0]=x;
00123     return assign(home, xv, sa, NULL, vvp);
00124   }
00125   
00126 }
00127 
00128 // STATISTICS: set-post