Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
member.cpp
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, 2011
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#include <gecode/minimodel.hh>
35#include "test/int.hh"
36
37namespace Test { namespace Int {
38
40 namespace Member {
41
48 class Int : public Test {
49 public:
51 Int(int n) : Test("Member::Int::"+str(n),n+1,0,n,true) {}
53 virtual bool solution(const Assignment& x) const {
54 int n = x.size() - 1;
55 for (int i=n; i--; )
56 if (x[i] == x[n])
57 return true;
58 return false;
59 }
61 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
62 using namespace Gecode;
63 int n = x.size() - 1;
64 IntVarArgs y(n);
65 for (int i=n; i--; )
66 y[i] = x[i];
67 member(home, y, x[n]);
68 }
72 using namespace Gecode;
73 int n = x.size() - 1;
74 IntVarArgs y(n);
75 for (int i=n; i--; )
76 y[i] = x[i];
77 member(home, y, x[n], r);
78 }
79 };
80
82 class Bool : public Test {
83 public:
85 Bool(int n) : Test("Member::Bool::"+str(n),n+1,0,1,true) {}
87 virtual bool solution(const Assignment& x) const {
88 int n = x.size() - 1;
89 for (int i=n; i--; )
90 if (x[i] == x[n])
91 return true;
92 return false;
93 }
95 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
96 using namespace Gecode;
97 int n = x.size() - 1;
98 BoolVarArgs y(n);
99 for (int i=n; i--; )
100 y[i] = channel(home,x[i]);
101 member(home, y, channel(home,x[n]));
102 }
106 using namespace Gecode;
107 int n = x.size() - 1;
108 BoolVarArgs y(n);
109 for (int i=n; i--; )
110 y[i] = channel(home,x[i]);
111 member(home, y, channel(home,x[n]), r);
112 }
113 };
114
116 class Create {
117 public:
119 Create(void) {
120 for (int i=0; i<=4; i++) {
121 (void) new Int(i);
122 (void) new Bool(i);
123 }
124 }
125 };
126
129
130 }
131}}
132
133// STATISTICS: test-int
134
int n
Number of negative literals for node type.
Node * x
Pointer to corresponding Boolean expression node.
Passing Boolean variables.
Definition int.hh:712
Passing integer variables.
Definition int.hh:656
Integer variable array.
Definition int.hh:763
Reification specification.
Definition int.hh:876
Computation spaces.
Definition core.hpp:1742
Base class for assignments
Definition int.hh:59
Test membership for Boolean variables
Definition member.cpp:82
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition member.cpp:104
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition member.cpp:95
Bool(int n)
Create and register test.
Definition member.cpp:85
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition member.cpp:87
Help class to create and register tests.
Definition member.cpp:116
Create(void)
Perform creation and registration.
Definition member.cpp:119
Test membership for integer variables
Definition member.cpp:48
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition member.cpp:61
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition member.cpp:70
Int(int n)
Create and register test.
Definition member.cpp:51
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition member.cpp:53
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
Gecode toplevel namespace
General test support.
Definition afc.cpp:39
Region r
Definition region.cpp:65