Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
array.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 * Copyright:
7 * Christian Schulte, 2009
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Int {
35
36 /*
37 * Task array
38 */
39
40 template<class Task>
43 : n(0), t(NULL) {}
44 template<class Task>
47 : n(n0), t(home.alloc<Task>(n)) {
48 assert(n > 0);
49 }
50 template<class Task>
53 : n(a.n), t(a.t) {}
54 template<class Task>
57 n=a.n; t=a.t;
58 return *this;
59 }
60
61 template<class Task>
62 forceinline int
64 return n;
65 }
66 template<class Task>
67 forceinline void
69 n = n0;
70 }
71
72 template<class Task>
75 assert((i >= 0) && (i < n));
76 return t[i];
77 }
78 template<class Task>
79 forceinline const Task&
81 assert((i >= 0) && (i < n));
82 return t[i];
83 }
84
85 template<class Task>
86 forceinline void
88 for (int i=0; i<n; i++)
89 t[i].subscribe(home,p,pc);
90 }
91
92 template<class Task>
93 forceinline void
95 for (int i=0; i<n; i++)
96 t[i].cancel(home,p,pc);
97 }
98
99 template<class Task>
100 forceinline void
102 for (int i=0; i<n; i++)
103 t[i].reschedule(home,p,pc);
104 }
105
106 template<class Task>
107 forceinline void
109 n=a.n; t=home.alloc<Task>(n);
110 for (int i=0; i<n; i++)
111 t[i].update(home,a.t[i]);
112 }
113
114
115 template<class Char, class Traits, class Task>
116 std::basic_ostream<Char,Traits>&
117 operator <<(std::basic_ostream<Char,Traits>& os,
118 const TaskArray<Task>& t) {
119 std::basic_ostringstream<Char,Traits> s;
120 s.copyfmt(os); s.width(0);
121 s << '{';
122 if (t.size() > 0) {
123 s << t[0];
124 for (int i=1; i<t.size(); i++)
125 s << ", " << t[i];
126 }
127 s << '}';
128 return os << s.str();
129 }
130
132 /*
133 * Task view array
134 */
135 template<class TaskView>
139
140 template<class TaskView>
141 forceinline int
143 return t.size();
144 }
145
146 template<class TaskView>
147 forceinline void
149 t.size(n);
150 }
151
152 template<class TaskView>
153 forceinline TaskView&
155 return static_cast<TaskView&>(t[i]);
156 }
157 template<class TaskView>
158 forceinline const TaskView&
160 return static_cast<const TaskView&>(t[i]);
161 }
162
163 template<class Char, class Traits, class TaskView>
164 std::basic_ostream<Char,Traits>&
165 operator <<(std::basic_ostream<Char,Traits>& os,
166 const TaskViewArray<TaskView>& t) {
167 std::basic_ostringstream<Char,Traits> s;
168 s.copyfmt(os); s.width(0);
169 s << '{';
170 if (t.size() > 0) {
171 s << t[0];
172 for (int i=1; i<t.size(); i++)
173 s << ", " << t[i];
174 }
175 s << '}';
176 return os << s.str();
177 }
178
179
180}}
182// STATISTICS: int-other
int size(void) const
Return size of array (number of elements)
Definition array.hpp:1613
Task array.
Definition task.hh:165
Task & operator[](int i)
Return task at position i.
Definition array.hpp:74
void update(Space &, TaskArray &a)
Update array to be a clone of array a.
Definition array.hpp:108
TaskArray(void)
Default constructor (array of size 0)
Definition array.hpp:42
void subscribe(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Subscribe propagator p to all tasks.
Definition array.hpp:87
void cancel(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Cancel subscription of propagator p for all tasks.
Definition array.hpp:94
void reschedule(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Schedule propagator p.
Definition array.hpp:101
int size(void) const
Return size of array (number of elements)
Definition array.hpp:63
const TaskArray< Task > & operator=(const TaskArray< Task > &a)
Initialize from task array a (share elements)
Definition array.hpp:56
Task view array.
Definition task.hh:233
TaskArray< Task > & t
Access to task array.
Definition task.hh:238
TaskViewArray(TaskArray< Task > &t)
Initialize from task array a.
Definition array.hpp:137
int size(void) const
Return size of array (number of elements)
Definition array.hpp:142
TaskView & operator[](int i)
Return task view at position i.
Definition array.hpp:154
Base-class for propagators.
Definition core.hpp:1066
Computation spaces.
Definition core.hpp:1744
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2841
void update(const NoOffset &)
Integer-precision integer scale view.
Definition view.hpp:638
Finite domain integers.
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
#define forceinline
Definition config.hpp:194