node.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, 2003 00008 * 00009 * This file is part of Gecode, the generic constraint 00010 * development environment: 00011 * http://www.gecode.org 00012 * 00013 * Permission is hereby granted, free of charge, to any person obtaining 00014 * a copy of this software and associated documentation files (the 00015 * "Software"), to deal in the Software without restriction, including 00016 * without limitation the rights to use, copy, modify, merge, publish, 00017 * distribute, sublicense, and/or sell copies of the Software, and to 00018 * permit persons to whom the Software is furnished to do so, subject to 00019 * the following conditions: 00020 * 00021 * The above copyright notice and this permission notice shall be 00022 * included in all copies or substantial portions of the Software. 00023 * 00024 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00025 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00026 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00027 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00028 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00029 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00030 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00031 * 00032 */ 00033 00034 namespace Gecode { namespace Int { namespace ViewValGraph { 00035 00036 /* 00037 * Nodes 00038 * 00039 */ 00040 00041 template<class View> 00042 forceinline 00043 Node<View>::Node(void) : min(0) { 00044 // Must be initialized such that the node is considered unvisited initially 00045 } 00046 template<class View> 00047 forceinline Edge<View>* 00048 Node<View>::edge_fst(void) const { 00049 return static_cast<Edge<View>*>(BiLink::next()); 00050 } 00051 template<class View> 00052 forceinline Edge<View>* 00053 Node<View>::edge_lst(void) const { 00054 return static_cast<Edge<View>*>(static_cast<BiLink*>(const_cast<Node<View>*>(this))); 00055 } 00056 template<class View> 00057 forceinline void 00058 Node<View>::operator delete(void*, size_t) {} 00059 template<class View> 00060 forceinline void 00061 Node<View>::operator delete(void*,Space&) {} 00062 template<class View> 00063 forceinline void* 00064 Node<View>::operator new(size_t s, Space& home) { 00065 return home.ralloc(s); 00066 } 00067 00068 /* 00069 * Value nodes 00070 * 00071 */ 00072 00073 00074 template<class View> 00075 forceinline 00076 ValNode<View>::ValNode(int v) 00077 : _val(v), _matching(NULL) {} 00078 template<class View> 00079 forceinline 00080 ValNode<View>::ValNode(int v, ValNode<View>* n) 00081 : _val(v), _matching(NULL), _next_val(n) {} 00082 template<class View> 00083 forceinline int 00084 ValNode<View>::val(void) const { 00085 return _val; 00086 } 00087 template<class View> 00088 forceinline void 00089 ValNode<View>::matching(Edge<View>* m) { 00090 _matching = m; 00091 } 00092 template<class View> 00093 forceinline Edge<View>* 00094 ValNode<View>::matching(void) const { 00095 return _matching; 00096 } 00097 template<class View> 00098 forceinline ValNode<View>** 00099 ValNode<View>::next_val_ref(void) { 00100 return &_next_val; 00101 } 00102 template<class View> 00103 forceinline ValNode<View>* 00104 ValNode<View>::next_val(void) const { 00105 return _next_val; 00106 } 00107 template<class View> 00108 forceinline void 00109 ValNode<View>::next_val(ValNode<View>* n) { 00110 _next_val = n; 00111 } 00112 00113 00114 00115 /* 00116 * View nodes 00117 * 00118 */ 00119 00120 template<class View> 00121 forceinline 00122 ViewNode<View>::ViewNode(void) 00123 : _view(View(NULL)) {} 00124 template<class View> 00125 forceinline 00126 ViewNode<View>::ViewNode(View x) 00127 : _size(x.size()), _view(x) {} 00128 template<class View> 00129 forceinline Edge<View>* 00130 ViewNode<View>::val_edges(void) const { 00131 return _val_edges; 00132 } 00133 template<class View> 00134 forceinline Edge<View>** 00135 ViewNode<View>::val_edges_ref(void) { 00136 return &_val_edges; 00137 } 00138 template<class View> 00139 forceinline bool 00140 ViewNode<View>::fake(void) const { 00141 return _view.varimp() == NULL; 00142 } 00143 template<class View> 00144 forceinline View 00145 ViewNode<View>::view(void) const { 00146 return _view; 00147 } 00148 template<class View> 00149 forceinline bool 00150 ViewNode<View>::changed(void) const { 00151 return _size != _view.size(); 00152 } 00153 template<class View> 00154 forceinline void 00155 ViewNode<View>::update(void) { 00156 _size = _view.size(); 00157 } 00158 template<class View> 00159 forceinline bool 00160 ViewNode<View>::matched(void) const { 00161 return Node<View>::edge_fst() != Node<View>::edge_lst(); 00162 } 00163 00164 }}} 00165 00166 // STATISTICS: int-prop 00167