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

afc.hpp

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, 2013
00008  *
00009  *  Last modified:
00010  *     $Date: 2014-05-27 14:57:59 +0200 (Tue, 27 May 2014) $ by $Author: schulte $
00011  *     $Revision: 14124 $
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 {
00039 
00044   class AFC {
00045   protected:
00047     int n;
00048   public:
00050 
00051 
00058     AFC(void);
00060     AFC(const AFC& a);
00062     AFC& operator =(const AFC& a);
00064     template<class Var>
00065     AFC(Home home, const VarArgArray<Var>& x, double d);
00067     template<class Var>
00068     void init(Home home, const VarArgArray<Var>& x, double d);
00070     bool initialized(void) const;
00072     void set(Space& home, double a=1.0);
00074     GECODE_KERNEL_EXPORT static const AFC def;
00076 
00078 
00079 
00080     void update(Space& home, bool share, AFC& a);
00082     ~AFC(void);
00084     
00086 
00087 
00088     int size(void) const;
00090 
00092 
00093 
00094     void decay(Space& home, double d);
00096     double decay(const Space& home) const;
00098   };
00099 
00104   template<class Char, class Traits>
00105   std::basic_ostream<Char,Traits>&
00106   operator <<(std::basic_ostream<Char,Traits>& os,
00107              const AFC& a);
00108 
00109   /*
00110    * AFC
00111    *
00112    */
00113   forceinline int
00114   AFC::size(void) const {
00115     assert(n >= 0);
00116     return n;
00117   }
00118 
00119   forceinline
00120   AFC::AFC(void) : n(-1) {}
00121 
00122   forceinline bool
00123   AFC::initialized(void) const {
00124     return n >= 0;
00125   }
00126 
00127   template<class Var>
00128   forceinline
00129   AFC::AFC(Home home, const VarArgArray<Var>& x, double d) 
00130     : n(x.size()) {
00131     if ((d < 0.0) || (d > 1.0))
00132       throw IllegalDecay("AFC");
00133     static_cast<Space&>(home).afc_decay(d);
00134   }
00135   template<class Var>
00136   forceinline void
00137   AFC::init(Home home, const VarArgArray<Var>& x, double d) {
00138     n = x.size();
00139     if ((d < 0.0) || (d > 1.0))
00140       throw IllegalDecay("AFC");
00141     static_cast<Space&>(home).afc_decay(d);
00142   }
00143 
00144   
00145   forceinline
00146   AFC::AFC(const AFC& a)
00147     : n(a.n) {}
00148   forceinline AFC&
00149   AFC::operator =(const AFC& a) {
00150     n=a.n;
00151     return *this;
00152   }
00153   forceinline
00154   AFC::~AFC(void) {}
00155 
00156   forceinline void
00157   AFC::update(Space&, bool, AFC& a) {
00158     n=a.n;
00159   }
00160 
00161   forceinline void
00162   AFC::decay(Space& home, double d) {
00163     if ((d < 0.0) || (d > 1.0))
00164       throw IllegalDecay("AFC");
00165     home.afc_decay(d);
00166   }
00167 
00168   forceinline void
00169   AFC::set(Space& home, double a) {
00170     home.afc_set(a);
00171   }
00172 
00173   forceinline double
00174   AFC::decay(const Space& home) const {
00175     return home.afc_decay();
00176   }
00177 
00178 
00179   template<class Char, class Traits>
00180   std::basic_ostream<Char,Traits>&
00181   operator <<(std::basic_ostream<Char,Traits>& os,
00182               const AFC& a) {
00183     (void)a;
00184     return os << "AFC(no information available)";
00185   }
00186   
00187 }
00188 
00189 // STATISTICS: kernel-branch