[gecode-users] a matrix with two lines complementaries by a OR
Claudio Cesar de Sá
claudio at colmeia.udesc.br
Thu May 6 14:36:01 CEST 2010
Hi
I am trying to obtain as result a matrix with two or more lines that are
complementaries in one.
Ex:
0|0 0 1
1|0 1 0
2|0 1 1
In this case, this matrix should accepted, once the lines 0 and 2 make a
bitwise with OR resulting in ONE.
The idea is a comparing in pairs the m matrix (idea from Guido, that I am
trying to reuse now ) .
Each two lines I did a rel(*this, L1 OR L2, aux)
Before to start a new comparision, rel( *this , BOT_AND, aux , 1 ); ... a
constraint that in aux-temporary this filled with one.
Follow part of the code, commented, as well the results:
...............................................................................................
BoolVarArray aux (*this, mat_size , 0, 1 );
for (int i=0; i < mat_size-1; i++)
for (int j=i+1; j < mat_size;j++) {
std::cout << ":\n i:" << i << " j:" << j;
// using an temporary array to store two lines per time
BoolVarArray lines(*this, 2*mat_size, 0, 1);
// from matrix target m -- copy two lines
for (int k=0; k < mat_size; k++) {
lines[2*k] = m(i , k);
lines[2*k+1] = m(j , k);
// std::cout << ":\n | " << lines[2*k] << "| " <<
lines[2*k+1];
} // two lines copied ... in an Array
// from these two lines ...in pairs
// a bitwise OR with rel ... considering this result in aux matrix
for (int k=0, index=0; k < mat_size; k++, index++)
{
rel(*this, lines[2*k], BOT_OR, lines[(2*k)+1], aux[index]);
std::cout << " \n L1:" << lines[2*k] << " L2:" << lines[2*k+1];
std::cout << " aux:" << aux[index] << " ind:" << index;
}
rel( *this , BOT_AND, aux , 1 );
// index = 0;
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
A content of matrix m:
[0..1] [0..1] [0..1]
0 [0..1] 0
[0..1] [0..1] [0..1]
Partial results for a matrix 3x3:
:
i:0 j:1
L1:[0..1] L2:0 aux:[0..1] ind:0
L1:[0..1] L2:[0..1] aux:[0..1] ind:1
L1:[0..1] L2:0 aux:[0..1] ind:2:
i:0 j:2
L1:[0..1] L2:[0..1] aux:1 ind:0
L1:[0..1] L2:[0..1] aux:1 ind:1
L1:[0..1] L2:[0..1] aux:1 ind:2:
i:1 j:2
L1:0 L2:1 aux:1 ind:0
L1:[0..1] L2:[0..1] aux:1 ind:1
L1:0 L2:1 aux:1 ind:2
...............................................................................................
Maybe I need a matrix to store all the combinations ... and post something
like
for (int i=0 ; i < mat_size ; i++)
rel( *this , BOT_AND, m_aux.row(i) , 1 );
but this number increase exponentially ...
claudio
(
))
|""|-.
|__|-'
**********************************************************************
Skype: claudio_cesar_sa
Links:
http://www.colmeia.udesc.br/
http://www2.joinville.udesc.br/~coca/
http://www2.joinville.udesc.br/~esp7maratona/
Blog: http://claudiocesar.wordpress.com/
***********************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20100506/5b379dec/attachment.htm>
More information about the users
mailing list