Generated on Sat Feb 7 2015 02:01:29 for Gecode by doxygen 1.8.9.1
convex.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2005
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/set.hh"
39 
40 using namespace Gecode;
41 
42 namespace Test { namespace Set {
43 
45  namespace Convex {
46 
52 
53  static IntSet ds_33(-4,4);
54 
56  class Convex : public SetTest {
57  public:
59  Convex(const char* t)
60  : SetTest(t,1,ds_33,false) {}
62  virtual bool solution(const SetAssignment& x) const {
63  CountableSetRanges xr0(x.lub, x[0]);
64  if (!xr0())
65  return true;
66  ++xr0;
67  if (!xr0())
68  return true;
69  return false;
70  }
72  virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
73  Gecode::convex(home, x[0]);
74  }
75  };
76  Convex _convex("Convex::Convex");
77 
79  class ConvexHull : public SetTest {
80  public:
82  ConvexHull(const char* t)
83  : SetTest(t,2,ds_33,false) {}
85  virtual bool solution(const SetAssignment& x) const {
86  CountableSetRanges xr0(x.lub, x[0]);
87  CountableSetRanges xr1(x.lub, x[1]);
88 
89  if (!xr0())
90  return !xr1();
91 
92  int x0min = xr0.min();
93  int x0max = xr0.max();
94  ++xr0;
95  if (!xr0()) {
96  if (!xr1()) return false;
97  if (x0min != xr1.min()) return false;
98  int x1max = Gecode::Set::Limits::min;
99  while (xr1()) { x1max = xr1.max(); ++xr1;}
100  if (x0max != x1max) return false;
101  return true;
102  }
103  return false;
104  }
106  virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
107  Gecode::convex(home, x[1], x[0]);
108  }
109  };
110  ConvexHull _convexhull("Convex::ConvexHull");
111 
113  class ConvexHullS : public SetTest {
114  public:
116  ConvexHullS(const char* t)
117  : SetTest(t,1,ds_33,false) {}
119  virtual bool solution(const SetAssignment& x) const {
120  CountableSetRanges xr0(x.lub, x[0]);
121  if (!xr0())
122  return true;
123  ++xr0;
124  if (!xr0())
125  return true;
126  return false;
127  }
129  virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
130  Gecode::convex(home, x[0], x[0]);
131  }
132  };
133  ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS");
134 
136 
137 }}}
138 
139 // STATISTICS: test-set
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: convex.cpp:62
NodeType t
Type of node.
Definition: bool-expr.cpp:234
const int min
Smallest allowed integer in integer set.
Definition: set.hh:101
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition: convex.cpp:129
Test for convexity propagator
Definition: convex.cpp:56
int max(void) const
Return largest value of range.
Integer variable array.
Definition: int.hh:741
Test for convex hull propagator
Definition: convex.cpp:79
Computation spaces.
Definition: core.hpp:1362
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: convex.cpp:85
ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS")
int min(void) const
Return smallest value of range.
ConvexHull _convexhull("Convex::ConvexHull")
Gecode::IntSet lub
The common superset for all domains.
Definition: set.hh:170
Integer sets.
Definition: int.hh:171
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition: convex.cpp:106
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: convex.cpp:119
General test support.
Definition: afc.cpp:43
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Sharing test for convex hull propagator.
Definition: convex.cpp:113
Convex _convex("Convex::Convex")
Base class for tests with set constraints
Definition: set.hh:271
Generate all set assignments.
Definition: set.hh:158
void convex(Home home, SetVar x)
Post propagator that propagates that x is convex.
Definition: convex.cpp:45
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition: convex.cpp:72
ConvexHullS(const char *t)
Create and register test.
Definition: convex.cpp:116
Range iterator producing subsets of an IntSet.
Definition: set.hh:114
Set variable array
Definition: set.hh:571
Gecode toplevel namespace
ConvexHull(const char *t)
Create and register test.
Definition: convex.cpp:82
Convex(const char *t)
Create and register test.
Definition: convex.cpp:59