Generated on Mon Aug 25 11:35:33 2008 for Gecode by doxygen 1.5.6

select-view.icc

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, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-18 05:36:02 +0100 (Mon, 18 Feb 2008) $ by $Author: schulte $
00011  *     $Revision: 6194 $
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 namespace Gecode { namespace Int { namespace Branch {
00039 
00040   // Select first variable
00041   template<class View>
00042   forceinline ViewSelStatus
00043   ByNone<View>::init(const Space*, View) {
00044     return VSS_COMMIT;
00045   }
00046   template<class View>
00047   forceinline ViewSelStatus
00048   ByNone<View>::select(const Space*, View) {
00049     GECODE_NEVER;
00050     return VSS_NONE;
00051   }
00052   template<class View>
00053   inline Support::Symbol
00054   ByNone<View>::type(void) {
00055     return Support::Symbol("Gecode::Int::Branch::ByNone");
00056   }
00057 
00058   // Select variable with smallest min
00059   template<class View>
00060   forceinline ViewSelStatus
00061   ByMinMin<View>::init(const Space*, View x) {
00062     min = x.min();
00063     return VSS_SELECT;
00064   }
00065   template<class View>
00066   forceinline ViewSelStatus
00067   ByMinMin<View>::select(const Space*, View x) {
00068     if (x.min() < min) {
00069       min = x.min(); return VSS_SELECT;
00070     }
00071     return VSS_NONE;
00072   }
00073   template<class View>
00074   inline Support::Symbol
00075   ByMinMin<View>::type(void) {
00076     return Support::Symbol("Gecode::Int::Branch::ByMinMin");
00077   }
00078 
00079   // Select variable with largest min
00080   template<class View>
00081   forceinline ViewSelStatus
00082   ByMinMax<View>::init(const Space*, View x) {
00083     min = x.min();
00084     return VSS_SELECT;
00085   }
00086   template<class View>
00087   forceinline ViewSelStatus
00088   ByMinMax<View>::select(const Space*, View x) {
00089     if (x.min() > min) {
00090       min = x.min(); return VSS_SELECT;
00091     }
00092     return VSS_NONE;
00093   }
00094   template<class View>
00095   inline Support::Symbol
00096   ByMinMax<View>::type(void) {
00097     return Support::Symbol("Gecode::Int::Branch::ByMinMax");
00098   }
00099 
00100   // Select variable with smallest max
00101   template<class View>
00102   forceinline ViewSelStatus
00103   ByMaxMin<View>::init(const Space*, View x) {
00104     max = x.max();
00105     return VSS_SELECT;
00106   }
00107   template<class View>
00108   forceinline ViewSelStatus
00109   ByMaxMin<View>::select(const Space*, View x) {
00110     if (x.max() < max) {
00111       max = x.max(); return VSS_SELECT;
00112     }
00113     return VSS_NONE;
00114   }
00115   template<class View>
00116   inline Support::Symbol
00117   ByMaxMin<View>::type(void) {
00118     return Support::Symbol("Gecode::Int::Branch::ByMaxMin");
00119   }
00120 
00121   // Select variable with largest max
00122   template<class View>
00123   forceinline ViewSelStatus
00124   ByMaxMax<View>::init(const Space*, View x) {
00125     max = x.max();
00126     return VSS_SELECT;
00127   }
00128   template<class View>
00129   forceinline ViewSelStatus
00130   ByMaxMax<View>::select(const Space*, View x) {
00131     if (x.max() > max) {
00132       max = x.max(); return VSS_SELECT;
00133     }
00134     return VSS_NONE;
00135   }
00136   template<class View>
00137   inline Support::Symbol
00138   ByMaxMax<View>::type(void) {
00139     return Support::Symbol("Gecode::Int::Branch::ByMaxMax");
00140   }
00141 
00142   // Select variable with smallest size
00143   template<class View>
00144   forceinline ViewSelStatus
00145   BySizeMin<View>::init(const Space*, View x) {
00146     size = x.size();
00147     return (size == 2) ? VSS_COMMIT : VSS_SELECT;
00148   }
00149   template<class View>
00150   forceinline ViewSelStatus
00151   BySizeMin<View>::select(const Space*, View x) {
00152     if (x.size() < size) {
00153       size = x.size();
00154       return (size == 2) ? VSS_COMMIT : VSS_SELECT;
00155     }
00156     return VSS_NONE;
00157   }
00158   template<class View>
00159   inline Support::Symbol
00160   BySizeMin<View>::type(void) {
00161     return Support::Symbol("Gecode::Int::Branch::BySizeMin");
00162   }
00163 
00164   // Select variable with largest size
00165   template<class View>
00166   forceinline ViewSelStatus
00167   BySizeMax<View>::init(const Space*, View x) {
00168     size = x.size();
00169     return VSS_SELECT;
00170   }
00171   template<class View>
00172   forceinline ViewSelStatus
00173   BySizeMax<View>::select(const Space*, View x) {
00174     if (x.size() > size) {
00175       size = x.size(); return VSS_SELECT;
00176     }
00177     return VSS_NONE;
00178   }
00179   template<class View>
00180   inline Support::Symbol
00181   BySizeMax<View>::type(void) {
00182     return Support::Symbol("Gecode::Int::Branch::BySizeMax");
00183   }
00184 
00185   // Select variable with smallest degree (and smallest size in case of ties)
00186   template<class View>
00187   forceinline ViewSelStatus
00188   ByDegreeMin<View>::init(const Space*, View x) {
00189     degree = x.degree(); size = x.size();
00190     return VSS_SELECT;
00191   }
00192   template<class View>
00193   forceinline ViewSelStatus
00194   ByDegreeMin<View>::select(const Space*, View x) {
00195     if (x.degree() < degree) {
00196       degree = x.degree();
00197       size   = x.size();
00198       return VSS_SELECT;
00199     } else if ((x.degree() == degree) && (x.size() < size)) {
00200       size = x.size();
00201       return VSS_SELECT;
00202     }
00203     return VSS_NONE;
00204   }
00205   template<class View>
00206   inline Support::Symbol
00207   ByDegreeMin<View>::type(void) {
00208     return Support::Symbol("Gecode::Int::Branch::ByDegreeMin");
00209   }
00210 
00211   // Select variable with smallest degree (and smallest size in case of ties)
00212   template<class View>
00213   forceinline ViewSelStatus
00214   ByDegreeMax<View>::init(const Space*, View x) {
00215     degree = x.degree(); size = x.size();
00216     return VSS_SELECT;
00217   }
00218   template<class View>
00219   forceinline ViewSelStatus
00220   ByDegreeMax<View>::select(const Space*, View x) {
00221     if (x.degree() > degree) {
00222       degree = x.degree();
00223       size   = x.size();
00224       return VSS_SELECT;
00225     } else if ((x.degree() == degree) && (x.size() < size)) {
00226       size = x.size();
00227       return VSS_SELECT;
00228     }
00229     return VSS_NONE;
00230   }
00231   template<class View>
00232   inline Support::Symbol
00233   ByDegreeMax<View>::type(void) {
00234     return Support::Symbol("Gecode::Int::Branch::ByDegreeMax");
00235   }
00236 
00237 
00238   // Select variable with smallest degree
00239   template<class View>
00240   forceinline ViewSelStatus
00241   ByDegreeMinNoTies<View>::init(const Space*, View x) {
00242     degree = x.degree();
00243     return (degree == 0) ? VSS_COMMIT : VSS_SELECT;
00244   }
00245   template<class View>
00246   forceinline ViewSelStatus
00247   ByDegreeMinNoTies<View>::select(const Space*, View x) {
00248     if (x.degree() < degree) {
00249       degree = x.degree();
00250       return (degree == 0) ? VSS_COMMIT : VSS_SELECT;
00251     }
00252     return VSS_NONE;
00253   }
00254   template<class View>
00255   inline Support::Symbol
00256   ByDegreeMinNoTies<View>::type(void) {
00257     return Support::Symbol("Gecode::Int::Branch::ByDegreeMinNoTies");
00258   }
00259 
00260   // Select variable with smallest degree
00261   template<class View>
00262   forceinline ViewSelStatus
00263   ByDegreeMaxNoTies<View>::init(const Space*, View x) {
00264     degree = x.degree();
00265     return VSS_SELECT;
00266   }
00267   template<class View>
00268   forceinline ViewSelStatus
00269   ByDegreeMaxNoTies<View>::select(const Space*, View x) {
00270     if (x.degree() > degree) {
00271       degree = x.degree(); return VSS_SELECT;
00272     }
00273     return VSS_NONE;
00274   }
00275   template<class View>
00276   inline Support::Symbol
00277   ByDegreeMaxNoTies<View>::type(void) {
00278     return Support::Symbol("Gecode::Int::Branch::ByDegreeMaxNoTies");
00279   }
00280 
00281 
00282   // Select variable with smallest size/degree
00283   template<class View>
00284   forceinline ViewSelStatus
00285   BySizeDegreeMin<View>::init(const Space*, View x) {
00286     sizedegree = 
00287       static_cast<double>(x.size())/static_cast<double>(x.degree());
00288     return VSS_SELECT;
00289   }
00290   template<class View>
00291   forceinline ViewSelStatus
00292   BySizeDegreeMin<View>::select(const Space*, View x) {
00293     double sd = 
00294       static_cast<double>(x.size())/static_cast<double>(x.degree());
00295     if (sd < sizedegree) {
00296       sizedegree = sd;
00297       return VSS_SELECT;
00298     }
00299     return VSS_NONE;
00300   }
00301   template<class View>
00302   inline Support::Symbol
00303   BySizeDegreeMin<View>::type(void) {
00304     return Support::Symbol("Gecode::Int::Branch::BySizeDegreeMin");
00305   }
00306 
00307   // Select variable with largest size/degree
00308   template<class View>
00309   forceinline ViewSelStatus
00310   BySizeDegreeMax<View>::init(const Space*, View x) {
00311     sizedegree = 
00312       static_cast<double>(x.size())/static_cast<double>(x.degree());
00313     return VSS_SELECT;
00314   }
00315   template<class View>
00316   forceinline ViewSelStatus
00317   BySizeDegreeMax<View>::select(const Space*, View x) {
00318     double sd = 
00319       static_cast<double>(x.size())/static_cast<double>(x.degree());
00320     if (sd > sizedegree) {
00321       sizedegree = sd; 
00322       return VSS_SELECT;
00323     }
00324     return VSS_NONE;
00325   }
00326   template<class View>
00327   inline Support::Symbol
00328   BySizeDegreeMax<View>::type(void) {
00329     return Support::Symbol("Gecode::Int::Branch::BySizeDegreeMax");
00330   }
00331 
00332   // Select variable with smallest min-regret
00333   template<class View>
00334   forceinline ViewSelStatus
00335   ByRegretMinMin<View>::init(const Space*, View x) {
00336     regret = x.regret_min();
00337     return (regret == 1) ? VSS_COMMIT : VSS_SELECT;
00338   }
00339   template<class View>
00340   forceinline ViewSelStatus
00341   ByRegretMinMin<View>::select(const Space*, View x) {
00342     if (x.regret_min() < regret) {
00343       regret = x.regret_min();
00344       return (regret == 1) ? VSS_COMMIT : VSS_SELECT;
00345     }
00346     return VSS_NONE;
00347   }
00348   template<class View>
00349   inline Support::Symbol
00350   ByRegretMinMin<View>::type(void) {
00351     return Support::Symbol("Gecode::Int::Branch::ByRegretMinMin");
00352   }
00353 
00354   // Select variable with largest min-regret
00355   template<class View>
00356   forceinline ViewSelStatus
00357   ByRegretMinMax<View>::init(const Space*, View x) {
00358     regret = x.regret_min();
00359     return VSS_SELECT;
00360   }
00361   template<class View>
00362   forceinline ViewSelStatus
00363   ByRegretMinMax<View>::select(const Space*, View x) {
00364     if (x.regret_min() > regret) {
00365       regret = x.regret_min(); return VSS_SELECT;
00366     }
00367     return VSS_NONE;
00368   }
00369   template<class View>
00370   inline Support::Symbol
00371   ByRegretMinMax<View>::type(void) {
00372     return Support::Symbol("Gecode::Int::Branch::ByRegretMinMax");
00373   }
00374 
00375   // Select variable with smallest max-regret
00376   template<class View>
00377   forceinline ViewSelStatus
00378   ByRegretMaxMin<View>::init(const Space*, View x) {
00379     regret = x.regret_max();
00380     return (regret == 1) ? VSS_COMMIT : VSS_SELECT;
00381   }
00382   template<class View>
00383   forceinline ViewSelStatus
00384   ByRegretMaxMin<View>::select(const Space*, View x) {
00385     if (x.regret_max() < regret) {
00386       regret = x.regret_max();
00387       return (regret == 1) ? VSS_COMMIT : VSS_SELECT;
00388     }
00389     return VSS_NONE;
00390   }
00391   template<class View>
00392   inline Support::Symbol
00393   ByRegretMaxMin<View>::type(void) {
00394     return Support::Symbol("Gecode::Int::Branch::ByRegretMaxMin");
00395   }
00396 
00397   // Select variable with smallest min-regret
00398   template<class View>
00399   forceinline ViewSelStatus
00400   ByRegretMaxMax<View>::init(const Space*, View x) {
00401     regret = x.regret_max();
00402     return VSS_SELECT;
00403   }
00404   template<class View>
00405   forceinline ViewSelStatus
00406   ByRegretMaxMax<View>::select(const Space*, View x) {
00407     if (x.regret_max() > regret) {
00408       regret = x.regret_max(); return VSS_SELECT;
00409     }
00410     return VSS_NONE;
00411   }
00412   template<class View>
00413   inline Support::Symbol
00414   ByRegretMaxMax<View>::type(void) {
00415     return Support::Symbol("Gecode::Int::Branch::ByRegretMaxMax");
00416   }
00417 
00418 }}}
00419 
00420 // STATISTICS: int-branch
00421