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 * Copyright:
7 * Christian Schulte, 2011
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#ifndef GECODE_INT_MEMBER_HH
35#define GECODE_INT_MEMBER_HH
36
37#include <gecode/int.hh>
38#include <gecode/int/val-set.hh>
39
40/**
41 * \namespace Gecode::Int::Member
42 * \brief Membership propagators
43 */
44
45namespace Gecode { namespace Int { namespace Member {
46
47 /**
48 * \brief Membership propagator
49 *
50 * Requires \code #include <gecode/int/member.hh> \endcode
51 * \ingroup FuncIntProp
52 */
53 template<class View>
54 class Prop : public NaryOnePropagator<View,PC_INT_DOM> {
55 protected:
56 using NaryOnePropagator<View,PC_INT_DOM>::x;
57 using NaryOnePropagator<View,PC_INT_DOM>::y;
58 /// Value set storing the values of already assigned views
59 ValSet vs;
60 /// Add values of assigned views in \a x to value set \a va
61 static void add(Space& home, ValSet& vs, ViewArray<View>& x);
62 /// Eliminate views from \a x that are not equal to \a y or ar subsumed by \a vs
63 void eliminate(Space& home);
64 /// Constructor for posting
65 Prop(Home home, ValSet& vs, ViewArray<View>& x, View y);
66 /// Constructor for cloning \a p
67 Prop(Space& home, Prop<View>& p);
68 public:
69 /// Cost function
70 virtual PropCost cost(const Space&, const ModEventDelta& med) const;
71 /// Copy propagator during cloning
72 virtual Propagator* copy(Space& home);
73 /// Perform propagation
74 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
75 /// Post propagator for \f$y\in \{x_0,\ldots,x_{|x|-1}\}\f$
76 static ExecStatus post(Home home, ViewArray<View>& x, View y);
77 /// Post propagator for \f$y\in vs\cup \{x_0,\ldots,x_{|x|-1}\}\f$
78 static ExecStatus post(Home home, ValSet& vs, ViewArray<View>& x, View y);
79 /// Delete propagator and return its size
80 virtual size_t dispose(Space& home);
81 };
82
83 /**
84 * \brief Reified membership propagator
85 *
86 * Requires \code #include <gecode/int/member.hh> \endcode
87 * \ingroup FuncIntProp
88 */
89 template<class View, ReifyMode rm>
90 class ReProp : public Prop<View> {
91 protected:
92 using Prop<View>::x;
93 using Prop<View>::y;
94 using Prop<View>::vs;
95 using Prop<View>::add;
96 using Prop<View>::eliminate;
97 /// Boolean control variable
98 BoolView b;
99 /// Constructor for posting
100 ReProp(Home home, ValSet& vs, ViewArray<View>& x, View y, BoolView b);
101 /// Constructor for cloning \a p
102 ReProp(Space& home, ReProp<View,rm>& p);
103 public:
104 /// Copy propagator during cloning
105 virtual Propagator* copy(Space& home);
106 /// Perform propagation
107 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
108 /// Post propagator for \f$\left(y\in \{x_0,\ldots,x_{|x|-1}\}\right)\Leftrightarrow b\f$
109 static ExecStatus post(Home home, ViewArray<View>& x, View y, BoolView b);
110 /// Delete propagator and return its size
111 virtual size_t dispose(Space& home);
112 };
113
114}}}
115
116#include <gecode/int/member/prop.hpp>
117#include <gecode/int/member/re-prop.hpp>
118
119#endif
120
121// STATISTICS: int-prop