Generated on Fri Jan 10 2020 11:38:25 for Gecode by doxygen 1.8.16
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  };
59  template<>
61  public:
63  };
64 
65  template<class View>
68  return home.alloc<IdxView<View> >(n);
69  }
70 
71  template<class View>
73  IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
74 
75  template<class View>
78  n = a.n; xs = a.xs;
79  }
80 
81  template<class View>
84  const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
85  n = xa.size();
86  if (n>0) {
87  xs = IdxView<View>::allocate(home, n);
88  for (int i=0; i<n; i++) {
89  xs[i].idx = i; xs[i].view = xa[i];
90  }
91  }
92  }
93 
94  template<class View>
96  IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
97  n = n0;
98  if (n>0) {
99  xs = IdxView<View>::allocate(home, n);
100  }
101  }
102 
103  template<class View>
104  forceinline int
106  return n;
107  }
108 
109  template<class View>
110  forceinline void
112  n = n0;
113  }
114 
115  template<class View>
118  assert((i >= 0) && (i < size()));
119  return xs[i];
120  }
121 
122  template<class View>
125  assert((i >= 0) && (i < size()));
126  return xs[i];
127  }
128 
129  template<class View>
130  forceinline void
132  bool process) {
133  for (int i=0; i<n; i++)
134  xs[i].view.subscribe(home,p,pc,process);
135  }
136 
137  template<class View>
138  forceinline void
140  for (int i=0; i<n; i++)
141  xs[i].view.cancel(home,p,pc);
142  }
143 
144  template<class View>
145  forceinline void
147  for (int i=0; i<n; i++)
148  xs[i].view.reschedule(home,p,pc);
149  }
150 
151  template<class View>
152  forceinline void
154  n = a.size();
155  if (n>0) {
156  xs = IdxView<View>::allocate(home,n);
157  for (int i=0; i<n; i++) {
158  xs[i].idx = a[i].idx;
159  xs[i].view.update(home,a[i].view);
160  }
161  }
162  }
163 
164 
165  template<class Char, class Traits, class View>
166  std::basic_ostream<Char,Traits>&
167  operator <<(std::basic_ostream<Char,Traits>& os,
168  const IdxViewArray<View>& x) {
169  std::basic_ostringstream<Char,Traits> s;
170  s.copyfmt(os); s.width(0);
171  s << '{';
172  if (x.size() > 0) {
173  s << x[0].idx << ':' << x[0].view;
174  for (int i=1; i<x.size(); i++)
175  s << ", " << x[i].idx << ':' << x[i].view;
176  }
177  s << '}';
178  return os << s.str();
179  }
180 
181 }}
182 
183 // STATISTICS: int-prop
184 
Negated Boolean view.
Definition: view.hpp:1574
An array of IdxView pairs.
Definition: idx-view.hh:67
static IdxView * allocate(Space &home, int n)
Allocate memory for n index-view pairs.
Definition: idx-view.hpp:67
Passing integer variables.
Definition: int.hh:656
unsigned int size(I &i)
Size of all ranges of range iterator i.
Minus integer view.
Definition: view.hpp:282
Class to map VarArg type to view.
Definition: idx-view.hh:60
Computation spaces.
Definition: core.hpp:1742
Boolean view for Boolean variables.
Definition: view.hpp:1380
Gecode toplevel namespace
Base-class for propagators.
Definition: core.hpp:1064
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const FloatView &x)
Print float variable view.
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
Passing Boolean variables.
Definition: int.hh:712
IntVarArgs argtype
Definition: idx-view.hpp:50
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition: core.hpp:2837
BoolVarArgs argtype
Definition: idx-view.hpp:62
IntVarArgs argtype
Definition: idx-view.hpp:44
int PropCond
Type for propagation conditions.
Definition: core.hpp:72
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
IdxViewArray(void)
Default constructor.
Definition: idx-view.hpp:73
Integer view for integer variables.
Definition: view.hpp:129
BoolVarArgs argtype
Definition: idx-view.hpp:56
#define forceinline
Definition: config.hpp:185
Class for pair of index and view.
Definition: idx-view.hh:48
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:71
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232