Generated on Tue May 22 09:39:40 2018 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/set/branch.hh>
00035 
00036 namespace Gecode {
00037 
00038   void
00039   branch(Home home, const SetVarArgs& x,
00040          SetVarBranch vars, SetValBranch vals,
00041          SetBranchFilter bf,
00042          SetVarValPrint vvp) {
00043     using namespace Set;
00044     if (home.failed()) return;
00045     vars.expand(home,x);
00046     ViewArray<SetView> xv(home,x);
00047     ViewSel<SetView>* vs[1] = {
00048       Branch::viewsel(home,vars)
00049     };
00050     postviewvalbrancher<SetView,1,int,2>
00051       (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00052   }
00053 
00054   void
00055   branch(Home home, const SetVarArgs& x,
00056          TieBreak<SetVarBranch> vars, SetValBranch vals,
00057          SetBranchFilter bf,
00058          SetVarValPrint vvp) {
00059     using namespace Set;
00060     if (home.failed()) return;
00061     vars.a.expand(home,x);
00062     if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
00063         (vars.a.select() == SetVarBranch::SEL_RND))
00064       vars.b = SET_VAR_NONE();
00065     vars.b.expand(home,x);
00066     if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
00067         (vars.b.select() == SetVarBranch::SEL_RND))
00068       vars.c = SET_VAR_NONE();
00069     vars.c.expand(home,x);
00070     if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
00071         (vars.c.select() == SetVarBranch::SEL_RND))
00072       vars.d = SET_VAR_NONE();
00073     vars.d.expand(home,x);
00074     if (vars.b.select() == SetVarBranch::SEL_NONE) {
00075       branch(home,x,vars.a,vals,bf,vvp);
00076     } else {
00077       ViewArray<SetView> xv(home,x);
00078       ValSelCommitBase<SetView,int>* vsc = Branch::valselcommit(home,vals);
00079       if (vars.c.select() == SetVarBranch::SEL_NONE) {
00080         ViewSel<SetView>* vs[2] = {
00081           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00082         };
00083         postviewvalbrancher<SetView,2,int,2>(home,xv,vs,vsc,bf,vvp);
00084       } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
00085         ViewSel<SetView>* vs[3] = {
00086           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00087           Branch::viewsel(home,vars.c)
00088         };
00089         postviewvalbrancher<SetView,3,int,2>(home,xv,vs,vsc,bf,vvp);
00090       } else {
00091         ViewSel<SetView>* vs[4] = {
00092           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00093           Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00094         };
00095         postviewvalbrancher<SetView,4,int,2>(home,xv,vs,vsc,bf,vvp);
00096       }
00097     }
00098   }
00099 
00100   void
00101   branch(Home home, SetVar x, SetValBranch vals, SetVarValPrint vvp) {
00102     SetVarArgs xv(1); xv[0]=x;
00103     branch(home, xv, SET_VAR_NONE(), vals, nullptr, vvp);
00104   }
00105 
00106   void
00107   assign(Home home, const SetVarArgs& x, SetAssign sa,
00108          SetBranchFilter bf,
00109          SetVarValPrint vvp) {
00110     using namespace Set;
00111     if (home.failed()) return;
00112     ViewArray<SetView> xv(home,x);
00113     ViewSel<SetView>* vs[1] = {
00114       new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
00115     };
00116     postviewvalbrancher<SetView,1,int,1>
00117       (home,xv,vs,Branch::valselcommit(home,sa),bf,vvp);
00118   }
00119 
00120   void
00121   assign(Home home, SetVar x, SetAssign sa, SetVarValPrint vvp) {
00122     SetVarArgs xv(1); xv[0]=x;
00123     assign(home, xv, sa, nullptr, vvp);
00124   }
00125 
00126 }
00127 
00128 // STATISTICS: set-post