* \defgroup TaskTestSetExec Synchronized execution * \ingroup TaskTestSet */ @{ Simple test for wait (set variables)
| 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 |
| 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 |
| 58 | virtual bool solution(const SetAssignment& x) const { |
| 59 | (void) x; |
| 60 | return true; |
| 61 | } |
| 62 | /// Post wait on \a x |
| 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 |
| 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); |