Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
36using namespace Gecode;
37
38namespace 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) {}
57
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 }
67
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) {}
80
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 }
101
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) {}
114
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 }
124
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
Integer sets.
Definition int.hh:174
Integer variable array.
Definition int.hh:772
int min(void) const
Return smallest value of range.
int max(void) const
Return largest value of range.
Set variable array
Definition set.hh:573
Computation spaces.
Definition core.hpp:1744
Sharing test for convex hull propagator.
Definition convex.cpp:109
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition convex.cpp:115
ConvexHullS(const char *t)
Create and register test.
Definition convex.cpp:112
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition convex.cpp:125
Test for convex hull propagator
Definition convex.cpp:75
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition convex.cpp:102
ConvexHull(const char *t)
Create and register test.
Definition convex.cpp:78
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition convex.cpp:81
Test for convexity propagator
Definition convex.cpp:52
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition convex.cpp:68
Convex(const char *t)
Create and register test.
Definition convex.cpp:55
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition convex.cpp:58
Range iterator producing subsets of an IntSet.
Definition set.hh:99
Generate all set assignments.
Definition set.hh:142
SetTest(const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Constructor.
Definition set.hh:304
const int min
Smallest allowed integer in integer set.
Definition set.hh:99
Gecode toplevel namespace
Post propagator that propagates that a x is convex void convex(Home home, SetVar x)
Definition convex.cpp:41
Post propagator for SetVar x
Definition set.hh:773
ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS")
Convex _convex("Convex::Convex")
ConvexHull _convexhull("Convex::ConvexHull")
Testing finite sets.
Definition set.cpp:42
General test support.
Definition afc.cpp:39