Libraries for creating and ranking ordered combinations?

I am looking for a library that can rank / deselect ordered combinations, where ranking means from the combination that it gives you, which nth combinations are gray code or lexicographic or some other algorithm, without warming up - the reversal process.

I am looking for a library that runs many algorithms such as Gray code, lexicographic, rev-lexicographic, enup, etc.

If he does only a generation, it might be good if he also has a lot of algorithms.

I found the FXT library, but did not use ordered combinations; it executes compositions, but does not seem to execute the ranking algorithm, since I need it, it is comparable to ranks / undefined unordered combinations.

+3
source share
2 answers

This is not quite the answer to your question, but there is an excellent book on this topic called Combinatorial algorithms: generation, enumeration and search .

It is well balanced between the algorithmic / mathematical side and the actual implementation. Most examples are simple enough that they can be written in a procedural language such as C in a very short amount of time.

+2
source

You need something like this:

// get a combination of a rank
// n number k choices N rank

void unrankComb(int* &K, int n, int k, int N)
{
 int e, N2, t, m, p;

 e = nCr(n,k);
 N2 = e-1-N;
 e = ((n - k)*e)/n;
 t = n - k + 1;
 m = k;
 p = n -1;
 do
 {
  if(e <= N2)
  {
   K[k-m] = n - t - m + 2;
   if(e > 0)
   {
    N2 = N2 -e;
    e = (e * m) / p;
   }
   m = m -1;
   p = p -1;
  }
  else
  {
   e = ((p - m)*e) / p;
   t = t - 1;
   p = p - 1;
  }

 }while(m != 0);
}
+1
source

Source: https://habr.com/ru/post/1745792/


All Articles