Generated on Thu Mar 22 10:39:41 2012 for Gecode by doxygen 1.6.3

view-val-graph.hh

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  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Guido Tack, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2011-09-08 14:34:40 +0200 (Thu, 08 Sep 2011) $ by $Author: schulte $
00013  *     $Revision: 12395 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: int-prop
00334