Generated on Wed Sep 3 2014 02:16:33 for Gecode by doxygen 1.8.7
dom.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-03-05 13:52:08 +0100 (Tue, 05 Mar 2013) $ by $Author: schulte $
13  * $Revision: 13434 $
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 Dom {
48 
54  class Val : public Test {
56  protected:
59  public:
62  : Test("Dom::Val::"+str(n)+"::"+str(c0),
63  n,-3,3,st,CPLT_ASSIGNMENT,n==1), c(c0) {}
65  virtual MaybeType solution(const Assignment& x) const {
66  for (int i=x.size(); i--; )
67  if ((x[i].max() > c.max()) || (x[i].min() < c.min()))
68  return MT_FALSE;
69  return MT_TRUE;
70  }
72  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
73  if (x.size() == 1)
74  Gecode::dom(home, x[0], c);
75  else
76  Gecode::dom(home, x, c);
77  }
79  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
80  Gecode::Reify r) {
81  assert(x.size() == 1);
82  Gecode::dom(home, x[0], c, r);
83  }
84  };
85 
87  class Num : public Test {
88  protected:
93  public:
97  : Test("Dom::Num::"+str(n)+"::"+str(min0)+"::"+str(max0),
98  n,-3,3,st,CPLT_ASSIGNMENT,n==1), min(min0), max(max0) {}
100  virtual MaybeType solution(const Assignment& x) const {
101  if (max < min)
102  return MT_FALSE;
103  for (int i=x.size(); i--; )
104  if ((x[i].max() > max) || (x[i].min() < min))
105  return MT_FALSE;
106  return MT_TRUE;
107  }
109  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
110  if (x.size() == 1)
111  Gecode::dom(home, x[0], min, max);
112  else
113  Gecode::dom(home, x, min, max);
114  }
117  Gecode::Reify r) {
118  assert(x.size() == 1);
119  Gecode::dom(home, x[0], min, max, r);
120  }
121  };
122 
124  class Create {
125  public:
127  Create(void) {
128  using namespace Gecode;
129  FloatNum step = 0.7;
130  for (int c=-4; c<=4; c++) {
131  (void) new Val(1,c,step);
132  (void) new Val(2,c,step);
133  for (int d=-3; d<=3; d++) {
134  (void) new Num(1,c,d,step);
135  (void) new Num(2,c,d,step);
136  }
137  }
138  }
139  };
140 
143 
144  }
145 
146 }}
147 
148 // STATISTICS: test-float
const Gecode::FloatNum step
Definition: arithmetic.cpp:789
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition: dom.cpp:109
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
Base class for tests with float constraints
Definition: float.hh:242
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:79
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition: dom.cpp:72
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Test for domain constraints with a float value
Definition: dom.cpp:55
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition: float.hpp:198
Float variable array.
Definition: float.hh:1016
Computation spaces.
Definition: core.hpp:1325
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: dom.cpp:116
Gecode::IntSet d(r, 4)
const FloatNum min
Smallest allowed float value.
Definition: float.hh:833
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Reification specification.
Definition: int.hh:852
Create c
Definition: dom.cpp:141
Num(int n, Gecode::FloatNum min0, Gecode::FloatNum max0, Gecode::FloatNum st)
Create and register test.
Definition: dom.cpp:95
Help class to create and register tests.
Definition: dom.cpp:124
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:100
Gecode::FloatVal c
Float constant.
Definition: dom.cpp:58
Float value type.
Definition: float.hh:321
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
MaybeType
Type for comparisons and solutions.
Definition: float.hh:55
Create(void)
Perform creation and registration.
Definition: dom.cpp:127
int size(void) const
Return number of variables.
Definition: float.hpp:52
Test for domain constraints with float numbers
Definition: dom.cpp:87
Val(int n, Gecode::FloatVal c0, Gecode::FloatNum st)
Create and register test.
Definition: dom.cpp:61
Gecode::FloatNum max
Float number.
Definition: dom.cpp:92
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:390
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:402
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition: dom.cpp:65
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
double FloatNum
Floating point number base type.
Definition: float.hh:108
const int r[4][2]
Definition: dom.cpp:126
Gecode::FloatNum min
Float number.
Definition: dom.cpp:90
Base class for assignments
Definition: float.hh:84