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