Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
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  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Int {
39 
41  template<>
43  public:
45  };
47  template<>
49  public:
51  };
53  template<>
55  public:
57  };
58 
59  template<class View>
62  return home.alloc<IdxView<View> >(n);
63  }
64 
65  template<class View>
67  IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
68 
69  template<class View>
72  n = a.n; xs = a.xs;
73  }
74 
75  template<class View>
78  const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
79  n = xa.size();
80  if (n>0) {
81  xs = IdxView<View>::allocate(home, n);
82  for (int i=0; i<n; i++) {
83  xs[i].idx = i; xs[i].view = xa[i];
84  }
85  }
86  }
87 
88  template<class View>
90  IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
91  n = n0;
92  if (n>0) {
93  xs = IdxView<View>::allocate(home, n);
94  }
95  }
96 
97  template<class View>
98  forceinline int
100  return n;
101  }
102 
103  template<class View>
104  forceinline void
106  n = n0;
107  }
108 
109  template<class View>
112  assert((i >= 0) && (i < size()));
113  return xs[i];
114  }
115 
116  template<class View>
119  assert((i >= 0) && (i < size()));
120  return xs[i];
121  }
122 
123  template<class View>
124  forceinline void
126  bool process) {
127  for (int i=0; i<n; i++)
128  xs[i].view.subscribe(home,p,pc,process);
129  }
130 
131  template<class View>
132  forceinline void
134  for (int i=0; i<n; i++)
135  xs[i].view.cancel(home,p,pc);
136  }
137 
138  template<class View>
139  forceinline void
141  for (int i=0; i<n; i++)
142  xs[i].view.reschedule(home,p,pc);
143  }
144 
145  template<class View>
146  forceinline void
148  n = a.size();
149  if (n>0) {
150  xs = IdxView<View>::allocate(home,n);
151  for (int i=0; i<n; i++) {
152  xs[i].idx = a[i].idx;
153  xs[i].view.update(home,a[i].view);
154  }
155  }
156  }
157 
158 
159  template<class Char, class Traits, class View>
160  std::basic_ostream<Char,Traits>&
161  operator <<(std::basic_ostream<Char,Traits>& os,
162  const IdxViewArray<View>& x) {
163  std::basic_ostringstream<Char,Traits> s;
164  s.copyfmt(os); s.width(0);
165  s << '{';
166  if (x.size() > 0) {
167  s << x[0].idx << ':' << x[0].view;
168  for (int i=1; i<x.size(); i++)
169  s << ", " << x[i].idx << ':' << x[i].view;
170  }
171  s << '}';
172  return os << s.str();
173  }
174 
175 }}
176 
177 // STATISTICS: int-prop
178 
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
Base-class for propagators.
Definition: core.hpp:1023
void update(Space &home, IdxViewArray< View > &x)
Cloning.
Definition: idx-view.hpp:147
#define forceinline
Definition: config.hpp:185
static IdxView * allocate(Space &home, int n)
Allocate memory for n index-view pairs.
Definition: idx-view.hpp:61
Computation spaces.
Definition: core.hpp:1701
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition: core.hpp:2794
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})
int PropCond
Type for propagation conditions.
Definition: core.hpp:72
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:71
unsigned int size(I &i)
Size of all ranges of range iterator i.
int size(void) const
Return the current size.
Definition: idx-view.hpp:99
Passing integer variables.
Definition: int.hh:656
Passing Boolean variables.
Definition: int.hh:712
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
Minus integer view.
Definition: view.hpp:282
IdxViewArray(void)
Default constructor.
Definition: idx-view.hpp:67
An array of IdxView pairs.
Definition: idx-view.hh:67
Gecode toplevel namespace
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
Class to map VarArg type to view.
Definition: idx-view.hh:60
Class for pair of index and view.
Definition: idx-view.hh:48
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
Boolean view for Boolean variables.
Definition: view.hpp:1380