Generated on for Gecode by doxygen 1.15.0
groups.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.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2019
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
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 <gecode/kernel.hh>
35#include <gecode/int.hh>
36
37#include "test/test.hh"
38
39namespace Test { namespace Groups {
40
42 class GroupSpace : public Gecode::Space {
43 protected:
46 public:
50 GroupSpace(int n) : x(*this,10,-10,10) {
51 using namespace Gecode;
52 switch (n) {
53 case 2:
54 distinct((*this)(b), x, IPL_DOM);
55 // fall through
56 case 1:
57 rel((*this)(a), x[0], Gecode::IRT_LE, x[1]);
58 break;
59 default:
60 break;
61 }
62 }
63
64 GroupSpace(GroupSpace& s) : Space(s), a(s.a), b(s.b) {
65 x.update(*this,s.x);
66 }
67
68 virtual Space* copy(void) {
69 return new GroupSpace(*this);
70 }
71 };
72
74 class Kill : public Test::Base {
75 protected:
77 int n;
79 bool fix;
81 bool all;
82 public:
84 Kill(int n0, bool fix0, bool all0)
85 : Test::Base("PropagatorGroup::Kill::"+
86 str(n0)+"::"+str(fix0)+"::"+str(all0)),
87 n(n0), fix(fix0), all(all0) {}
88
89 bool run(void) {
90 using namespace Gecode;
91 GroupSpace* s = new GroupSpace(n);
92 if (fix)
93 (void) s->status();
94 if (all) {
95 PropagatorGroup::all.kill(*s);
96 } else {
97 s->a.kill(*s);
98 s->b.kill(*s);
99 }
100 (void) s->status();
101 unsigned int p = PropagatorGroup::all.size(*s);
102 delete s;
103 return p == 0U;
104 }
105 };
106
107
109 class Create {
110 public:
112 Create(void) {
113 for (int n=0; n<=2; n++) {
114 (void) new Kill(n,true,false);
115 (void) new Kill(n,false,false);
116 (void) new Kill(n,true,true);
117 (void) new Kill(n,false,true);
118 }
119 }
120 };
121
123
124}}
125
126// STATISTICS: test-core
Integer variable array.
Definition int.hh:791
Group of propagators.
Definition core.hpp:734
void kill(Space &home)
Kill all propagators in a group.
Definition core.cpp:1021
static PropagatorGroup all
Group of all propagators.
Definition core.hpp:796
Computation spaces.
Definition core.hpp:1775
Base class for all tests to be run
Definition test.hh:121
Base(std::string s)
Create and register test with name s.
Definition test.cpp:60
static std::string str(bool b)
Map bool to string.
Definition test.hpp:77
Help class to create and register tests.
Definition groups.cpp:109
Create(void)
Perform creation and registration.
Definition groups.cpp:112
GroupSpace(GroupSpace &s)
Constructor for cloning s.
Definition groups.cpp:64
GroupSpace(int n)
Constructor for creation.
Definition groups.cpp:50
Gecode::IntVarArray x
Integer variables.
Definition groups.cpp:45
Gecode::PropagatorGroup a
Propagator groups.
Definition groups.cpp:48
virtual Space * copy(void)
Copy during cloning.
Definition groups.cpp:68
Gecode::PropagatorGroup b
Definition groups.cpp:48
Test for killing propagators
Definition groups.cpp:74
bool all
Whether to kill all propagators.
Definition groups.cpp:81
bool fix
Whether to compute fixpoint first.
Definition groups.cpp:79
Kill(int n0, bool fix0, bool all0)
Initialize test.
Definition groups.cpp:84
bool run(void)
Perform actual tests.
Definition groups.cpp:89
int n
Number of propagators.
Definition groups.cpp:77
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
@ IRT_LE
Less ( ).
Definition int.hh:963
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:1013
Space(void)
Default constructor.
Definition core.cpp:121
SpaceStatus status(StatusStatistics &stat)
Query space status.
Definition core.cpp:282
Gecode toplevel namespace
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl=IPL_DEF)
Post propagator for for all .
Definition distinct.cpp:46
General test support.
Definition afc.cpp:39