Generated on Sat Jul 28 2018 17:10:09 for Gecode by doxygen 1.8.14
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  * Last modified:
10  * $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15137 $
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 
40  /*
41  * Task array
42  */
43 
44  template<class Task>
47  : n(0), t(NULL) {}
48  template<class Task>
51  : n(n0), t(home.alloc<Task>(n)) {
52  assert(n > 0);
53  }
54  template<class Task>
57  : n(a.n), t(a.t) {}
58  template<class Task>
61  n=a.n; t=a.t;
62  return *this;
63  }
64 
65  template<class Task>
66  forceinline int
67  TaskArray<Task>::size(void) const {
68  return n;
69  }
70  template<class Task>
71  forceinline void
73  n = n0;
74  }
75 
76  template<class Task>
77  forceinline Task&
79  assert((i >= 0) && (i < n));
80  return t[i];
81  }
82  template<class Task>
83  forceinline const Task&
85  assert((i >= 0) && (i < n));
86  return t[i];
87  }
88 
89  template<class Task>
90  forceinline void
92  for (int i=n; i--; )
93  t[i].subscribe(home,p,pc);
94  }
95 
96  template<class Task>
97  forceinline void
99  for (int i=n; i--; )
100  t[i].cancel(home,p,pc);
101  }
102 
103  template<class Task>
104  forceinline void
106  for (int i=n; i--; )
107  t[i].reschedule(home,p,pc);
108  }
109 
110  template<class Task>
111  forceinline void
112  TaskArray<Task>::update(Space& home, bool share, TaskArray& a) {
113  n=a.n; t=home.alloc<Task>(n);
114  for (int i=n; i--; )
115  t[i].update(home,share,a.t[i]);
116  }
117 
118 
119  template<class Char, class Traits, class Task>
120  std::basic_ostream<Char,Traits>&
121  operator <<(std::basic_ostream<Char,Traits>& os,
122  const TaskArray<Task>& t) {
123  std::basic_ostringstream<Char,Traits> s;
124  s.copyfmt(os); s.width(0);
125  s << '{';
126  if (t.size() > 0) {
127  s << t[0];
128  for (int i=1; i<t.size(); i++)
129  s << ", " << t[i];
130  }
131  s << '}';
132  return os << s.str();
133  }
134 
135 
136  /*
137  * Task view array
138  */
139  template<class TaskView>
142  : t(t0) {}
143 
144  template<class TaskView>
145  forceinline int
147  return t.size();
148  }
149 
150  template<class TaskView>
151  forceinline void
153  t.size(n);
154  }
155 
156  template<class TaskView>
157  forceinline TaskView&
159  return static_cast<TaskView&>(t[i]);
160  }
161  template<class TaskView>
162  forceinline const TaskView&
164  return static_cast<const TaskView&>(t[i]);
165  }
166 
167  template<class Char, class Traits, class TaskView>
168  std::basic_ostream<Char,Traits>&
169  operator <<(std::basic_ostream<Char,Traits>& os,
170  const TaskViewArray<TaskView>& t) {
171  std::basic_ostringstream<Char,Traits> s;
172  s.copyfmt(os); s.width(0);
173  s << '{';
174  if (t.size() > 0) {
175  s << t[0];
176  for (int i=1; i<t.size(); i++)
177  s << ", " << t[i];
178  }
179  s << '}';
180  return os << s.str();
181  }
182 
183 
184 }}
185 
186 // STATISTICS: int-other
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Task view array.
Definition: task.hh:237
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:146
Base-class for propagators.
Definition: core.hpp:1092
TaskArray(void)
Default constructor (array of size 0)
Definition: array.hpp:46
Task array.
Definition: task.hh:169
Computation spaces.
Definition: core.hpp:1748
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition: core.hpp:2868
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
int PropCond
Type for propagation conditions.
Definition: core.hpp:152
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
unsigned int size(I &i)
Size of all ranges of range iterator i.
TaskView & operator[](int i)
Return task view at position i.
Definition: array.hpp:158
#define forceinline
Definition: config.hpp:173
Gecode toplevel namespace
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96