Generated on Fri Jan 28 2022 04:43:06 for Gecode by doxygen 1.8.13
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  * 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/set.hh"
35 
36 using namespace Gecode;
37 
38 namespace Test { namespace Set {
39 
41  namespace Convex {
42 
48 
49  static IntSet ds_33(-4,4);
50 
52  class Convex : public SetTest {
53  public:
55  Convex(const char* t)
56  : SetTest(t,1,ds_33,false) {}
58  virtual bool solution(const SetAssignment& x) const {
59  CountableSetRanges xr0(x.lub, x[0]);
60  if (!xr0())
61  return true;
62  ++xr0;
63  if (!xr0())
64  return true;
65  return false;
66  }
68  virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
69  Gecode::convex(home, x[0]);
70  }
71  };
72  Convex _convex("Convex::Convex");
73 
75  class ConvexHull : public SetTest {
76  public:
78  ConvexHull(const char* t)
79  : SetTest(t,2,ds_33,false) {}
81  virtual bool solution(const SetAssignment& x) const {
82  CountableSetRanges xr0(x.lub, x[0]);
83  CountableSetRanges xr1(x.lub, x[1]);
84 
85  if (!xr0())
86  return !xr1();
87 
88  int x0min = xr0.min();
89  int x0max = xr0.max();
90  ++xr0;
91  if (!xr0()) {
92  if (!xr1()) return false;
93  if (x0min != xr1.min()) return false;
94  int x1max = Gecode::Set::Limits::min;
95  while (xr1()) { x1max = xr1.max(); ++xr1;}
96  if (x0max != x1max) return false;
97  return true;
98  }
99  return false;
100  }
102  virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
103  Gecode::convex(home, x[1], x[0]);
104  }
105  };
106  ConvexHull _convexhull("Convex::ConvexHull");
107 
109  class ConvexHullS : public SetTest {
110  public:
112  ConvexHullS(const char* t)
113  : SetTest(t,1,ds_33,false) {}
115  virtual bool solution(const SetAssignment& x) const {
116  CountableSetRanges xr0(x.lub, x[0]);
117  if (!xr0())
118  return true;
119  ++xr0;
120  if (!xr0())
121  return true;
122  return false;
123  }
125  virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
126  Gecode::convex(home, x[0], x[0]);
127  }
128  };
129  ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS");
130 
132 
133 }}}
134 
135 // STATISTICS: test-set
NodeType t
Type of node.
Definition: bool-expr.cpp:230
const int min
Smallest allowed integer in integer set.
Definition: set.hh:99
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition: convex.cpp:125
Test for convexity propagator
Definition: convex.cpp:52
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: convex.cpp:81
int max(void) const
Return largest value of range.
Integer variable array.
Definition: int.hh:763
Test for convex hull propagator
Definition: convex.cpp:75
Computation spaces.
Definition: core.hpp:1701
ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS")
ConvexHull _convexhull("Convex::ConvexHull")
Gecode::IntSet lub
The common superset for all domains.
Definition: set.hh:154
Integer sets.
Definition: int.hh:174
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: convex.cpp:58
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition: convex.cpp:102
void convex(Home home, SetVar x)
Definition: convex.cpp:41
General test support.
Definition: afc.cpp:39
Sharing test for convex hull propagator.
Definition: convex.cpp:109
Convex _convex("Convex::Convex")
Base class for tests with set constraints
Definition: set.hh:273
Generate all set assignments.
Definition: set.hh:142
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition: convex.cpp:68
ConvexHullS(const char *t)
Create and register test.
Definition: convex.cpp:112
Range iterator producing subsets of an IntSet.
Definition: set.hh:98
Post propagator for SetVar x
Definition: set.hh:767
Set variable array
Definition: set.hh:570
Gecode toplevel namespace
ConvexHull(const char *t)
Create and register test.
Definition: convex.cpp:78
int min(void) const
Return smallest value of range.
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: convex.cpp:115
Convex(const char *t)
Create and register test.
Definition: convex.cpp:55