Generated on Sat Feb 7 2015 02:01:32 for Gecode by doxygen 1.8.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  * Last modified:
10  * $Date: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $
11  * $Revision: 10684 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include "test/int.hh"
39 
40 #include <gecode/minimodel.hh>
41 
42 namespace Test { namespace Int {
43 
45  namespace MiniModel {
46 
52  class IntLex : public Test {
54  protected:
57  public:
60  : Test("MiniModel::Lex::Int::"+str(irt0),6,-2,2), irt(irt0) {}
62  virtual bool solution(const Assignment& x) const {
63  int n=x.size() >> 1;
64  for (int i=0; i<n; i++)
65  if (x[i] != x[n+i])
66  return cmp(x[i],irt,x[n+i]);
67  return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
68  (irt == Gecode::IRT_EQ));
70  return false;
71  }
73  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
74  using namespace Gecode;
75  int n=x.size() >> 1;
76  IntVarArgs y(n); IntVarArgs z(n);
77  for (int i=0; i<n; i++) {
78  y[i]=x[i]; z[i]=x[n+i];
79  }
80  lex(home, y, irt, z);
81  }
82  };
83 
85  class BoolLex : public Test {
86  protected:
89  public:
92  : Test("MiniModel::Lex::Bool::"+str(irt0),10,0,1), irt(irt0) {}
94  virtual bool solution(const Assignment& x) const {
95  int n=x.size() >> 1;
96  for (int i=0; i<n; i++)
97  if (x[i] != x[n+i])
98  return cmp(x[i],irt,x[n+i]);
99  return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
100  (irt == Gecode::IRT_EQ));
101  GECODE_NEVER;
102  return false;
103  }
105  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
106  using namespace Gecode;
107  int n=x.size() >> 1;
108  BoolVarArgs y(n); BoolVarArgs z(n);
109  for (int i=0; i<n; i++) {
110  y[i]=channel(home,x[i]); z[i]=channel(home,x[n+i]);
111  }
112  lex(home, y, irt, z);
113  }
114  };
115 
117  class Create {
118  public:
120  Create(void) {
121  using namespace Gecode;
122  for (IntRelTypes irts; irts(); ++irts) {
123  (void) new IntLex(irts.irt());
124  (void) new BoolLex(irts.irt());
125  }
126  }
127  };
128 
131 
132  }
133 
134 }}
135 
136 // STATISTICS: test-minimodel
Create(void)
Perform creation and registration.
Definition: mm-rel.cpp:120
Help class to create and register tests.
Definition: mm-rel.cpp:117
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: mm-rel.cpp:62
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: arithmetic.cpp:218
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: mm-rel.cpp:56
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: mm-rel.cpp:94
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:284
Less or equal ( )
Definition: int.hh:906
Integer variable array.
Definition: int.hh:741
Computation spaces.
Definition: core.hpp:1362
Greater or equal ( )
Definition: int.hh:908
static std::string str(Gecode::ExtensionalPropKind epk)
Map extensional propagation kind to string.
Definition: int.hpp:212
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Equality ( )
Definition: int.hh:904
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: mm-rel.cpp:73
IntRelType
Relation types for integers.
Definition: int.hh:903
Iterator for integer relation types.
Definition: int.hh:342
void lex(Home home, const IntVarArgs &x, IntRelType r, const IntVarArgs &y, IntConLevel icl=ICL_DEF)
Post lexical order between x and y.
Definition: minimodel.hh:1855
Test for relation between arrays of integer variables
Definition: mm-rel.cpp:53
Passing integer variables.
Definition: int.hh:636
Passing Boolean variables.
Definition: int.hh:690
General test support.
Definition: afc.cpp:43
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: mm-rel.cpp:88
IntLex(Gecode::IntRelType irt0)
Create and register test.
Definition: mm-rel.cpp:59
Base class for assignments
Definition: int.hh:63
BoolLex(Gecode::IntRelType irt0)
Create and register test.
Definition: mm-rel.cpp:91
Gecode toplevel namespace
Test for relation between arrays of Boolean variables
Definition: mm-rel.cpp:85
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: mm-rel.cpp:105
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
int size(void) const
Return number of variables.
Definition: int.hpp:50