permutations
This commit is contained in:
parent
dff9e91123
commit
859dd3ef82
|
@ -5,21 +5,43 @@ using namespace ccr;
|
|||
|
||||
void permutation::compute_inversion (permutation&r)
|
||||
{
|
||||
|
||||
r.resize (size(), 0);
|
||||
for (uint i = 0; i < size(); ++i)
|
||||
r[item (i) ] = i;
|
||||
}
|
||||
|
||||
void permutation::generate_random (uint size, prng&rng)
|
||||
{
|
||||
resize (size, 0);
|
||||
uint i;
|
||||
for (i = 0; i < size; ++i) item (i) = i;
|
||||
|
||||
//knuth shuffle
|
||||
for (i = size - 1; i > 0; --i) {
|
||||
uint j = rng.random (i + 1);
|
||||
if (i != j) {
|
||||
uint t = item (i);
|
||||
item (i) = item (j);
|
||||
item (j) = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void permutation::permute_cols (const matrix&a, matrix&r)
|
||||
void permutation::permute (const bvector&a, bvector&r)
|
||||
{
|
||||
r.resize (a.size() );
|
||||
for (uint i = 0; i < size(); ++i) r[item (i) ] = a[i];
|
||||
}
|
||||
|
||||
void permutation::permute (const matrix&a, matrix&r)
|
||||
{
|
||||
r.resize (a.size() );
|
||||
for (uint i = 0; i < size(); ++i) r[item (i) ] = a[i];
|
||||
}
|
||||
|
||||
void permutation::permute_rows (const matrix&a, matrix&r)
|
||||
{
|
||||
|
||||
r.resize (a.size() );
|
||||
for (uint i = 0; i < a.size(); ++i) permute (a[i], r[i]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue