exec.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2009
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "test/set.hh"
namespace Test { namespace Set {
namespace Exec {
class Wait : public SetTest {
protected:
bool sf;
public:
Wait(int n, bool sf0)
: SetTest("Wait::"+str(n)+"::"+
(sf0 ? "std::function" : "funptr"),n,
Gecode::IntSet(0,n),false), sf(sf0) {}
virtual bool solution(const SetAssignment& x) const {
(void) x;
return true;
}
virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
Gecode::IntVarArray&) {
using namespace Gecode;
auto f = static_cast<std::function<void(Space&)>>
([](Space& home) { c(home); });
if (x.size() > 1) {
if (sf)
Gecode::wait(home, x, f);
else
Gecode::wait(home, x, &c);
} else {
if (sf)
Gecode::wait(home, x[0], f);
else
Gecode::wait(home, x[0], &c);
}
}
static void c(Gecode::Space& _home) {
SetTestSpace& home = static_cast<SetTestSpace&>(_home);
for (int i=0; i<home.x.size(); i++)
if (!home.x[i].assigned())
home.fail();
}
};
Wait w1t(1,true), w2t(2,true);
Wait w1f(1,false), w2f(2,false);
}
}}
// STATISTICS: test-int
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
Gecode::SetVarArray
Set variable array
Definition set.hh:570
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::VarArray::assigned
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1026
Gecode::VarArray::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:926
Test::Set::Exec::Wait
Simple test for wait (set variables).
Definition exec.cpp:47
Test::Set::Exec::Wait::Wait
Wait(int n, bool sf0)
Create and register test.
Definition exec.cpp:53
Test::Set::Exec::Wait::post
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post wait on x.
Definition exec.cpp:63
Test::Set::Exec::Wait::sf
bool sf
Whether to use std::function.
Definition exec.cpp:50
Test::Set::Exec::Wait::c
static void c(Gecode::Space &_home)
Continuation to be executed.
Definition exec.cpp:81
Test::Set::Exec::Wait::solution
virtual bool solution(const SetAssignment &x) const
Check whether x is solution.
Definition exec.cpp:58
Test::Set::SetAssignment
Generate all set assignments.
Definition set.hh:142
Test::Set::SetTestSpace
Space for executing set tests.
Definition set.hh:182
Test::Set::SetTestSpace::x
Gecode::SetVarArray x
Set variables to be tested.
Definition set.hh:187
Test::Set::SetTest::str
static std::string str(Gecode::SetRelType srt)
Map set relation to string.
Definition set.hpp:46
Test::Set::SetTest::SetTest
SetTest(const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Constructor.
Definition set.hh:304
Gecode::Space::fail
void fail(void)
Fail space.
Definition core.hpp:4030
Gecode
Gecode toplevel namespace
Test::Set::Exec
Tests for synchronized execution
Definition exec.cpp:39
Test::Set::Exec::w2t
Wait w2t(2, true)
Test::Set::Exec::w1f
Wait w1f(1, false)
Test::Set::Exec::w1t
Wait w1t(1, true)
Test::Set::Exec::w2f
Wait w2f(2, false)
Test::Set
Testing finite sets.
Definition set.cpp:42
Test
General test support.
Definition afc.cpp:39
set.hh