var.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, 2008 00008 * 00009 * Last modified: 00010 * $Date: 2017-02-23 06:10:29 +0100 (Thu, 23 Feb 2017) $ by $Author: schulte $ 00011 * $Revision: 15476 $ 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 Var {}; 00045 00050 template<class VarImp> 00051 class VarImpVar : public Var { 00052 protected: 00054 VarImp* x; 00056 VarImpVar(void); 00058 VarImpVar(VarImp* y); 00059 public: 00061 typedef VarImp VarImpType; 00063 00064 00065 VarImp* varimp(void) const; 00067 unsigned int degree(void) const; 00069 double afc(void) const; 00071 00073 00074 00075 bool assigned(void) const; 00077 00079 00080 00081 void update(Space& home, bool share, VarImpVar<VarImp>& y); 00083 00085 00086 00087 bool same(const VarImpVar<VarImp>& y) const; 00089 bool before(const VarImpVar<VarImp>& y) const; 00091 }; 00092 00093 00094 /* 00095 * Variable: contains a pointer to a variable implementation 00096 * 00097 */ 00098 template<class VarImp> 00099 forceinline 00100 VarImpVar<VarImp>::VarImpVar(void) 00101 : x(NULL) {} 00102 template<class VarImp> 00103 forceinline 00104 VarImpVar<VarImp>::VarImpVar(VarImp* y) 00105 : x(y) {} 00106 template<class VarImp> 00107 forceinline VarImp* 00108 VarImpVar<VarImp>::varimp(void) const { 00109 return x; 00110 } 00111 template<class VarImp> 00112 forceinline unsigned int 00113 VarImpVar<VarImp>::degree(void) const { 00114 return x->degree(); 00115 } 00116 template<class VarImp> 00117 forceinline double 00118 VarImpVar<VarImp>::afc(void) const { 00119 return x->afc(); 00120 } 00121 template<class VarImp> 00122 forceinline bool 00123 VarImpVar<VarImp>::assigned(void) const { 00124 return x->assigned(); 00125 } 00126 template<class VarImp> 00127 forceinline void 00128 VarImpVar<VarImp>::update(Space& home, bool share, VarImpVar<VarImp>& y) { 00129 x = y.x->copy(home,share); 00130 } 00131 template<class VarImp> 00132 forceinline bool 00133 VarImpVar<VarImp>::same(const VarImpVar<VarImp>& y) const { 00134 return varimp() == y.varimp(); 00135 } 00136 template<class VarImp> 00137 forceinline bool 00138 VarImpVar<VarImp>::before(const VarImpVar<VarImp>& y) const { 00139 return varimp() < y.varimp(); 00140 } 00141 00142 } 00143 00144 // STATISTICS: kernel-var