this repo has no description
at develop 3.5 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 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.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 <gecode/kernel.hh> 35#include <gecode/int.hh> 36 37#include "test/test.hh" 38 39namespace Test { namespace Groups { 40 41 /// Test space 42 class GroupSpace : public Gecode::Space { 43 protected: 44 /// Integer variables 45 Gecode::IntVarArray x; 46 public: 47 /// Propagator groups 48 Gecode::PropagatorGroup a, b; 49 /// Constructor for creation 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 /// Constructor for cloning \a s 64 GroupSpace(GroupSpace& s) : Space(s), a(s.a), b(s.b) { 65 x.update(*this,s.x); 66 } 67 /// Copy during cloning 68 virtual Space* copy(void) { 69 return new GroupSpace(*this); 70 } 71 }; 72 73 /// %Test for killing propagators 74 class Kill : public Test::Base { 75 protected: 76 /// Number of propagators 77 int n; 78 /// Whether to compute fixpoint first 79 bool fix; 80 /// Whether to kill all propagators 81 bool all; 82 public: 83 /// Initialize test 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 /// Perform actual tests 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 108 /// Help class to create and register tests 109 class Create { 110 public: 111 /// Perform creation and registration 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 122 Create c; 123 124}} 125 126// STATISTICS: test-core