Generated on Thu Jan 20 2022 00:00:00 for Gecode by doxygen 1.9.1
mm-rel.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, 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 
38 namespace Test { namespace Int {
39 
41  namespace MiniModel {
42 
49  class IntLex : public Test {
50  protected:
53  public:
56  : Test("MiniModel::Lex::Int::"+str(irt0),6,-2,2), irt(irt0) {}
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));
66  return false;
67  }
69  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
70  using namespace Gecode;
71  int n=x.size() >> 1;
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 
81  class BoolLex : public Test {
82  protected:
85  public:
88  : Test("MiniModel::Lex::Bool::"+str(irt0),10,0,1), irt(irt0) {}
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));
98  return false;
99  }
101  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
102  using namespace Gecode;
103  int n=x.size() >> 1;
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 
113  class Create {
114  public:
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 
127 
128  }
129 
130 }}
131 
132 // STATISTICS: test-minimodel
void lex(Home home, const IntVarArgs &x, IntRelType r, const IntVarArgs &y, IntPropLevel ipl)
Post lexical order between x and y.
Definition: aliases.hpp:132
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
Passing Boolean variables.
Definition: int.hh:712
Passing integer variables.
Definition: int.hh:656
Integer variable array.
Definition: int.hh:763
Computation spaces.
Definition: core.hpp:1742
Base class for assignments
Definition: int.hh:59
Iterator for integer relation types.
Definition: int.hh:368
Test for relation between arrays of Boolean variables
Definition: mm-rel.cpp:81
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: mm-rel.cpp:101
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: mm-rel.cpp:84
BoolLex(Gecode::IntRelType irt0)
Create and register test.
Definition: mm-rel.cpp:87
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: mm-rel.cpp:90
Help class to create and register tests.
Definition: mm-rel.cpp:113
Create(void)
Perform creation and registration.
Definition: mm-rel.cpp:116
Test for relation between arrays of integer variables
Definition: mm-rel.cpp:49
IntLex(Gecode::IntRelType irt0)
Create and register test.
Definition: mm-rel.cpp:55
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: mm-rel.cpp:52
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: mm-rel.cpp:58
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: mm-rel.cpp:69
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:209
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:285
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: channel.cpp:41
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
IntRelType
Relation types for integers.
Definition: int.hh:925
@ IRT_EQ
Equality ( )
Definition: int.hh:926
@ IRT_GQ
Greater or equal ( )
Definition: int.hh:930
@ IRT_LQ
Less or equal ( )
Definition: int.hh:928
Gecode::IntArgs i({1, 2, 3, 4})
General test support.
Definition: afc.cpp:39
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56