main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Jul 27 2020 00:00:00 for Gecode by
doxygen
1.8.18
gecode
kernel
branch
val-commit.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
ValCommit
{
45
public
:
47
typedef
_View
View
;
49
typedef
typename
View::VarType
Var
;
51
typedef
_Val
Val
;
52
public
:
54
ValCommit
(
Space
& home,
const
ValBranch<Var>
& vb);
56
ValCommit
(
Space
& home,
ValCommit<View,Val>
& vs);
58
bool
notice
(
void
)
const
;
60
void
dispose
(
Space
& home);
61
};
62
64
template
<
class
View>
65
class
ValCommitFunction
:
public
66
ValCommit
<View,
67
typename BranchTraits<typename View::VarType>::ValType> {
68
typedef
typename
ValCommit
<
View
,
69
typename
BranchTraits<typename View::VarType>
70
::ValType>::Val Val;
71
public
:
73
typedef
typename
View::VarType
Var
;
75
typedef
typename
BranchTraits<Var>::Commit
CommitFunction
;
76
protected
:
78
SharedData<CommitFunction>
c
;
79
public
:
81
ValCommitFunction
(
Space
& home,
const
ValBranch<Var>
& vb);
83
ValCommitFunction
(
Space
& home,
ValCommitFunction
& vc);
85
ModEvent
commit
(
Space
& home,
unsigned
int
a
,
View
x
,
int
i
, Val
n
);
87
NGL
*
ngl
(
Space
& home,
unsigned
int
a
,
View
x
, Val
n
)
const
;
89
void
print
(
const
Space
& home,
unsigned
int
a
,
View
x
,
int
i
,
90
const
Val&
n
, std::ostream& o)
const
;
92
bool
notice
(
void
)
const
;
94
void
dispose
(
Space
& home);
95
};
97
98
// Baseclass for value commit
99
template
<
class
View,
class
Val>
100
forceinline
101
ValCommit<View,Val>::ValCommit
(
Space
&,
const
ValBranch<Var>
&) {}
102
template
<
class
View,
class
Val>
103
forceinline
104
ValCommit<View,Val>::ValCommit
(
Space
&,
ValCommit<View,Val>
&) {}
105
template
<
class
View,
class
Val>
106
forceinline
bool
107
ValCommit<View,Val>::notice
(
void
)
const
{
108
return
false
;
109
}
110
template
<
class
View,
class
Val>
111
forceinline
void
112
ValCommit<View,Val>::dispose
(
Space
&) {}
113
114
115
// User-defined value selection
116
template
<
class
View>
117
forceinline
118
ValCommitFunction<View>::ValCommitFunction
(
Space
& home,
119
const
ValBranch<Var>
& vb)
120
:
ValCommit
<View,Val>(home,vb),
c
(vb.commit()) {
121
if
(!
c
())
122
throw
InvalidFunction
(
"ValCommitFunction::ValCommitFunction"
);
123
}
124
template
<
class
View>
125
forceinline
126
ValCommitFunction<View>::ValCommitFunction
(
Space
& home,
127
ValCommitFunction<View>
& vc)
128
:
ValCommit
<View,Val>(home,vc),
c
(vc.
c
) {
129
}
130
template
<
class
View>
131
forceinline
ModEvent
132
ValCommitFunction<View>::commit
(
Space
& home,
unsigned
int
a
, View
x
,
int
i
,
133
Val
n
) {
134
typename
View::VarType
y
(
x
.
varimp
());
135
GECODE_VALID_FUNCTION
(
c
());
136
c
()(home,
a
,
y
,
i
,
n
);
137
return
home.
failed
() ?
ES_FAILED
:
ES_OK
;
138
}
139
template
<
class
View>
140
forceinline
NGL
*
141
ValCommitFunction<View>::ngl
(
Space
&,
unsigned
int
, View, Val)
const
{
142
return
NULL;
143
}
144
template
<
class
View>
145
forceinline
void
146
ValCommitFunction<View>::print
(
const
Space
&,
unsigned
int
,
147
View,
int
i
,
const
Val&,
148
std::ostream& o)
const
{
149
o <<
"var["
<<
i
<<
"] is user-defined."
;
150
}
151
template
<
class
View>
152
forceinline
bool
153
ValCommitFunction<View>::notice
(
void
)
const
{
154
return
true
;
155
}
156
template
<
class
View>
157
forceinline
void
158
ValCommitFunction<View>::dispose
(
Space
&) {
159
c
.~SharedData<
CommitFunction
>();
160
}
161
162
}
163
164
// STATISTICS: kernel-branch
Gecode::ValCommitFunction::Var
View::VarType Var
The corresponding variable type.
Definition:
val-commit.hpp:73
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::SharedData< CommitFunction >
Gecode::ValCommitFunction::ngl
NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for alternative a.
Definition:
val-commit.hpp:141
Gecode::ValCommitFunction::CommitFunction
BranchTraits< Var >::Commit CommitFunction
The corresponding commit function.
Definition:
val-commit.hpp:75
Gecode::ValCommit
Base class for value commit.
Definition:
val-commit.hpp:44
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::ValCommit::Var
View::VarType Var
Corresponding variable type.
Definition:
val-commit.hpp:49
Gecode::ValCommit::ValCommit
ValCommit(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition:
val-commit.hpp:101
Gecode::BranchTraits
Traits for branching.
Definition:
traits.hpp:55
GECODE_VALID_FUNCTION
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition:
macros.hpp:94
Gecode::ValCommit::Val
_Val Val
Value type.
Definition:
val-commit.hpp:51
Gecode::ValCommitFunction::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition:
val-commit.hpp:153
Gecode
Gecode toplevel namespace
Gecode::ValCommit::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition:
val-commit.hpp:107
Gecode::VarImpVar::varimp
VarImp * varimp(void) const
Return variable implementation of variable.
Definition:
var.hpp:96
Gecode::ValCommitFunction::commit
ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)
Perform user-defined commit.
Definition:
val-commit.hpp:132
Gecode::ValBranch
Value branching information.
Definition:
val.hpp:41
Gecode::ValCommit::View
_View View
View type.
Definition:
val-commit.hpp:47
a
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Gecode::ValCommitFunction::print
void print(const Space &home, unsigned int a, View x, int i, const Val &n, std::ostream &o) const
Print on o the alternative with view x at position i and value n.
Definition:
val-commit.hpp:146
Gecode::ValCommit::ValCommit
ValCommit(Space &home, ValCommit< View, Val > &vs)
Constructor for cloning.
Definition:
val-commit.hpp:104
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition:
core.hpp:62
Gecode::Space::failed
bool failed(void) const
Check whether space is failed.
Definition:
core.hpp:4044
Gecode::InvalidFunction
Exception: invalid function
Definition:
exception.hpp:114
forceinline
#define forceinline
Definition:
config.hpp:185
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::NGL
No-good literal recorded during search.
Definition:
core.hpp:1340
Gecode::ValCommitFunction::c
SharedData< CommitFunction > c
The user-defined commit function.
Definition:
val-commit.hpp:78
Gecode::ValCommitFunction::dispose
void dispose(Space &home)
Delete value commit.
Definition:
val-commit.hpp:158
Gecode::ValCommitFunction
Class for user-defined value commit.
Definition:
val-commit.hpp:67
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::ValCommitFunction::ValCommitFunction
ValCommitFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition:
val-commit.hpp:118
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition:
core.hpp:474
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::ValCommit::dispose
void dispose(Space &home)
Delete value commit.
Definition:
val-commit.hpp:112
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:476