this repo has no description
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, 2008
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 "test/int.hh"
35
36#include <gecode/minimodel.hh>
37
38namespace Test { namespace Int {
39
40 /// %Tests for minimal modelling constraints (simple relations)
41 namespace MiniModel {
42
43 /**
44 * \defgroup TaskTestIntMiniModelRel Minimal modelling constraints (relation)
45 * \ingroup TaskTestInt
46 */
47 //@{
48 /// %Test for relation between arrays of integer variables
49 class IntLex : public Test {
50 protected:
51 /// Integer relation type to propagate
52 Gecode::IntRelType irt;
53 public:
54 /// Create and register test
55 IntLex(Gecode::IntRelType irt0)
56 : Test("MiniModel::Lex::Int::"+str(irt0),6,-2,2), irt(irt0) {}
57 /// %Test whether \a x is solution
58 virtual bool solution(const Assignment& x) const {
59 int n=x.size() >> 1;
60 for (int i=0; i<n; i++)
61 if (x[i] != x[n+i])
62 return cmp(x[i],irt,x[n+i]);
63 return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
64 (irt == Gecode::IRT_EQ));
65 GECODE_NEVER;
66 return false;
67 }
68 /// Post constraint on \a x
69 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
70 using namespace Gecode;
71 int n=x.size() >> 1;
72 IntVarArgs y(n); IntVarArgs z(n);
73 for (int i=0; i<n; i++) {
74 y[i]=x[i]; z[i]=x[n+i];
75 }
76 lex(home, y, irt, z);
77 }
78 };
79
80 /// %Test for relation between arrays of Boolean variables
81 class BoolLex : public Test {
82 protected:
83 /// Integer relation type to propagate
84 Gecode::IntRelType irt;
85 public:
86 /// Create and register test
87 BoolLex(Gecode::IntRelType irt0)
88 : Test("MiniModel::Lex::Bool::"+str(irt0),10,0,1), irt(irt0) {}
89 /// %Test whether \a x is solution
90 virtual bool solution(const Assignment& x) const {
91 int n=x.size() >> 1;
92 for (int i=0; i<n; i++)
93 if (x[i] != x[n+i])
94 return cmp(x[i],irt,x[n+i]);
95 return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
96 (irt == Gecode::IRT_EQ));
97 GECODE_NEVER;
98 return false;
99 }
100 /// Post constraint on \a x
101 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
102 using namespace Gecode;
103 int n=x.size() >> 1;
104 BoolVarArgs y(n); BoolVarArgs z(n);
105 for (int i=0; i<n; i++) {
106 y[i]=channel(home,x[i]); z[i]=channel(home,x[n+i]);
107 }
108 lex(home, y, irt, z);
109 }
110 };
111
112 /// Help class to create and register tests
113 class Create {
114 public:
115 /// Perform creation and registration
116 Create(void) {
117 using namespace Gecode;
118 for (IntRelTypes irts; irts(); ++irts) {
119 (void) new IntLex(irts.irt());
120 (void) new BoolLex(irts.irt());
121 }
122 }
123 };
124
125 Create c;
126 //@}
127
128 }
129
130}}
131
132// STATISTICS: test-minimodel