main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
gecode
kernel
branch
val-sel.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main author:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2012
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
namespace
Gecode
{
35
42
template
<
class
_View,
class
_Val>
44
class
ValSel
{
45
public
:
47
typedef
_View
View
;
49
typedef
typename
View::VarType
Var
;
51
typedef
_Val
Val
;
52
public
:
54
ValSel
(
Space
& home,
const
ValBranch<Var>
& vb);
56
ValSel
(
Space
& home,
ValSel<View,Val>
& vs);
58
bool
notice
(
void
)
const
;
60
void
dispose
(
Space
& home);
61
};
62
64
template
<
class
View>
65
class
ValSelFunction
:
66
public
ValSel
<View,
67
typename BranchTraits<typename View::VarType>::ValType> {
68
using
typename
ValSel
<
View
,
69
typename
BranchTraits<typename View::VarType>::ValType
>
::Var
;
70
public
:
72
typedef
typename
ValSel
<
View
,
73
typename
BranchTraits<typename View::VarType>
74
::ValType>
::Val
Val
;
76
typedef
typename
BranchTraits<Var>::Val
ValFunction
;
77
protected
:
79
SharedData<ValFunction>
v
;
80
public
:
82
ValSelFunction
(
Space
& home,
const
ValBranch<Var>
& vb);
84
ValSelFunction
(
Space
& home,
ValSelFunction<View>
& vs);
86
Val
val
(
const
Space
& home,
View
x
,
int
i
);
88
bool
notice
(
void
)
const
;
90
void
dispose
(
Space
& home);
91
};
93
94
95
// Baseclass value selection
96
template
<
class
View,
class
Val>
97
forceinline
98
ValSel<View,Val>::ValSel
(
Space
&,
const
ValBranch<Var>
&) {}
99
template
<
class
View,
class
Val>
100
forceinline
101
ValSel<View,Val>::ValSel
(
Space
&,
ValSel<View,Val>
&) {}
102
template
<
class
View,
class
Val>
103
forceinline
bool
104
ValSel<View,Val>::notice
(
void
)
const
{
105
return
false
;
106
}
107
template
<
class
View,
class
Val>
108
forceinline
void
109
ValSel<View,Val>::dispose
(
Space
&) {}
110
111
112
// User-defined value selection
113
template
<
class
View>
114
forceinline
115
ValSelFunction<View>::ValSelFunction
116
(
Space
& home,
const
ValBranch
<
ValSelFunction<View>::Var
>& vb)
117
:
ValSel
<View,Val>(home,vb),
v
(vb.val()) {
118
if
(!
v
())
119
throw
InvalidFunction
(
"ValSelFunction::ValSelFunction"
);
120
}
121
template
<
class
View>
122
forceinline
123
ValSelFunction<View>::ValSelFunction
(
Space
& home,
ValSelFunction<View>
& vs)
124
:
ValSel
<View,
Val
>(home,vs),
v
(vs.
v
) {
125
}
126
template
<
class
View>
127
forceinline
typename
ValSelFunction<View>::Val
128
ValSelFunction<View>::val
(
const
Space
& home, View
x
,
int
i
) {
129
typename
View::VarType
y
(
x
.
varimp
());
130
GECODE_VALID_FUNCTION
(
v
());
131
return
v
()(home,
y
,
i
);
132
}
133
template
<
class
View>
134
forceinline
bool
135
ValSelFunction<View>::notice
(
void
)
const
{
136
return
true
;
137
}
138
template
<
class
View>
139
forceinline
void
140
ValSelFunction<View>::dispose
(
Space
&) {
141
v
.~SharedData<
ValFunction
>();
142
}
143
144
}
145
146
// STATISTICS: kernel-branch
Gecode::ValSelFunction::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition:
val-sel.hpp:135
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
Gecode::ValSelFunction::ValFunction
BranchTraits< Var >::Val ValFunction
The corresponding value function.
Definition:
val-sel.hpp:76
Gecode::ValSelFunction::ValSelFunction
ValSelFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Gecode::SharedData< ValFunction >
Gecode::ValSel
Base class for value selection.
Definition:
val-sel.hpp:44
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::BranchTraits
Traits for branching.
Definition:
traits.hpp:55
Gecode::ValSel::Var
View::VarType Var
Corresponding variable type.
Definition:
val-sel.hpp:49
GECODE_VALID_FUNCTION
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition:
macros.hpp:94
Gecode::ValSel::View
_View View
View type.
Definition:
val-sel.hpp:47
Gecode
Gecode toplevel namespace
Gecode::ValSelFunction
User-defined value selection.
Definition:
val-sel.hpp:65
Gecode::VarImpVar::varimp
VarImp * varimp(void) const
Return variable implementation of variable.
Definition:
var.hpp:96
Gecode::ValSel::ValSel
ValSel(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition:
val-sel.hpp:98
Gecode::ValBranch
Value branching information.
Definition:
val.hpp:41
Gecode::IntVar
Integer variables.
Definition:
int.hh:371
Gecode::ValSelFunction::v
SharedData< ValFunction > v
The user-defined value function.
Definition:
val-sel.hpp:79
Gecode::ValSel::Val
_Val Val
Value type.
Definition:
val-sel.hpp:51
Gecode::ValSelFunction::dispose
void dispose(Space &home)
Delete value selection.
Definition:
val-sel.hpp:140
Test::Int::Distinct::v
const int v[7]
Definition:
distinct.cpp:259
Gecode::InvalidFunction
Exception: invalid function
Definition:
exception.hpp:114
Gecode::ValSelFunction::Val
ValSel< View, typename BranchTraits< typename View::VarType >::ValType >::Val Val
The corresponding value type.
Definition:
val-sel.hpp:74
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::ValSel::dispose
void dispose(Space &home)
Delete value selection.
Definition:
val-sel.hpp:109
Gecode::ValSelFunction::val
Val val(const Space &home, View x, int i)
Return user-defined value of view x at position i.
Definition:
val-sel.hpp:128
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::ValSel::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition:
val-sel.hpp:104