main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:28 for Gecode by
doxygen
1.8.4
gecode
int
extensional.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Mikael Lagerkvist <lagerkvist@gecode.org>
5
* Christian Schulte <schulte@gecode.org>
6
*
7
* Copyright:
8
* Mikael Lagerkvist, 2007
9
* Christian Schulte, 2004
10
*
11
* Last modified:
12
* $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
13
* $Revision: 13068 $
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/int/extensional.hh
>
41
42
namespace
Gecode {
43
44
void
45
extensional
(
Home
home,
const
IntVarArgs
&
x
,
DFA
dfa,
46
IntConLevel
) {
47
using namespace
Int;
48
if
(x.
same
(home))
49
throw
ArgumentSame
(
"Int::extensional"
);
50
if
(home.
failed
())
return
;
51
GECODE_ES_FAIL
(
Extensional::post_lgp
(home,x,dfa));
52
}
53
54
void
55
extensional
(
Home
home,
const
BoolVarArgs
&
x
,
DFA
dfa,
56
IntConLevel
) {
57
using namespace
Int;
58
if
(x.
same
(home))
59
throw
ArgumentSame
(
"Int::extensional"
);
60
if
(home.
failed
())
return
;
61
GECODE_ES_FAIL
(
Extensional::post_lgp
(home,x,dfa));
62
}
63
64
void
65
extensional
(
Home
home,
const
IntVarArgs
&
x
,
const
TupleSet
&
t
,
66
ExtensionalPropKind
epk,
IntConLevel
) {
67
using namespace
Int;
68
if
(!t.
finalized
())
69
throw
NotYetFinalized
(
"Int::extensional"
);
70
if
(t.
tuples
()==0) {
71
if
(x.
size
()!=0) {
72
home.
fail
();
73
}
74
return
;
75
}
76
77
if
(t.
arity
() != x.
size
())
78
throw
ArgumentSizeMismatch
(
"Int::extensional"
);
79
if
(home.
failed
())
return
;
80
81
// Construct view array
82
ViewArray<IntView>
xv(home,x);
83
switch
(epk) {
84
case
EPK_SPEED
:
85
GECODE_ES_FAIL
((
Extensional::Incremental<IntView>
86
::
post
(home,xv,t)));
87
break
;
88
default
:
89
if
(x.
same
(home)) {
90
GECODE_ES_FAIL
((
Extensional::Basic<IntView,true>
91
::
post
(home,xv,t)));
92
}
else
{
93
GECODE_ES_FAIL
((
Extensional::Basic<IntView,false>
94
::
post
(home,xv,t)));
95
}
96
break
;
97
}
98
}
99
100
void
101
extensional
(
Home
home,
const
BoolVarArgs
&
x
,
const
TupleSet
&
t
,
102
ExtensionalPropKind
epk,
IntConLevel
) {
103
using namespace
Int;
104
if
(!t.
finalized
())
105
throw
NotYetFinalized
(
"Int::extensional"
);
106
107
if
(t.
tuples
()==0) {
108
if
(x.
size
()!=0) {
109
home.
fail
();
110
}
111
return
;
112
}
113
114
if
(t.
arity
() != x.
size
())
115
throw
ArgumentSizeMismatch
(
"Int::extensional"
);
116
if
(home.
failed
())
return
;
117
118
// Construct view array
119
ViewArray<BoolView>
xv(home,x);
120
switch
(epk) {
121
case
EPK_SPEED
:
122
GECODE_ES_FAIL
((
Extensional::Incremental<BoolView>
123
::
post
(home,xv,t)));
124
break
;
125
default
:
126
if
(x.
same
(home)) {
127
GECODE_ES_FAIL
((
Extensional::Basic<BoolView,true>
128
::
post
(home,xv,t)));
129
}
else
{
130
GECODE_ES_FAIL
((
Extensional::Basic<BoolView,false>
131
::
post
(home,xv,t)));
132
}
133
break
;
134
}
135
}
136
137
}
138
139
// STATISTICS: int-post