main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Jan 1 2020 10:37:59 for Gecode by
doxygen
1.8.16
gecode
kernel
branch
filter.hpp
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, 2017
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 <functional>
35
36
namespace
Gecode
{
37
39
template
<
class
Var>
40
using
BranchFilter
= std::function<bool(
const
Space& home,
41
Var
x
,
int
i
)>;
42
44
template
<
class
View>
45
class
BrancherFilter
{
46
public
:
48
typedef
typename
View::VarType
Var
;
49
protected
:
50
SharedData<BranchFilter<Var>
>
f
;
51
public
:
53
BrancherFilter
(
BranchFilter<Var>
bf);
55
BrancherFilter
(
BrancherFilter
& bf);
57
operator
bool(
void
)
const
;
59
bool
operator ()
(
const
Space
& home, View
x
,
int
i
)
const
;
61
bool
notice
(
void
)
const
;
63
void
dispose
(
Space
& home);
64
};
65
67
template
<
class
View>
68
class
BrancherNoFilter
{
69
public
:
71
typedef
typename
View::VarType
Var
;
72
public
:
74
BrancherNoFilter
(
BranchFilter<Var>
bf);
76
BrancherNoFilter
(
BrancherNoFilter
& bf);
78
operator
bool(
void
)
const
;
80
bool
operator ()
(
const
Space
& home, View
x
,
int
i
)
const
;
82
bool
notice
(
void
)
const
;
84
void
dispose
(
Space
& home);
85
};
86
87
88
template
<
class
View>
89
forceinline
90
BrancherFilter<View>::BrancherFilter
(
BranchFilter<Var>
bf) :
f
(bf) {
91
if
(!bf)
92
throw
Gecode::InvalidFunction
(
"BrancherFilter::BrancherFilter"
);
93
}
94
95
template
<
class
View>
96
forceinline
97
BrancherFilter<View>::BrancherFilter
(
BrancherFilter<View>
& bf)
98
:
f
(bf.
f
) {
99
}
100
101
template
<
class
View>
102
forceinline
103
BrancherFilter<View>::operator
bool(
void
)
const
{
104
return
true
;
105
}
106
107
template
<
class
View>
108
forceinline
bool
109
BrancherFilter<View>::operator ()
(
const
Space
& home, View
x
,
int
i
)
const
{
110
GECODE_VALID_FUNCTION
(
f
());
111
Var
xv(
x
.
varimp
());
112
return
f
()(home,xv,
i
);
113
}
114
115
template
<
class
View>
116
forceinline
bool
117
BrancherFilter<View>::notice
(
void
)
const
{
118
return
true
;
119
}
120
121
template
<
class
View>
122
forceinline
void
123
BrancherFilter<View>::dispose
(
Space
&) {
124
f
.~SharedData<
BranchFilter<Var>
>();
125
}
126
127
128
template
<
class
View>
129
forceinline
130
BrancherNoFilter<View>::BrancherNoFilter
(
BranchFilter<Var>
bf) {
131
assert(!bf);
132
(void) bf;
133
}
134
135
template
<
class
View>
136
forceinline
137
BrancherNoFilter<View>::BrancherNoFilter
(
BrancherNoFilter<View>
&) {}
138
139
template
<
class
View>
140
forceinline
141
BrancherNoFilter<View>::operator
bool(
void
)
const
{
142
return
false
;
143
}
144
145
template
<
class
View>
146
forceinline
bool
147
BrancherNoFilter<View>::operator ()
(
const
Space
&, View,
int
)
const
{
148
return
true
;
149
}
150
template
<
class
View>
151
forceinline
bool
152
BrancherNoFilter<View>::notice
(
void
)
const
{
153
return
false
;
154
}
155
156
template
<
class
View>
157
forceinline
void
158
BrancherNoFilter<View>::dispose
(
Space
&) {
159
}
160
161
}
162
163
// STATISTICS: kernel-branch
Gecode::BranchFilter
std::function< bool(const Space &home, Var x, int i)> BranchFilter
Function type for branch filter functions.
Definition:
filter.hpp:41
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::BrancherNoFilter
Class withot a branch filter function.
Definition:
filter.hpp:68
Gecode::SharedData
Class for sharing data between spaces.
Definition:
shared-data.hpp:38
Gecode::BrancherNoFilter::BrancherNoFilter
BrancherNoFilter(BranchFilter< Var > bf)
Initialize.
Definition:
filter.hpp:130
Gecode::BrancherNoFilter::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition:
filter.hpp:152
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::BrancherFilter::dispose
void dispose(Space &home)
Delete object.
Definition:
filter.hpp:123
GECODE_VALID_FUNCTION
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition:
macros.hpp:94
Gecode::Var
Base class for variables.
Definition:
var.hpp:40
Gecode
Gecode toplevel namespace
Gecode::BrancherNoFilter::Var
View::VarType Var
The corresponding variable type.
Definition:
filter.hpp:71
Gecode::VarImpVar::varimp
VarImp * varimp(void) const
Return variable implementation of variable.
Definition:
var.hpp:96
Gecode::BrancherFilter::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition:
filter.hpp:117
Gecode::BrancherFilter::operator()
bool operator()(const Space &home, View x, int i) const
Invoke filter function.
Definition:
filter.hpp:109
Gecode::BrancherNoFilter::operator()
bool operator()(const Space &home, View x, int i) const
Invoke filter function.
Definition:
filter.hpp:147
Gecode::BrancherFilter::BrancherFilter
BrancherFilter(BranchFilter< Var > bf)
Initialize.
Definition:
filter.hpp:90
Gecode::BrancherFilter
Class storing a branch filter function.
Definition:
filter.hpp:45
Gecode::InvalidFunction
Exception: invalid function
Definition:
exception.hpp:114
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::f
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::BrancherNoFilter::dispose
void dispose(Space &home)
Delete object.
Definition:
filter.hpp:158
Gecode::BrancherFilter::f
SharedData< BranchFilter< Var > > f
Definition:
filter.hpp:50
Gecode::BrancherFilter::Var
View::VarType Var
The corresponding variable type.
Definition:
filter.hpp:48