Generated on Sat Feb 7 2015 02:01:25 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2010-03-03 16:38:41 +0100 (Wed, 03 Mar 2010) $
11  * $Revision: 10359 $
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 namespace Gecode { namespace Int { namespace Sequence {
39 
41  enum TakesStatus {
45  };
46 
48  template<class View>
50  takes(const View& x, int s) {
51  if (x.in(s))
52  return x.assigned() ? TS_YES : TS_MAYBE;
53  else
54  return TS_NO;
55  }
57  template<class View>
59  takes(const View& x, const IntSet& s) {
60  if ((x.max() < s.min()) || (x.min() > s.max()))
61  return TS_NO;
62  ViewRanges<View> ix(x);
63  IntSetRanges is(s);
64  switch (Iter::Ranges::compare(ix,is)) {
65  case Iter::Ranges::CS_SUBSET: return TS_YES;
66  case Iter::Ranges::CS_DISJOINT: return TS_NO;
67  case Iter::Ranges::CS_NONE: return TS_MAYBE;
68  default: GECODE_NEVER;
69  }
70  return TS_MAYBE;
71  }
72 
74  template<class View>
75  forceinline bool
76  includes(const View& x, int s) {
77  return x.assigned() && x.in(s);
78  }
80  template<class View>
81  forceinline bool
82  includes(const View& x, const IntSet& s) {
83  if ((x.max() < s.min()) || (x.min() > s.max()))
84  return false;
85  ViewRanges<View> ix(x);
86  IntSetRanges is(s);
87  return Iter::Ranges::subset(ix,is);
88  }
89 
91  template<class View>
92  forceinline bool
93  excludes(const View& x, int s) {
94  return !x.in(s);
95  }
97  template<class View>
98  forceinline bool
99  excludes(const View& x, const IntSet& s) {
100  if ((x.max() < s.min()) || (x.min() > s.max()))
101  return true;
102  ViewRanges<View> ix(x);
103  IntSetRanges is(s);
104  return Iter::Ranges::disjoint(ix,is);
105  }
106 
108  template<class View>
109  forceinline bool
110  undecided(const View& x, int s) {
111  return !x.assigned() && x.in(s);
112  }
114  template<class View>
115  forceinline bool
116  undecided(const View& x, const IntSet& s) {
117  if ((x.max() < s.min()) || (x.min() > s.max()))
118  return false;
119  ViewRanges<View> ix(x);
120  IntSetRanges is(s);
122  }
123 
125  template<class View>
127  include(Space& home, View& x, int s) {
128  return x.eq(home,s);
129  }
131  template<class View>
133  include(Space& home, View& x, const IntSet& s) {
134  IntSetRanges is(s);
135  return x.inter_r(home,is,false);
136  }
137 
139  template<class View>
141  exclude(Space& home, View& x, int s) {
142  return x.nq(home,s);
143  }
145  template<class View>
147  exclude(Space& home, View& x, const IntSet& s) {
148  IntSetRanges is(s);
149  return x.minus_r(home,is,false);
150  }
151 
152 }}}
153 
154 // STATISTICS: int-prop
TakesStatus
Status of whether a view takes a value from a set.
Definition: set-op.hpp:41
bool includes(const View &x, int s)
Test whether all values of view x are included in s.
Definition: set-op.hpp:76
Range iterator for integer sets.
Definition: int.hh:271
Definitely not.
Definition: set-op.hpp:42
Maybe or maybe not.
Definition: set-op.hpp:44
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:110
int ModEvent
Type for modification events.
Definition: core.hpp:146
Computation spaces.
Definition: core.hpp:1362
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:141
Integer sets.
Definition: int.hh:171
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
ModEvent include(Space &home, View &x, int s)
Prune view x to only include values from s.
Definition: set-op.hpp:127
TakesStatus takes(const View &x, int s)
Return whether view x takes value s.
Definition: set-op.hpp:50
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
#define forceinline
Definition: config.hpp:132
Definitely yes.
Definition: set-op.hpp:43
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:93
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:60
int max(int i) const
Return maximum of range at position i.
Definition: int-set-1.hpp:121
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:115