main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
set
ldsb
sym-imp.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christopher Mears <chris.mears@monash.edu>
5
*
6
* Copyright:
7
* Christopher Mears, 2012
8
*
9
* Last modified:
10
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11
* $Revision: 14967 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include <
gecode/set/ldsb.hh
>
39
40
namespace
Gecode
{
namespace
Set {
namespace
LDSB {
41
// XXX: implementation of equalValues could be improved?
42
44
bool
45
equalLUB
(
const
Set::SetView
&
x
,
const
Set::SetView
&
y
) {
46
unsigned
int
n
=
x
.
lubSize
();
47
if
(
n
!=
y
.
lubSize
())
return
false
;
48
for
(
unsigned
int
i
= 0 ;
i
<
n
;
i
++)
49
if
(
x
.lubMinN(
i
) !=
y
.lubMinN(
i
))
50
return
false
;
51
return
true
;
52
}
53
}}}
54
55
// Note carefully that this is in the Gecode::Int::LDSB namespace, not
56
// Gecode::Set::LDSB.
57
namespace
Gecode
{
namespace
Int {
namespace
LDSB {
58
template
<>
59
ArgArray<Literal>
60
VariableSymmetryImp<Set::SetView>
61
::symmetric
(
Literal
l
,
const
ViewArray<Set::SetView>
&
x
)
const
{
62
(void)
x
;
63
if
(indices.valid(
l
._variable) && indices.get(
l
._variable)) {
64
int
n
= 0;
65
for
(
Iter::Values::BitSetOffset
<
Support::BitSetOffset<Space>
>
i
(indices) ;
i
() ; ++
i
)
66
n
++;
67
ArgArray<Literal>
lits(
n
);
68
int
j = 0;
69
for
(
Iter::Values::BitSetOffset
<
Support::BitSetOffset<Space>
>
i
(indices) ;
i
() ; ++
i
) {
70
lits[j++] =
Literal
(
i
.val(),
l
._value);
71
}
72
return
lits;
73
}
else
{
74
return
ArgArray<Literal>
(0);
75
}
76
}
77
78
template
<>
79
ArgArray<Literal>
80
ValueSymmetryImp<Set::SetView>
81
::symmetric
(
Literal
l
,
const
ViewArray<Set::SetView>
&
x
)
const
{
82
(void)
x
;
83
if
(
values
.valid(
l
._value) &&
values
.get(
l
._value)) {
84
int
n
= 0;
85
for
(
Iter::Values::BitSetOffset
<
Support::BitSetOffset<Space>
>
i
(
values
) ;
i
() ; ++
i
)
86
n
++;
87
ArgArray<Literal>
lits(
n
);
88
int
j = 0;
89
for
(
Iter::Values::BitSetOffset
<
Support::BitSetOffset<Space>
>
i
(
values
) ;
i
() ; ++
i
) {
90
lits[j++] =
Literal
(
l
._variable,
i
.val());
91
}
92
return
lits;
93
}
else
{
94
return
ArgArray<Literal>
(0);
95
}
96
}
97
98
template
<>
99
ArgArray<Literal>
100
VariableSequenceSymmetryImp<Set::SetView>
101
::symmetric
(
Literal
l
,
const
ViewArray<Set::SetView>
&
x
)
const
{
102
Support::DynamicStack<Literal, Heap>
s(
heap
);
103
if
(
l
._variable < (
int
)lookup_size) {
104
int
posIt = lookup[
l
._variable];
105
if
(posIt == -1) {
106
return
dynamicStackToArgArray
(s);
107
}
108
unsigned
int
seqNum = posIt / seq_size;
109
unsigned
int
seqPos = posIt % seq_size;
110
for
(
unsigned
int
seq = 0 ; seq < n_seqs ; seq++) {
111
if
(seq == seqNum) {
112
continue
;
113
}
114
if
(
x
[getVal(seq, seqPos)].
assigned
()) {
115
continue
;
116
}
117
bool
active =
true
;
118
const
unsigned
int
*firstSeq = &indices[seqNum*seq_size];
119
const
unsigned
int
*secondSeq = &indices[seq*seq_size];
120
for
(
unsigned
int
i
= 0 ;
i
< seq_size ;
i
++) {
121
const
Set::SetView
& xv =
x
[firstSeq[
i
]];
122
const
Set::SetView
& yv =
x
[secondSeq[
i
]];
123
if
((!xv.
assigned
() && !yv.
assigned
())
124
|| (xv.
assigned
() && yv.
assigned
() &&
Set::LDSB::equalLUB
(xv, yv))) {
125
continue
;
126
}
else
{
127
active =
false
;
128
break
;
129
}
130
}
131
132
if
(active) {
133
s.
push
(
Literal
(secondSeq[seqPos],
l
._value));
134
}
135
}
136
}
137
return
dynamicStackToArgArray
(s);
138
}
139
140
template
<>
141
ArgArray<Literal>
142
ValueSequenceSymmetryImp<Set::SetView>
143
::symmetric
(
Literal
l
,
const
ViewArray<Set::SetView>
&
x
)
const
{
144
(void)
x
;
145
Support::DynamicStack<Literal, Heap>
s(
heap
);
146
std::pair<int,int> location =
findVar
(
values
, n_values, seq_size,
l
._value);
147
if
(location.first == -1)
return
dynamicStackToArgArray
(s);
148
unsigned
int
seqNum = location.first;
149
unsigned
int
seqPos = location.second;
150
for
(
unsigned
int
seq = 0 ; seq < n_seqs ; seq++) {
151
if
(seq == seqNum)
continue
;
152
if
(dead_sequences.get(seq))
continue
;
153
s.
push
(
Literal
(
l
._variable, getVal(seq,seqPos)));
154
}
155
return
dynamicStackToArgArray
(s);
156
}
157
}}}
158
159
// STATISTICS: set-branch
Gecode::values
void values(Home home, const IntVarArgs &x, IntSet y, IntPropLevel ipl=IPL_DEF)
Post constraint .
Definition:
minimodel.hh:1868
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::Set::LDSB::equalLUB
bool equalLUB(const Set::SetView &x, const Set::SetView &y)
Do two set variables have equal least-upper-bounds?
Definition:
sym-imp.cpp:45
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:784
Gecode::VarImpView::assigned
bool assigned(void) const
Test whether view is assigned.
Gecode::Int::Precede::assigned
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition:
single.hpp:47
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Int::LDSB::ValueSymmetryImp::symmetric
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
Gecode::Int::LDSB::VariableSequenceSymmetryImp::symmetric
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
Definition:
sym-imp.hpp:235
Gecode
Gecode toplevel namespace
Gecode::Support::DynamicStack::push
void push(const T &x)
Push element x on top of stack.
Definition:
dynamic-stack.hpp:144
Gecode::Int::LDSB::ValueSequenceSymmetryImp::symmetric
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
Gecode::SetVar::lubSize
unsigned int lubSize(void) const
Return number of elements in the least upper bound.
Definition:
set.hpp:70
Gecode::ArgArray
Argument array for non-primitive types.
Definition:
array.hpp:727
ldsb.hh
Gecode::Iter::Values::BitSetOffset
Value iterator for values in an offset bitset.
Definition:
values-bitsetoffset.hpp:49
Gecode::Int::LDSB::Literal
A Literal is a pair of variable index and value.
Definition:
ldsb.hh:50
Gecode::heap
Heap heap
The single global heap.
Definition:
heap.cpp:48
l
NNF * l
Left subtree.
Definition:
bool-expr.cpp:244
Gecode::Set::SetView
Set view for set variables
Definition:
view.hpp:60
Gecode::Int::LDSB::VariableSymmetryImp::symmetric
virtual ArgArray< Literal > symmetric(Literal, const ViewArray< View > &) const
Compute symmetric literals.
Gecode::Support::DynamicStack
Stack with arbitrary number of elements.
Definition:
dynamic-stack.hpp:46
Gecode::Int::LDSB::findVar
std::pair< int, int > findVar(int *indices, unsigned int n_values, unsigned int seq_size, int index)
Find the location of an integer in a collection of sequences.
Definition:
ldsb.cpp:46
Gecode::ViewArray
View arrays.
Definition:
array.hpp:234
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::Support::BitSetOffset
Bitsets with index offset.
Definition:
bitset-offset.hpp:55
Gecode::Int::LDSB::dynamicStackToArgArray
ArgArray< T > dynamicStackToArgArray(const Support::DynamicStack< T, A > &s)
Convert a DynamicStack<T,A> into an ArgArray<T>
Definition:
sym-imp.hpp:43