Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
42using namespace Gecode;
43
44namespace 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) {}
69
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 }
80
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) {}
103
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 }
114
117 Gecode::precede(home, x, c);
118 }
119 };
120
121 Single _a(2, 3);
122 Single _b(0, 3);
123
127
128 }
129
130}}
131
132// STATISTICS: test-set
Passing integer arguments.
Definition int.hh:634
Integer sets.
Definition int.hh:174
Integer variable array.
Definition int.hh:772
Range iterator for singleton range.
Set variable array
Definition set.hh:573
Computation spaces.
Definition core.hpp:1744
Range iterator producing subsets of an IntSet.
Definition set.hh:99
Test for multiple value precedence constraint
Definition precede.cpp:88
Multi(const Gecode::IntArgs &c0)
Create and register test.
Definition precede.cpp:101
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition precede.cpp:115
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition precede.cpp:104
Test for single value precedence constraint
Definition precede.cpp:52
Single(int s0, int t0)
Create and register test.
Definition precede.cpp:66
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition precede.cpp:81
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition precede.cpp:70
Generate all set assignments.
Definition set.hh:142
static std::string str(Gecode::SetRelType srt)
Map set relation to string.
Definition set.hpp:46
SetTest(const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Constructor.
Definition set.hh:304
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel=IPL_DEF)
Post propagator that s precedes t in x.
Definition precede.cpp:43
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Gecode toplevel namespace
Post propagator for SetVar x
Definition set.hh:773
Tests for value precedence constraints
Definition precede.cpp:47
Multi _c(Gecode::IntArgs({1, 2, 3}))
Single _a(2, 3)
Multi _e(Gecode::IntArgs({4, 2, 3, 1}))
Single _b(0, 3)
Multi _d(Gecode::IntArgs({3, 2, 1}))
Testing finite sets.
Definition set.cpp:42
General test support.
Definition afc.cpp:39