main page
modules
namespaces
classes
files
Gecode home
Generated on Fri Aug 24 2012 04:52:15 for Gecode by
doxygen
1.8.1.1
gecode
int
cumulative
man-prop.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
* Guido Tack <tack@gecode.org>
6
*
7
* Copyright:
8
* Christian Schulte, 2009
9
* Guido Tack, 2010
10
*
11
* Last modified:
12
* $Date: 2011-07-14 06:44:50 +1000 (Thu, 14 Jul 2011) $ by $Author: tack $
13
* $Revision: 12202 $
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
namespace
Gecode {
namespace
Int {
namespace
Cumulative {
41
42
template
<
class
ManTask,
class
Cap>
43
forceinline
44
ManProp<ManTask,Cap>::ManProp
(
Home
home, Cap c0,
TaskArray<ManTask>
& t)
45
:
TaskProp
<ManTask,Int::
PC_INT_DOM
>(home,t),
c
(c0) {
46
c
.subscribe(home,*
this
,
Int::PC_INT_BND
);
47
}
48
49
template
<
class
ManTask,
class
Cap>
50
forceinline
51
ManProp<ManTask,Cap>::ManProp
(
Space
& home,
bool
shared
,
52
ManProp<ManTask,Cap>
& p)
53
:
TaskProp
<ManTask,Int::
PC_INT_DOM
>(home,shared,p) {
54
c
.update(home,shared,p.
c
);
55
}
56
57
template
<
class
ManTask,
class
Cap>
58
forceinline
ExecStatus
59
ManProp<ManTask,Cap>::post
(
Home
home, Cap
c
,
TaskArray<ManTask>
& t) {
60
// Capacity must be nonnegative
61
GECODE_ME_CHECK
(c.gq(home, 0));
62
// Check that tasks do not overload resource
63
for
(
int
i
=t.
size
();
i
--; )
64
if
(t[
i
].
c
() > c.
max
())
65
return
ES_FAILED
;
66
if
(t.
size
() == 1)
67
GECODE_ME_CHECK
(c.gq(home, t[0].c()));
68
if
(t.
size
() > 1) {
69
if
(c.assigned() && c.val()==1) {
70
TaskArray<typename TaskTraits<ManTask>::UnaryTask
> mt(home,t.
size
());
71
for
(
int
i
=t.
size
();
i
--; )
72
mt[
i
]=t[
i
];
73
return
Unary::ManProp<typename TaskTraits<ManTask>::UnaryTask
>
74
::post
(home,mt);
75
}
else
{
76
(void)
new
(home)
ManProp<ManTask,Cap>
(home,
c
,t);
77
}
78
}
79
return
ES_OK
;
80
}
81
82
template
<
class
ManTask,
class
Cap>
83
Actor
*
84
ManProp<ManTask,Cap>::copy
(
Space
& home,
bool
share) {
85
return
new
(home)
ManProp<ManTask,Cap>
(home,share,*
this
);
86
}
87
88
template
<
class
ManTask,
class
Cap>
89
forceinline
size_t
90
ManProp<ManTask,Cap>::dispose
(
Space
& home) {
91
(void)
TaskProp<ManTask,Int::PC_INT_DOM>::dispose
(home);
92
c
.cancel(home,*
this
,
PC_INT_BND
);
93
return
sizeof
(*this);
94
}
95
96
template
<
class
ManTask,
class
Cap>
97
ExecStatus
98
ManProp<ManTask,Cap>::propagate
(
Space
& home,
const
ModEventDelta
& med) {
99
// Only bounds changes?
100
if
(
Int::IntView::me
(med) !=
Int::ME_INT_DOM
)
101
GECODE_ES_CHECK
(
overload
(home,
c
.
max
(),t));
102
GECODE_ES_CHECK
(
edgefinding
(home,
c
.
max
(),t));
103
bool
subsumed
;
104
ExecStatus
es =
basic
(home,subsumed,
c
,t);
105
GECODE_ES_CHECK
(es);
106
if
(subsumed)
107
return
home.
ES_SUBSUMED
(*
this
);
108
if
(Cap::varderived() &&
c
.assigned() &&
c
.val()==1) {
109
// Check that tasks do not overload resource
110
for
(
int
i
=t.
size
();
i
--; )
111
if
(t[
i
].
c
() > 1)
112
return
ES_FAILED
;
113
// Rewrite to unary resource constraint
114
TaskArray<typename TaskTraits<ManTask>::UnaryTask
> ut(home,t.size());
115
for
(
int
i
=t.
size
();
i
--;)
116
ut[
i
]=t[
i
];
117
GECODE_REWRITE
(*
this
,
118
(
Unary::ManProp
<
typename
TaskTraits<ManTask>::UnaryTask
>
119
::
post
(home(*
this
),ut)));
120
}
else
{
121
return
es;
122
}
123
}
124
125
}}}
126
127
// STATISTICS: int-prop