Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
38namespace 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>
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 }
103 template<class View>
106 return n;
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
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Passing Boolean variables.
Definition int.hh:712
Passing integer variables.
Definition int.hh:656
Boolean view for Boolean variables.
Definition view.hpp:1380
An array of IdxView pairs.
Definition idx-view.hh:67
IdxView< View > & operator[](int n)
Access element n.
Definition idx-view.hpp:117
void subscribe(Space &home, Propagator &p, PropCond pc, bool process=true)
Definition idx-view.hpp:131
void reschedule(Space &home, Propagator &p, PropCond pc)
Schedule propagator p.
Definition idx-view.hpp:146
IdxViewArray(void)
Default constructor.
Definition idx-view.hpp:73
void update(Space &home, IdxViewArray< View > &x)
Cloning.
Definition idx-view.hpp:153
void cancel(Space &home, Propagator &p, PropCond pc)
Definition idx-view.hpp:139
int size(void) const
Return the current size.
Definition idx-view.hpp:105
Class for pair of index and view.
Definition idx-view.hh:48
static IdxView * allocate(Space &home, int n)
Allocate memory for n index-view pairs.
Definition idx-view.hpp:67
Integer view for integer variables.
Definition view.hpp:129
Minus integer view.
Definition view.hpp:282
Negated Boolean view.
Definition view.hpp:1574
Class to map VarArg type to view.
Definition idx-view.hh:60
Base-class for propagators.
Definition core.hpp:1064
Computation spaces.
Definition core.hpp:1742
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2837
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const IdxViewArray< View > &x)
Definition idx-view.hpp:167
Gecode toplevel namespace
int PropCond
Type for propagation conditions.
Definition core.hpp:72
Post propagator for SetVar x
Definition set.hh:767
#define forceinline
Definition config.hpp:187