main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Feb 14 2013 20:59:31 for Gecode by
doxygen
1.8.3.1
gecode
kernel
branch.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
* Mikael Lagerkvist <lagerkvist@gecode.org>
6
*
7
* Copyright:
8
* Christian Schulte, 2008
9
* Mikael Lagerkvist, 2008
10
*
11
* Last modified:
12
* $Date: 2011-05-11 20:44:17 +1000 (Wed, 11 May 2011) $ by $Author: tack $
13
* $Revision: 12001 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include <
gecode/kernel.hh
>
41
42
namespace
Gecode {
43
44
const
VarBranchOptions
VarBranchOptions::def
;
45
46
const
ValBranchOptions
ValBranchOptions::def
;
47
48
const
TieBreakVarBranchOptions
TieBreakVarBranchOptions::def
;
49
50
51
/*
52
* Function brancher
53
*/
54
56
class
GECODE_KERNEL_EXPORT
FunctionBranch
:
public
Brancher
{
57
protected
:
59
class
GECODE_KERNEL_EXPORT
Description
:
public
Choice
{
60
public
:
62
Description
(
const
Brancher
&
b
,
unsigned
int
a
) :
Choice
(b,a) {}
64
virtual
size_t
size
(
void
)
const
{
return
sizeof
(
Description
); }
66
virtual
void
archive
(
Archive
& e)
const
{
67
Choice::archive
(e);
68
}
69
};
71
void (*f)(
Space
&);
73
bool
done
;
75
FunctionBranch
(
Home
home,
void
(*f0)(
Space
&))
76
:
Brancher
(home), f(f0), done(false) {}
78
FunctionBranch
(
Space
& home,
bool
share,
FunctionBranch
&
b
)
79
:
Brancher
(home,share,b), f(b.f), done(b.done) {}
80
public
:
82
virtual
bool
status
(
const
Space
&)
const
{
83
return
!done;
84
}
86
virtual
const
Choice
*
choice
(
Space
&) {
87
assert(!done);
88
return
new
Description
(*
this
,1);
89
}
91
virtual
const
Choice
*
choice
(
const
Space
&,
Archive
&) {
92
return
new
Description
(*
this
,1);
93
}
95
virtual
ExecStatus
96
commit
(
Space
& home,
const
Choice
&,
unsigned
int
) {
97
done =
true
;
98
f(home);
99
return
home.
failed
() ?
ES_FAILED
:
ES_OK
;
100
}
102
virtual
Actor
*
copy
(
Space
& home,
bool
share) {
103
return
new
(home)
FunctionBranch
(home,share,*
this
);
104
}
106
static
void
post
(
Home
home,
void
(*f)(
Space
&)) {
107
(void)
new
(home)
FunctionBranch
(home,f);
108
}
109
};
110
111
112
void
113
branch
(
Home
home,
void
(*f)(
Space
& home)) {
114
if
(home.
failed
())
115
return
;
116
FunctionBranch::post
(home,f);
117
}
118
119
}
120
121
// STATISTICS: kernel-branch