view-val-graph.hh
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef __GECODE_INT_VIEW_VAL_GRAPH_HH__
00041 #define __GECODE_INT_VIEW_VAL_GRAPH_HH__
00042
00043 #include <gecode/int.hh>
00044
00049 namespace Gecode { namespace Int { namespace ViewValGraph {
00050
00057 template<class T>
00058 class CombPtrFlag {
00059 private:
00061 ptrdiff_t cpf;
00062 public:
00064 CombPtrFlag(T* p1, T* p2);
00066 void init(T* p1, T* p2);
00068 T* ptr(T* p) const;
00070 int is_set(void) const;
00072 void set(void);
00074 void unset(void);
00075 };
00076
00078 class BiLink {
00079 private:
00081 BiLink* _prev;
00083 BiLink* _next;
00084 public:
00086 BiLink(void);
00088 BiLink* prev(void) const;
00090 BiLink* next(void) const;
00092 void prev(BiLink* l);
00094 void next(BiLink* l);
00096 void add(BiLink* l);
00098 void unlink(void);
00100 void mark(void);
00102 bool marked(void) const;
00104 bool empty(void) const;
00105 };
00106
00107
00108 template<class View> class Edge;
00109
00119 template<class View>
00120 class Node : public BiLink {
00121 public:
00123 Edge<View>* iter;
00125 unsigned int low, min, comp;
00127 Node(void);
00129 Edge<View>* edge_fst(void) const;
00131 Edge<View>* edge_lst(void) const;
00132
00134 static void* operator new(size_t, Space&);
00136 static void operator delete(void*, size_t);
00138 static void operator delete(void*,Space&);
00139 };
00140
00145 template<class View>
00146 class ValNode : public Node<View> {
00147 protected:
00149 const int _val;
00151 Edge<View>* _matching;
00153 ValNode<View>* _next_val;
00154 public:
00156 ValNode(int v);
00158 ValNode(int v, ValNode<View>* n);
00160 int val(void) const;
00162 void matching(Edge<View>* m);
00164 Edge<View>* matching(void) const;
00166 ValNode<View>** next_val_ref(void);
00168 ValNode<View>* next_val(void) const;
00170 void next_val(ValNode<View>* v);
00171 };
00172
00177 template<class View>
00178 class ViewNode : public Node<View> {
00179 protected:
00181 unsigned int _size;
00183 View _view;
00185 Edge<View>* _val_edges;
00186 public:
00188 ViewNode(void);
00190 ViewNode(View x);
00192 Edge<View>* val_edges(void) const;
00194 Edge<View>** val_edges_ref(void);
00196 bool fake(void) const;
00198 View view(void) const;
00200 void update(void);
00202 bool changed(void) const;
00204 bool matched(void) const;
00205 };
00206
00211 template<class View>
00212 class Edge : public BiLink {
00213 protected:
00215 Edge<View>* _next_edge;
00217 CombPtrFlag<Node<View> > sd;
00218 public:
00220 Edge(ValNode<View>* v, ViewNode<View>* x);
00222 Edge(ValNode<View>* v, ViewNode<View>* x, Edge<View>* n);
00224 Node<View>* dst(Node<View>* s) const;
00225
00227 ViewNode<View>* view(ValNode<View>* v) const;
00229 ValNode<View>* val(ViewNode<View>* x) const;
00230
00232 bool used(Node<View>* v) const;
00234 void use(void);
00236 void free(void);
00237
00239 void revert(Node<View>* d);
00240
00242 Edge<View>* next_edge(void) const;
00244 Edge<View>** next_edge_ref(void);
00246 Edge<View>* next(void) const;
00247
00249 static void* operator new(size_t, Space&);
00251 static void operator delete(void*, size_t);
00253 static void operator delete(void*,Space&);
00254 };
00255
00257 template<class View>
00258 class IterPruneVal {
00259 protected:
00261 ViewNode<View>* x;
00263 Edge<View>* e;
00264 public:
00266
00267
00268 IterPruneVal(ViewNode<View>* x);
00270
00272
00273
00274 bool operator ()(void) const;
00276 void operator ++(void);
00278
00280
00281
00282 int val(void) const;
00284 };
00285
00286 }}}
00287
00288 #include <gecode/int/view-val-graph/comb-ptr-flag.hpp>
00289 #include <gecode/int/view-val-graph/bi-link.hpp>
00290 #include <gecode/int/view-val-graph/edge.hpp>
00291 #include <gecode/int/view-val-graph/node.hpp>
00292 #include <gecode/int/view-val-graph/iter-prune-val.hpp>
00293
00294 namespace Gecode { namespace Int { namespace ViewValGraph {
00295
00297 template<class View>
00298 class Graph {
00299 protected:
00301 ViewNode<View>** view;
00303 ValNode<View>* val;
00305 int n_view;
00307 int n_val;
00309 unsigned int count;
00311 typedef Support::StaticStack<ViewNode<View>*,Region> ViewNodeStack;
00313 void init(Space& home, ViewNode<View>* x);
00315 bool match(ViewNodeStack& m, ViewNode<View>* x);
00317 void scc(Space& home);
00318 public:
00320 Graph(void);
00322 bool initialized(void) const;
00324 void purge(void);
00325 };
00326
00327 }}}
00328
00329 #include <gecode/int/view-val-graph/graph.hpp>
00330
00331 #endif
00332
00333
00334