Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
dom.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Matthias Balzer <matthias.balzer@itwm.fraunhofer.de>
5  *
6  * Copyright:
7  * Fraunhofer ITWM, 2017
8  *
9  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
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 #include <gecode/minimodel.hh>
39 
40 #include <cstddef>
41 #include <tuple>
42 #include <utility>
43 
45 namespace { namespace cxx14 {
46 
47  namespace detail {
48 
49  template<std::size_t...>
50  struct sequence {};
51 
52  template<std::size_t N, std::size_t... I>
53  struct make_sequence : make_sequence<N - 1, N - 1, I...> {};
54 
55  template<std::size_t... I>
56  struct make_sequence<0, I...> {
57  using type = sequence<I...>;
58  };
59  }
60 
61  template<std::size_t... I>
62  using index_sequence = detail::sequence<I...>;
63 
64  template<typename... Ts>
65  using index_sequence_for = typename detail::make_sequence<sizeof...(Ts)>::type;
66 }}
67 
68 
69 namespace Gecode {
70 
71  namespace {
73  template<typename... Args>
74  class DomArgs {
75  public:
77  DomArgs(Args...);
78 
79  protected:
81  template<std::size_t... I>
82  void apply(Home, BoolVar, IntPropLevel, cxx14::index_sequence<I...>);
83 
84  private:
86  std::tuple<Args...> _args;
87  };
88 
90  template<typename... Args>
91  class DomArgs<IntVar, Args...> {
92  public:
94  DomArgs(IntVar, Args...);
95 
96  protected:
98  template<std::size_t... I>
99  void apply(Home, BoolVar, IntPropLevel, cxx14::index_sequence<I...>);
100 
101  private:
103  std::tuple<IntVar, Args...> _args;
104  };
105 
106  /*
107  * Operations for argument buffer
108  *
109  */
110  template<typename... Args>
111  DomArgs<Args...>::DomArgs(Args... args)
112  : _args(std::forward<Args>(args)...) {}
113 
114  template<typename... Args>
115  template<std::size_t... I>
116  void
117  DomArgs<Args...>::apply(Home home, BoolVar b, IntPropLevel,
118  cxx14::index_sequence<I...>) {
119  dom(home, std::get<I>(_args)..., b);
120  }
121 
122  template<typename... Args>
123  DomArgs<IntVar, Args...>::DomArgs(IntVar x, Args... args)
124  : _args (x, std::forward<Args>(args)...) {}
125 
126  template<typename... Args>
127  template<std::size_t... I>
128  void
129  DomArgs<IntVar, Args...>::apply(Home home, BoolVar b, IntPropLevel ipl,
130  cxx14::index_sequence<I...>) {
131  dom(home, std::get<I>(_args)..., b, ipl);
132  }
133 
134 
136  template<typename... Args>
137  class DomExpr : public DomArgs<Args...>, public BoolExpr::Misc
138  {
139  public:
140  using DomArgs<Args...>::DomArgs;
141 
143  virtual void post(Home, BoolVar b, bool neg, IntPropLevel) override;
145  virtual ~DomExpr() = default;
146  };
147 
148  template<typename... Args>
149  void
150  DomExpr<Args...>::post(Home home, BoolVar b, bool neg, IntPropLevel ipl)
151  {
152  DomArgs<Args...>::apply(home, neg ? (!b).expr (home, ipl) : b, ipl,
153  cxx14::index_sequence_for<Args...>{});
154  }
155  }
156 
157 
158  /*
159  * Domain constraints
160  *
161  */
162  BoolExpr
163  dom(const IntVar& x, int n) {
164  return BoolExpr(new DomExpr<IntVar, int>(x, n));
165  }
166 
167  BoolExpr
168  dom(const IntVar& x, int l, int u) {
169  return BoolExpr(new DomExpr<IntVar, int, int>(x, l, u));
170  }
171 
172  BoolExpr
173  dom(const IntVar& x, const IntSet& s) {
174  return BoolExpr(new DomExpr<IntVar, IntSet>(x, s));
175  }
176 
177 #ifdef GECODE_HAS_SET_VARS
178  BoolExpr
179  dom(const SetVar& x, SetRelType rt, int i) {
180  return BoolExpr(new DomExpr<SetVar, SetRelType, int>(x, rt, i));
181  }
182 
183  BoolExpr
184  dom(const SetVar& x, SetRelType rt, int i, int j) {
185  return BoolExpr(new DomExpr<SetVar, SetRelType, int, int>(x, rt, i, j));
186  }
187 
188  BoolExpr
189  dom(const SetVar& x, SetRelType rt, const IntSet& s) {
190  return BoolExpr(new DomExpr<SetVar, SetRelType, IntSet>(x, rt, s));
191  }
192 #endif
193 
194 #ifdef GECODE_HAS_FLOAT_VARS
195  BoolExpr
196  dom(const FloatVar& x, const FloatVal& n) {
197  return BoolExpr(new DomExpr<FloatVar, FloatVal>(x, n));
198  }
199 
200  BoolExpr
202  return BoolExpr(new DomExpr<FloatVar, FloatNum, FloatNum>(x, l, u));
203  }
204 #endif
205 }
206 
207 // STATISTICS: minimodel-any
void dom(Home home, const SetVarArgs &x, const SetVarArgs &d)
Constrain domain of according to domain of for all .
Definition: dom.cpp:649
SetRelType
Common relation types for sets.
Definition: set.hh:645
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:242
void sequence(Home home, const IntVarArgs &x, const IntSet &s, int q, int l, int u, IntPropLevel)
Post propagator for .
Definition: sequence.cpp:51
Definition: dom.cpp:45
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
union Gecode::@585::NNF::@62 u
Union depending on nodetype t.
Integer sets.
Definition: int.hh:174
Boolean expressions.
Definition: minimodel.hh:1229
BoolVar expr(Home home, const BoolExpr &e, IntPropLevel ipl)
Post Boolean expression and return its value.
Definition: bool-expr.cpp:632
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:953
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Float value type.
Definition: float.hh:338
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:131
Integer variables.
Definition: int.hh:351
Float variables.
Definition: float.hh:874
Gecode toplevel namespace
double FloatNum
Floating point number base type.
Definition: float.hh:110
bool neg
Is atomic formula negative.
Definition: bool-expr.cpp:251