Generated on Fri Oct 19 11:24:50 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/float/branch.hh>
00035 
00036 namespace Gecode {
00037 
00038   void
00039   branch(Home home, const FloatVarArgs& x,
00040          FloatVarBranch vars, FloatValBranch vals,
00041          FloatBranchFilter bf,
00042          FloatVarValPrint vvp) {
00043     using namespace Float;
00044     if (home.failed()) return;
00045     vars.expand(home,x);
00046     ViewArray<FloatView> xv(home,x);
00047     ViewSel<FloatView>* vs[1] = {
00048       Branch::viewsel(home,vars)
00049     };
00050     postviewvalbrancher<FloatView,1,FloatNumBranch,2>
00051       (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00052   }
00053 
00054   void
00055   branch(Home home, const FloatVarArgs& x,
00056          TieBreak<FloatVarBranch> vars, FloatValBranch vals,
00057          FloatBranchFilter bf,
00058          FloatVarValPrint vvp) {
00059     using namespace Float;
00060     if (home.failed()) return;
00061     vars.a.expand(home,x);
00062     if ((vars.a.select() == FloatVarBranch::SEL_NONE) ||
00063         (vars.a.select() == FloatVarBranch::SEL_RND))
00064       vars.b = FLOAT_VAR_NONE();
00065     vars.b.expand(home,x);
00066     if ((vars.b.select() == FloatVarBranch::SEL_NONE) ||
00067         (vars.b.select() == FloatVarBranch::SEL_RND))
00068       vars.c = FLOAT_VAR_NONE();
00069     vars.c.expand(home,x);
00070     if ((vars.c.select() == FloatVarBranch::SEL_NONE) ||
00071         (vars.c.select() == FloatVarBranch::SEL_RND))
00072       vars.d = FLOAT_VAR_NONE();
00073     vars.d.expand(home,x);
00074     if (vars.b.select() == FloatVarBranch::SEL_NONE) {
00075       branch(home,x,vars.a,vals,bf,vvp);
00076     } else {
00077       ViewArray<FloatView> xv(home,x);
00078       ValSelCommitBase<FloatView,FloatNumBranch>*
00079         vsc = Branch::valselcommit(home,vals);
00080       if (vars.c.select() == FloatVarBranch::SEL_NONE) {
00081         ViewSel<FloatView>* vs[2] = {
00082           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00083         };
00084         postviewvalbrancher<FloatView,2,FloatNumBranch,2>
00085           (home,xv,vs,vsc,bf,vvp);
00086       } else if (vars.d.select() == FloatVarBranch::SEL_NONE) {
00087         ViewSel<FloatView>* vs[3] = {
00088           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00089           Branch::viewsel(home,vars.c)
00090         };
00091         postviewvalbrancher<FloatView,3,FloatNumBranch,2>
00092           (home,xv,vs,vsc,bf,vvp);
00093       } else {
00094         ViewSel<FloatView>* vs[4] = {
00095           Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00096           Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00097         };
00098         postviewvalbrancher<FloatView,4,FloatNumBranch,2>
00099           (home,xv,vs,vsc,bf,vvp);
00100       }
00101     }
00102   }
00103 
00104   void
00105   branch(Home home, FloatVar x, FloatValBranch vals, FloatVarValPrint vvp) {
00106     FloatVarArgs xv(1); xv[0]=x;
00107     branch(home, xv, FLOAT_VAR_NONE(), vals, nullptr, vvp);
00108   }
00109 
00110   void
00111   assign(Home home, const FloatVarArgs& x, FloatAssign fa,
00112          FloatBranchFilter bf,
00113          FloatVarValPrint vvp) {
00114     using namespace Float;
00115     if (home.failed()) return;
00116     ViewArray<FloatView> xv(home,x);
00117     ViewSel<FloatView>* vs[1] = {
00118       new (home) ViewSelNone<FloatView>(home,FLOAT_VAR_NONE())
00119     };
00120     postviewvalbrancher<FloatView,1,FloatNumBranch,1>
00121       (home,xv,vs,Branch::valselcommit(home,fa),bf,vvp);
00122   }
00123 
00124   void
00125   assign(Home home, FloatVar x, FloatAssign fa, FloatVarValPrint vvp) {
00126     FloatVarArgs xv(1); xv[0]=x;
00127     assign(home, xv, fa, nullptr, vvp);
00128   }
00129 
00130 }
00131 
00132 // STATISTICS: float-post