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, 2009 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 namespace Test { namespace Set { 37 38 /// %Tests for synchronized execution 39 namespace Exec { 40 41 /** 42 * \defgroup TaskTestSetExec Synchronized execution 43 * \ingroup TaskTestSet 44 */ 45 //@{ 46 /// Simple test for wait (set variables) 47 class Wait : public SetTest { 48 protected: 49 /// Whether to use std::function 50 bool sf; 51 public: 52 /// Create and register test Wait(int n,bool sf0)53 Wait(int n, bool sf0) 54 : SetTest("Wait::"+str(n)+"::"+ 55 (sf0 ? "std::function" : "funptr"),n, 56 Gecode::IntSet(0,n),false), sf(sf0) {} 57 /// Check whether \a x is solution solution(const SetAssignment & x) const58 virtual bool solution(const SetAssignment& x) const { 59 (void) x; 60 return true; 61 } 62 /// Post wait on \a x post(Gecode::Space & home,Gecode::SetVarArray & x,Gecode::IntVarArray &)63 virtual void post(Gecode::Space& home, Gecode::SetVarArray& x, 64 Gecode::IntVarArray&) { 65 using namespace Gecode; 66 auto f = static_cast<std::function<void(Space&)>> 67 ([](Space& home) { c(home); }); 68 if (x.size() > 1) { 69 if (sf) 70 Gecode::wait(home, x, f); 71 else 72 Gecode::wait(home, x, &c); 73 } else { 74 if (sf) 75 Gecode::wait(home, x[0], f); 76 else 77 Gecode::wait(home, x[0], &c); 78 } 79 } 80 /// Continuation to be executed c(Gecode::Space & _home)81 static void c(Gecode::Space& _home) { 82 SetTestSpace& home = static_cast<SetTestSpace&>(_home); 83 for (int i=0; i<home.x.size(); i++) 84 if (!home.x[i].assigned()) 85 home.fail(); 86 } 87 }; 88 89 Wait w1t(1,true), w2t(2,true); 90 Wait w1f(1,false), w2f(2,false); 91 92 //@} 93 94 } 95 96 }} 97 98 // STATISTICS: test-int 99