Generated on Thu Apr 11 13:58:54 2019 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 
00107   void
00108   assign(Home home, const SetVarArgs& x,
00109          SetVarBranch vars, SetAssign vals,
00110          SetBranchFilter bf,
00111          SetVarValPrint vvp) {
00112     using namespace Set;
00113     if (home.failed()) return;
00114     ViewArray<SetView> xv(home,x);
00115     ViewSel<SetView>* vs[1] = {
00116       new (home) ViewSelNone<SetView>(home,vars)
00117     };
00118     postviewvalbrancher<SetView,1,int,1>
00119       (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00120   }
00121 
00122   void
00123   assign(Home home, const SetVarArgs& x,
00124          TieBreak<SetVarBranch> vars, SetAssign vals,
00125          SetBranchFilter bf,
00126          SetVarValPrint vvp) {
00127     using namespace Set;
00128     if (home.failed()) return;
00129     vars.a.expand(home,x);
00130     if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
00131         (vars.a.select() == SetVarBranch::SEL_RND))
00132       vars.b = SET_VAR_NONE();
00133     vars.b.expand(home,x);
00134     if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
00135         (vars.b.select() == SetVarBranch::SEL_RND))
00136       vars.c = SET_VAR_NONE();
00137     vars.c.expand(home,x);
00138     if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
00139         (vars.c.select() == SetVarBranch::SEL_RND))
00140       vars.d = SET_VAR_NONE();
00141     vars.d.expand(home,x);
00142     if (vars.b.select() == SetVarBranch::SEL_NONE) {
00143       assign(home,x,vars.a,vals,bf,vvp);
00144     } else {
00145       ViewArray<SetView> xv(home,x);
00146       ValSelCommitBase<SetView,int>* vsc = Branch::valselcommit(home,vals);
00147       if (vars.c.select() == SetVarBranch::SEL_NONE) {
00148         ViewSel<SetView>* vs[2] = {
00149           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00150         };
00151         postviewvalbrancher<SetView,2,int,1>(home,xv,vs,vsc,bf,vvp);
00152       } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
00153         ViewSel<SetView>* vs[3] = {
00154           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00155           Branch::viewsel(home,vars.c)
00156         };
00157         postviewvalbrancher<SetView,3,int,1>(home,xv,vs,vsc,bf,vvp);
00158       } else {
00159         ViewSel<SetView>* vs[4] = {
00160           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00161           Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00162         };
00163         postviewvalbrancher<SetView,4,int,1>(home,xv,vs,vsc,bf,vvp);
00164       }
00165     }
00166   }
00167 
00168   void
00169   assign(Home home, SetVar x, SetAssign vars, SetVarValPrint vvp) {
00170     SetVarArgs xv(1); xv[0]=x;
00171     assign(home, xv, SET_VAR_NONE(), vars, nullptr, vvp);
00172   }
00173 
00174 }
00175 
00176 // STATISTICS: set-post