Generated on Sat Oct 20 2018 12:43:45 for Gecode by doxygen 1.8.13
set-op.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  * 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 namespace Gecode { namespace Int { namespace Sequence {
35 
37  enum TakesStatus {
41  };
42 
44  template<class View>
46  takes(const View& x, int s) {
47  if (x.in(s))
48  return x.assigned() ? TS_YES : TS_MAYBE;
49  else
50  return TS_NO;
51  }
53  template<class View>
55  takes(const View& x, const IntSet& s) {
56  if ((x.max() < s.min()) || (x.min() > s.max()))
57  return TS_NO;
58  ViewRanges<View> ix(x);
59  IntSetRanges is(s);
60  switch (Iter::Ranges::compare(ix,is)) {
61  case Iter::Ranges::CS_SUBSET: return TS_YES;
62  case Iter::Ranges::CS_DISJOINT: return TS_NO;
63  case Iter::Ranges::CS_NONE: return TS_MAYBE;
64  default: GECODE_NEVER;
65  }
66  return TS_MAYBE;
67  }
68 
70  template<class View>
71  forceinline bool
72  includes(const View& x, int s) {
73  return x.assigned() && x.in(s);
74  }
76  template<class View>
77  forceinline bool
78  includes(const View& x, const IntSet& s) {
79  if ((x.max() < s.min()) || (x.min() > s.max()))
80  return false;
81  ViewRanges<View> ix(x);
82  IntSetRanges is(s);
83  return Iter::Ranges::subset(ix,is);
84  }
85 
87  template<class View>
88  forceinline bool
89  excludes(const View& x, int s) {
90  return !x.in(s);
91  }
93  template<class View>
94  forceinline bool
95  excludes(const View& x, const IntSet& s) {
96  if ((x.max() < s.min()) || (x.min() > s.max()))
97  return true;
98  ViewRanges<View> ix(x);
99  IntSetRanges is(s);
100  return Iter::Ranges::disjoint(ix,is);
101  }
102 
104  template<class View>
105  forceinline bool
106  undecided(const View& x, int s) {
107  return !x.assigned() && x.in(s);
108  }
110  template<class View>
111  forceinline bool
112  undecided(const View& x, const IntSet& s) {
113  if ((x.max() < s.min()) || (x.min() > s.max()))
114  return false;
115  ViewRanges<View> ix(x);
116  IntSetRanges is(s);
118  }
119 
121  template<class View>
123  include(Space& home, View& x, int s) {
124  return x.eq(home,s);
125  }
127  template<class View>
129  include(Space& home, View& x, const IntSet& s) {
130  IntSetRanges is(s);
131  return x.inter_r(home,is,false);
132  }
133 
135  template<class View>
137  exclude(Space& home, View& x, int s) {
138  return x.nq(home,s);
139  }
141  template<class View>
143  exclude(Space& home, View& x, const IntSet& s) {
144  IntSetRanges is(s);
145  return x.minus_r(home,is,false);
146  }
147 
148 }}}
149 
150 // STATISTICS: int-prop
TakesStatus
Status of whether a view takes a value from a set.
Definition: set-op.hpp:37
bool includes(const View &x, int s)
Test whether all values of view x are included in s.
Definition: set-op.hpp:72
Range iterator for integer sets.
Definition: int.hh:292
Definitely not.
Definition: set-op.hpp:38
Maybe or maybe not.
Definition: set-op.hpp:40
First is subset of second iterator.
bool undecided(const View &x, int s)
Test whether no decision on inclusion or exclusion of values of view x in s can be made...
Definition: set-op.hpp:106
int ModEvent
Type for modification events.
Definition: core.hpp:62
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:149
Range iterator for integer views.
Definition: view.hpp:54
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
Definition: set-op.hpp:137
int max(int i) const
Return maximum of range at position i.
Definition: int-set-1.hpp:155
Integer sets.
Definition: int.hh:174
ModEvent include(Space &home, View &x, int s)
Prune view x to only include values from s.
Definition: set-op.hpp:123
TakesStatus takes(const View &x, int s)
Return whether view x takes value s.
Definition: set-op.hpp:46
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
Post propagator for SetVar x
Definition: set.hh:767
Definitely yes.
Definition: set-op.hpp:39
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
bool excludes(const View &x, int s)
Test whether all values of view x are excluded from s.
Definition: set-op.hpp:89
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Gecode toplevel namespace
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56