this repo has no description
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
40 /// VarArg type for integer views
41 template<>
42 class ViewToVarArg<IntView> {
43 public:
44 typedef IntVarArgs argtype;
45 };
46 /// VarArg type for minus views
47 template<>
48 class ViewToVarArg<MinusView> {
49 public:
50 typedef IntVarArgs argtype;
51 };
52 /// VarArg type for Boolean views
53 template<>
54 class ViewToVarArg<BoolView> {
55 public:
56 typedef BoolVarArgs argtype;
57 };
58 /// VarArg type for Boolean views
59 template<>
60 class ViewToVarArg<NegBoolView> {
61 public:
62 typedef BoolVarArgs argtype;
63 };
64
65 template<class View>
66 forceinline IdxView<View>*
67 IdxView<View>::allocate(Space& home, int n) {
68 return home.alloc<IdxView<View> >(n);
69 }
70
71 template<class View>
72 forceinline
73 IdxViewArray<View>::IdxViewArray(void) : xs(nullptr), n(0) {}
74
75 template<class View>
76 forceinline
77 IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
78 n = a.n; xs = a.xs;
79 }
80
81 template<class View>
82 forceinline
83 IdxViewArray<View>::IdxViewArray(Space& home,
84 const typename ViewToVarArg<View>::argtype& xa) : xs(nullptr) {
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>
95 forceinline
96 IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(nullptr) {
97 n = n0;
98 if (n>0) {
99 xs = IdxView<View>::allocate(home, n);
100 }
101 }
102
103 template<class View>
104 forceinline int
105 IdxViewArray<View>::size(void) const {
106 return n;
107 }
108
109 template<class View>
110 forceinline void
111 IdxViewArray<View>::size(int n0) {
112 n = n0;
113 }
114
115 template<class View>
116 forceinline IdxView<View>&
117 IdxViewArray<View>::operator [](int i) {
118 assert((i >= 0) && (i < size()));
119 return xs[i];
120 }
121
122 template<class View>
123 forceinline const IdxView<View>&
124 IdxViewArray<View>::operator [](int i) const {
125 assert((i >= 0) && (i < size()));
126 return xs[i];
127 }
128
129 template<class View>
130 forceinline void
131 IdxViewArray<View>::subscribe(Space& home, Propagator& p, PropCond pc,
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
139 IdxViewArray<View>::cancel(Space& home, Propagator& p, PropCond pc) {
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
146 IdxViewArray<View>::reschedule(Space& home, Propagator& p, PropCond pc) {
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
153 IdxViewArray<View>::update(Space& home, IdxViewArray<View>& a) {
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