Generated on Sat Nov 9 2013 19:18:26 for Gecode by doxygen 1.8.4
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  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6  *
7  * Copyright:
8  * Christian Schulte, 2005
9  * Vincent Barichard, 2012
10  *
11  * Last modified:
12  * $Date: 2013-02-12 20:48:02 +0100 (Tue, 12 Feb 2013) $ by $Author: vbarichard $
13  * $Revision: 13281 $
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/float.hh"
41 
42 #include <gecode/minimodel.hh>
43 
44 namespace Test { namespace Float {
45 
47  namespace Rel {
48 
54  class FloatVarXY : public Test {
56  protected:
59  public:
62  : Test("Rel::Float::Var::XY::"+str(frt0)+"::"+str(n),
63  n+1,-3,3,st,CPLT_ASSIGNMENT,n==1),
64  frt(frt0) {}
66  virtual MaybeType solution(const Assignment& x) const {
67  if (x.size() == 2) {
68  return cmp(x[0],frt,x[1]);
69  } else {
70  MaybeType r1 = cmp(x[0],frt,x[2]);
71  MaybeType r2 = cmp(x[1],frt,x[2]);
72  if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
73  else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
74  else return MT_MAYBE;
75  }
76  }
78  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
79  using namespace Gecode;
80  if (x.size() == 2) {
81  rel(home, x[0], frt, x[1]);
82  } else {
83  FloatVarArgs y(2);
84  y[0]=x[0]; y[1]=x[1];
85  rel(home, y, frt, x[2]);
86  }
87  }
89  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
90  Gecode::Reify r) {
91  assert(x.size() == 2);
92  Gecode::rel(home, x[0], frt, x[1], r);
93  }
94  };
95 
97  class FloatVarXX : public Test {
98  protected:
101  public:
104  : Test("Rel::Float::Var::XX::"+str(frt0),
105  1,-3,3,st,CPLT_ASSIGNMENT,true),
106  frt(frt0) { }
108  virtual MaybeType solution(const Assignment& x) const {
109  return cmp(x[0],frt,x[0]);
110  }
112  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
113  Gecode::rel(home, x[0], frt, x[0]);
114  }
117  Gecode::Reify r) {
118  Gecode::rel(home, x[0], frt, x[0], r);
119  }
120  };
121 
123  class FloatFloat : public Test {
124  protected:
129  public:
132  Gecode::FloatNum st)
133  : Test("Rel::Float::Float::"+str(frt0)+"::"+str(n)+"::"+str(c0),
134  n,-3,3,st,CPLT_ASSIGNMENT,n==1),
135  frt(frt0), c(c0) {}
137  virtual MaybeType solution(const Assignment& x) const {
138  if (x.size() == 1) {
139  return cmp(x[0],frt,c);
140  } else {
141  return cmp(x[0],frt,c) & cmp(x[1],frt,c);
142  }
143  }
145  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
146  using namespace Gecode;
147  if (x.size() == 1)
148  rel(home, x[0], frt, c);
149  else
150  rel(home, x, frt, c);
151  }
154  Gecode::Reify r) {
155  assert(x.size() == 1);
156  Gecode::rel(home, x[0], frt, c, r);
157  }
158  };
159 
161  class Create {
162  public:
164  Create(void) {
165  using namespace Gecode;
166  Gecode::FloatNum step = 0.7;
167  for (FloatRelTypes frts; frts(); ++frts) {
168  (void) new FloatVarXY(frts.frt(),1,step);
169  (void) new FloatVarXY(frts.frt(),2,step);
170  (void) new FloatVarXX(frts.frt(),step);
171  for (int c=-4; c<=4; c++) {
172  (void) new FloatFloat(frts.frt(),1,c,step);
173  (void) new FloatFloat(frts.frt(),2,c,step);
174  }
175  }
176  }
177  };
178 
181 
182  }
183 
184 }}
185 
186 // STATISTICS: test-float