Generated on Fri Mar 20 15:55:58 2015 for Gecode by doxygen 1.6.3

val-sel-commit.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-03-05 20:51:24 +0100 (Tue, 05 Mar 2013) $ by $Author: schulte $
00011  *     $Revision: 13438 $
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/int/branch.hh>
00039 
00040 namespace Gecode { namespace Int { namespace Branch {
00041 
00042   ValSelCommitBase<IntView,int>* 
00043   valselcommitint(Space& home, int n, const IntValBranch& ivb) {
00044     assert((ivb.select() != IntValBranch::SEL_VALUES_MIN) &&
00045            (ivb.select() != IntValBranch::SEL_VALUES_MAX));
00046     switch (ivb.select()) {
00047     case IntValBranch::SEL_MIN:
00048       return new (home) 
00049         ValSelCommit<ValSelMin<IntView>,ValCommitEq<IntView> >(home,ivb);
00050     case IntValBranch::SEL_MED:
00051       return new (home) 
00052         ValSelCommit<ValSelMed<IntView>,ValCommitEq<IntView> >(home,ivb);
00053     case IntValBranch::SEL_MAX:
00054       return new (home) 
00055         ValSelCommit<ValSelMax<IntView>,ValCommitEq<IntView> >(home,ivb);
00056     case IntValBranch::SEL_RND:
00057       return new (home) 
00058         ValSelCommit<ValSelRnd<IntView>,ValCommitEq<IntView> >(home,ivb);
00059     case IntValBranch::SEL_SPLIT_MIN:
00060       return new (home) 
00061         ValSelCommit<ValSelAvg<IntView>,ValCommitLq<IntView> >(home,ivb);
00062     case IntValBranch::SEL_SPLIT_MAX:
00063       return new (home) 
00064         ValSelCommit<ValSelAvg<IntView>,ValCommitGr<IntView> >(home,ivb);
00065     case IntValBranch::SEL_RANGE_MIN:
00066       return new (home) 
00067         ValSelCommit<ValSelRangeMin,ValCommitLq<IntView> >(home,ivb);
00068     case IntValBranch::SEL_RANGE_MAX:
00069       return new (home) 
00070         ValSelCommit<ValSelRangeMax,ValCommitGq<IntView> >(home,ivb);
00071     case IntValBranch::SEL_VAL_COMMIT:
00072       if (ivb.commit() == NULL) {
00073         return new (home) 
00074           ValSelCommit<ValSelFunction<IntView>,ValCommitEq<IntView> >(home,ivb);
00075       } else {
00076         return new (home) 
00077           ValSelCommit<ValSelFunction<IntView>,ValCommitFunction<IntView> >(home,ivb);
00078       }
00079     case IntValBranch::SEL_NEAR_MIN:
00080     case IntValBranch::SEL_NEAR_MAX:
00081     case IntValBranch::SEL_NEAR_INC:
00082     case IntValBranch::SEL_NEAR_DEC:
00083       {
00084         IntSharedArray v(ivb.values());
00085         if (n != v.size())
00086           throw ArgumentSizeMismatch("Int::branch");
00087         for (int i=n; i--; )
00088           Limits::check(v[i],"Int::branch");
00089         switch (ivb.select()) {
00090         case IntValBranch::SEL_NEAR_MIN:
00091           return new (home) 
00092             ValSelCommit<ValSelNearMinMax<IntView,true>,
00093              ValCommitEq<IntView> >(home,ivb);
00094         case IntValBranch::SEL_NEAR_MAX:
00095           return new (home) 
00096             ValSelCommit<ValSelNearMinMax<IntView,false>,
00097              ValCommitEq<IntView> >(home,ivb);
00098         case IntValBranch::SEL_NEAR_INC:
00099           return new (home) 
00100             ValSelCommit<ValSelNearIncDec<IntView,true>,
00101              ValCommitEq<IntView> >(home,ivb);
00102         case IntValBranch::SEL_NEAR_DEC:
00103           return new (home) 
00104             ValSelCommit<ValSelNearIncDec<IntView,false>,
00105              ValCommitEq<IntView> >(home,ivb);
00106         default: GECODE_NEVER;
00107         }
00108       }
00109     default:
00110       throw UnknownBranching("Int::branch");
00111     }
00112   }
00113 
00114   ValSelCommitBase<IntView,int>* 
00115   valselcommitint(Space& home, const IntAssign& ia) {
00116     switch (ia.select()) {
00117     case IntAssign::SEL_MIN:
00118       return new (home) 
00119         ValSelCommit<ValSelMin<IntView>,ValCommitEq<IntView> >(home,ia);
00120     case IntAssign::SEL_MED:
00121       return new (home) 
00122         ValSelCommit<ValSelMed<IntView>,ValCommitEq<IntView> >(home,ia);
00123     case IntAssign::SEL_MAX:
00124       return new (home) 
00125         ValSelCommit<ValSelMax<IntView>,ValCommitEq<IntView> >(home,ia);
00126     case IntAssign::SEL_RND:
00127       return new (home) 
00128         ValSelCommit<ValSelRnd<IntView>,ValCommitEq<IntView> >(home,ia);
00129     case IntAssign::SEL_VAL_COMMIT:
00130       if (ia.commit() == NULL) {
00131         return new (home) 
00132           ValSelCommit<ValSelFunction<IntView>,ValCommitEq<IntView> >(home,ia);
00133       } else {
00134         return new (home) 
00135           ValSelCommit<ValSelFunction<IntView>,ValCommitFunction<IntView> >(home,ia);
00136       }
00137     default:
00138       throw UnknownBranching("Int::assign");
00139     }
00140   }
00141 
00142   ValSelCommitBase<BoolView,int>* 
00143   valselcommitbool(Space& home, int n, const IntValBranch& ivb) {
00144     switch (ivb.select()) {
00145     case IntValBranch::SEL_MIN:
00146     case IntValBranch::SEL_MED:
00147     case IntValBranch::SEL_SPLIT_MIN:
00148     case IntValBranch::SEL_RANGE_MIN:
00149     case IntValBranch::SEL_VALUES_MIN:
00150       return new (home) 
00151         ValSelCommit<ValSelMin<BoolView>,ValCommitEq<BoolView> >(home,ivb);
00152     case IntValBranch::SEL_MAX:
00153     case IntValBranch::SEL_SPLIT_MAX:
00154     case IntValBranch::SEL_RANGE_MAX:
00155     case IntValBranch::SEL_VALUES_MAX:
00156       return new (home) 
00157         ValSelCommit<ValSelMax<BoolView>,ValCommitEq<BoolView> >(home,ivb);
00158     case IntValBranch::SEL_RND:
00159       return new (home) 
00160         ValSelCommit<ValSelRnd<BoolView>,ValCommitEq<BoolView> >(home,ivb);
00161     case IntValBranch::SEL_VAL_COMMIT:
00162       if (ivb.commit() == NULL) {
00163         return new (home) 
00164           ValSelCommit<ValSelFunction<BoolView>,ValCommitEq<BoolView> >(home,ivb);
00165       } else {
00166         return new (home) 
00167           ValSelCommit<ValSelFunction<BoolView>,ValCommitFunction<BoolView> >(home,ivb);
00168       }
00169     case IntValBranch::SEL_NEAR_MIN:
00170     case IntValBranch::SEL_NEAR_MAX:
00171     case IntValBranch::SEL_NEAR_INC:
00172     case IntValBranch::SEL_NEAR_DEC:
00173       {
00174         IntSharedArray v(ivb.values());
00175         if (n != v.size())
00176           throw ArgumentSizeMismatch("Int::branch");
00177         for (int i=n; i--; )
00178           if ((v[i] < 0) || (v[i] > 1))
00179             throw OutOfLimits("Int::branch");
00180         switch (ivb.select()) {
00181         case IntValBranch::SEL_NEAR_MIN:
00182           return new (home) 
00183             ValSelCommit<ValSelNearMinMax<BoolView,true>,
00184              ValCommitEq<BoolView> >(home,ivb);
00185         case IntValBranch::SEL_NEAR_MAX:
00186           return new (home) 
00187             ValSelCommit<ValSelNearMinMax<BoolView,false>,
00188              ValCommitEq<BoolView> >(home,ivb);
00189         case IntValBranch::SEL_NEAR_INC:
00190           return new (home) 
00191             ValSelCommit<ValSelNearIncDec<BoolView,true>,
00192              ValCommitEq<BoolView> >(home,ivb);
00193         case IntValBranch::SEL_NEAR_DEC:
00194           return new (home) 
00195             ValSelCommit<ValSelNearIncDec<BoolView,false>,
00196              ValCommitEq<BoolView> >(home,ivb);
00197         default: GECODE_NEVER;
00198         }
00199       }
00200     default:
00201       throw UnknownBranching("Int::branch");
00202     }
00203   }
00204 
00205   ValSelCommitBase<BoolView,int>* 
00206   valselcommitbool(Space& home, const IntAssign& ia) {
00207     switch (ia.select()) {
00208     case IntAssign::SEL_MIN:
00209       return new (home) 
00210         ValSelCommit<ValSelMin<BoolView>,ValCommitEq<BoolView> >(home,ia);
00211     case IntAssign::SEL_MED:
00212       return new (home) 
00213         ValSelCommit<ValSelMed<BoolView>,ValCommitEq<BoolView> >(home,ia);
00214     case IntAssign::SEL_MAX:
00215       return new (home) 
00216         ValSelCommit<ValSelMax<BoolView>,ValCommitEq<BoolView> >(home,ia);
00217     case IntAssign::SEL_RND:
00218       return new (home) 
00219         ValSelCommit<ValSelRnd<BoolView>,ValCommitEq<BoolView> >(home,ia);
00220     case IntAssign::SEL_VAL_COMMIT:
00221       if (ia.commit() == NULL) {
00222         return new (home) 
00223           ValSelCommit<ValSelFunction<BoolView>,ValCommitEq<BoolView> >(home,ia);
00224       } else {
00225         return new (home) 
00226           ValSelCommit<ValSelFunction<BoolView>,ValCommitFunction<BoolView> >(home,ia);
00227       }
00228     default:
00229       throw UnknownBranching("Bool::assign");
00230     }
00231   }
00232 
00233 }}}
00234 
00235 
00236 // STATISTICS: int-branch
00237