Generated on Sat Feb 7 2015 02:01:21 for Gecode by doxygen 1.8.9.1
cumulatives.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Mikael Lagerkvist <lagerkvist@gecode.org>
5  *
6  * Copyright:
7  * Mikael Lagerkvist, 2005
8  *
9  * Last modified:
10  * $Date: 2011-07-13 14:17:55 +0200 (Wed, 13 Jul 2011) $ by $Author: tack $
11  * $Revision: 12188 $
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 
39 
40 namespace Gecode {
41 
42  using namespace Int;
43 
44  namespace {
45  ViewArray<IntView>
46  make_view_array(Space& home, const IntVarArgs& in) {
47  return ViewArray<Int::IntView>(home, in);
48  }
49 
50  ViewArray<ConstIntView>
51  make_view_array(Space& home, const IntArgs& in) {
52  ViewArray<Int::ConstIntView> res(home, in.size());
53  for (int i = in.size(); i--; ) {
54  Int::Limits::check(in[i],"Int::cumulatives");
55  res[i] = Int::ConstIntView(in[i]);
56  }
57 
58  return res;
59  }
60 
61  template<class In> class ViewType;
62 
63  template<>
64  class ViewType<IntArgs> {
65  public:
66  typedef Int::ConstIntView Result;
67  };
68 
69  template<>
70  class ViewType<IntVarArgs> {
71  public:
72  typedef Int::IntView Result;
73  };
74 
75  template<class Machine, class Processing, class Usage>
76  void
77  post_cumulatives(Home home, const Machine& m,
78  const IntVarArgs& s, const Processing& p,
79  const IntVarArgs& e, const Usage& u,
80  const IntArgs& c, bool at_most,
81  IntConLevel) {
82  if (m.size() != s.size() ||
83  s.size() != p.size() ||
84  p.size() != e.size() ||
85  e.size() != u.size())
86  throw Int::ArgumentSizeMismatch("Int::cumulatives");
87  if (home.failed()) return;
88 
89  ViewArray<typename ViewType<Machine>::Result>
90  vm = make_view_array(home, m);
91  ViewArray<typename ViewType<Processing>::Result>
92  vp = make_view_array(home, p);
93  ViewArray<typename ViewType<Usage>::Result>
94  vu = make_view_array(home, u);
95  ViewArray<IntView>
96  vs = make_view_array(home, s),
97  ve = make_view_array(home, e);
98 
99  SharedArray<int> c_s(c.size());
100  for (int i=c.size(); i--;)
101  c_s[i] = c[i];
102 
103  // There is only the value-consistent propagator for this constraint
104  GECODE_ES_FAIL((Int::Cumulatives::Val<
105  typename ViewType<Machine>::Result,
106  typename ViewType<Processing>::Result,
107  typename ViewType<Usage>::Result,
108  IntView>::post(home, vm,vs,vp,ve,vu,c_s,at_most)));
109 
110  }
111  }
112 
113  void
114  cumulatives(Home home, const IntVarArgs& m,
115  const IntVarArgs& s, const IntVarArgs& p,
116  const IntVarArgs& e, const IntVarArgs& u,
117  const IntArgs& c, bool at_most,
118  IntConLevel cl) {
119  post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
120  }
121 
122  void
123  cumulatives(Home home, const IntArgs& m,
124  const IntVarArgs& s, const IntVarArgs& p,
125  const IntVarArgs& e, const IntVarArgs& u,
126  const IntArgs& c, bool at_most,
127  IntConLevel cl) {
128  post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
129  }
130 
131  void
132  cumulatives(Home home, const IntVarArgs& m,
133  const IntVarArgs& s, const IntArgs& p,
134  const IntVarArgs& e, const IntVarArgs& u,
135  const IntArgs& c, bool at_most,
136  IntConLevel cl) {
137  post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
138  }
139 
140  void
141  cumulatives(Home home, const IntArgs& m,
142  const IntVarArgs& s, const IntArgs& p,
143  const IntVarArgs& e, const IntVarArgs& u,
144  const IntArgs& c, bool at_most,
145  IntConLevel cl) {
146  post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
147  }
148 
149  void
150  cumulatives(Home home, const IntVarArgs& m,
151  const IntVarArgs& s, const IntVarArgs& p,
152  const IntVarArgs& e, const IntArgs& u,
153  const IntArgs& c, bool at_most,
154  IntConLevel cl) {
155  post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
156  }
157 
158  void
159  cumulatives(Home home, const IntArgs& m,
160  const IntVarArgs& s, const IntVarArgs& p,
161  const IntVarArgs& e, const IntArgs& u,
162  const IntArgs& c, bool at_most,
163  IntConLevel cl) {
164  post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
165  }
166 
167  void
168  cumulatives(Home home, const IntVarArgs& m,
169  const IntVarArgs& s, const IntArgs& p,
170  const IntVarArgs& e, const IntArgs& u,
171  const IntArgs& c, bool at_most,
172  IntConLevel cl) {
173  post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
174  }
175 
176  void
177  cumulatives(Home home, const IntArgs& m,
178  const IntVarArgs& s, const IntArgs& p,
179  const IntVarArgs& e, const IntArgs& u,
180  const IntArgs& c, bool at_most,
181  IntConLevel cl) {
182  post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
183  }
184 
185 }
186 
187 // STATISTICS: int-post
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
void cumulatives(Home home, const IntVarArgs &m, const IntVarArgs &s, const IntVarArgs &p, const IntVarArgs &e, const IntVarArgs &u, const IntArgs &c, bool at_most, IntConLevel cl)
Post propagators for the cumulatives constraint.
Passing integer variables.
Definition: int.hh:636
Passing integer arguments.
Definition: int.hh:607
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
Gecode toplevel namespace
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition: limits.hpp:50
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96