Generated on Sat Feb 7 2015 02:01:25 for Gecode by doxygen 1.8.9.1
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  * Last modified:
16  * $Date: 2011-07-12 12:49:06 +0200 (Tue, 12 Jul 2011) $ by $Author: tack $
17  * $Revision: 12172 $
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 #include "test/set.hh"
45 
46 using namespace Gecode;
47 
48 namespace Test { namespace Set {
49 
51  namespace Precede {
52 
53  static IntSet ds(-1,3);
54 
56  class Single : public SetTest {
57  private:
59  int s, t;
60 
62  bool in(int i, int x) const {
63  CountableSetRanges xr(ds,x);
65  return Iter::Ranges::subset(ir,xr);
66  }
67 
68  public:
70  Single(int s0, int t0)
71  : SetTest("Precede::Single::"+str(s0)+"<"+str(t0),4,ds,false),
72  s(s0), t(t0) {}
74  virtual bool solution(const SetAssignment& x) const {
75  int n = x.size();
76  for (int i = 0 ; i < n ; i++) {
77  if (!in(s,x[i]) && in(t,x[i]))
78  return false;
79  if (in(s,x[i]) && !in(t,x[i]))
80  return true;
81  }
82  return true;
83  }
85  virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
87  Gecode::precede(home, x, s, t);
88  }
89  };
90 
92  class Multi : public SetTest {
93  private:
96 
98  bool in(int i, int x) const {
99  CountableSetRanges xr(ds,x);
100  Iter::Ranges::Singleton ir(i,i);
101  return Iter::Ranges::subset(ir,xr);
102  }
103  public:
106  : SetTest("Precede::Multi::"+str(c0),4,ds,false), c(c0) {}
108  virtual bool solution(const SetAssignment& x) const {
109  for (int j=0; j<c.size()-1; j++)
110  for (int i=0; i<x.size(); i++) {
111  if (!in(c[j],x[i]) && in(c[j+1],x[i]))
112  return false;
113  if (in(c[j],x[i]) && !in(c[j+1],x[i]))
114  break;
115  }
116  return true;
117  }
119  virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
121  Gecode::precede(home, x, c);
122  }
123  };
124 
125  Single _a(2, 3);
126  Single _b(0, 3);
127 
128  Multi _c(Gecode::IntArgs(3, 1,2,3));
129  Multi _d(Gecode::IntArgs(3, 3,2,1));
130  Multi _e(Gecode::IntArgs(4, 4,2,3,1));
131 
132  }
133 
134 }}
135 
136 // STATISTICS: test-set
NodeType t
Type of node.
Definition: bool-expr.cpp:234
int size(void) const
Return arity.
Definition: set.hh:189
Range iterator for singleton range.
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: precede.cpp:108
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
Multi(const Gecode::IntArgs &c0)
Create and register test.
Definition: precede.cpp:105
Multi _c(Gecode::IntArgs(3, 1, 2, 3))
Integer variable array.
Definition: int.hh:741
Single(int s0, int t0)
Create and register test.
Definition: precede.cpp:70
Computation spaces.
Definition: core.hpp:1362
Single _a(2, 3)
Gecode::FloatVal c(-8, 8)
Single _b(0, 3)
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition: precede.cpp:119
Multi _d(Gecode::IntArgs(3, 3, 2, 1))
void precede(Home home, const IntVarArgs &x, int s, int t, IntConLevel)
Post propagator that s precedes t in x.
Definition: precede.cpp:47
Integer sets.
Definition: int.hh:171
Passing integer arguments.
Definition: int.hh:607
General test support.
Definition: afc.cpp:43
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Test for single value precedence constraint
Definition: precede.cpp:56
Base class for tests with set constraints
Definition: set.hh:271
Generate all set assignments.
Definition: set.hh:158
Multi _e(Gecode::IntArgs(4, 4, 2, 3, 1))
Range iterator producing subsets of an IntSet.
Definition: set.hh:114
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Set variable array
Definition: set.hh:571
Gecode toplevel namespace
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: precede.cpp:74
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition: precede.cpp:85
Test for multiple value precedence constraint
Definition: precede.cpp:92