Generated on Sat Oct 20 2018 12:43:45 for Gecode by doxygen 1.8.13
precede.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christopher Mears <Chris.Mears@monash.edu>
5  *
6  * Contributing authors:
7  * Christian Schulte <schulte@gecode.org>
8  * Guido Tack <tack@gecode.org>
9  *
10  * Copyright:
11  * Christopher Mears, 2011
12  * Christian Schulte, 2011
13  * Guido Tack, 2011
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include "test/set.hh"
41 
42 using namespace Gecode;
43 
44 namespace Test { namespace Set {
45 
47  namespace Precede {
48 
49  static IntSet ds(-1,3);
50 
52  class Single : public SetTest {
53  private:
55  int s, t;
56 
58  bool in(int i, int x) const {
59  CountableSetRanges xr(ds,x);
61  return Iter::Ranges::subset(ir,xr);
62  }
63 
64  public:
66  Single(int s0, int t0)
67  : SetTest("Precede::Single::"+str(s0)+"<"+str(t0),4,ds,false),
68  s(s0), t(t0) {}
70  virtual bool solution(const SetAssignment& x) const {
71  int n = x.size();
72  for (int i = 0 ; i < n ; i++) {
73  if (!in(s,x[i]) && in(t,x[i]))
74  return false;
75  if (in(s,x[i]) && !in(t,x[i]))
76  return true;
77  }
78  return true;
79  }
81  virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
83  Gecode::precede(home, x, s, t);
84  }
85  };
86 
88  class Multi : public SetTest {
89  private:
92 
94  bool in(int i, int x) const {
95  CountableSetRanges xr(ds,x);
97  return Iter::Ranges::subset(ir,xr);
98  }
99  public:
102  : SetTest("Precede::Multi::"+str(c0),4,ds,false), c(c0) {}
104  virtual bool solution(const SetAssignment& x) const {
105  for (int j=0; j<c.size()-1; j++)
106  for (int i=0; i<x.size(); i++) {
107  if (!in(c[j],x[i]) && in(c[j+1],x[i]))
108  return false;
109  if (in(c[j],x[i]) && !in(c[j+1],x[i]))
110  break;
111  }
112  return true;
113  }
115  virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
117  Gecode::precede(home, x, c);
118  }
119  };
120 
121  Single _a(2, 3);
122  Single _b(0, 3);
123 
124  Multi _c(Gecode::IntArgs({1,2,3}));
125  Multi _d(Gecode::IntArgs({3,2,1}));
126  Multi _e(Gecode::IntArgs({4,2,3,1}));
127 
128  }
129 
130 }}
131 
132 // STATISTICS: test-set
NodeType t
Type of node.
Definition: bool-expr.cpp:230
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1569
Range iterator for singleton range.
Multi(const Gecode::IntArgs &c0)
Create and register test.
Definition: precede.cpp:101
Multi _e(Gecode::IntArgs({4, 2, 3, 1}))
Integer variable array.
Definition: int.hh:763
Single(int s0, int t0)
Create and register test.
Definition: precede.cpp:66
Computation spaces.
Definition: core.hpp:1701
Single _a(2, 3)
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: precede.cpp:104
Gecode::FloatVal c(-8, 8)
Single _b(0, 3)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition: precede.cpp:115
Multi _d(Gecode::IntArgs({3, 2, 1}))
Integer sets.
Definition: int.hh:174
Passing integer arguments.
Definition: int.hh:628
General test support.
Definition: afc.cpp:39
Multi _c(Gecode::IntArgs({1, 2, 3}))
Test for single value precedence constraint
Definition: precede.cpp:52
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: precede.cpp:70
Base class for tests with set constraints
Definition: set.hh:273
Generate all set assignments.
Definition: set.hh:142
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel)
Post propagator that s precedes t in x.
Definition: precede.cpp:43
Range iterator producing subsets of an IntSet.
Definition: set.hh:98
Post propagator for SetVar x
Definition: set.hh:767
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Set variable array
Definition: set.hh:570
Gecode toplevel namespace
int size(void) const
Return arity.
Definition: set.hh:173
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition: precede.cpp:81
Test for multiple value precedence constraint
Definition: precede.cpp:88