Generated on Sat Feb 7 2015 02:01:14 for Gecode by doxygen 1.8.9.1
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: 2011-05-25 16:56:41 +0200 (Wed, 25 May 2011) $ by $Author: schulte $
11  * $Revision: 12022 $
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  inline void
92  for (int i=n; i--; )
93  t[i].subscribe(home,p,pc);
94  }
95 
96  template<class Task>
97  inline void
99  for (int i=n; i--; )
100  t[i].cancel(home,p,pc);
101  }
102 
103  template<class Task>
104  forceinline void
105  TaskArray<Task>::update(Space& home, bool share, TaskArray& a) {
106  n=a.n; t=home.alloc<Task>(n);
107  for (int i=n; i--; )
108  t[i].update(home,share,a.t[i]);
109  }
110 
111 
112  template<class Char, class Traits, class Task>
113  std::basic_ostream<Char,Traits>&
114  operator <<(std::basic_ostream<Char,Traits>& os,
115  const TaskArray<Task>& t) {
116  std::basic_ostringstream<Char,Traits> s;
117  s.copyfmt(os); s.width(0);
118  s << '{';
119  if (t.size() > 0) {
120  s << t[0];
121  for (int i=1; i<t.size(); i++)
122  s << ", " << t[i];
123  }
124  s << '}';
125  return os << s.str();
126  }
127 
128 
129  /*
130  * Task view array
131  */
132  template<class TaskView>
135  : t(t0) {}
136 
137  template<class TaskView>
138  forceinline int
140  return t.size();
141  }
142 
143  template<class TaskView>
144  forceinline void
146  t.size(n);
147  }
148 
149  template<class TaskView>
150  forceinline TaskView&
152  return static_cast<TaskView&>(t[i]);
153  }
154  template<class TaskView>
155  forceinline const TaskView&
157  return static_cast<const TaskView&>(t[i]);
158  }
159 
160  template<class Char, class Traits, class TaskView>
161  std::basic_ostream<Char,Traits>&
162  operator <<(std::basic_ostream<Char,Traits>& os,
163  const TaskViewArray<TaskView>& t) {
164  std::basic_ostringstream<Char,Traits> s;
165  s.copyfmt(os); s.width(0);
166  s << '{';
167  if (t.size() > 0) {
168  s << t[0];
169  for (int i=1; i<t.size(); i++)
170  s << ", " << t[i];
171  }
172  s << '}';
173  return os << s.str();
174  }
175 
176 
177 }}
178 
179 // STATISTICS: int-other
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Task view array.
Definition: task.hh:233
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:84
Base-class for propagators.
Definition: core.hpp:755
TaskArray(void)
Default constructor (array of size 0)
Definition: array.hpp:46
Task array.
Definition: task.hh:167
Computation spaces.
Definition: core.hpp:1362
TaskViewArray(TaskArray< Task > &t)
Initialize from task array a.
Definition: array.hpp:134
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition: core.hpp:2397
Task & operator[](int i)
Return task at position i.
Definition: array.hpp:78
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
void update(Space &, bool share, TaskArray &a)
Update array to be a clone of array a.
Definition: array.hpp:105
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:156
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:74
TaskView & operator[](int i)
Return task view at position i.
Definition: array.hpp:151
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:139
void subscribe(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Subscribe propagator p to all tasks.
Definition: array.hpp:91
#define forceinline
Definition: config.hpp:132
void cancel(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Cancel subscription of propagator p for all tasks.
Definition: array.hpp:98
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:67
Gecode toplevel namespace
const TaskArray< Task > & operator=(const TaskArray< Task > &a)
Initialize from task array a (share elements)
Definition: array.hpp:60
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.