Generated on Sat Feb 7 2015 02:01:23 for Gecode by doxygen 1.8.9.1
idx-view.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Contributing authors:
7  * Guido Tack <tack@gecode.org>
8  *
9  * Copyright:
10  * Christian Schulte, 2004
11  * Guido Tack, 2004
12  *
13  * Last modified:
14  * $Date: 2015-01-16 14:10:48 +0100 (Fri, 16 Jan 2015) $ by $Author: schulte $
15  * $Revision: 14362 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 namespace Gecode { namespace Int {
43 
45  template<>
47  public:
49  };
51  template<>
53  public:
55  };
57  template<>
59  public:
61  };
62 
63  template<class View>
66  return home.alloc<IdxView<View> >(n);
67  }
68 
69  template<class View>
71  IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
72 
73  template<class View>
76  n = a.n; xs = a.xs;
77  }
78 
79  template<class View>
82  const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
83  n = xa.size();
84  if (n>0) {
85  xs = IdxView<View>::allocate(home, n);
86  for (int i = n; i--; ) {
87  xs[i].idx = i; xs[i].view = xa[i];
88  }
89  }
90  }
91 
92  template<class View>
94  IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
95  n = n0;
96  if (n>0) {
97  xs = IdxView<View>::allocate(home, n);
98  }
99  }
100 
101  template<class View>
102  forceinline int
104  return n;
105  }
106 
107  template<class View>
108  forceinline void
110  n = n0;
111  }
112 
113  template<class View>
116  assert((i >= 0) && (i < size()));
117  return xs[i];
118  }
119 
120  template<class View>
123  assert((i >= 0) && (i < size()));
124  return xs[i];
125  }
126 
127  template<class View>
128  forceinline void
130  bool process) {
131  for (int i = n; i--; )
132  xs[i].view.subscribe(home,p,pc,process);
133  }
134 
135  template<class View>
136  forceinline void
138  for (int i = n; i--; )
139  xs[i].view.cancel(home,p,pc);
140  }
141 
142  template<class View>
143  forceinline void
145  n = a.size();
146  if (n>0) {
147  xs = IdxView<View>::allocate(home,n);
148  for (int i=n; i--; ) {
149  xs[i].idx = a[i].idx;
150  xs[i].view.update(home,share,a[i].view);
151  }
152  }
153  }
154 
155 
156  template<class Char, class Traits, class View>
157  std::basic_ostream<Char,Traits>&
158  operator <<(std::basic_ostream<Char,Traits>& os,
159  const IdxViewArray<View>& x) {
160  std::basic_ostringstream<Char,Traits> s;
161  s.copyfmt(os); s.width(0);
162  s << '{';
163  if (x.size() > 0) {
164  s << x[0].idx << ':' << x[0].view;
165  for (int i=1; i<x.size(); i++)
166  s << ", " << x[i].idx << ':' << x[i].view;
167  }
168  s << '}';
169  return os << s.str();
170  }
171 
172 }}
173 
174 // STATISTICS: int-prop
175 
IdxView< View > & operator[](int n)
Access element n.
Definition: idx-view.hpp:115
Base-class for propagators.
Definition: core.hpp:755
static IdxView * allocate(Space &home, int n)
Allocate memory for n index-view pairs.
Definition: idx-view.hpp:65
Computation spaces.
Definition: core.hpp:1362
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition: core.hpp:2397
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
void cancel(Space &home, Propagator &p, PropCond pc)
Definition: idx-view.hpp:137
int PropCond
Type for propagation conditions.
Definition: core.hpp:156
unsigned int size(I &i)
Size of all ranges of range iterator i.
Passing integer variables.
Definition: int.hh:636
Passing Boolean variables.
Definition: int.hh:690
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
void subscribe(Space &home, Propagator &p, PropCond pc, bool process=true)
Definition: idx-view.hpp:129
Minus integer view.
Definition: view.hpp:276
#define forceinline
Definition: config.hpp:132
IdxViewArray(void)
Default constructor.
Definition: idx-view.hpp:71
An array of IdxView pairs.
Definition: idx-view.hh:71
Gecode toplevel namespace
Class to map VarArg type to view.
Definition: idx-view.hh:64
Class for pair of index and view.
Definition: idx-view.hh:52
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
int size(void) const
Return the current size.
Definition: idx-view.hpp:103
void update(Space &home, bool share, IdxViewArray< View > &x)
Cloning.
Definition: idx-view.hpp:144
Boolean view for Boolean variables.
Definition: view.hpp:1315