this repo has no description
at develop 4.2 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, 2008 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/int.hh" 35 36#include <gecode/minimodel.hh> 37 38namespace Test { namespace Int { 39 40 /// %Tests for unsharing variables in arrays 41 namespace Unshare { 42 43 /** 44 * \defgroup TaskTestIntUnshare Unsharing variables in arrays 45 * \ingroup TaskTestInt 46 */ 47 //@{ 48 /// %Test for unsharing integer variables 49 class Int : public Test { 50 public: 51 /// Create and register test 52 Int(Gecode::IntPropLevel ipl) 53 : Test("Unshare::Int::"+str(ipl),9,-1,1,false,ipl) {} 54 /// %Test whether \a x is solution 55 virtual bool solution(const Assignment& x) const { 56 return ((x[0] == x[3]) && 57 (x[1] == x[4]) && (x[1] == x[6]) && 58 (x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8])); 59 } 60 /// Post constraint on \a x 61 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { 62 using namespace Gecode; 63 IntVarArgs y(6); 64 y[0]=x[0]; y[1]=y[3]=x[1]; y[2]=y[4]=y[5]=x[2]; 65 unshare(home, y, ipl); 66 for (int i=0; i<6; i++) 67 rel(home, y[i], IRT_EQ, x[3+i], IPL_DOM); 68 } 69 }; 70 71 /// %Test for unsharing Boolean variables 72 class Bool : public Test { 73 public: 74 /// Create and register test 75 Bool(void) 76 : Test("Unshare::Bool",9,0,1,false) {} 77 /// %Test whether \a x is solution 78 virtual bool solution(const Assignment& x) const { 79 return ((x[0] == x[3]) && 80 (x[1] == x[4]) && (x[1] == x[6]) && 81 (x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8])); 82 } 83 /// Post constraint on \a x 84 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { 85 using namespace Gecode; 86 BoolVarArgs y(6); 87 y[0]=channel(home,x[0]); 88 y[1]=y[3]=channel(home,x[1]); 89 y[2]=y[4]=y[5]=channel(home,x[2]); 90 unshare(home, y); 91 for (int i=0; i<6; i++) 92 rel(home, y[i], IRT_EQ, channel(home,x[3+i])); 93 } 94 }; 95 96 /// %Test for unsharing in failed spaces 97 class Failed : public Test { 98 public: 99 /// Create and register test 100 Failed(void) 101 : Test("Unshare::Failed",1,-1,1) {} 102 /// %Test whether \a x is solution 103 virtual bool solution(const Assignment& x) const { 104 (void) x; 105 return false; 106 } 107 /// Post constraint on \a x 108 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { 109 using namespace Gecode; 110 home.fail(); 111 IntVarArgs y(2); 112 y[0]=x[0]; y[1]=x[0]; 113 unshare(home, y); 114 REG r(1); 115 extensional(home, y, r); 116 } 117 }; 118 119 Int i_bnd(Gecode::IPL_BND); 120 Int i_dom(Gecode::IPL_DOM); 121 122 Bool b; 123 124 Failed f; 125 //@} 126 127 } 128}} 129 130// STATISTICS: test-int