main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
test
set
exec.cpp
Go to the documentation of this file.
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
* Last modified:
10
* $Date: 2017-03-14 22:28:47 +0100 (Tue, 14 Mar 2017) $ by $Author: schulte $
11
* $Revision: 15581 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include "
test/set.hh
"
39
40
namespace
Test
{
namespace
Set {
41
43
namespace
Exec {
44
50
class
Wait
:
public
SetTest
{
52
protected
:
54
bool
sf
;
55
public
:
57
Wait
(
int
n
,
bool
sf0)
58
:
SetTest
(
"Wait::"
+
str
(
n
)+
"::"
+
59
(sf0 ?
"std::function"
:
"funptr"
),
n
,
60
Gecode
::IntSet(0,
n
),false),
sf
(sf0) {}
62
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
63
(void)
x
;
64
return
true
;
65
}
67
virtual
void
post
(
Gecode::Space
& home,
Gecode::SetVarArray
&
x
,
68
Gecode::IntVarArray
&) {
69
using namespace
Gecode
;
70
auto
f
=
static_cast<
std::function<
void
(
Space
&)
>
>
71
([](
Space
& home) {
c
(home); });
72
if
(
x
.size() > 1) {
73
if
(
sf
)
74
Gecode::wait
(home,
x
,
f
);
75
else
76
Gecode::wait
(home,
x
, &
c
);
77
}
else
{
78
if
(
sf
)
79
Gecode::wait
(home,
x
[0],
f
);
80
else
81
Gecode::wait
(home,
x
[0], &
c
);
82
}
83
}
85
static
void
c
(
Gecode::Space
& _home) {
86
SetTestSpace
& home =
static_cast<
SetTestSpace
&
>
(_home);
87
for
(
int
i
=0;
i
<home.
x
.
size
();
i
++)
88
if
(!home.
x
[
i
].
assigned
())
89
home.
fail
();
90
}
91
};
92
93
Wait
w1t
(1,
true
),
w2t
(2,
true
);
94
Wait
w1f
(1,
false
),
w2f
(2,
false
);
95
97
98
}
99
100
}}
101
102
// STATISTICS: test-int
Test::Set::SetTestSpace::x
Gecode::SetVarArray x
Set variables to be tested.
Definition:
set.hh:203
Test::Set::SetTestSpace
Space for executing set tests.
Definition:
set.hh:198
Test::Set::Exec::Wait::Wait
Wait(int n, bool sf0)
Create and register test.
Definition:
exec.cpp:57
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Test::Set::Exec::w1f
Wait w1f(1, false)
Test::Set::Exec::Wait::sf
bool sf
Whether to use std::function.
Definition:
exec.cpp:54
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:744
Gecode::VarArray::size
int size(void) const
Return size of array (number of elements)
Definition:
array.hpp:985
set.hh
Test::Set::SetAssignment
Generate all set assignments.
Definition:
set.hh:158
Gecode::VarArray::assigned
bool assigned(void) const
Test if all variables are assigned.
Definition:
array.hpp:1085
Gecode
Gecode toplevel namespace
Test::Set::Exec::Wait::c
static void c(Gecode::Space &_home)
Continuation to be executed.
Definition:
exec.cpp:85
Test::Set::Exec::Wait::solution
virtual bool solution(const SetAssignment &x) const
Check whether x is solution.
Definition:
exec.cpp:62
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:253
Test::Set::SetTest
Base class for tests with set constraints
Definition:
set.hh:289
Test::Set::Exec::w2f
Wait w2f(2, false)
Test::Set::Exec::w2t
Wait w2t(2, true)
Test::Set::Exec::Wait
Simple test for wait (set variables)
Definition:
exec.cpp:51
Test::Set::Exec::Wait::post
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post wait on x.
Definition:
exec.cpp:67
Test::Set::SetTest::str
static std::string str(Gecode::SetRelType srt)
Map set relation to string.
Definition:
set.hpp:50
Gecode::wait
void wait(Home home, FloatVar x, std::function< void(Space &home)> c)
Execute c when x becomes assigned.
Definition:
exec.cpp:44
Gecode::Space::fail
void fail(void)
Fail space.
Definition:
core.hpp:4081
Test::Set::Exec::w1t
Wait w1t(1, true)
Test
General test support.
Definition:
afc.cpp:43
Gecode::f
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Gecode::SetVarArray
Set variable array
Definition:
set.hh:572
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238