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