Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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 
34 namespace 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
63  TaskArray<Task>::size(void) const {
64  return n;
65  }
66  template<class Task>
67  forceinline void
69  n = n0;
70  }
71 
72  template<class Task>
73  forceinline 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 
131 
132  /*
133  * Task view array
134  */
135  template<class TaskView>
138  : t(t0) {}
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 }}
181 
182 // STATISTICS: int-other
NodeType t
Type of node.
Definition: bool-expr.cpp:230
Computation spaces.
Definition: core.hpp:1742
void subscribe(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Subscribe propagator p to all tasks.
Definition: array.hpp:87
Gecode toplevel namespace
Base-class for propagators.
Definition: core.hpp:1064
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
TaskArray(void)
Default constructor (array of size 0)
Definition: array.hpp:42
void reschedule(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Schedule propagator p.
Definition: array.hpp:101
Task & operator[](int i)
Return task at position i.
Definition: array.hpp:74
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
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
void cancel(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Cancel subscription of propagator p for all tasks.
Definition: array.hpp:94
int PropCond
Type for propagation conditions.
Definition: core.hpp:72
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:63
TaskView & operator[](int i)
Return task view at position i.
Definition: array.hpp:154
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
const TaskArray< Task > & operator=(const TaskArray< Task > &a)
Initialize from task array a (share elements)
Definition: array.hpp:56
void update(Space &, TaskArray &a)
Update array to be a clone of array a.
Definition: array.hpp:108
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:142
Task array.
Definition: task.hh:165
#define forceinline
Definition: config.hpp:185
TaskViewArray(TaskArray< Task > &t)
Initialize from task array a.
Definition: array.hpp:137
Task view array.
Definition: task.hh:233
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